xref: /netbsd/sys/kern/kern_sdt.c (revision 6550d01e)
1 /*	$NetBSD: kern_sdt.c,v 1.1 2010/03/01 21:10:17 darran 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@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 
66 #include <sys/cdefs.h>
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/sdt.h>
70 
71 void sdt_probe_stub(u_int32_t, uintptr_t, uintptr_t,
72 	uintptr_t, uintptr_t, uintptr_t);
73 
74 /*
75  * Hook for the DTrace probe function. The 'sdt' provider will set this
76  * to dtrace_probe when it loads.
77  */
78 sdt_probe_func_t sdt_probe_func = sdt_probe_stub;
79 
80 /*
81  * This is a stub for probe calls in case kernel DTrace support isn't
82  * compiled in. It should never get called because there is no DTrace
83  * support to enable it.
84  */
85 void
86 sdt_probe_stub(u_int32_t id, uintptr_t arg0, uintptr_t arg1,
87     uintptr_t arg2, uintptr_t arg3, uintptr_t arg4)
88 {
89 	printf("%s: XXX should not be called\n", __func__);
90 }
91 
92 /*
93  * initialize the SDT dtrace probe function
94  */
95 void
96 sdt_init(void *dtrace_probe)
97 {
98 
99 	sdt_probe_func = dtrace_probe;
100 }
101 
102 /*
103  * Disable the SDT dtrace probe function
104  */
105 void
106 sdt_exit(void)
107 {
108 
109 	sdt_probe_func = sdt_probe_stub;
110 }
111