1*b51f985dSriastradh /* $NetBSD: kern_sdt.c,v 1.4 2024/06/29 13:03:02 riastradh Exp $ */
26a9056a9Sdarran
36a9056a9Sdarran /*-
46a9056a9Sdarran * Copyright (c) 2010 The NetBSD Foundation, Inc.
56a9056a9Sdarran * All rights reserved.
66a9056a9Sdarran *
76a9056a9Sdarran * This code is derived from software contributed to The NetBSD Foundation
86a9056a9Sdarran * by CoyotePoint Systems, Inc. It was developed under contract to
96a9056a9Sdarran * CoyotePoint by Darran Hunt.
106a9056a9Sdarran *
116a9056a9Sdarran * Redistribution and use in source and binary forms, with or without
126a9056a9Sdarran * modification, are permitted provided that the following conditions
136a9056a9Sdarran * are met:
146a9056a9Sdarran * 1. Redistributions of source code must retain the above copyright
156a9056a9Sdarran * notice, this list of conditions and the following disclaimer.
166a9056a9Sdarran * 2. Redistributions in binary form must reproduce the above copyright
176a9056a9Sdarran * notice, this list of conditions and the following disclaimer in the
186a9056a9Sdarran * documentation and/or other materials provided with the distribution.
196a9056a9Sdarran *
206a9056a9Sdarran *
216a9056a9Sdarran * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
226a9056a9Sdarran * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
236a9056a9Sdarran * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
246a9056a9Sdarran * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
256a9056a9Sdarran * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
266a9056a9Sdarran * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
276a9056a9Sdarran * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
286a9056a9Sdarran * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
296a9056a9Sdarran * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
306a9056a9Sdarran * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
316a9056a9Sdarran * POSSIBILITY OF SUCH DAMAGE.
326a9056a9Sdarran */
336a9056a9Sdarran
346a9056a9Sdarran /*-
356a9056a9Sdarran * Copyright 2006-2008 John Birrell <jb@FreeBSD.org>
366a9056a9Sdarran *
376a9056a9Sdarran * Redistribution and use in source and binary forms, with or without
386a9056a9Sdarran * modification, are permitted provided that the following conditions
396a9056a9Sdarran * are met:
406a9056a9Sdarran * 1. Redistributions of source code must retain the above copyright
416a9056a9Sdarran * notice, this list of conditions and the following disclaimer.
426a9056a9Sdarran * 2. Redistributions in binary form must reproduce the above copyright
436a9056a9Sdarran * notice, this list of conditions and the following disclaimer in the
446a9056a9Sdarran * documentation and/or other materials provided with the distribution.
456a9056a9Sdarran *
466a9056a9Sdarran * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
476a9056a9Sdarran * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
486a9056a9Sdarran * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
496a9056a9Sdarran * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
506a9056a9Sdarran * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
516a9056a9Sdarran * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
526a9056a9Sdarran * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
536a9056a9Sdarran * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
546a9056a9Sdarran * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
556a9056a9Sdarran * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
566a9056a9Sdarran * SUCH DAMAGE.
576a9056a9Sdarran *
586a9056a9Sdarran * $FreeBSD: src/sys/kern/kern_sdt.c,v 1.1.4.1 2009/08/03 08:13:06 kensmith Exp $
596a9056a9Sdarran *
606a9056a9Sdarran * Backend for the Statically Defined Tracing (SDT) kernel support. This is
616a9056a9Sdarran * required to allow a module to load even though DTrace kernel support may
626a9056a9Sdarran * not be present. A module may be built with SDT probes in it.
636a9056a9Sdarran *
646a9056a9Sdarran */
65db70f181Schristos #ifdef _KERNEL_OPT
66db70f181Schristos #include "opt_dtrace.h"
67db70f181Schristos #endif
686a9056a9Sdarran
696a9056a9Sdarran #include <sys/cdefs.h>
706a9056a9Sdarran #include <sys/param.h>
716a9056a9Sdarran #include <sys/systm.h>
726a9056a9Sdarran #include <sys/sdt.h>
736a9056a9Sdarran
7488626023Sknakahara SDT_PROVIDER_DEFINE(sdt);
7588626023Sknakahara
766a9056a9Sdarran void sdt_probe_stub(u_int32_t, uintptr_t, uintptr_t,
776a9056a9Sdarran uintptr_t, uintptr_t, uintptr_t);
786a9056a9Sdarran
79db70f181Schristos __link_set_decl(sdt_providers_set, struct sdt_provider);
80db70f181Schristos __link_set_decl(sdt_probes_set, struct sdt_probe);
81db70f181Schristos __link_set_decl(sdt_argtypes_set, struct sdt_argtype);
82db70f181Schristos
836a9056a9Sdarran /*
846a9056a9Sdarran * Hook for the DTrace probe function. The 'sdt' provider will set this
856a9056a9Sdarran * to dtrace_probe when it loads.
866a9056a9Sdarran */
876a9056a9Sdarran sdt_probe_func_t sdt_probe_func = sdt_probe_stub;
886a9056a9Sdarran
896a9056a9Sdarran /*
906a9056a9Sdarran * This is a stub for probe calls in case kernel DTrace support isn't
916a9056a9Sdarran * compiled in. It should never get called because there is no DTrace
926a9056a9Sdarran * support to enable it.
936a9056a9Sdarran */
946a9056a9Sdarran void
sdt_probe_stub(u_int32_t id,uintptr_t arg0,uintptr_t arg1,uintptr_t arg2,uintptr_t arg3,uintptr_t arg4)956a9056a9Sdarran sdt_probe_stub(u_int32_t id, uintptr_t arg0, uintptr_t arg1,
966a9056a9Sdarran uintptr_t arg2, uintptr_t arg3, uintptr_t arg4)
976a9056a9Sdarran {
98db70f181Schristos struct sdt_provider * const * provider;
99db70f181Schristos struct sdt_probe * const * probe;
100db70f181Schristos struct sdt_argtype * const * argtype;
1016a9056a9Sdarran printf("%s: XXX should not be called\n", __func__);
102db70f181Schristos printf("providers: ");
103db70f181Schristos __link_set_foreach(provider, sdt_providers_set)
104db70f181Schristos printf("%s ", (*provider)->name);
105db70f181Schristos printf("\nprobes: ");
106db70f181Schristos __link_set_foreach(probe, sdt_probes_set)
107db70f181Schristos printf("%s ", (*probe)->name);
108db70f181Schristos printf("\nargtypes: ");
109db70f181Schristos __link_set_foreach(argtype, sdt_argtypes_set)
110db70f181Schristos printf("%s ", (*argtype)->type);
111db70f181Schristos printf("\n");
1126a9056a9Sdarran }
1136a9056a9Sdarran
1146a9056a9Sdarran /*
1156a9056a9Sdarran * initialize the SDT dtrace probe function
1166a9056a9Sdarran */
1176a9056a9Sdarran void
sdt_init(void * dtrace_probe)1186a9056a9Sdarran sdt_init(void *dtrace_probe)
1196a9056a9Sdarran {
1206a9056a9Sdarran
1216a9056a9Sdarran sdt_probe_func = dtrace_probe;
1226a9056a9Sdarran }
1236a9056a9Sdarran
1246a9056a9Sdarran /*
1256a9056a9Sdarran * Disable the SDT dtrace probe function
1266a9056a9Sdarran */
1276a9056a9Sdarran void
sdt_exit(void)1286a9056a9Sdarran sdt_exit(void)
1296a9056a9Sdarran {
1306a9056a9Sdarran
1316a9056a9Sdarran sdt_probe_func = sdt_probe_stub;
1326a9056a9Sdarran }
133*b51f985dSriastradh
134*b51f985dSriastradh SDT_PROBE_DEFINE1(sdt, , , set__error, "int");
135