From owner-svn-src-all@freebsd.org Tue Dec 6 04:14:21 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B28AFC69328; Tue, 6 Dec 2016 04:14:21 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 751E8176A; Tue, 6 Dec 2016 04:14:21 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uB64EKBT063503; Tue, 6 Dec 2016 04:14:20 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uB64EKRm063498; Tue, 6 Dec 2016 04:14:20 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201612060414.uB64EKRm063498@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Tue, 6 Dec 2016 04:14:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r309592 - head/lib/libproc X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Dec 2016 04:14:21 -0000 Author: markj Date: Tue Dec 6 04:14:20 2016 New Revision: 309592 URL: https://svnweb.freebsd.org/changeset/base/309592 Log: 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. Modified: head/lib/libproc/_libproc.h head/lib/libproc/libproc.h head/lib/libproc/proc_create.c head/lib/libproc/proc_sym.c head/lib/libproc/proc_util.c Modified: head/lib/libproc/_libproc.h ============================================================================== --- head/lib/libproc/_libproc.h Tue Dec 6 04:13:02 2016 (r309591) +++ head/lib/libproc/_libproc.h Tue Dec 6 04:14:20 2016 (r309592) @@ -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. */ Modified: head/lib/libproc/libproc.h ============================================================================== --- head/lib/libproc/libproc.h Tue Dec 6 04:13:02 2016 (r309591) +++ head/lib/libproc/libproc.h Tue Dec 6 04:14:20 2016 (r309592) @@ -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 pr 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); Modified: head/lib/libproc/proc_create.c ============================================================================== --- head/lib/libproc/proc_create.c Tue Dec 6 04:13:02 2016 (r309591) +++ head/lib/libproc/proc_create.c Tue Dec 6 04:14:20 2016 (r309592) @@ -79,7 +79,7 @@ proc_init(pid_t pid, int flags, int stat 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 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; Modified: head/lib/libproc/proc_sym.c ============================================================================== --- head/lib/libproc/proc_sym.c Tue Dec 6 04:13:02 2016 (r309591) +++ head/lib/libproc/proc_sym.c Tue Dec 6 04:14:20 2016 (r309592) @@ -208,7 +208,7 @@ proc_addr2map(struct proc_handle *p, uin * 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; Modified: head/lib/libproc/proc_util.c ============================================================================== --- head/lib/libproc/proc_util.c Tue Dec 6 04:13:02 2016 (r309591) +++ head/lib/libproc/proc_util.c Tue Dec 6 04:14:20 2016 (r309592) @@ -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 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 *ph 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;