FreeBSD/Linux Kernel Cross Reference
sys/sys/dtrace_bsd.h
1 /* $NetBSD: dtrace_bsd.h,v 1.9 2018/04/19 21:19:07 christos Exp $ */
2
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 * $FreeBSD: src/sys/sys/dtrace_bsd.h,v 1.3.2.1 2009/08/03 08:13:06 kensmith Exp $
29 *
30 * This file contains BSD shims for Sun's DTrace code.
31 */
32
33 #ifndef _SYS_DTRACE_BSD_H
34 #define _SYS_DTRACE_BSD_H
35
36 #if defined(_KERNEL_OPT)
37 #include "opt_dtrace.h"
38 #endif
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/kmem.h>
44 #include <sys/proc.h>
45
46 /* Forward definitions: */
47 struct mbuf;
48 struct trapframe;
49 struct lwp;
50 struct vattr;
51 struct vnode;
52 struct ucred;
53
54 /*
55 * Cyclic clock function type definition used to hook the cyclic
56 * subsystem into the appropriate timer interrupt.
57 */
58 typedef void (*cyclic_clock_func_t)(struct clockframe *);
59 extern cyclic_clock_func_t cyclic_clock_func[];
60
61 /*
62 * The dtrace module handles traps that occur during a DTrace probe.
63 * This type definition is used in the trap handler to provide a
64 * hook for the dtrace module to register its handler with.
65 */
66 typedef int (*dtrace_trap_func_t)(struct trapframe *, u_int);
67
68 int dtrace_trap(struct trapframe *, u_int);
69
70 extern dtrace_trap_func_t dtrace_trap_func;
71
72 /* Used by the machine dependent trap() code. */
73 typedef int (*dtrace_invop_func_t)(uintptr_t, uintptr_t *, uintptr_t);
74 typedef void (*dtrace_doubletrap_func_t)(void);
75
76 /* Global variables in trap.c */
77 extern dtrace_invop_func_t dtrace_invop_func;
78 extern dtrace_doubletrap_func_t dtrace_doubletrap_func;
79
80 /* Virtual time hook function type. */
81 typedef void (*dtrace_vtime_switch_func_t)(struct lwp *);
82
83 extern int dtrace_vtime_active;
84 extern dtrace_vtime_switch_func_t dtrace_vtime_switch_func;
85
86 /* The fasttrap module hooks into the fork, exit and exit. */
87 typedef void (*dtrace_fork_func_t)(struct proc *, struct proc *);
88 typedef void (*dtrace_execexit_func_t)(struct proc *);
89
90 /* Global variable in kern_fork.c */
91 extern dtrace_fork_func_t dtrace_fasttrap_fork;
92
93 /* Global variable in kern_exec.c */
94 extern dtrace_execexit_func_t dtrace_fasttrap_exec;
95
96 /* Global variable in kern_exit.c */
97 extern dtrace_execexit_func_t dtrace_fasttrap_exit;
98
99 /* The dtmalloc provider hooks into malloc. */
100 typedef void (*dtrace_malloc_probe_func_t)(u_int32_t, uintptr_t arg0,
101 uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4);
102
103 extern dtrace_malloc_probe_func_t dtrace_malloc_probe;
104
105 /* dtnfsclient NFSv3 access cache provider hooks. */
106 typedef void (*dtrace_nfsclient_accesscache_flush_probe_func_t)(uint32_t,
107 struct vnode *);
108 extern dtrace_nfsclient_accesscache_flush_probe_func_t
109 dtrace_nfsclient_accesscache_flush_done_probe;
110
111 typedef void (*dtrace_nfsclient_accesscache_get_probe_func_t)(uint32_t,
112 struct vnode *, uid_t, uint32_t);
113 extern dtrace_nfsclient_accesscache_get_probe_func_t
114 dtrace_nfsclient_accesscache_get_hit_probe,
115 dtrace_nfsclient_accesscache_get_miss_probe;
116
117 typedef void (*dtrace_nfsclient_accesscache_load_probe_func_t)(uint32_t,
118 struct vnode *, uid_t, uint32_t, int);
119 extern dtrace_nfsclient_accesscache_load_probe_func_t
120 dtrace_nfsclient_accesscache_load_done_probe;
121
122 /* dtnfsclient NFSv[23] attribute cache provider hooks. */
123 typedef void (*dtrace_nfsclient_attrcache_flush_probe_func_t)(uint32_t,
124 struct vnode *);
125 extern dtrace_nfsclient_attrcache_flush_probe_func_t
126 dtrace_nfsclient_attrcache_flush_done_probe;
127
128 typedef void (*dtrace_nfsclient_attrcache_get_hit_probe_func_t)(uint32_t,
129 struct vnode *, struct vattr *);
130 extern dtrace_nfsclient_attrcache_get_hit_probe_func_t
131 dtrace_nfsclient_attrcache_get_hit_probe;
132
133 typedef void (*dtrace_nfsclient_attrcache_get_miss_probe_func_t)(uint32_t,
134 struct vnode *);
135 extern dtrace_nfsclient_attrcache_get_miss_probe_func_t
136 dtrace_nfsclient_attrcache_get_miss_probe;
137
138 typedef void (*dtrace_nfsclient_attrcache_load_probe_func_t)(uint32_t,
139 struct vnode *, struct vattr *, int);
140 extern dtrace_nfsclient_attrcache_load_probe_func_t
141 dtrace_nfsclient_attrcache_load_done_probe;
142
143 /* dtnfsclient NFSv[23] RPC provider hooks. */
144 typedef void (*dtrace_nfsclient_nfs23_start_probe_func_t)(uint32_t,
145 struct vnode *, struct mbuf *, struct ucred *, int);
146 extern dtrace_nfsclient_nfs23_start_probe_func_t
147 dtrace_nfsclient_nfs23_start_probe;
148
149 typedef void (*dtrace_nfsclient_nfs23_done_probe_func_t)(uint32_t,
150 struct vnode *, struct mbuf *, struct ucred *, int, int);
151 extern dtrace_nfsclient_nfs23_done_probe_func_t
152 dtrace_nfsclient_nfs23_done_probe;
153
154 /*
155 * OpenSolaris compatible time functions returning nanoseconds.
156 * On OpenSolaris these return hrtime_t which we define as uint64_t.
157 */
158 uint64_t dtrace_gethrtime(void);
159 uint64_t dtrace_gethrestime(void);
160
161 /* sizes based on DTrace structure requirements */
162 #define KDTRACE_PROC_SIZE 64
163 #define KDTRACE_PROC_ZERO 8
164 #define KDTRACE_THREAD_SIZE 256
165 #define KDTRACE_THREAD_ZERO 64
166
167 /*
168 * Functions for managing the opaque DTrace memory areas for
169 * processes and lwps.
170 */
171
172 static __inline size_t kdtrace_proc_size(void);
173 static __inline void kdtrace_proc_ctor(void *, struct proc *);
174 static __inline void kdtrace_proc_dtor(void *, struct proc *);
175 static __inline size_t kdtrace_thread_size(void);
176 static __inline void kdtrace_thread_ctor(void *, struct lwp *);
177 static __inline void kdtrace_thread_dtor(void *, struct lwp *);
178
179
180 /* Return the DTrace process data size compiled in the kernel hooks. */
181 static __inline size_t
182 kdtrace_proc_size(void)
183 {
184
185 return KDTRACE_PROC_SIZE;
186 }
187
188 /* Return the DTrace thread data size compiled in the kernel hooks. */
189 static __inline size_t
190 kdtrace_thread_size(void)
191 {
192
193 return KDTRACE_THREAD_SIZE;
194 }
195
196 static __inline void
197 kdtrace_proc_ctor(void *arg, struct proc *p)
198 {
199
200 #ifdef KDTRACE_HOOKS
201 p->p_dtrace = kmem_zalloc(KDTRACE_PROC_SIZE, KM_SLEEP);
202 #endif
203 }
204
205 static __inline void
206 kdtrace_proc_dtor(void *arg, struct proc *p)
207 {
208
209 #ifdef KDTRACE_HOOKS
210 if (p->p_dtrace != NULL) {
211 kmem_free(p->p_dtrace, KDTRACE_PROC_SIZE);
212 p->p_dtrace = NULL;
213 }
214 #endif
215 }
216
217 static __inline void
218 kdtrace_thread_ctor(void *arg, struct lwp *l)
219 {
220
221 #ifdef KDTRACE_HOOKS
222 l->l_dtrace = kmem_zalloc(KDTRACE_THREAD_SIZE, KM_SLEEP);
223 #endif
224 }
225
226 static __inline void
227 kdtrace_thread_dtor(void *arg, struct lwp *l)
228 {
229
230 #ifdef KDTRACE_HOOKS
231 if (l->l_dtrace != NULL) {
232 kmem_free(l->l_dtrace, KDTRACE_THREAD_SIZE);
233 l->l_dtrace = NULL;
234 }
235 #endif
236 }
237
238 #endif /* _SYS_DTRACE_BSD_H */
Cache object: 485a5714341f1d5c8f39466beb3e49e5
|