From 6744527ba7a66fb8f409c8aea6c9c6ac3b8b84c6 Mon Sep 17 00:00:00 2001 From: markj Date: Mon, 7 Dec 2015 21:44:05 +0000 Subject: Modify DTRACEHIOC_ADDDOF to copy the DOF section from the target process. r281257 added support for lazyload mode by allowing dtrace(1) to register a DOF section on behalf of a traced process. This was implemented by having libdtrace copy the DOF section into a heap-allocated buffer and passing its address to the ioctl handler. However, DTrace uses the DOF section address as a lookup key in certain cases, so the ioctl handler should be given the target process' DOF section address instead. This change modifies the ADDDOF handler to copy the DOF section in from the target process, rather than from dtrace(1). --- .../opensolaris/lib/libdtrace/common/dt_pid.c | 50 ++-------------------- 1 file changed, 4 insertions(+), 46 deletions(-) (limited to 'cddl') diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pid.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pid.c index c61a710..5444477 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pid.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_pid.c @@ -571,12 +571,6 @@ dt_pid_usdt_mapping(void *data, const prmap_t *pmp, const char *oname) prsyminfo_t sip; dof_helper_t dh; GElf_Half e_type; -#ifdef __FreeBSD__ - dof_hdr_t hdr; - size_t sz; - uint64_t dofmax; - void *dof; -#endif const char *mname; const char *syms[] = { "___SUNW_dof", "__SUNW_dof" }; int i, fd = -1; @@ -606,61 +600,25 @@ dt_pid_usdt_mapping(void *data, const prmap_t *pmp, const char *oname) continue; } -#ifdef __FreeBSD__ + dh.dofhp_dof = sym.st_value; dh.dofhp_addr = (e_type == ET_EXEC) ? 0 : pmp->pr_vaddr; - if (Pread(P, &hdr, sizeof (hdr), sym.st_value) != - sizeof (hdr)) { - dt_dprintf("read of DOF header failed\n"); - continue; - } - - sz = sizeof(dofmax); - if (sysctlbyname("kern.dtrace.dof_maxsize", &dofmax, &sz, - NULL, 0) != 0) { - dt_dprintf("failed to read dof_maxsize: %s\n", - strerror(errno)); - continue; - } - if (dofmax < hdr.dofh_loadsz) { - dt_dprintf("DOF load size exceeds maximum\n"); - continue; - } - - if ((dof = malloc(hdr.dofh_loadsz)) == NULL) - return (-1); - - if (Pread(P, dof, hdr.dofh_loadsz, sym.st_value) != - hdr.dofh_loadsz) { - free(dof); - dt_dprintf("read of DOF section failed\n"); - continue; - } - - dh.dofhp_dof = (uintptr_t)dof; - dh.dofhp_pid = proc_getpid(P); dt_pid_objname(dh.dofhp_mod, sizeof (dh.dofhp_mod), sip.prs_lmid, mname); +#ifdef __FreeBSD__ + dh.dofhp_pid = proc_getpid(P); + if (fd == -1 && (fd = open("/dev/dtrace/helper", O_RDWR, 0)) < 0) { dt_dprintf("open of helper device failed: %s\n", strerror(errno)); - free(dof); return (-1); /* errno is set for us */ } if (ioctl(fd, DTRACEHIOC_ADDDOF, &dh, sizeof (dh)) < 0) dt_dprintf("DOF was rejected for %s\n", dh.dofhp_mod); - - free(dof); #else - dh.dofhp_dof = sym.st_value; - dh.dofhp_addr = (e_type == ET_EXEC) ? 0 : pmp->pr_vaddr; - - dt_pid_objname(dh.dofhp_mod, sizeof (dh.dofhp_mod), - sip.prs_lmid, mname); - if (fd == -1 && (fd = pr_open(P, "/dev/dtrace/helper", O_RDWR, 0)) < 0) { dt_dprintf("pr_open of helper device failed: %s\n", -- cgit v1.1