]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/cddl/dev/dtrace/dtrace_test.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / sys / cddl / dev / dtrace / dtrace_test.c
1 /*-
2  * Copyright 2008 John Birrell <jb@FreeBSD.org>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  * 
13  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  *
27  */
28 #include "opt_kdtrace.h"
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);