191eaf3e1SJohn Birrell /*
291eaf3e1SJohn Birrell * CDDL HEADER START
391eaf3e1SJohn Birrell *
491eaf3e1SJohn Birrell * The contents of this file are subject to the terms of the
591eaf3e1SJohn Birrell * Common Development and Distribution License (the "License").
691eaf3e1SJohn Birrell * You may not use this file except in compliance with the License.
791eaf3e1SJohn Birrell *
891eaf3e1SJohn Birrell * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
991eaf3e1SJohn Birrell * or http://www.opensolaris.org/os/licensing.
1091eaf3e1SJohn Birrell * See the License for the specific language governing permissions
1191eaf3e1SJohn Birrell * and limitations under the License.
1291eaf3e1SJohn Birrell *
1391eaf3e1SJohn Birrell * When distributing Covered Code, include this CDDL HEADER in each
1491eaf3e1SJohn Birrell * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1591eaf3e1SJohn Birrell * If applicable, add the following below this CDDL HEADER, with the
1691eaf3e1SJohn Birrell * fields enclosed by brackets "[]" replaced with your own identifying
1791eaf3e1SJohn Birrell * information: Portions Copyright [yyyy] [name of copyright owner]
1891eaf3e1SJohn Birrell *
1991eaf3e1SJohn Birrell * CDDL HEADER END
2091eaf3e1SJohn Birrell *
2191eaf3e1SJohn Birrell * Portions Copyright 2006-2008 John Birrell jb@freebsd.org
2291eaf3e1SJohn Birrell */
2391eaf3e1SJohn Birrell
2491eaf3e1SJohn Birrell /*
2591eaf3e1SJohn Birrell * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
2691eaf3e1SJohn Birrell * Use is subject to license terms.
2791eaf3e1SJohn Birrell */
2891eaf3e1SJohn Birrell
2991eaf3e1SJohn Birrell #include <sys/param.h>
3091eaf3e1SJohn Birrell #include <sys/systm.h>
3191eaf3e1SJohn Birrell #include <sys/conf.h>
3291eaf3e1SJohn Birrell #include <sys/cpuvar.h>
338ff6d9ddSMark Johnston #include <sys/dtrace.h>
3491eaf3e1SJohn Birrell #include <sys/fcntl.h>
3591eaf3e1SJohn Birrell #include <sys/filio.h>
3691eaf3e1SJohn Birrell #include <sys/kdb.h>
3791eaf3e1SJohn Birrell #include <sys/kernel.h>
3891eaf3e1SJohn Birrell #include <sys/kmem.h>
3991eaf3e1SJohn Birrell #include <sys/kthread.h>
4091eaf3e1SJohn Birrell #include <sys/limits.h>
4191eaf3e1SJohn Birrell #include <sys/linker.h>
4291eaf3e1SJohn Birrell #include <sys/lock.h>
4391eaf3e1SJohn Birrell #include <sys/malloc.h>
4491eaf3e1SJohn Birrell #include <sys/module.h>
4591eaf3e1SJohn Birrell #include <sys/mutex.h>
4691eaf3e1SJohn Birrell #include <sys/poll.h>
4791eaf3e1SJohn Birrell #include <sys/proc.h>
4891eaf3e1SJohn Birrell #include <sys/selinfo.h>
4991eaf3e1SJohn Birrell #include <sys/smp.h>
50*e453e498SBrooks Davis #include <sys/stdarg.h>
51f5a97d1bSCraig Rodrigues #include <sys/sysent.h>
52feea5135SMark Johnston #include <sys/sysproto.h>
5391eaf3e1SJohn Birrell #include <sys/uio.h>
5491eaf3e1SJohn Birrell #include <sys/unistd.h>
5591eaf3e1SJohn Birrell
568ff6d9ddSMark Johnston #include <cddl/dev/dtrace/dtrace_cddl.h>
578ff6d9ddSMark Johnston
58f5a97d1bSCraig Rodrigues #ifdef LINUX_SYSTRACE
59308bce2aSAndriy Gapon #if defined(__amd64__)
602f99bcceSJohn Baldwin #include <amd64/linux/linux.h>
612f99bcceSJohn Baldwin #include <amd64/linux/linux_proto.h>
622f99bcceSJohn Baldwin #include <amd64/linux/linux_syscalls.c>
632f99bcceSJohn Baldwin #include <amd64/linux/linux_systrace_args.c>
64308bce2aSAndriy Gapon #elif defined(__i386__)
65308bce2aSAndriy Gapon #include <i386/linux/linux.h>
66308bce2aSAndriy Gapon #include <i386/linux/linux_proto.h>
67308bce2aSAndriy Gapon #include <i386/linux/linux_syscalls.c>
68308bce2aSAndriy Gapon #include <i386/linux/linux_systrace_args.c>
69308bce2aSAndriy Gapon #else
70308bce2aSAndriy Gapon #error Only i386 and amd64 are supported.
71308bce2aSAndriy Gapon #endif
722f99bcceSJohn Baldwin #define MODNAME "linux"
73f5a97d1bSCraig Rodrigues extern struct sysent linux_sysent[];
74f5a97d1bSCraig Rodrigues #define MAXSYSCALL LINUX_SYS_MAXSYSCALL
75f5a97d1bSCraig Rodrigues #define SYSCALLNAMES linux_syscallnames
76f5a97d1bSCraig Rodrigues #define SYSENT linux_sysent
772f99bcceSJohn Baldwin #elif defined(LINUX32_SYSTRACE)
782f99bcceSJohn Baldwin #if defined(__amd64__)
792f99bcceSJohn Baldwin #include <amd64/linux32/linux.h>
802f99bcceSJohn Baldwin #include <amd64/linux32/linux32_proto.h>
812f99bcceSJohn Baldwin #include <amd64/linux32/linux32_syscalls.c>
822f99bcceSJohn Baldwin #include <amd64/linux32/linux32_systrace_args.c>
832f99bcceSJohn Baldwin #else
842f99bcceSJohn Baldwin #error Only amd64 is supported.
852f99bcceSJohn Baldwin #endif
862f99bcceSJohn Baldwin #define MODNAME "linux32"
872f99bcceSJohn Baldwin extern struct sysent linux32_sysent[];
882f99bcceSJohn Baldwin #define MAXSYSCALL LINUX32_SYS_MAXSYSCALL
892f99bcceSJohn Baldwin #define SYSCALLNAMES linux32_syscallnames
902f99bcceSJohn Baldwin #define SYSENT linux32_sysent
91308bce2aSAndriy Gapon #elif defined(FREEBSD32_SYSTRACE)
92308bce2aSAndriy Gapon /*
93308bce2aSAndriy Gapon * The syscall arguments are processed into a DTrace argument array
94913bfd86SBrooks Davis * using a generated function. See sys/tools/syscalls/README.md.
95308bce2aSAndriy Gapon */
96308bce2aSAndriy Gapon #include <compat/freebsd32/freebsd32_proto.h>
97308bce2aSAndriy Gapon #include <compat/freebsd32/freebsd32_util.h>
98308bce2aSAndriy Gapon #include <compat/freebsd32/freebsd32_syscall.h>
99308bce2aSAndriy Gapon #include <compat/freebsd32/freebsd32_systrace_args.c>
100308bce2aSAndriy Gapon extern const char *freebsd32_syscallnames[];
101308bce2aSAndriy Gapon #define MODNAME "freebsd32"
102308bce2aSAndriy Gapon #define MAXSYSCALL FREEBSD32_SYS_MAXSYSCALL
103308bce2aSAndriy Gapon #define SYSCALLNAMES freebsd32_syscallnames
104308bce2aSAndriy Gapon #define SYSENT freebsd32_sysent
105f5a97d1bSCraig Rodrigues #else
106f5a97d1bSCraig Rodrigues /*
107f5a97d1bSCraig Rodrigues * The syscall arguments are processed into a DTrace argument array
108913bfd86SBrooks Davis * using a generated function. See sys/tools/syscalls/README.md.
109f5a97d1bSCraig Rodrigues */
110f5a97d1bSCraig Rodrigues #include <sys/syscall.h>
111f5a97d1bSCraig Rodrigues #include <kern/systrace_args.c>
112308bce2aSAndriy Gapon #define MODNAME "freebsd"
113f5a97d1bSCraig Rodrigues #define MAXSYSCALL SYS_MAXSYSCALL
114f5a97d1bSCraig Rodrigues #define SYSCALLNAMES syscallnames
115f5a97d1bSCraig Rodrigues #define SYSENT sysent
1162f99bcceSJohn Baldwin #define NATIVE_ABI
117f5a97d1bSCraig Rodrigues #endif
118f5a97d1bSCraig Rodrigues
119308bce2aSAndriy Gapon #define PROVNAME "syscall"
120308bce2aSAndriy Gapon #define DEVNAME "dtrace/systrace/" MODNAME
121308bce2aSAndriy Gapon
12291eaf3e1SJohn Birrell #define SYSTRACE_ARTIFICIAL_FRAMES 1
12391eaf3e1SJohn Birrell
12491eaf3e1SJohn Birrell #define SYSTRACE_SHIFT 16
12591eaf3e1SJohn Birrell #define SYSTRACE_ISENTRY(x) ((int)(x) >> SYSTRACE_SHIFT)
12691eaf3e1SJohn Birrell #define SYSTRACE_SYSNUM(x) ((int)(x) & ((1 << SYSTRACE_SHIFT) - 1))
12791eaf3e1SJohn Birrell #define SYSTRACE_ENTRY(id) ((1 << SYSTRACE_SHIFT) | (id))
12891eaf3e1SJohn Birrell #define SYSTRACE_RETURN(id) (id)
12991eaf3e1SJohn Birrell
130f5a97d1bSCraig Rodrigues #if ((1 << SYSTRACE_SHIFT) <= MAXSYSCALL)
13191eaf3e1SJohn Birrell #error 1 << SYSTRACE_SHIFT must exceed number of system calls
13291eaf3e1SJohn Birrell #endif
13391eaf3e1SJohn Birrell
1349d68f774SMateusz Guzik static int systrace_enabled_count;
1359d68f774SMateusz Guzik
136feea5135SMark Johnston static void systrace_load(void *);
137feea5135SMark Johnston static void systrace_unload(void *);
138feea5135SMark Johnston
139feea5135SMark Johnston static void systrace_getargdesc(void *, dtrace_id_t, void *,
140feea5135SMark Johnston dtrace_argdesc_t *);
1418ff6d9ddSMark Johnston static uint64_t systrace_getargval(void *, dtrace_id_t, void *, int, int);
14291eaf3e1SJohn Birrell static void systrace_provide(void *, dtrace_probedesc_t *);
14391eaf3e1SJohn Birrell static void systrace_destroy(void *, dtrace_id_t, void *);
14491eaf3e1SJohn Birrell static void systrace_enable(void *, dtrace_id_t, void *);
14591eaf3e1SJohn Birrell static void systrace_disable(void *, dtrace_id_t, void *);
14691eaf3e1SJohn Birrell
147f5a97d1bSCraig Rodrigues static union {
148f5a97d1bSCraig Rodrigues const char **p_constnames;
149f5a97d1bSCraig Rodrigues char **pp_syscallnames;
150f5a97d1bSCraig Rodrigues } uglyhack = { SYSCALLNAMES };
151f5a97d1bSCraig Rodrigues
15291eaf3e1SJohn Birrell static dtrace_pattr_t systrace_attr = {
15391eaf3e1SJohn Birrell { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
15491eaf3e1SJohn Birrell { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
15591eaf3e1SJohn Birrell { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
15691eaf3e1SJohn Birrell { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
15791eaf3e1SJohn Birrell { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
15891eaf3e1SJohn Birrell };
15991eaf3e1SJohn Birrell
16091eaf3e1SJohn Birrell static dtrace_pops_t systrace_pops = {
16147f11baaSMark Johnston .dtps_provide = systrace_provide,
16247f11baaSMark Johnston .dtps_provide_module = NULL,
16347f11baaSMark Johnston .dtps_enable = systrace_enable,
16447f11baaSMark Johnston .dtps_disable = systrace_disable,
16547f11baaSMark Johnston .dtps_suspend = NULL,
16647f11baaSMark Johnston .dtps_resume = NULL,
16747f11baaSMark Johnston .dtps_getargdesc = systrace_getargdesc,
16847f11baaSMark Johnston .dtps_getargval = systrace_getargval,
16947f11baaSMark Johnston .dtps_usermode = NULL,
17047f11baaSMark Johnston .dtps_destroy = systrace_destroy
17191eaf3e1SJohn Birrell };
17291eaf3e1SJohn Birrell
17391eaf3e1SJohn Birrell static dtrace_provider_id_t systrace_id;
17491eaf3e1SJohn Birrell
1752f99bcceSJohn Baldwin #ifdef NATIVE_ABI
17691eaf3e1SJohn Birrell /*
177f5a97d1bSCraig Rodrigues * Probe callback function.
178f5a97d1bSCraig Rodrigues *
179f5a97d1bSCraig Rodrigues * Note: This function is called for _all_ syscalls, regardless of which sysent
180f5a97d1bSCraig Rodrigues * array the syscall comes from. It could be a standard syscall or a
181f5a97d1bSCraig Rodrigues * compat syscall from something like Linux.
18291eaf3e1SJohn Birrell */
18391eaf3e1SJohn Birrell static void
systrace_probe(struct syscall_args * sa,enum systrace_probe_t type,int retval)1848ff6d9ddSMark Johnston systrace_probe(struct syscall_args *sa, enum systrace_probe_t type, int retval)
18591eaf3e1SJohn Birrell {
1868ff6d9ddSMark Johnston uint64_t uargs[nitems(sa->args)];
1878ff6d9ddSMark Johnston dtrace_id_t id;
1888ff6d9ddSMark Johnston int n_args, sysnum;
18991eaf3e1SJohn Birrell
1908ff6d9ddSMark Johnston sysnum = sa->code;
191c6f5742fSRui Paulo memset(uargs, 0, sizeof(uargs));
192feea5135SMark Johnston
1938ff6d9ddSMark Johnston if (type == SYSTRACE_ENTRY) {
19436f5d077SMark Johnston if ((id = sa->callp->sy_entry) == DTRACE_IDNONE)
19536f5d077SMark Johnston return;
1968ff6d9ddSMark Johnston
1978ff6d9ddSMark Johnston if (sa->callp->sy_systrace_args_func != NULL)
19891eaf3e1SJohn Birrell /*
19991eaf3e1SJohn Birrell * Convert the syscall parameters using the registered
20091eaf3e1SJohn Birrell * function.
20191eaf3e1SJohn Birrell */
2028ff6d9ddSMark Johnston (*sa->callp->sy_systrace_args_func)(sysnum, sa->args,
2038ff6d9ddSMark Johnston uargs, &n_args);
2048ff6d9ddSMark Johnston else
20591eaf3e1SJohn Birrell /*
20691eaf3e1SJohn Birrell * Use the built-in system call argument conversion
20791eaf3e1SJohn Birrell * function to translate the syscall structure fields
2088ff6d9ddSMark Johnston * into the array of 64-bit values that DTrace expects.
20991eaf3e1SJohn Birrell */
2108ff6d9ddSMark Johnston systrace_args(sysnum, sa->args, uargs, &n_args);
211c6f5742fSRui Paulo /*
2128ff6d9ddSMark Johnston * Save probe arguments now so that we can retrieve them if
2138ff6d9ddSMark Johnston * the getargval method is called from further down the stack.
214c6f5742fSRui Paulo */
2158ff6d9ddSMark Johnston curthread->t_dtrace_systrace_args = uargs;
2168ff6d9ddSMark Johnston } else {
21736f5d077SMark Johnston if ((id = sa->callp->sy_return) == DTRACE_IDNONE)
21836f5d077SMark Johnston return;
2198ff6d9ddSMark Johnston
2208ff6d9ddSMark Johnston curthread->t_dtrace_systrace_args = NULL;
2218ff6d9ddSMark Johnston /* Set arg0 and arg1 as the return value of this syscall. */
2228ff6d9ddSMark Johnston uargs[0] = uargs[1] = retval;
223c6f5742fSRui Paulo }
22491eaf3e1SJohn Birrell
22591eaf3e1SJohn Birrell /* Process the probe using the converted argments. */
2268ff6d9ddSMark Johnston dtrace_probe(id, uargs[0], uargs[1], uargs[2], uargs[3], uargs[4]);
22791eaf3e1SJohn Birrell }
228f5a97d1bSCraig Rodrigues #endif
22991eaf3e1SJohn Birrell
23091eaf3e1SJohn Birrell static void
systrace_getargdesc(void * arg,dtrace_id_t id,void * parg,dtrace_argdesc_t * desc)231feea5135SMark Johnston systrace_getargdesc(void *arg, dtrace_id_t id, void *parg,
232feea5135SMark Johnston dtrace_argdesc_t *desc)
23391eaf3e1SJohn Birrell {
23491eaf3e1SJohn Birrell int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
23591eaf3e1SJohn Birrell
236493b584dSRyan Stone if (SYSTRACE_ISENTRY((uintptr_t)parg))
237493b584dSRyan Stone systrace_entry_setargdesc(sysnum, desc->dtargd_ndx,
238493b584dSRyan Stone desc->dtargd_native, sizeof(desc->dtargd_native));
239493b584dSRyan Stone else
240493b584dSRyan Stone systrace_return_setargdesc(sysnum, desc->dtargd_ndx,
241493b584dSRyan Stone desc->dtargd_native, sizeof(desc->dtargd_native));
24291eaf3e1SJohn Birrell
24391eaf3e1SJohn Birrell if (desc->dtargd_native[0] == '\0')
24491eaf3e1SJohn Birrell desc->dtargd_ndx = DTRACE_ARGNONE;
24591eaf3e1SJohn Birrell }
24691eaf3e1SJohn Birrell
2478ff6d9ddSMark Johnston static uint64_t
systrace_getargval(void * arg __unused,dtrace_id_t id __unused,void * parg __unused,int argno,int aframes __unused)2488ff6d9ddSMark Johnston systrace_getargval(void *arg __unused, dtrace_id_t id __unused,
2498ff6d9ddSMark Johnston void *parg __unused, int argno, int aframes __unused)
2508ff6d9ddSMark Johnston {
2518ff6d9ddSMark Johnston uint64_t *uargs;
2528ff6d9ddSMark Johnston
2538ff6d9ddSMark Johnston uargs = curthread->t_dtrace_systrace_args;
2548ff6d9ddSMark Johnston if (uargs == NULL)
2558ff6d9ddSMark Johnston /* This is a return probe. */
2568ff6d9ddSMark Johnston return (0);
2578ff6d9ddSMark Johnston if (argno >= nitems(((struct syscall_args *)NULL)->args))
2588ff6d9ddSMark Johnston return (0);
2598ff6d9ddSMark Johnston return (uargs[argno]);
2608ff6d9ddSMark Johnston }
2618ff6d9ddSMark Johnston
26291eaf3e1SJohn Birrell static void
systrace_provide(void * arg,dtrace_probedesc_t * desc)26391eaf3e1SJohn Birrell systrace_provide(void *arg, dtrace_probedesc_t *desc)
26491eaf3e1SJohn Birrell {
26591eaf3e1SJohn Birrell int i;
26691eaf3e1SJohn Birrell
26791eaf3e1SJohn Birrell if (desc != NULL)
26891eaf3e1SJohn Birrell return;
26991eaf3e1SJohn Birrell
270f5a97d1bSCraig Rodrigues for (i = 0; i < MAXSYSCALL; i++) {
271308bce2aSAndriy Gapon if (dtrace_probe_lookup(systrace_id, MODNAME,
272f5a97d1bSCraig Rodrigues uglyhack.pp_syscallnames[i], "entry") != 0)
27391eaf3e1SJohn Birrell continue;
27491eaf3e1SJohn Birrell
275feea5135SMark Johnston (void)dtrace_probe_create(systrace_id, MODNAME,
276feea5135SMark Johnston uglyhack.pp_syscallnames[i], "entry",
277feea5135SMark Johnston SYSTRACE_ARTIFICIAL_FRAMES,
27891eaf3e1SJohn Birrell (void *)((uintptr_t)SYSTRACE_ENTRY(i)));
279feea5135SMark Johnston (void)dtrace_probe_create(systrace_id, MODNAME,
280feea5135SMark Johnston uglyhack.pp_syscallnames[i], "return",
281feea5135SMark Johnston SYSTRACE_ARTIFICIAL_FRAMES,
28291eaf3e1SJohn Birrell (void *)((uintptr_t)SYSTRACE_RETURN(i)));
28391eaf3e1SJohn Birrell }
28491eaf3e1SJohn Birrell }
28591eaf3e1SJohn Birrell
28691eaf3e1SJohn Birrell static void
systrace_destroy(void * arg,dtrace_id_t id,void * parg)28791eaf3e1SJohn Birrell systrace_destroy(void *arg, dtrace_id_t id, void *parg)
28891eaf3e1SJohn Birrell {
2899e5787d2SMatt Macy #ifdef SYSTRACE_DEBUG
29091eaf3e1SJohn Birrell int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
29191eaf3e1SJohn Birrell
29291eaf3e1SJohn Birrell /*
29391eaf3e1SJohn Birrell * There's nothing to do here but assert that we have actually been
29491eaf3e1SJohn Birrell * disabled.
29591eaf3e1SJohn Birrell */
29691eaf3e1SJohn Birrell if (SYSTRACE_ISENTRY((uintptr_t)parg)) {
297a7261520SMark Johnston ASSERT(sysent[sysnum].sy_entry == DTRACE_IDNONE);
29891eaf3e1SJohn Birrell } else {
299a7261520SMark Johnston ASSERT(sysent[sysnum].sy_return == DTRACE_IDNONE);
30091eaf3e1SJohn Birrell }
30191eaf3e1SJohn Birrell #endif
30291eaf3e1SJohn Birrell }
30391eaf3e1SJohn Birrell
30491eaf3e1SJohn Birrell static void
systrace_enable(void * arg,dtrace_id_t id,void * parg)30591eaf3e1SJohn Birrell systrace_enable(void *arg, dtrace_id_t id, void *parg)
30691eaf3e1SJohn Birrell {
30791eaf3e1SJohn Birrell int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
30891eaf3e1SJohn Birrell
309f5a97d1bSCraig Rodrigues SYSENT[sysnum].sy_systrace_args_func = systrace_args;
310f5a97d1bSCraig Rodrigues
31191eaf3e1SJohn Birrell if (SYSTRACE_ISENTRY((uintptr_t)parg))
312f5a97d1bSCraig Rodrigues SYSENT[sysnum].sy_entry = id;
31391eaf3e1SJohn Birrell else
314f5a97d1bSCraig Rodrigues SYSENT[sysnum].sy_return = id;
3159d68f774SMateusz Guzik systrace_enabled_count++;
3169d68f774SMateusz Guzik if (systrace_enabled_count == 1)
3179d68f774SMateusz Guzik systrace_enabled = true;
31891eaf3e1SJohn Birrell }
31991eaf3e1SJohn Birrell
32091eaf3e1SJohn Birrell static void
systrace_disable(void * arg,dtrace_id_t id,void * parg)32191eaf3e1SJohn Birrell systrace_disable(void *arg, dtrace_id_t id, void *parg)
32291eaf3e1SJohn Birrell {
32391eaf3e1SJohn Birrell int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
32491eaf3e1SJohn Birrell
325a7261520SMark Johnston SYSENT[sysnum].sy_systrace_args_func = NULL;
326a7261520SMark Johnston SYSENT[sysnum].sy_entry = DTRACE_IDNONE;
327a7261520SMark Johnston SYSENT[sysnum].sy_return = DTRACE_IDNONE;
3289d68f774SMateusz Guzik systrace_enabled_count--;
3299d68f774SMateusz Guzik if (systrace_enabled_count == 0)
3309d68f774SMateusz Guzik systrace_enabled = false;
33191eaf3e1SJohn Birrell }
33291eaf3e1SJohn Birrell
33391eaf3e1SJohn Birrell static void
systrace_load(void * dummy __unused)334feea5135SMark Johnston systrace_load(void *dummy __unused)
33591eaf3e1SJohn Birrell {
33691eaf3e1SJohn Birrell
337feea5135SMark Johnston if (dtrace_register(PROVNAME, &systrace_attr, DTRACE_PRIV_USER, NULL,
338feea5135SMark Johnston &systrace_pops, NULL, &systrace_id) != 0)
33991eaf3e1SJohn Birrell return;
34091eaf3e1SJohn Birrell
3412f99bcceSJohn Baldwin #ifdef NATIVE_ABI
34291eaf3e1SJohn Birrell systrace_probe_func = systrace_probe;
343f5a97d1bSCraig Rodrigues #endif
34491eaf3e1SJohn Birrell }
34591eaf3e1SJohn Birrell
346feea5135SMark Johnston static void
systrace_unload(void * dummy __unused)347feea5135SMark Johnston systrace_unload(void *dummy __unused)
34891eaf3e1SJohn Birrell {
34991eaf3e1SJohn Birrell
3502f99bcceSJohn Baldwin #ifdef NATIVE_ABI
35191eaf3e1SJohn Birrell systrace_probe_func = NULL;
352f5a97d1bSCraig Rodrigues #endif
35391eaf3e1SJohn Birrell
354feea5135SMark Johnston if (dtrace_unregister(systrace_id) != 0)
355feea5135SMark Johnston return;
35691eaf3e1SJohn Birrell }
35791eaf3e1SJohn Birrell
35891eaf3e1SJohn Birrell static int
systrace_modevent(module_t mod __unused,int type,void * data __unused)35991eaf3e1SJohn Birrell systrace_modevent(module_t mod __unused, int type, void *data __unused)
36091eaf3e1SJohn Birrell {
361feea5135SMark Johnston int error;
36291eaf3e1SJohn Birrell
363feea5135SMark Johnston error = 0;
36491eaf3e1SJohn Birrell switch (type) {
36591eaf3e1SJohn Birrell case MOD_LOAD:
36691eaf3e1SJohn Birrell break;
36791eaf3e1SJohn Birrell
36891eaf3e1SJohn Birrell case MOD_UNLOAD:
36991eaf3e1SJohn Birrell break;
37091eaf3e1SJohn Birrell
37191eaf3e1SJohn Birrell case MOD_SHUTDOWN:
37291eaf3e1SJohn Birrell break;
37391eaf3e1SJohn Birrell
37491eaf3e1SJohn Birrell default:
37591eaf3e1SJohn Birrell error = EOPNOTSUPP;
37691eaf3e1SJohn Birrell break;
37791eaf3e1SJohn Birrell
37891eaf3e1SJohn Birrell }
37991eaf3e1SJohn Birrell return (error);
38091eaf3e1SJohn Birrell }
38191eaf3e1SJohn Birrell
382feea5135SMark Johnston SYSINIT(systrace_load, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY,
383feea5135SMark Johnston systrace_load, NULL);
384feea5135SMark Johnston SYSUNINIT(systrace_unload, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY,
385feea5135SMark Johnston systrace_unload, NULL);
38691eaf3e1SJohn Birrell
387f5a97d1bSCraig Rodrigues #ifdef LINUX_SYSTRACE
3882f99bcceSJohn Baldwin DEV_MODULE(systrace_linux, systrace_modevent, NULL);
3892f99bcceSJohn Baldwin MODULE_VERSION(systrace_linux, 1);
3902f99bcceSJohn Baldwin #ifdef __amd64__
3912f99bcceSJohn Baldwin MODULE_DEPEND(systrace_linux, linux64, 1, 1, 1);
3922f99bcceSJohn Baldwin #else
3932f99bcceSJohn Baldwin MODULE_DEPEND(systrace_linux, linux, 1, 1, 1);
3942f99bcceSJohn Baldwin #endif
3952f99bcceSJohn Baldwin MODULE_DEPEND(systrace_linux, dtrace, 1, 1, 1);
3962f99bcceSJohn Baldwin MODULE_DEPEND(systrace_linux, opensolaris, 1, 1, 1);
3972f99bcceSJohn Baldwin #elif defined(LINUX32_SYSTRACE)
398308bce2aSAndriy Gapon DEV_MODULE(systrace_linux32, systrace_modevent, NULL);
399308bce2aSAndriy Gapon MODULE_VERSION(systrace_linux32, 1);
400308bce2aSAndriy Gapon MODULE_DEPEND(systrace_linux32, linux, 1, 1, 1);
401308bce2aSAndriy Gapon MODULE_DEPEND(systrace_linux32, dtrace, 1, 1, 1);
402308bce2aSAndriy Gapon MODULE_DEPEND(systrace_linux32, opensolaris, 1, 1, 1);
403308bce2aSAndriy Gapon #elif defined(FREEBSD32_SYSTRACE)
404308bce2aSAndriy Gapon DEV_MODULE(systrace_freebsd32, systrace_modevent, NULL);
405308bce2aSAndriy Gapon MODULE_VERSION(systrace_freebsd32, 1);
406308bce2aSAndriy Gapon MODULE_DEPEND(systrace_freebsd32, dtrace, 1, 1, 1);
407308bce2aSAndriy Gapon MODULE_DEPEND(systrace_freebsd32, opensolaris, 1, 1, 1);
408f5a97d1bSCraig Rodrigues #else
40991eaf3e1SJohn Birrell DEV_MODULE(systrace, systrace_modevent, NULL);
41091eaf3e1SJohn Birrell MODULE_VERSION(systrace, 1);
41191eaf3e1SJohn Birrell MODULE_DEPEND(systrace, dtrace, 1, 1, 1);
41291eaf3e1SJohn Birrell MODULE_DEPEND(systrace, opensolaris, 1, 1, 1);
413f5a97d1bSCraig Rodrigues #endif
414