git: 2179a159ea93 - main - libdtrace: Add kinst support
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 11 Oct 2022 22:35:36 UTC
The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=2179a159ea93e37b7fb2126ae0b1627b875f808b commit 2179a159ea93e37b7fb2126ae0b1627b875f808b Author: Christos Margiolis <christos@FreeBSD.org> AuthorDate: 2022-10-11 15:33:52 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2022-10-11 22:19:08 +0000 libdtrace: Add kinst support kinst does not instantiate its probes automatically, it only does so on demand via an ioctl interface implemented by /dev/kinst. This change modifies libdtrace to perform that work when the script references the kinst provider, similar to the way pid provider probes are implemented. Reviewed by: markj MFC after: 3 months Sponsored by: Google, Inc. (GSoC 2022) Differential Revision: https://reviews.freebsd.org/D36852 --- .../opensolaris/lib/libdtrace/common/dt_impl.h | 1 + .../opensolaris/lib/libdtrace/common/dt_open.c | 3 +++ .../opensolaris/lib/libdtrace/common/dt_provider.c | 29 ++++++++++++++++++++++ cddl/lib/libdtrace/Makefile | 1 + 4 files changed, 34 insertions(+) diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_impl.h b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_impl.h index b3f69bb6329d..1e62bd6b21db 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_impl.h +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_impl.h @@ -323,6 +323,7 @@ struct dtrace_hdl { #endif int dt_fd; /* file descriptor for dtrace pseudo-device */ int dt_ftfd; /* file descriptor for fasttrap pseudo-device */ + int dt_kinstfd; /* file descriptor for kinst pseudo-device */ int dt_fterr; /* saved errno from failed open of dt_ftfd */ int dt_cdefs_fd; /* file descriptor for C CTF debugging cache */ int dt_ddefs_fd; /* file descriptor for D CTF debugging cache */ diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c index 9621a0fcb391..867259b5d77c 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c @@ -1173,6 +1173,7 @@ alloc: dtp->dt_version = version; dtp->dt_fd = dtfd; dtp->dt_ftfd = ftfd; + dtp->dt_kinstfd = -1; dtp->dt_fterr = fterr; dtp->dt_cdefs_fd = -1; dtp->dt_ddefs_fd = -1; @@ -1681,6 +1682,8 @@ dtrace_close(dtrace_hdl_t *dtp) (void) close(dtp->dt_fd); if (dtp->dt_ftfd != -1) (void) close(dtp->dt_ftfd); + if (dtp->dt_kinstfd != -1) + (void) close(dtp->dt_kinstfd); if (dtp->dt_cdefs_fd != -1) (void) close(dtp->dt_cdefs_fd); if (dtp->dt_ddefs_fd != -1) diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_provider.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_provider.c index 7cf352d4d505..2391690afc0b 100644 --- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_provider.c +++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_provider.c @@ -48,6 +48,7 @@ #include <dt_list.h> #include <dt_pid.h> #include <dtrace.h> +#include <kinst.h> static dt_provider_t * dt_provider_insert(dtrace_hdl_t *dtp, dt_provider_t *pvp, uint_t h) @@ -699,6 +700,34 @@ dt_probe_info(dtrace_hdl_t *dtp, prp = idp->di_data; else if (pdp->dtpd_id != DTRACE_IDNONE) prp = dt_probe_discover(pvp, pdp); + + if (strcmp(pvp->pv_desc.dtvd_name, "kinst") == 0) { + dtrace_kinst_probedesc_t pd; + + if (dtp->dt_kinstfd == -1) { + int fd; + + fd = open("/dev/dtrace/kinst", O_WRONLY); + if (fd < 0) { + (void) dt_set_errno(dtp, errno); + return (NULL); + } + dtp->dt_kinstfd = fd; + } + memset(&pd, 0, sizeof(pd)); + strlcpy(pd.kpd_func, pdp->dtpd_func, + sizeof (pd.kpd_func)); + + if (n_is_glob) + pd.kpd_off = -1; + else + pd.kpd_off = strtol(pdp->dtpd_name, NULL, 10); + if (ioctl(dtp->dt_kinstfd, KINSTIOC_MAKEPROBE, &pd) != + 0) { + (void) dt_set_errno(dtp, errno); + return (NULL); + } + } } /* diff --git a/cddl/lib/libdtrace/Makefile b/cddl/lib/libdtrace/Makefile index f95517f10ebb..651609409a3a 100644 --- a/cddl/lib/libdtrace/Makefile +++ b/cddl/lib/libdtrace/Makefile @@ -84,6 +84,7 @@ CFLAGS+= -DHAVE_ISSETUGID CFLAGS+= -I${.OBJDIR} -I${.CURDIR} \ -I${SRCTOP}/sys/cddl/dev/dtrace/${MACHINE_ARCH} \ + -I${SRCTOP}/sys/cddl/dev/kinst \ -I${SRCTOP}/sys/cddl/compat/opensolaris \ -I${SRCTOP}/cddl/compat/opensolaris/include \ -I${OPENSOLARIS_USR_DISTDIR}/head \