1 /* $NetBSD: dtrace_test.c,v 1.3 2018/05/28 21:05:03 chs Exp $ */ 2 3 /*- 4 * Copyright 2008 John Birrell <jb@FreeBSD.org> 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * $FreeBSD: head/sys/cddl/dev/dtrace/dtrace_test.c 258622 2013-11-26 08:46:27Z avg $ 28 * 29 */ 30 #include <sys/cdefs.h> 31 #include <sys/types.h> 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 35 #include <sys/conf.h> 36 #include <sys/kernel.h> 37 #include <sys/module.h> 38 #include <sys/sdt.h> 39 #include <sys/sysctl.h> 40 #include <sys/vnode.h> 41 42 SDT_PROVIDER_DEFINE(test); 43 44 SDT_PROBE_DEFINE7(test, , , sdttest, "int", "int", "int", "int", "int", 45 "int", "int"); 46 47 /* 48 * These are variables that the DTrace test suite references in the 49 * Solaris kernel. We define them here so that the tests function 50 * unaltered. 51 */ 52 int kmem_flags; 53 54 typedef struct vnode vnode_t; 55 vnode_t dummy; 56 vnode_t *rootvp = &dummy; 57 58 /* 59 * Test SDT probes with more than 5 arguments. On amd64, such probes require 60 * special handling since only the first 5 arguments will be passed to 61 * dtrace_probe() in registers; the rest must be fetched off the stack. 62 */ 63 static int 64 dtrace_test_sdttest(SYSCTL_HANDLER_ARGS) 65 { 66 int val, error; 67 68 val = 0; 69 error = sysctl_handle_int(oidp, &val, 0, req); 70 if (error || req->newptr == NULL) 71 return (error); 72 else if (val == 0) 73 return (0); 74 75 SDT_PROBE7(test, , , sdttest, 1, 2, 3, 4, 5, 6, 7); 76 77 return (error); 78 } 79 80 static SYSCTL_NODE(_debug, OID_AUTO, dtracetest, CTLFLAG_RD, 0, ""); 81 82 SYSCTL_PROC(_debug_dtracetest, OID_AUTO, sdttest, CTLTYPE_INT | CTLFLAG_RW, 83 NULL, 0, dtrace_test_sdttest, "I", "Trigger the SDT test probe"); 84 85 static int 86 dtrace_test_modevent(module_t mod, int type, void *data) 87 { 88 int error = 0; 89 90 switch (type) { 91 case MOD_LOAD: 92 break; 93 94 case MOD_UNLOAD: 95 break; 96 97 case MOD_SHUTDOWN: 98 break; 99 100 default: 101 error = EOPNOTSUPP; 102 break; 103 104 } 105 return (error); 106 } 107 108 DEV_MODULE(dtrace_test, dtrace_test_modevent, NULL); 109 MODULE_VERSION(dtrace_test, 1); 110 MODULE_DEPEND(dtrace_test, dtraceall, 1, 1, 1); 111