1 /* $NetBSD: prototype.c,v 1.4 2016/04/09 15:18:48 riastradh Exp $ */
2
3 /*-
4 * Copyright (c) 2015 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __RCSID("$NetBSD: prototype.c,v 1.4 2016/04/09 15:18:48 riastradh Exp $");
31
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/conf.h>
35 #include <sys/dtrace.h>
36 #include <sys/module.h>
37 #include <sys/systm.h>
38
39 static dtrace_provider_id_t prototype_id;
40
41 static void
prototype_enable(void * arg,dtrace_id_t id,void * parg)42 prototype_enable(void *arg, dtrace_id_t id, void *parg)
43 {
44 /* Enable the probe for id. */
45 }
46
47 static void
prototype_disable(void * arg,dtrace_id_t id,void * parg)48 prototype_disable(void *arg, dtrace_id_t id, void *parg)
49 {
50 /* Disable the probe for id. */
51 }
52
53 static void
prototype_getargdesc(void * arg,dtrace_id_t id,void * parg,dtrace_argdesc_t * desc)54 prototype_getargdesc(void *arg, dtrace_id_t id, void *parg,
55 dtrace_argdesc_t *desc)
56 {
57 /* Get the argument descriptions for the probe id. */
58 }
59
60 static uint64_t
prototype_getargval(void * arg,dtrace_id_t id,void * parg,int argno,int aframes)61 prototype_getargval(void *arg, dtrace_id_t id, void *parg, int argno,
62 int aframes)
63 {
64 /* Get the value for the argno'th argument to the probe id. */
65 }
66
67 static void
prototype_provide(void * arg,const dtrace_probedesc_t * desc)68 prototype_provide(void *arg, const dtrace_probedesc_t *desc)
69 {
70 /*
71 * Create all probes for this provider. Cookie passed to
72 * dtrace_probe_create will be passed on to prototype_destroy.
73 */
74 }
75
76 static void
prototype_destroy(void * arg,dtrace_id_t id,void * parg)77 prototype_destroy(void *arg, dtrace_id_t id, void *parg)
78 {
79 /*
80 * Destroy a probe for this provider. parg is cookie that was
81 * passed to dtrace_probe_create for this probe.
82 */
83 }
84
85 static dtrace_pattr_t prototype_attr = {
86 /* provider attributes */
87 { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
88 /* module attributes */
89 { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
90 /* function attributes */
91 { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
92 /* name attributes */
93 { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
94 /* arguments attributes */
95 { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
96 };
97
98 static dtrace_pops_t prototype_pops = {
99 prototype_provide,
100 NULL, /* provide_module (NYI) */
101 prototype_enable,
102 prototype_disable,
103 NULL, /* suspend (NYI) */
104 NULL, /* resume (NYI) */
105 prototype_getargdesc, /* optional */
106 prototype_getargval, /* optional */
107 NULL, /* usermode permissions check */
108 prototype_destroy,
109 };
110
111 static int
prototype_init(void)112 prototype_init(void)
113 {
114 int error;
115
116 /* Set up any necessary state, or fail. */
117
118 /* Register the dtrace provider. */
119 KASSERT(prototype_id == 0);
120 error = dtrace_register("prototype", &prototype_attr, DTRACE_PRIV_USER,
121 NULL, &prototype_pops, NULL, &prototype_id);
122 if (error) {
123 printf("dtrace_prototype: failed to register dtrace provider"
124 ": %d\n", error);
125 goto fail0;
126 }
127 KASSERT(prototype_id != 0);
128
129 /* Success! */
130 return 0;
131
132 fail0: KASSERT(error);
133 return error;
134 }
135
136 static int
prototype_fini(void)137 prototype_fini(void)
138 {
139 int error;
140
141 /*
142 * Deregister the dtrace provider, unless we already did but
143 * something below failed.
144 */
145 if (prototype_id != 0) {
146 error = dtrace_unregister(prototype_id);
147 if (error) {
148 printf("dtrace prototype"
149 ": failed to unregister dtrace provider: %d\n",
150 error);
151 return error;
152 }
153 prototype_id = 0;
154 }
155
156 /* Tear down any necessary state, or fail. */
157
158 /* Success! */
159 return 0;
160 }
161
162 static int
dtrace_prototype_modcmd(modcmd_t cmd,void * data)163 dtrace_prototype_modcmd(modcmd_t cmd, void *data)
164 {
165
166 switch (cmd) {
167 case MODULE_CMD_INIT:
168 return prototype_init();
169 case MODULE_CMD_FINI:
170 return prototype_fini();
171 case MODULE_CMD_AUTOUNLOAD:
172 if (prototype_users)
173 return EBUSY;
174 return 0;
175 default:
176 return ENOTTY;
177 }
178 }
179
180 MODULE(MODULE_CLASS_MISC, dtrace_prototype, "dtrace");
181