Module Name: src Committed By: christos Date: Thu Apr 28 00:02:40 UTC 2016
Modified Files: src/external/cddl/osnet/dist/lib/libdtrace/common: dt_impl.h dt_module.c dt_open.c Log Message: Introduce dt_bootfile() and use it to avoid hard-coded kernel values. Fixes dtrace hang for kernels not named netbsd. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 \ src/external/cddl/osnet/dist/lib/libdtrace/common/dt_impl.h cvs rdiff -u -r1.12 -r1.13 \ src/external/cddl/osnet/dist/lib/libdtrace/common/dt_module.c cvs rdiff -u -r1.10 -r1.11 \ src/external/cddl/osnet/dist/lib/libdtrace/common/dt_open.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/cddl/osnet/dist/lib/libdtrace/common/dt_impl.h diff -u src/external/cddl/osnet/dist/lib/libdtrace/common/dt_impl.h:1.6 src/external/cddl/osnet/dist/lib/libdtrace/common/dt_impl.h:1.7 --- src/external/cddl/osnet/dist/lib/libdtrace/common/dt_impl.h:1.6 Thu Sep 24 10:25:29 2015 +++ src/external/cddl/osnet/dist/lib/libdtrace/common/dt_impl.h Wed Apr 27 20:02:40 2016 @@ -744,6 +744,10 @@ extern int _dtrace_argmax; /* default m extern const char *_dtrace_libdir; /* default library directory */ extern const char *_dtrace_moddir; /* default kernel module directory */ +#ifndef illumos +extern const char *dt_bootfile(char *, size_t); +#endif + #if defined(__FreeBSD__) || defined(__NetBSD__) extern int gmatch(const char *, const char *); extern int yylex(void); Index: src/external/cddl/osnet/dist/lib/libdtrace/common/dt_module.c diff -u src/external/cddl/osnet/dist/lib/libdtrace/common/dt_module.c:1.12 src/external/cddl/osnet/dist/lib/libdtrace/common/dt_module.c:1.13 --- src/external/cddl/osnet/dist/lib/libdtrace/common/dt_module.c:1.12 Mon Oct 5 21:18:47 2015 +++ src/external/cddl/osnet/dist/lib/libdtrace/common/dt_module.c Wed Apr 27 20:02:40 2016 @@ -1180,7 +1180,7 @@ dt_module_update(dtrace_hdl_t *dtp, stru if (strcmp("netbsd", name) == 0) { /* want the kernel */ - strncpy(fname, "/netbsd", sizeof(fname)); + dt_bootfile(fname, sizeof(fname)); } else { /* build stand module path from system */ Index: src/external/cddl/osnet/dist/lib/libdtrace/common/dt_open.c diff -u src/external/cddl/osnet/dist/lib/libdtrace/common/dt_open.c:1.10 src/external/cddl/osnet/dist/lib/libdtrace/common/dt_open.c:1.11 --- src/external/cddl/osnet/dist/lib/libdtrace/common/dt_open.c:1.10 Wed Feb 24 16:11:34 2016 +++ src/external/cddl/osnet/dist/lib/libdtrace/common/dt_open.c Wed Apr 27 20:02:40 2016 @@ -1025,6 +1025,37 @@ dt_get_sysinfo(int cmd, char *buf, size_ } #endif +#ifndef illumos +# ifdef __FreeBSD__ +# define DEFKERNEL "kernel" +# define BOOTFILE "kern.bootfile" +# endif +# ifdef __NetBSD__ +# define DEFKERNEL "netbsd" +# define BOOTFILE "machdep.booted_kernel" +# endif + +const char * +dt_bootfile(char *bootfile, size_t len) +{ + char *p; + size_t olen = len; + + /* This call shouldn't fail, but use a default just in case.*/ + if (sysctlbyname(BOOTFILE, bootfile, &len, NULL, 0) != 0) + strlcpy(bootfile, DEFKERNEL, olen); + + if ((p = strrchr(bootfile, '/')) != NULL) + p++; + else + p = bootfile; + return p; +} + +# undef DEFKERNEL +# undef BOOTFILE +#endif + static dtrace_hdl_t * dt_vopen(int version, int flags, int *errp, const dtrace_vector_t *vector, void *arg) @@ -1309,37 +1340,25 @@ alloc: /* * On FreeBSD the kernel module name can't be hard-coded. The - * 'kern.bootfile' sysctl value tells us exactly which file is being - * used as the kernel. + * 'kern.bootfile' sysctl value tells us exactly which file is + * being used as the kernel. */ #ifndef illumos +# ifdef __FreeBSD__ +# define THREAD "struct thread" +# define MUTEX "struct mtx" +# define RWLOCK "struct rwlock" +# endif +# ifdef __NetBSD__ +# define THREAD "struct lwp" +# define MUTEX "struct kmutex" +# define RWLOCK "struct krwlock" +# endif { - char bootfile[MAXPATHLEN]; - char *p; - size_t len = sizeof(bootfile); + const char *p; + char kernname[512]; -#ifdef __FreeBSD__ -#define DEFKERNEL "kernel" -#define BOOTFILE "kern.bootfile" -#define THREAD "struct thread" -#define MUTEX "struct mtx" -#define RWLOCK "struct rwlock" -#endif -#ifdef __NetBSD__ -#define DEFKERNEL "netbsd" -#define BOOTFILE "machdep.booted_kernel" -#define THREAD "struct lwp" -#define MUTEX "struct kmutex" -#define RWLOCK "struct krwlock" -#endif - /* This call shouldn't fail, but use a default just in case. */ - if (sysctlbyname(BOOTFILE, bootfile, &len, NULL, 0) != 0) - strlcpy(bootfile, DEFKERNEL, sizeof(bootfile)); - - if ((p = strrchr(bootfile, '/')) != NULL) - p++; - else - p = bootfile; + p = dt_bootfile(kernname, sizeof(kernname)); /* * Format the global variables based on the kernel module name. @@ -1349,8 +1368,11 @@ alloc: snprintf(threadmtx_str, sizeof(threadmtx_str), "%s *(%s`%s *)", THREAD, p, MUTEX); snprintf(rwlock_str, sizeof(rwlock_str), "int(%s`%s *)", p, RWLOCK); - snprintf(sxlock_str, sizeof(sxlock_str), "int(%s`struct sxlock *)",p); + snprintf(sxlock_str, sizeof(sxlock_str), "int(%s`struct sxlock *)", p); } +# undef THREAD +# undef MUTEX +# undef RWLOCK #endif dtp->dt_macros = dt_idhash_create("macro", NULL, 0, UINT_MAX);