17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5ad4023c4Sdp  * Common Development and Distribution License (the "License").
6ad4023c4Sdp  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22b9e93c10SJonathan Haslam  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <sys/dtrace.h>
287c478bd9Sstevel@tonic-gate #include <sys/systrace.h>
297c478bd9Sstevel@tonic-gate #include <sys/stat.h>
307c478bd9Sstevel@tonic-gate #include <sys/systm.h>
317c478bd9Sstevel@tonic-gate #include <sys/conf.h>
327c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
337c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
347c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #define	SYSTRACE_ARTIFICIAL_FRAMES	1
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #define	SYSTRACE_SHIFT			16
397c478bd9Sstevel@tonic-gate #define	SYSTRACE_ISENTRY(x)		((int)(x) >> SYSTRACE_SHIFT)
407c478bd9Sstevel@tonic-gate #define	SYSTRACE_SYSNUM(x)		((int)(x) & ((1 << SYSTRACE_SHIFT) - 1))
417c478bd9Sstevel@tonic-gate #define	SYSTRACE_ENTRY(id)		((1 << SYSTRACE_SHIFT) | (id))
427c478bd9Sstevel@tonic-gate #define	SYSTRACE_RETURN(id)		(id)
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #if ((1 << SYSTRACE_SHIFT) <= NSYSCALL)
457c478bd9Sstevel@tonic-gate #error 1 << SYSTRACE_SHIFT must exceed number of system calls
467c478bd9Sstevel@tonic-gate #endif
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate static dev_info_t *systrace_devi;
497c478bd9Sstevel@tonic-gate static dtrace_provider_id_t systrace_id;
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate static void
systrace_init(struct sysent * actual,systrace_sysent_t ** interposed)527c478bd9Sstevel@tonic-gate systrace_init(struct sysent *actual, systrace_sysent_t **interposed)
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate 	systrace_sysent_t *sysent = *interposed;
557c478bd9Sstevel@tonic-gate 	int i;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 	if (sysent == NULL) {
587c478bd9Sstevel@tonic-gate 		*interposed = sysent = kmem_zalloc(sizeof (systrace_sysent_t) *
597c478bd9Sstevel@tonic-gate 		    NSYSCALL, KM_SLEEP);
607c478bd9Sstevel@tonic-gate 	}
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 	for (i = 0; i < NSYSCALL; i++) {
637c478bd9Sstevel@tonic-gate 		struct sysent *a = &actual[i];
647c478bd9Sstevel@tonic-gate 		systrace_sysent_t *s = &sysent[i];
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 		if (LOADABLE_SYSCALL(a) && !LOADED_SYSCALL(a))
677c478bd9Sstevel@tonic-gate 			continue;
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 		if (a->sy_callc == dtrace_systrace_syscall)
707c478bd9Sstevel@tonic-gate 			continue;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
737c478bd9Sstevel@tonic-gate 		if (a->sy_callc == dtrace_systrace_syscall32)
747c478bd9Sstevel@tonic-gate 			continue;
757c478bd9Sstevel@tonic-gate #endif
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 		s->stsy_underlying = a->sy_callc;
787c478bd9Sstevel@tonic-gate 	}
797c478bd9Sstevel@tonic-gate }
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*ARGSUSED*/
827c478bd9Sstevel@tonic-gate static void
systrace_provide(void * arg,const dtrace_probedesc_t * desc)837c478bd9Sstevel@tonic-gate systrace_provide(void *arg, const dtrace_probedesc_t *desc)
847c478bd9Sstevel@tonic-gate {
857c478bd9Sstevel@tonic-gate 	int i;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	if (desc != NULL)
887c478bd9Sstevel@tonic-gate 		return;
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate 	systrace_init(sysent, &systrace_sysent);
917c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
927c478bd9Sstevel@tonic-gate 	systrace_init(sysent32, &systrace_sysent32);
937c478bd9Sstevel@tonic-gate #endif
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	for (i = 0; i < NSYSCALL; i++) {
967c478bd9Sstevel@tonic-gate 		if (systrace_sysent[i].stsy_underlying == NULL)
977c478bd9Sstevel@tonic-gate 			continue;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 		if (dtrace_probe_lookup(systrace_id, NULL,
1007c478bd9Sstevel@tonic-gate 		    syscallnames[i], "entry") != 0)
1017c478bd9Sstevel@tonic-gate 			continue;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 		(void) dtrace_probe_create(systrace_id, NULL, syscallnames[i],
1047c478bd9Sstevel@tonic-gate 		    "entry", SYSTRACE_ARTIFICIAL_FRAMES,
1057c478bd9Sstevel@tonic-gate 		    (void *)((uintptr_t)SYSTRACE_ENTRY(i)));
1067c478bd9Sstevel@tonic-gate 		(void) dtrace_probe_create(systrace_id, NULL, syscallnames[i],
1077c478bd9Sstevel@tonic-gate 		    "return", SYSTRACE_ARTIFICIAL_FRAMES,
1087c478bd9Sstevel@tonic-gate 		    (void *)((uintptr_t)SYSTRACE_RETURN(i)));
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 		systrace_sysent[i].stsy_entry = DTRACE_IDNONE;
1117c478bd9Sstevel@tonic-gate 		systrace_sysent[i].stsy_return = DTRACE_IDNONE;
1127c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
1137c478bd9Sstevel@tonic-gate 		systrace_sysent32[i].stsy_entry = DTRACE_IDNONE;
1147c478bd9Sstevel@tonic-gate 		systrace_sysent32[i].stsy_return = DTRACE_IDNONE;
1157c478bd9Sstevel@tonic-gate #endif
1167c478bd9Sstevel@tonic-gate 	}
1177c478bd9Sstevel@tonic-gate }
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1207c478bd9Sstevel@tonic-gate static void
systrace_destroy(void * arg,dtrace_id_t id,void * parg)1217c478bd9Sstevel@tonic-gate systrace_destroy(void *arg, dtrace_id_t id, void *parg)
1227c478bd9Sstevel@tonic-gate {
1237c478bd9Sstevel@tonic-gate 	int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	/*
1267c478bd9Sstevel@tonic-gate 	 * There's nothing to do here but assert that we have actually been
1277c478bd9Sstevel@tonic-gate 	 * disabled.
1287c478bd9Sstevel@tonic-gate 	 */
1297c478bd9Sstevel@tonic-gate 	if (SYSTRACE_ISENTRY((uintptr_t)parg)) {
1307c478bd9Sstevel@tonic-gate 		ASSERT(systrace_sysent[sysnum].stsy_entry == DTRACE_IDNONE);
1317c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
1327c478bd9Sstevel@tonic-gate 		ASSERT(systrace_sysent32[sysnum].stsy_entry == DTRACE_IDNONE);
1337c478bd9Sstevel@tonic-gate #endif
1347c478bd9Sstevel@tonic-gate 	} else {
1357c478bd9Sstevel@tonic-gate 		ASSERT(systrace_sysent[sysnum].stsy_return == DTRACE_IDNONE);
1367c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
1377c478bd9Sstevel@tonic-gate 		ASSERT(systrace_sysent32[sysnum].stsy_return == DTRACE_IDNONE);
1387c478bd9Sstevel@tonic-gate #endif
1397c478bd9Sstevel@tonic-gate 	}
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /*ARGSUSED*/
143b9e93c10SJonathan Haslam static int
systrace_enable(void * arg,dtrace_id_t id,void * parg)1447c478bd9Sstevel@tonic-gate systrace_enable(void *arg, dtrace_id_t id, void *parg)
1457c478bd9Sstevel@tonic-gate {
1467c478bd9Sstevel@tonic-gate 	int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
1477c478bd9Sstevel@tonic-gate 	int enabled = (systrace_sysent[sysnum].stsy_entry != DTRACE_IDNONE ||
1487c478bd9Sstevel@tonic-gate 	    systrace_sysent[sysnum].stsy_return != DTRACE_IDNONE);
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	if (SYSTRACE_ISENTRY((uintptr_t)parg)) {
1517c478bd9Sstevel@tonic-gate 		systrace_sysent[sysnum].stsy_entry = id;
1527c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
1537c478bd9Sstevel@tonic-gate 		systrace_sysent32[sysnum].stsy_entry = id;
1547c478bd9Sstevel@tonic-gate #endif
1557c478bd9Sstevel@tonic-gate 	} else {
1567c478bd9Sstevel@tonic-gate 		systrace_sysent[sysnum].stsy_return = id;
1577c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
1587c478bd9Sstevel@tonic-gate 		systrace_sysent32[sysnum].stsy_return = id;
1597c478bd9Sstevel@tonic-gate #endif
1607c478bd9Sstevel@tonic-gate 	}
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	if (enabled) {
1637c478bd9Sstevel@tonic-gate 		ASSERT(sysent[sysnum].sy_callc == dtrace_systrace_syscall);
164b9e93c10SJonathan Haslam 		return (0);
1657c478bd9Sstevel@tonic-gate 	}
1667c478bd9Sstevel@tonic-gate 
16775d94465SJosef 'Jeff' Sipek 	(void) atomic_cas_ptr(&sysent[sysnum].sy_callc,
1687c478bd9Sstevel@tonic-gate 	    (void *)systrace_sysent[sysnum].stsy_underlying,
1697c478bd9Sstevel@tonic-gate 	    (void *)dtrace_systrace_syscall);
1707c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
17175d94465SJosef 'Jeff' Sipek 	(void) atomic_cas_ptr(&sysent32[sysnum].sy_callc,
1727c478bd9Sstevel@tonic-gate 	    (void *)systrace_sysent32[sysnum].stsy_underlying,
1737c478bd9Sstevel@tonic-gate 	    (void *)dtrace_systrace_syscall32);
1747c478bd9Sstevel@tonic-gate #endif
175b9e93c10SJonathan Haslam 	return (0);
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1797c478bd9Sstevel@tonic-gate static void
systrace_disable(void * arg,dtrace_id_t id,void * parg)1807c478bd9Sstevel@tonic-gate systrace_disable(void *arg, dtrace_id_t id, void *parg)
1817c478bd9Sstevel@tonic-gate {
1827c478bd9Sstevel@tonic-gate 	int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
1837c478bd9Sstevel@tonic-gate 	int disable = (systrace_sysent[sysnum].stsy_entry == DTRACE_IDNONE ||
1847c478bd9Sstevel@tonic-gate 	    systrace_sysent[sysnum].stsy_return == DTRACE_IDNONE);
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 	if (disable) {
18775d94465SJosef 'Jeff' Sipek 		(void) atomic_cas_ptr(&sysent[sysnum].sy_callc,
1887c478bd9Sstevel@tonic-gate 		    (void *)dtrace_systrace_syscall,
1897c478bd9Sstevel@tonic-gate 		    (void *)systrace_sysent[sysnum].stsy_underlying);
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
19275d94465SJosef 'Jeff' Sipek 		(void) atomic_cas_ptr(&sysent32[sysnum].sy_callc,
1937c478bd9Sstevel@tonic-gate 		    (void *)dtrace_systrace_syscall32,
1947c478bd9Sstevel@tonic-gate 		    (void *)systrace_sysent32[sysnum].stsy_underlying);
1957c478bd9Sstevel@tonic-gate #endif
1967c478bd9Sstevel@tonic-gate 	}
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	if (SYSTRACE_ISENTRY((uintptr_t)parg)) {
1997c478bd9Sstevel@tonic-gate 		systrace_sysent[sysnum].stsy_entry = DTRACE_IDNONE;
2007c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
2017c478bd9Sstevel@tonic-gate 		systrace_sysent32[sysnum].stsy_entry = DTRACE_IDNONE;
2027c478bd9Sstevel@tonic-gate #endif
2037c478bd9Sstevel@tonic-gate 	} else {
2047c478bd9Sstevel@tonic-gate 		systrace_sysent[sysnum].stsy_return = DTRACE_IDNONE;
2057c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
2067c478bd9Sstevel@tonic-gate 		systrace_sysent32[sysnum].stsy_return = DTRACE_IDNONE;
2077c478bd9Sstevel@tonic-gate #endif
2087c478bd9Sstevel@tonic-gate 	}
2097c478bd9Sstevel@tonic-gate }
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate static dtrace_pattr_t systrace_attr = {
2127c478bd9Sstevel@tonic-gate { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
2137c478bd9Sstevel@tonic-gate { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
2147c478bd9Sstevel@tonic-gate { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
2157c478bd9Sstevel@tonic-gate { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
2167c478bd9Sstevel@tonic-gate { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
2177c478bd9Sstevel@tonic-gate };
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate static dtrace_pops_t systrace_pops = {
2207c478bd9Sstevel@tonic-gate 	systrace_provide,
2217c478bd9Sstevel@tonic-gate 	NULL,
2227c478bd9Sstevel@tonic-gate 	systrace_enable,
2237c478bd9Sstevel@tonic-gate 	systrace_disable,
2247c478bd9Sstevel@tonic-gate 	NULL,
2257c478bd9Sstevel@tonic-gate 	NULL,
2267c478bd9Sstevel@tonic-gate 	NULL,
2277c478bd9Sstevel@tonic-gate 	NULL,
2287c478bd9Sstevel@tonic-gate 	NULL,
2297c478bd9Sstevel@tonic-gate 	systrace_destroy
2307c478bd9Sstevel@tonic-gate };
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate static int
systrace_attach(dev_info_t * devi,ddi_attach_cmd_t cmd)2337c478bd9Sstevel@tonic-gate systrace_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
2347c478bd9Sstevel@tonic-gate {
2357c478bd9Sstevel@tonic-gate 	switch (cmd) {
2367c478bd9Sstevel@tonic-gate 	case DDI_ATTACH:
2377c478bd9Sstevel@tonic-gate 		break;
2387c478bd9Sstevel@tonic-gate 	case DDI_RESUME:
2397c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
2407c478bd9Sstevel@tonic-gate 	default:
2417c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2427c478bd9Sstevel@tonic-gate 	}
2437c478bd9Sstevel@tonic-gate 
2442b6e762cSahl 	systrace_probe = (void (*)())dtrace_probe;
2457c478bd9Sstevel@tonic-gate 	membar_enter();
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 	if (ddi_create_minor_node(devi, "systrace", S_IFCHR, 0,
248*cd717361SToomas Soome 	    DDI_PSEUDO, 0) == DDI_FAILURE ||
249ad4023c4Sdp 	    dtrace_register("syscall", &systrace_attr, DTRACE_PRIV_USER, NULL,
2507c478bd9Sstevel@tonic-gate 	    &systrace_pops, NULL, &systrace_id) != 0) {
2517c478bd9Sstevel@tonic-gate 		systrace_probe = systrace_stub;
2527c478bd9Sstevel@tonic-gate 		ddi_remove_minor_node(devi, NULL);
2537c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2547c478bd9Sstevel@tonic-gate 	}
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate 	ddi_report_dev(devi);
2577c478bd9Sstevel@tonic-gate 	systrace_devi = devi;
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate static int
systrace_detach(dev_info_t * devi,ddi_detach_cmd_t cmd)2637c478bd9Sstevel@tonic-gate systrace_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
2647c478bd9Sstevel@tonic-gate {
2657c478bd9Sstevel@tonic-gate 	switch (cmd) {
2667c478bd9Sstevel@tonic-gate 	case DDI_DETACH:
2677c478bd9Sstevel@tonic-gate 		break;
2687c478bd9Sstevel@tonic-gate 	case DDI_SUSPEND:
2697c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
2707c478bd9Sstevel@tonic-gate 	default:
2717c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2727c478bd9Sstevel@tonic-gate 	}
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	if (dtrace_unregister(systrace_id) != 0)
2757c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	ddi_remove_minor_node(devi, NULL);
2787c478bd9Sstevel@tonic-gate 	systrace_probe = systrace_stub;
2797c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
2807c478bd9Sstevel@tonic-gate }
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2837c478bd9Sstevel@tonic-gate static int
systrace_info(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)2847c478bd9Sstevel@tonic-gate systrace_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
2857c478bd9Sstevel@tonic-gate {
2867c478bd9Sstevel@tonic-gate 	int error;
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 	switch (infocmd) {
2897c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
2907c478bd9Sstevel@tonic-gate 		*result = (void *)systrace_devi;
2917c478bd9Sstevel@tonic-gate 		error = DDI_SUCCESS;
2927c478bd9Sstevel@tonic-gate 		break;
2937c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
2947c478bd9Sstevel@tonic-gate 		*result = (void *)0;
2957c478bd9Sstevel@tonic-gate 		error = DDI_SUCCESS;
2967c478bd9Sstevel@tonic-gate 		break;
2977c478bd9Sstevel@tonic-gate 	default:
2987c478bd9Sstevel@tonic-gate 		error = DDI_FAILURE;
2997c478bd9Sstevel@tonic-gate 	}
3007c478bd9Sstevel@tonic-gate 	return (error);
3017c478bd9Sstevel@tonic-gate }
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3047c478bd9Sstevel@tonic-gate static int
systrace_open(dev_t * devp,int flag,int otyp,cred_t * cred_p)3057c478bd9Sstevel@tonic-gate systrace_open(dev_t *devp, int flag, int otyp, cred_t *cred_p)
3067c478bd9Sstevel@tonic-gate {
3077c478bd9Sstevel@tonic-gate 	return (0);
3087c478bd9Sstevel@tonic-gate }
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate static struct cb_ops systrace_cb_ops = {
3117c478bd9Sstevel@tonic-gate 	systrace_open,		/* open */
3127c478bd9Sstevel@tonic-gate 	nodev,			/* close */
3137c478bd9Sstevel@tonic-gate 	nulldev,		/* strategy */
3147c478bd9Sstevel@tonic-gate 	nulldev,		/* print */
3157c478bd9Sstevel@tonic-gate 	nodev,			/* dump */
3167c478bd9Sstevel@tonic-gate 	nodev,			/* read */
3177c478bd9Sstevel@tonic-gate 	nodev,			/* write */
3187c478bd9Sstevel@tonic-gate 	nodev,			/* ioctl */
3197c478bd9Sstevel@tonic-gate 	nodev,			/* devmap */
3207c478bd9Sstevel@tonic-gate 	nodev,			/* mmap */
3217c478bd9Sstevel@tonic-gate 	nodev,			/* segmap */
3227c478bd9Sstevel@tonic-gate 	nochpoll,		/* poll */
3237c478bd9Sstevel@tonic-gate 	ddi_prop_op,		/* cb_prop_op */
3247c478bd9Sstevel@tonic-gate 	0,			/* streamtab  */
3257c478bd9Sstevel@tonic-gate 	D_NEW | D_MP		/* Driver compatibility flag */
3267c478bd9Sstevel@tonic-gate };
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate static struct dev_ops systrace_ops = {
3297c478bd9Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev, */
3307c478bd9Sstevel@tonic-gate 	0,			/* refcnt  */
3317c478bd9Sstevel@tonic-gate 	systrace_info,		/* get_dev_info */
3327c478bd9Sstevel@tonic-gate 	nulldev,		/* identify */
3337c478bd9Sstevel@tonic-gate 	nulldev,		/* probe */
3347c478bd9Sstevel@tonic-gate 	systrace_attach,	/* attach */
3357c478bd9Sstevel@tonic-gate 	systrace_detach,	/* detach */
3367c478bd9Sstevel@tonic-gate 	nodev,			/* reset */
3377c478bd9Sstevel@tonic-gate 	&systrace_cb_ops,	/* driver operations */
3387c478bd9Sstevel@tonic-gate 	NULL,			/* bus operations */
33919397407SSherry Moore 	nodev,			/* dev power */
34019397407SSherry Moore 	ddi_quiesce_not_needed,		/* quiesce */
3417c478bd9Sstevel@tonic-gate };
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate /*
3447c478bd9Sstevel@tonic-gate  * Module linkage information for the kernel.
3457c478bd9Sstevel@tonic-gate  */
3467c478bd9Sstevel@tonic-gate static struct modldrv modldrv = {
3477c478bd9Sstevel@tonic-gate 	&mod_driverops,		/* module type (this is a pseudo driver) */
3487c478bd9Sstevel@tonic-gate 	"System Call Tracing",	/* name of module */
3497c478bd9Sstevel@tonic-gate 	&systrace_ops,		/* driver ops */
3507c478bd9Sstevel@tonic-gate };
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
3537c478bd9Sstevel@tonic-gate 	MODREV_1,
3547c478bd9Sstevel@tonic-gate 	(void *)&modldrv,
3557c478bd9Sstevel@tonic-gate 	NULL
3567c478bd9Sstevel@tonic-gate };
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate int
_init(void)3597c478bd9Sstevel@tonic-gate _init(void)
3607c478bd9Sstevel@tonic-gate {
3617c478bd9Sstevel@tonic-gate 	return (mod_install(&modlinkage));
3627c478bd9Sstevel@tonic-gate }
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)3657c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
3667c478bd9Sstevel@tonic-gate {
3677c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
3687c478bd9Sstevel@tonic-gate }
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate int
_fini(void)3717c478bd9Sstevel@tonic-gate _fini(void)
3727c478bd9Sstevel@tonic-gate {
3737c478bd9Sstevel@tonic-gate 	return (mod_remove(&modlinkage));
3747c478bd9Sstevel@tonic-gate }
375