kern_sdt.c revision 1.1.42.1 1 /* $NetBSD: kern_sdt.c,v 1.1.42.1 2015/12/27 12:10:05 skrll Exp $ */
2
3 /*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by CoyotePoint Systems, Inc. It was developed under contract to
9 * CoyotePoint by Darran Hunt.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /*-
35 * Copyright 2006-2008 John Birrell <jb (at) FreeBSD.org>
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 *
46 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 *
58 * $FreeBSD: src/sys/kern/kern_sdt.c,v 1.1.4.1 2009/08/03 08:13:06 kensmith Exp $
59 *
60 * Backend for the Statically Defined Tracing (SDT) kernel support. This is
61 * required to allow a module to load even though DTrace kernel support may
62 * not be present. A module may be built with SDT probes in it.
63 *
64 */
65 #ifdef _KERNEL_OPT
66 #include "opt_dtrace.h"
67 #endif
68
69 #include <sys/cdefs.h>
70 #include <sys/param.h>
71 #include <sys/systm.h>
72 #include <sys/sdt.h>
73
74 void sdt_probe_stub(u_int32_t, uintptr_t, uintptr_t,
75 uintptr_t, uintptr_t, uintptr_t);
76
77 __link_set_decl(sdt_providers_set, struct sdt_provider);
78 __link_set_decl(sdt_probes_set, struct sdt_probe);
79 __link_set_decl(sdt_argtypes_set, struct sdt_argtype);
80
81 /*
82 * Hook for the DTrace probe function. The 'sdt' provider will set this
83 * to dtrace_probe when it loads.
84 */
85 sdt_probe_func_t sdt_probe_func = sdt_probe_stub;
86
87 /*
88 * This is a stub for probe calls in case kernel DTrace support isn't
89 * compiled in. It should never get called because there is no DTrace
90 * support to enable it.
91 */
92 void
93 sdt_probe_stub(u_int32_t id, uintptr_t arg0, uintptr_t arg1,
94 uintptr_t arg2, uintptr_t arg3, uintptr_t arg4)
95 {
96 struct sdt_provider * const * provider;
97 struct sdt_probe * const * probe;
98 struct sdt_argtype * const * argtype;
99 printf("%s: XXX should not be called\n", __func__);
100 printf("providers: ");
101 __link_set_foreach(provider, sdt_providers_set)
102 printf("%s ", (*provider)->name);
103 printf("\nprobes: ");
104 __link_set_foreach(probe, sdt_probes_set)
105 printf("%s ", (*probe)->name);
106 printf("\nargtypes: ");
107 __link_set_foreach(argtype, sdt_argtypes_set)
108 printf("%s ", (*argtype)->type);
109 printf("\n");
110 }
111
112 /*
113 * initialize the SDT dtrace probe function
114 */
115 void
116 sdt_init(void *dtrace_probe)
117 {
118
119 sdt_probe_func = dtrace_probe;
120 }
121
122 /*
123 * Disable the SDT dtrace probe function
124 */
125 void
126 sdt_exit(void)
127 {
128
129 sdt_probe_func = sdt_probe_stub;
130 }
131