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