libproc: Make proc_getpid() an accessor for struct proc_handle.
This allows librtld_db to fetch the PID from a handle without calling into libproc. Together with r303531, this means that librtld_db no longer references symbols from libproc.
This commit is contained in:
parent
fcf9fc109e
commit
b1bb30e5c5
@ -39,7 +39,7 @@
|
||||
struct procstat;
|
||||
|
||||
struct proc_handle {
|
||||
pid_t pid; /* Process ID. */
|
||||
struct proc_handle_public public; /* Public fields. */
|
||||
int flags; /* Process flags. */
|
||||
int status; /* Process status (PS_*). */
|
||||
int wstat; /* Process wait status. */
|
||||
|
@ -116,6 +116,12 @@ typedef struct lwpstatus {
|
||||
#define PR_MODEL_ILP32 1
|
||||
#define PR_MODEL_LP64 2
|
||||
|
||||
struct proc_handle_public {
|
||||
pid_t pid;
|
||||
};
|
||||
|
||||
#define proc_getpid(phdl) (((struct proc_handle_public *)(phdl))->pid)
|
||||
|
||||
/* Function prototype definitions. */
|
||||
__BEGIN_DECLS
|
||||
|
||||
@ -140,7 +146,6 @@ struct ctf_file *proc_name2ctf(struct proc_handle *, const char *);
|
||||
int proc_setflags(struct proc_handle *, int);
|
||||
int proc_state(struct proc_handle *);
|
||||
int proc_getmodel(struct proc_handle *);
|
||||
pid_t proc_getpid(struct proc_handle *);
|
||||
int proc_wstatus(struct proc_handle *);
|
||||
int proc_getwstat(struct proc_handle *);
|
||||
char * proc_signame(int, char *, size_t);
|
||||
|
@ -79,7 +79,7 @@ proc_init(pid_t pid, int flags, int status, struct proc_handle **pphdl)
|
||||
goto out;
|
||||
|
||||
memset(phdl, 0, sizeof(*phdl));
|
||||
phdl->pid = pid;
|
||||
phdl->public.pid = pid;
|
||||
phdl->flags = flags;
|
||||
phdl->status = status;
|
||||
phdl->procstat = procstat_open_sysctl();
|
||||
@ -140,7 +140,7 @@ proc_attach(pid_t pid, int flags, struct proc_handle **pphdl)
|
||||
if (error != 0)
|
||||
goto out;
|
||||
|
||||
if (ptrace(PT_ATTACH, phdl->pid, 0, 0) != 0) {
|
||||
if (ptrace(PT_ATTACH, proc_getpid(phdl), 0, 0) != 0) {
|
||||
error = errno;
|
||||
DPRINTF("ERROR: cannot ptrace child process %d", pid);
|
||||
goto out;
|
||||
|
@ -208,7 +208,7 @@ proc_addr2map(struct proc_handle *p, uintptr_t addr)
|
||||
* it ourselves.
|
||||
*/
|
||||
if (p->nobjs == 0) {
|
||||
if ((kves = kinfo_getvmmap(p->pid, &cnt)) == NULL)
|
||||
if ((kves = kinfo_getvmmap(proc_getpid(p), &cnt)) == NULL)
|
||||
return (NULL);
|
||||
for (i = 0; i < (size_t)cnt; i++) {
|
||||
kve = kves + i;
|
||||
|
@ -70,7 +70,8 @@ proc_continue(struct proc_handle *phdl)
|
||||
pending = WSTOPSIG(phdl->wstat);
|
||||
else
|
||||
pending = 0;
|
||||
if (ptrace(PT_CONTINUE, phdl->pid, (caddr_t)(uintptr_t)1, pending) != 0)
|
||||
if (ptrace(PT_CONTINUE, proc_getpid(phdl), (caddr_t)(uintptr_t)1,
|
||||
pending) != 0)
|
||||
return (-1);
|
||||
|
||||
phdl->status = PS_RUN;
|
||||
@ -82,20 +83,22 @@ int
|
||||
proc_detach(struct proc_handle *phdl, int reason)
|
||||
{
|
||||
int status;
|
||||
pid_t pid;
|
||||
|
||||
if (phdl == NULL)
|
||||
return (EINVAL);
|
||||
if (reason == PRELEASE_KILL) {
|
||||
kill(phdl->pid, SIGKILL);
|
||||
kill(proc_getpid(phdl), SIGKILL);
|
||||
return (0);
|
||||
}
|
||||
if (ptrace(PT_DETACH, phdl->pid, 0, 0) != 0 && errno == ESRCH)
|
||||
pid = proc_getpid(phdl);
|
||||
if (ptrace(PT_DETACH, pid, 0, 0) != 0 && errno == ESRCH)
|
||||
return (0);
|
||||
if (errno == EBUSY) {
|
||||
kill(phdl->pid, SIGSTOP);
|
||||
waitpid(phdl->pid, &status, WUNTRACED);
|
||||
ptrace(PT_DETACH, phdl->pid, 0, 0);
|
||||
kill(phdl->pid, SIGCONT);
|
||||
kill(pid, SIGSTOP);
|
||||
waitpid(pid, &status, WUNTRACED);
|
||||
ptrace(PT_DETACH, pid, 0, 0);
|
||||
kill(pid, SIGCONT);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -134,16 +137,6 @@ proc_state(struct proc_handle *phdl)
|
||||
return (phdl->status);
|
||||
}
|
||||
|
||||
pid_t
|
||||
proc_getpid(struct proc_handle *phdl)
|
||||
{
|
||||
|
||||
if (phdl == NULL)
|
||||
return (-1);
|
||||
|
||||
return (phdl->pid);
|
||||
}
|
||||
|
||||
int
|
||||
proc_getmodel(struct proc_handle *phdl)
|
||||
{
|
||||
@ -161,7 +154,7 @@ proc_wstatus(struct proc_handle *phdl)
|
||||
|
||||
if (phdl == NULL)
|
||||
return (-1);
|
||||
if (waitpid(phdl->pid, &status, WUNTRACED) < 0) {
|
||||
if (waitpid(proc_getpid(phdl), &status, WUNTRACED) < 0) {
|
||||
if (errno != EINTR)
|
||||
DPRINTF("waitpid");
|
||||
return (-1);
|
||||
@ -206,7 +199,7 @@ proc_read(struct proc_handle *phdl, void *buf, size_t size, size_t addr)
|
||||
piod.piod_addr = (void *)buf;
|
||||
piod.piod_offs = (void *)addr;
|
||||
|
||||
if (ptrace(PT_IO, phdl->pid, (caddr_t)&piod, 0) < 0)
|
||||
if (ptrace(PT_IO, proc_getpid(phdl), (caddr_t)&piod, 0) < 0)
|
||||
return (-1);
|
||||
return (piod.piod_len);
|
||||
}
|
||||
@ -220,7 +213,7 @@ proc_getlwpstatus(struct proc_handle *phdl)
|
||||
|
||||
if (phdl == NULL)
|
||||
return (NULL);
|
||||
if (ptrace(PT_LWPINFO, phdl->pid, (caddr_t)&lwpinfo,
|
||||
if (ptrace(PT_LWPINFO, proc_getpid(phdl), (caddr_t)&lwpinfo,
|
||||
sizeof(lwpinfo)) < 0)
|
||||
return (NULL);
|
||||
siginfo = &lwpinfo.pl_siginfo;
|
||||
|
Loading…
Reference in New Issue
Block a user