FreeBSD kernel kern code
kern_dtrace.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2007-2008 John Birrell <jb@FreeBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD$");
31
32#include "opt_kdb.h"
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/eventhandler.h>
37#include <sys/kdb.h>
38#include <sys/kernel.h>
39#include <sys/malloc.h>
40#include <sys/proc.h>
41#include <sys/dtrace_bsd.h>
42#include <sys/sysctl.h>
43#include <sys/sysent.h>
44
45#define KDTRACE_PROC_SIZE 64
46#define KDTRACE_THREAD_SIZE 256
47
48FEATURE(kdtrace_hooks,
49 "Kernel DTrace hooks which are required to load DTrace kernel modules");
50
51static MALLOC_DEFINE(M_KDTRACE, "kdtrace", "DTrace hooks");
52
53/* Hooks used in the machine-dependent trap handlers. */
54dtrace_trap_func_t dtrace_trap_func;
55dtrace_doubletrap_func_t dtrace_doubletrap_func;
56dtrace_pid_probe_ptr_t dtrace_pid_probe_ptr;
57dtrace_return_probe_ptr_t dtrace_return_probe_ptr;
58
59bool __read_frequently systrace_enabled;
60systrace_probe_func_t systrace_probe_func;
61
62/* Return the DTrace process data size compiled in the kernel hooks. */
63size_t
65{
66
67 return (KDTRACE_PROC_SIZE);
68}
69
70void
71kdtrace_proc_ctor(struct proc *p)
72{
73
74 p->p_dtrace = malloc(KDTRACE_PROC_SIZE, M_KDTRACE, M_WAITOK|M_ZERO);
75}
76
77void
78kdtrace_proc_dtor(struct proc *p)
79{
80
81 free(p->p_dtrace, M_KDTRACE);
82 p->p_dtrace = NULL;
83}
84
85/* Return the DTrace thread data size compiled in the kernel hooks. */
86size_t
88{
89
90 return (KDTRACE_THREAD_SIZE);
91}
92
93void
94kdtrace_thread_ctor(struct thread *td)
95{
96
97 td->td_dtrace = malloc(KDTRACE_THREAD_SIZE, M_KDTRACE, M_WAITOK|M_ZERO);
98}
99
100void
101kdtrace_thread_dtor(struct thread *td)
102{
103
104 free(td->td_dtrace, M_KDTRACE);
105 td->td_dtrace = NULL;
106}
dtrace_pid_probe_ptr_t dtrace_pid_probe_ptr
Definition: kern_dtrace.c:56
void kdtrace_proc_dtor(struct proc *p)
Definition: kern_dtrace.c:78
void kdtrace_proc_ctor(struct proc *p)
Definition: kern_dtrace.c:71
void kdtrace_thread_dtor(struct thread *td)
Definition: kern_dtrace.c:101
size_t kdtrace_proc_size()
Definition: kern_dtrace.c:64
FEATURE(kdtrace_hooks, "Kernel DTrace hooks which are required to load DTrace kernel modules")
size_t kdtrace_thread_size()
Definition: kern_dtrace.c:87
systrace_probe_func_t systrace_probe_func
Definition: kern_dtrace.c:60
#define KDTRACE_THREAD_SIZE
Definition: kern_dtrace.c:46
dtrace_doubletrap_func_t dtrace_doubletrap_func
Definition: kern_dtrace.c:55
__FBSDID("$FreeBSD$")
dtrace_return_probe_ptr_t dtrace_return_probe_ptr
Definition: kern_dtrace.c:57
static MALLOC_DEFINE(M_KDTRACE, "kdtrace", "DTrace hooks")
bool __read_frequently systrace_enabled
Definition: kern_dtrace.c:59
dtrace_trap_func_t dtrace_trap_func
Definition: kern_dtrace.c:54
void kdtrace_thread_ctor(struct thread *td)
Definition: kern_dtrace.c:94
#define KDTRACE_PROC_SIZE
Definition: kern_dtrace.c:45
void *() malloc(size_t size, struct malloc_type *mtp, int flags)
Definition: kern_malloc.c:632
void free(void *addr, struct malloc_type *mtp)
Definition: kern_malloc.c:907