1/* $NetBSD: kern_sdt.c,v 1.3 2016/04/04 03:53:25 knakahara 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#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
74SDT_PROVIDER_DEFINE(sdt);
75
76void sdt_probe_stub(u_int32_t, uintptr_t, uintptr_t,
77 uintptr_t, uintptr_t, uintptr_t);
78
79__link_set_decl(sdt_providers_set, struct sdt_provider);
80__link_set_decl(sdt_probes_set, struct sdt_probe);
81__link_set_decl(sdt_argtypes_set, struct sdt_argtype);
82
83/*
84 * Hook for the DTrace probe function. The 'sdt' provider will set this
85 * to dtrace_probe when it loads.
86 */
87sdt_probe_func_t sdt_probe_func = sdt_probe_stub;
88
89/*
90 * This is a stub for probe calls in case kernel DTrace support isn't
91 * compiled in. It should never get called because there is no DTrace
92 * support to enable it.
93 */
94void
95sdt_probe_stub(u_int32_t id, uintptr_t arg0, uintptr_t arg1,
96 uintptr_t arg2, uintptr_t arg3, uintptr_t arg4)
97{
98 struct sdt_provider * const * provider;
99 struct sdt_probe * const * probe;
100 struct sdt_argtype * const * argtype;
101 printf("%s: XXX should not be called\n", __func__);
102 printf("providers: ");
103 __link_set_foreach(provider, sdt_providers_set)
104 printf("%s ", (*provider)->name);
105 printf("\nprobes: ");
106 __link_set_foreach(probe, sdt_probes_set)
107 printf("%s ", (*probe)->name);
108 printf("\nargtypes: ");
109 __link_set_foreach(argtype, sdt_argtypes_set)
110 printf("%s ", (*argtype)->type);
111 printf("\n");
112}
113
114/*
115 * initialize the SDT dtrace probe function
116 */
117void
118sdt_init(void *dtrace_probe)
119{
120
121 sdt_probe_func = dtrace_probe;
122}
123
124/*
125 * Disable the SDT dtrace probe function
126 */
127void
128sdt_exit(void)
129{
130
131 sdt_probe_func = sdt_probe_stub;
132}
133