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