Deleted Added
full compact
systrace.c (269272) systrace.c (294368)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 *
21 * Portions Copyright 2006-2008 John Birrell jb@freebsd.org
22 *
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 *
21 * Portions Copyright 2006-2008 John Birrell jb@freebsd.org
22 *
23 * $FreeBSD: stable/10/sys/cddl/dev/systrace/systrace.c 269272 2014-07-29 22:26:41Z markj $
23 * $FreeBSD: stable/10/sys/cddl/dev/systrace/systrace.c 294368 2016-01-20 01:09:53Z jhb $
24 *
25 */
26
27/*
28 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
29 * Use is subject to license terms.
30 */
31
32#include <sys/cdefs.h>
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/conf.h>
36#include <sys/cpuvar.h>
37#include <sys/fcntl.h>
38#include <sys/filio.h>
39#include <sys/kdb.h>
40#include <sys/kernel.h>
41#include <sys/kmem.h>
42#include <sys/kthread.h>
43#include <sys/limits.h>
44#include <sys/linker.h>
45#include <sys/lock.h>
46#include <sys/malloc.h>
47#include <sys/module.h>
48#include <sys/mutex.h>
49#include <sys/poll.h>
50#include <sys/proc.h>
51#include <sys/selinfo.h>
52#include <sys/smp.h>
53#include <sys/sysproto.h>
54#include <sys/sysent.h>
55#include <sys/uio.h>
56#include <sys/unistd.h>
57#include <machine/stdarg.h>
58
59#include <sys/dtrace.h>
60
61#ifdef LINUX_SYSTRACE
62#if defined(__amd64__)
24 *
25 */
26
27/*
28 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
29 * Use is subject to license terms.
30 */
31
32#include <sys/cdefs.h>
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/conf.h>
36#include <sys/cpuvar.h>
37#include <sys/fcntl.h>
38#include <sys/filio.h>
39#include <sys/kdb.h>
40#include <sys/kernel.h>
41#include <sys/kmem.h>
42#include <sys/kthread.h>
43#include <sys/limits.h>
44#include <sys/linker.h>
45#include <sys/lock.h>
46#include <sys/malloc.h>
47#include <sys/module.h>
48#include <sys/mutex.h>
49#include <sys/poll.h>
50#include <sys/proc.h>
51#include <sys/selinfo.h>
52#include <sys/smp.h>
53#include <sys/sysproto.h>
54#include <sys/sysent.h>
55#include <sys/uio.h>
56#include <sys/unistd.h>
57#include <machine/stdarg.h>
58
59#include <sys/dtrace.h>
60
61#ifdef LINUX_SYSTRACE
62#if defined(__amd64__)
63#include <amd64/linux32/linux.h>
64#include <amd64/linux32/linux32_proto.h>
65#include <amd64/linux32/linux32_syscalls.c>
66#include <amd64/linux32/linux32_systrace_args.c>
67#define MODNAME "linux32"
63#include
64#include <amd64/linux/linux_proto.h>
65#include <amd64/linux/linux_syscalls.c>
66#include <amd64/linux/linux_systrace_args.c>
68#elif defined(__i386__)
69#include <i386/linux/linux.h>
70#include <i386/linux/linux_proto.h>
71#include <i386/linux/linux_syscalls.c>
72#include <i386/linux/linux_systrace_args.c>
67#elif defined(__i386__)
68#include <i386/linux/linux.h>
69#include <i386/linux/linux_proto.h>
70#include <i386/linux/linux_syscalls.c>
71#include <i386/linux/linux_systrace_args.c>
73#define MODNAME "linux"
74#else
75#error Only i386 and amd64 are supported.
76#endif
72#else
73#error Only i386 and amd64 are supported.
74#endif
75#define MODNAME "linux"
77extern struct sysent linux_sysent[];
78#define MAXSYSCALL LINUX_SYS_MAXSYSCALL
79#define SYSCALLNAMES linux_syscallnames
80#define SYSENT linux_sysent
76extern struct sysent linux_sysent[];
77#define MAXSYSCALL LINUX_SYS_MAXSYSCALL
78#define SYSCALLNAMES linux_syscallnames
79#define SYSENT linux_sysent
80#elif defined(LINUX32_SYSTRACE)
81#if defined(__amd64__)
82#include <amd64/linux32/linux.h>
83#include <amd64/linux32/linux32_proto.h>
84#include <amd64/linux32/linux32_syscalls.c>
85#include <amd64/linux32/linux32_systrace_args.c>
86#else
87#error Only amd64 is supported.
88#endif
89#define MODNAME "linux32"
90extern struct sysent linux32_sysent[];
91#define MAXSYSCALL LINUX32_SYS_MAXSYSCALL
92#define SYSCALLNAMES linux32_syscallnames
93#define SYSENT linux32_sysent
81#elif defined(FREEBSD32_SYSTRACE)
82/*
83 * The syscall arguments are processed into a DTrace argument array
84 * using a generated function. See sys/kern/makesyscalls.sh.
85 */
86#include <compat/freebsd32/freebsd32_proto.h>
87#include <compat/freebsd32/freebsd32_util.h>
88#include <compat/freebsd32/freebsd32_syscall.h>
89#include <compat/freebsd32/freebsd32_systrace_args.c>
90extern const char *freebsd32_syscallnames[];
91#define MODNAME "freebsd32"
92#define MAXSYSCALL FREEBSD32_SYS_MAXSYSCALL
93#define SYSCALLNAMES freebsd32_syscallnames
94#define SYSENT freebsd32_sysent
95#else
96/*
97 * The syscall arguments are processed into a DTrace argument array
98 * using a generated function. See sys/kern/makesyscalls.sh.
99 */
100#include <sys/syscall.h>
101#include <kern/systrace_args.c>
102#define MODNAME "freebsd"
103#define MAXSYSCALL SYS_MAXSYSCALL
104#define SYSCALLNAMES syscallnames
105#define SYSENT sysent
94#elif defined(FREEBSD32_SYSTRACE)
95/*
96 * The syscall arguments are processed into a DTrace argument array
97 * using a generated function. See sys/kern/makesyscalls.sh.
98 */
99#include <compat/freebsd32/freebsd32_proto.h>
100#include <compat/freebsd32/freebsd32_util.h>
101#include <compat/freebsd32/freebsd32_syscall.h>
102#include <compat/freebsd32/freebsd32_systrace_args.c>
103extern const char *freebsd32_syscallnames[];
104#define MODNAME "freebsd32"
105#define MAXSYSCALL FREEBSD32_SYS_MAXSYSCALL
106#define SYSCALLNAMES freebsd32_syscallnames
107#define SYSENT freebsd32_sysent
108#else
109/*
110 * The syscall arguments are processed into a DTrace argument array
111 * using a generated function. See sys/kern/makesyscalls.sh.
112 */
113#include <sys/syscall.h>
114#include <kern/systrace_args.c>
115#define MODNAME "freebsd"
116#define MAXSYSCALL SYS_MAXSYSCALL
117#define SYSCALLNAMES syscallnames
118#define SYSENT sysent
119#define NATIVE_ABI
106#endif
107
108#define PROVNAME "syscall"
109#define DEVNAME "dtrace/systrace/" MODNAME
110
111#define SYSTRACE_ARTIFICIAL_FRAMES 1
112
113#define SYSTRACE_SHIFT 16
114#define SYSTRACE_ISENTRY(x) ((int)(x) >> SYSTRACE_SHIFT)
115#define SYSTRACE_SYSNUM(x) ((int)(x) & ((1 << SYSTRACE_SHIFT) - 1))
116#define SYSTRACE_ENTRY(id) ((1 << SYSTRACE_SHIFT) | (id))
117#define SYSTRACE_RETURN(id) (id)
118
119#if ((1 << SYSTRACE_SHIFT) <= MAXSYSCALL)
120#error 1 << SYSTRACE_SHIFT must exceed number of system calls
121#endif
122
123static d_open_t systrace_open;
124static int systrace_unload(void);
125static void systrace_getargdesc(void *, dtrace_id_t, void *, dtrace_argdesc_t *);
126static void systrace_provide(void *, dtrace_probedesc_t *);
127static void systrace_destroy(void *, dtrace_id_t, void *);
128static void systrace_enable(void *, dtrace_id_t, void *);
129static void systrace_disable(void *, dtrace_id_t, void *);
130static void systrace_load(void *);
131
132static struct cdevsw systrace_cdevsw = {
133 .d_version = D_VERSION,
134 .d_open = systrace_open,
120#endif
121
122#define PROVNAME "syscall"
123#define DEVNAME "dtrace/systrace/" MODNAME
124
125#define SYSTRACE_ARTIFICIAL_FRAMES 1
126
127#define SYSTRACE_SHIFT 16
128#define SYSTRACE_ISENTRY(x) ((int)(x) >> SYSTRACE_SHIFT)
129#define SYSTRACE_SYSNUM(x) ((int)(x) & ((1 << SYSTRACE_SHIFT) - 1))
130#define SYSTRACE_ENTRY(id) ((1 << SYSTRACE_SHIFT) | (id))
131#define SYSTRACE_RETURN(id) (id)
132
133#if ((1 << SYSTRACE_SHIFT) <= MAXSYSCALL)
134#error 1 << SYSTRACE_SHIFT must exceed number of system calls
135#endif
136
137static d_open_t systrace_open;
138static int systrace_unload(void);
139static void systrace_getargdesc(void *, dtrace_id_t, void *, dtrace_argdesc_t *);
140static void systrace_provide(void *, dtrace_probedesc_t *);
141static void systrace_destroy(void *, dtrace_id_t, void *);
142static void systrace_enable(void *, dtrace_id_t, void *);
143static void systrace_disable(void *, dtrace_id_t, void *);
144static void systrace_load(void *);
145
146static struct cdevsw systrace_cdevsw = {
147 .d_version = D_VERSION,
148 .d_open = systrace_open,
135#ifdef LINUX_SYSTRACE
149#ifndef NATIVE_ABI
136 .d_name = "systrace_" MODNAME,
137#else
138 .d_name = "systrace",
139#endif
140};
141
142static union {
143 const char **p_constnames;
144 char **pp_syscallnames;
145} uglyhack = { SYSCALLNAMES };
146
147static dtrace_pattr_t systrace_attr = {
148{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
149{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
150{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
151{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
152{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
153};
154
155static dtrace_pops_t systrace_pops = {
156 systrace_provide,
157 NULL,
158 systrace_enable,
159 systrace_disable,
160 NULL,
161 NULL,
162 systrace_getargdesc,
163 NULL,
164 NULL,
165 systrace_destroy
166};
167
168static struct cdev *systrace_cdev;
169static dtrace_provider_id_t systrace_id;
170
171typedef void (*systrace_dtrace_probe_t)(dtrace_id_t, uintptr_t, uintptr_t,
172 uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
173
150 .d_name = "systrace_" MODNAME,
151#else
152 .d_name = "systrace",
153#endif
154};
155
156static union {
157 const char **p_constnames;
158 char **pp_syscallnames;
159} uglyhack = { SYSCALLNAMES };
160
161static dtrace_pattr_t systrace_attr = {
162{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
163{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
164{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
165{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
166{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
167};
168
169static dtrace_pops_t systrace_pops = {
170 systrace_provide,
171 NULL,
172 systrace_enable,
173 systrace_disable,
174 NULL,
175 NULL,
176 systrace_getargdesc,
177 NULL,
178 NULL,
179 systrace_destroy
180};
181
182static struct cdev *systrace_cdev;
183static dtrace_provider_id_t systrace_id;
184
185typedef void (*systrace_dtrace_probe_t)(dtrace_id_t, uintptr_t, uintptr_t,
186 uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
187
174#if !defined(LINUX_SYSTRACE)
188#ifdef NATIVE_ABI
175/*
176 * Probe callback function.
177 *
178 * Note: This function is called for _all_ syscalls, regardless of which sysent
179 * array the syscall comes from. It could be a standard syscall or a
180 * compat syscall from something like Linux.
181 */
182static void
183systrace_probe(u_int32_t id, int sysnum, struct sysent *sysent, void *params,
184 int ret)
185{
186 systrace_dtrace_probe_t probe;
187 int n_args = 0;
188 u_int64_t uargs[8];
189
190 memset(uargs, 0, sizeof(uargs));
191 /*
192 * Check if this syscall has an argument conversion function
193 * registered.
194 */
195 if (params && sysent->sy_systrace_args_func != NULL) {
196 /*
197 * Convert the syscall parameters using the registered
198 * function.
199 */
200 (*sysent->sy_systrace_args_func)(sysnum, params, uargs, &n_args);
201 } else if (params) {
202 /*
203 * Use the built-in system call argument conversion
204 * function to translate the syscall structure fields
205 * into the array of 64-bit values that DTrace
206 * expects.
207 */
208 systrace_args(sysnum, params, uargs, &n_args);
209 } else {
210 /*
211 * Since params is NULL, this is a 'return' probe.
212 * Set arg0 and arg1 as the return value of this syscall.
213 */
214 uargs[0] = uargs[1] = ret;
215 }
216
217 /* Process the probe using the converted argments. */
218 probe = (systrace_dtrace_probe_t)dtrace_probe;
219 probe(id, uargs[0], uargs[1], uargs[2], uargs[3], uargs[4], uargs[5],
220 uargs[6], uargs[7]);
221}
222
223#endif
224
225static void
226systrace_getargdesc(void *arg, dtrace_id_t id, void *parg, dtrace_argdesc_t *desc)
227{
228 int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
229
230 if (SYSTRACE_ISENTRY((uintptr_t)parg))
231 systrace_entry_setargdesc(sysnum, desc->dtargd_ndx,
232 desc->dtargd_native, sizeof(desc->dtargd_native));
233 else
234 systrace_return_setargdesc(sysnum, desc->dtargd_ndx,
235 desc->dtargd_native, sizeof(desc->dtargd_native));
236
237 if (desc->dtargd_native[0] == '\0')
238 desc->dtargd_ndx = DTRACE_ARGNONE;
239
240 return;
241}
242
243static void
244systrace_provide(void *arg, dtrace_probedesc_t *desc)
245{
246 int i;
247
248 if (desc != NULL)
249 return;
250
251 for (i = 0; i < MAXSYSCALL; i++) {
252 if (dtrace_probe_lookup(systrace_id, MODNAME,
253 uglyhack.pp_syscallnames[i], "entry") != 0)
254 continue;
255
256 (void) dtrace_probe_create(systrace_id, MODNAME, uglyhack.pp_syscallnames[i],
257 "entry", SYSTRACE_ARTIFICIAL_FRAMES,
258 (void *)((uintptr_t)SYSTRACE_ENTRY(i)));
259 (void) dtrace_probe_create(systrace_id, MODNAME, uglyhack.pp_syscallnames[i],
260 "return", SYSTRACE_ARTIFICIAL_FRAMES,
261 (void *)((uintptr_t)SYSTRACE_RETURN(i)));
262 }
263}
264
265static void
266systrace_destroy(void *arg, dtrace_id_t id, void *parg)
267{
268#ifdef DEBUG
269 int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
270
271 /*
272 * There's nothing to do here but assert that we have actually been
273 * disabled.
274 */
275 if (SYSTRACE_ISENTRY((uintptr_t)parg)) {
276 ASSERT(sysent[sysnum].sy_entry == 0);
277 } else {
278 ASSERT(sysent[sysnum].sy_return == 0);
279 }
280#endif
281}
282
283static void
284systrace_enable(void *arg, dtrace_id_t id, void *parg)
285{
286 int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
287
288 if (SYSENT[sysnum].sy_systrace_args_func == NULL)
289 SYSENT[sysnum].sy_systrace_args_func = systrace_args;
290
291 if (SYSTRACE_ISENTRY((uintptr_t)parg))
292 SYSENT[sysnum].sy_entry = id;
293 else
294 SYSENT[sysnum].sy_return = id;
295}
296
297static void
298systrace_disable(void *arg, dtrace_id_t id, void *parg)
299{
300 int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
301
302 SYSENT[sysnum].sy_entry = 0;
303 SYSENT[sysnum].sy_return = 0;
304}
305
306static void
307systrace_load(void *dummy)
308{
309 /* Create the /dev/dtrace/systrace entry. */
310 systrace_cdev = make_dev(&systrace_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
311 DEVNAME);
312
313 if (dtrace_register(PROVNAME, &systrace_attr, DTRACE_PRIV_USER,
314 NULL, &systrace_pops, NULL, &systrace_id) != 0)
315 return;
316
189/*
190 * Probe callback function.
191 *
192 * Note: This function is called for _all_ syscalls, regardless of which sysent
193 * array the syscall comes from. It could be a standard syscall or a
194 * compat syscall from something like Linux.
195 */
196static void
197systrace_probe(u_int32_t id, int sysnum, struct sysent *sysent, void *params,
198 int ret)
199{
200 systrace_dtrace_probe_t probe;
201 int n_args = 0;
202 u_int64_t uargs[8];
203
204 memset(uargs, 0, sizeof(uargs));
205 /*
206 * Check if this syscall has an argument conversion function
207 * registered.
208 */
209 if (params && sysent->sy_systrace_args_func != NULL) {
210 /*
211 * Convert the syscall parameters using the registered
212 * function.
213 */
214 (*sysent->sy_systrace_args_func)(sysnum, params, uargs, &n_args);
215 } else if (params) {
216 /*
217 * Use the built-in system call argument conversion
218 * function to translate the syscall structure fields
219 * into the array of 64-bit values that DTrace
220 * expects.
221 */
222 systrace_args(sysnum, params, uargs, &n_args);
223 } else {
224 /*
225 * Since params is NULL, this is a 'return' probe.
226 * Set arg0 and arg1 as the return value of this syscall.
227 */
228 uargs[0] = uargs[1] = ret;
229 }
230
231 /* Process the probe using the converted argments. */
232 probe = (systrace_dtrace_probe_t)dtrace_probe;
233 probe(id, uargs[0], uargs[1], uargs[2], uargs[3], uargs[4], uargs[5],
234 uargs[6], uargs[7]);
235}
236
237#endif
238
239static void
240systrace_getargdesc(void *arg, dtrace_id_t id, void *parg, dtrace_argdesc_t *desc)
241{
242 int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
243
244 if (SYSTRACE_ISENTRY((uintptr_t)parg))
245 systrace_entry_setargdesc(sysnum, desc->dtargd_ndx,
246 desc->dtargd_native, sizeof(desc->dtargd_native));
247 else
248 systrace_return_setargdesc(sysnum, desc->dtargd_ndx,
249 desc->dtargd_native, sizeof(desc->dtargd_native));
250
251 if (desc->dtargd_native[0] == '\0')
252 desc->dtargd_ndx = DTRACE_ARGNONE;
253
254 return;
255}
256
257static void
258systrace_provide(void *arg, dtrace_probedesc_t *desc)
259{
260 int i;
261
262 if (desc != NULL)
263 return;
264
265 for (i = 0; i < MAXSYSCALL; i++) {
266 if (dtrace_probe_lookup(systrace_id, MODNAME,
267 uglyhack.pp_syscallnames[i], "entry") != 0)
268 continue;
269
270 (void) dtrace_probe_create(systrace_id, MODNAME, uglyhack.pp_syscallnames[i],
271 "entry", SYSTRACE_ARTIFICIAL_FRAMES,
272 (void *)((uintptr_t)SYSTRACE_ENTRY(i)));
273 (void) dtrace_probe_create(systrace_id, MODNAME, uglyhack.pp_syscallnames[i],
274 "return", SYSTRACE_ARTIFICIAL_FRAMES,
275 (void *)((uintptr_t)SYSTRACE_RETURN(i)));
276 }
277}
278
279static void
280systrace_destroy(void *arg, dtrace_id_t id, void *parg)
281{
282#ifdef DEBUG
283 int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
284
285 /*
286 * There's nothing to do here but assert that we have actually been
287 * disabled.
288 */
289 if (SYSTRACE_ISENTRY((uintptr_t)parg)) {
290 ASSERT(sysent[sysnum].sy_entry == 0);
291 } else {
292 ASSERT(sysent[sysnum].sy_return == 0);
293 }
294#endif
295}
296
297static void
298systrace_enable(void *arg, dtrace_id_t id, void *parg)
299{
300 int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
301
302 if (SYSENT[sysnum].sy_systrace_args_func == NULL)
303 SYSENT[sysnum].sy_systrace_args_func = systrace_args;
304
305 if (SYSTRACE_ISENTRY((uintptr_t)parg))
306 SYSENT[sysnum].sy_entry = id;
307 else
308 SYSENT[sysnum].sy_return = id;
309}
310
311static void
312systrace_disable(void *arg, dtrace_id_t id, void *parg)
313{
314 int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
315
316 SYSENT[sysnum].sy_entry = 0;
317 SYSENT[sysnum].sy_return = 0;
318}
319
320static void
321systrace_load(void *dummy)
322{
323 /* Create the /dev/dtrace/systrace entry. */
324 systrace_cdev = make_dev(&systrace_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
325 DEVNAME);
326
327 if (dtrace_register(PROVNAME, &systrace_attr, DTRACE_PRIV_USER,
328 NULL, &systrace_pops, NULL, &systrace_id) != 0)
329 return;
330
317#if !defined(LINUX_SYSTRACE)
331#ifdef NATIVE_ABI
318 systrace_probe_func = systrace_probe;
319#endif
320}
321
322
323static int
324systrace_unload()
325{
326 int error = 0;
327
328 if ((error = dtrace_unregister(systrace_id)) != 0)
329 return (error);
330
332 systrace_probe_func = systrace_probe;
333#endif
334}
335
336
337static int
338systrace_unload()
339{
340 int error = 0;
341
342 if ((error = dtrace_unregister(systrace_id)) != 0)
343 return (error);
344
331#if !defined(LINUX_SYSTRACE)
345#ifdef NATIVE_ABI
332 systrace_probe_func = NULL;
333#endif
334
335 destroy_dev(systrace_cdev);
336
337 return (error);
338}
339
340static int
341systrace_modevent(module_t mod __unused, int type, void *data __unused)
342{
343 int error = 0;
344
345 switch (type) {
346 case MOD_LOAD:
347 break;
348
349 case MOD_UNLOAD:
350 break;
351
352 case MOD_SHUTDOWN:
353 break;
354
355 default:
356 error = EOPNOTSUPP;
357 break;
358
359 }
360 return (error);
361}
362
363static int
364systrace_open(struct cdev *dev __unused, int oflags __unused, int devtype __unused, struct thread *td __unused)
365{
366 return (0);
367}
368
369SYSINIT(systrace_load, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY, systrace_load, NULL);
370SYSUNINIT(systrace_unload, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY, systrace_unload, NULL);
371
372#ifdef LINUX_SYSTRACE
346 systrace_probe_func = NULL;
347#endif
348
349 destroy_dev(systrace_cdev);
350
351 return (error);
352}
353
354static int
355systrace_modevent(module_t mod __unused, int type, void *data __unused)
356{
357 int error = 0;
358
359 switch (type) {
360 case MOD_LOAD:
361 break;
362
363 case MOD_UNLOAD:
364 break;
365
366 case MOD_SHUTDOWN:
367 break;
368
369 default:
370 error = EOPNOTSUPP;
371 break;
372
373 }
374 return (error);
375}
376
377static int
378systrace_open(struct cdev *dev __unused, int oflags __unused, int devtype __unused, struct thread *td __unused)
379{
380 return (0);
381}
382
383SYSINIT(systrace_load, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY, systrace_load, NULL);
384SYSUNINIT(systrace_unload, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY, systrace_unload, NULL);
385
386#ifdef LINUX_SYSTRACE
387DEV_MODULE(systrace_linux, systrace_modevent, NULL);
388MODULE_VERSION(systrace_linux, 1);
389#ifdef __amd64__
390MODULE_DEPEND(systrace_linux, linux64, 1, 1, 1);
391#else
392MODULE_DEPEND(systrace_linux, linux, 1, 1, 1);
393#endif
394MODULE_DEPEND(systrace_linux, dtrace, 1, 1, 1);
395MODULE_DEPEND(systrace_linux, opensolaris, 1, 1, 1);
396#elif defined(LINUX32_SYSTRACE)
373DEV_MODULE(systrace_linux32, systrace_modevent, NULL);
374MODULE_VERSION(systrace_linux32, 1);
375MODULE_DEPEND(systrace_linux32, linux, 1, 1, 1);
376MODULE_DEPEND(systrace_linux32, dtrace, 1, 1, 1);
377MODULE_DEPEND(systrace_linux32, opensolaris, 1, 1, 1);
378#elif defined(FREEBSD32_SYSTRACE)
379DEV_MODULE(systrace_freebsd32, systrace_modevent, NULL);
380MODULE_VERSION(systrace_freebsd32, 1);
381MODULE_DEPEND(systrace_freebsd32, dtrace, 1, 1, 1);
382MODULE_DEPEND(systrace_freebsd32, opensolaris, 1, 1, 1);
383#else
384DEV_MODULE(systrace, systrace_modevent, NULL);
385MODULE_VERSION(systrace, 1);
386MODULE_DEPEND(systrace, dtrace, 1, 1, 1);
387MODULE_DEPEND(systrace, opensolaris, 1, 1, 1);
388#endif
397DEV_MODULE(systrace_linux32, systrace_modevent, NULL);
398MODULE_VERSION(systrace_linux32, 1);
399MODULE_DEPEND(systrace_linux32, linux, 1, 1, 1);
400MODULE_DEPEND(systrace_linux32, dtrace, 1, 1, 1);
401MODULE_DEPEND(systrace_linux32, opensolaris, 1, 1, 1);
402#elif defined(FREEBSD32_SYSTRACE)
403DEV_MODULE(systrace_freebsd32, systrace_modevent, NULL);
404MODULE_VERSION(systrace_freebsd32, 1);
405MODULE_DEPEND(systrace_freebsd32, dtrace, 1, 1, 1);
406MODULE_DEPEND(systrace_freebsd32, opensolaris, 1, 1, 1);
407#else
408DEV_MODULE(systrace, systrace_modevent, NULL);
409MODULE_VERSION(systrace, 1);
410MODULE_DEPEND(systrace, dtrace, 1, 1, 1);
411MODULE_DEPEND(systrace, opensolaris, 1, 1, 1);
412#endif