xref: /freebsd/sys/sys/dtrace_bsd.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
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  * This file contains BSD shims for Sun's DTrace code.
29  */
30 
31 #ifndef _SYS_DTRACE_BSD_H
32 #define	_SYS_DTRACE_BSD_H
33 
34 /* Forward definitions: */
35 struct mbuf;
36 struct trapframe;
37 struct thread;
38 struct vattr;
39 struct vnode;
40 
41 int dtrace_trap(struct trapframe *, u_int);
42 
43 /*
44  * The dtrace module handles traps that occur during a DTrace probe.
45  * This type definition is used in the trap handler to provide a
46  * hook for the dtrace module to register its handler with.
47  */
48 typedef int (*dtrace_trap_func_t)(struct trapframe *, u_int);
49 extern dtrace_trap_func_t	dtrace_trap_func;
50 
51 /*
52  * A hook which removes active FBT probes before executing the double fault
53  * handler. We want to ensure that DTrace doesn't trigger another trap, which
54  * would result in a reset.
55  */
56 typedef void (*dtrace_doubletrap_func_t)(void);
57 extern	dtrace_doubletrap_func_t	dtrace_doubletrap_func;
58 
59 /* Pid provider hooks */
60 typedef int (*dtrace_pid_probe_ptr_t)(struct trapframe *);
61 extern	dtrace_pid_probe_ptr_t	dtrace_pid_probe_ptr;
62 typedef int (*dtrace_return_probe_ptr_t)(struct trapframe *);
63 extern	dtrace_return_probe_ptr_t	dtrace_return_probe_ptr;
64 
65 /* Virtual time hook function type. */
66 typedef	void (*dtrace_vtime_switch_func_t)(struct thread *);
67 
68 extern int			dtrace_vtime_active;
69 extern dtrace_vtime_switch_func_t	dtrace_vtime_switch_func;
70 
71 /* The fasttrap module hooks into the fork, exit and exit. */
72 typedef void (*dtrace_fork_func_t)(struct proc *, struct proc *);
73 typedef void (*dtrace_execexit_func_t)(struct proc *);
74 
75 /* Global variable in kern_fork.c */
76 extern dtrace_fork_func_t	dtrace_fasttrap_fork;
77 
78 /* Global variable in kern_exec.c */
79 extern dtrace_execexit_func_t	dtrace_fasttrap_exec;
80 
81 /* Global variable in kern_exit.c */
82 extern dtrace_execexit_func_t	dtrace_fasttrap_exit;
83 
84 /* The dtmalloc provider hooks into malloc. */
85 typedef	void (*dtrace_malloc_probe_func_t)(u_int32_t, uintptr_t arg0,
86     uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4);
87 
88 extern dtrace_malloc_probe_func_t   dtrace_malloc_probe;
89 
90 /* dtnfsclient NFSv[34] access cache provider hooks. */
91 typedef void (*dtrace_nfsclient_accesscache_flush_probe_func_t)(uint32_t,
92     struct vnode *);
93 extern dtrace_nfsclient_accesscache_flush_probe_func_t
94     dtrace_nfsclient_accesscache_flush_done_probe;
95 extern dtrace_nfsclient_accesscache_flush_probe_func_t
96     dtrace_nfscl_accesscache_flush_done_probe;
97 
98 typedef void (*dtrace_nfsclient_accesscache_get_probe_func_t)(uint32_t,
99     struct vnode *, uid_t, uint32_t);
100 extern dtrace_nfsclient_accesscache_get_probe_func_t
101     dtrace_nfsclient_accesscache_get_hit_probe,
102     dtrace_nfsclient_accesscache_get_miss_probe;
103 extern dtrace_nfsclient_accesscache_get_probe_func_t
104     dtrace_nfscl_accesscache_get_hit_probe,
105     dtrace_nfscl_accesscache_get_miss_probe;
106 
107 typedef void (*dtrace_nfsclient_accesscache_load_probe_func_t)(uint32_t,
108     struct vnode *, uid_t, uint32_t, int);
109 extern dtrace_nfsclient_accesscache_load_probe_func_t
110     dtrace_nfsclient_accesscache_load_done_probe;
111 extern dtrace_nfsclient_accesscache_load_probe_func_t
112     dtrace_nfscl_accesscache_load_done_probe;
113 
114 /* dtnfsclient NFSv[234] attribute cache provider hooks. */
115 typedef void (*dtrace_nfsclient_attrcache_flush_probe_func_t)(uint32_t,
116     struct vnode *);
117 extern dtrace_nfsclient_attrcache_flush_probe_func_t
118     dtrace_nfsclient_attrcache_flush_done_probe;
119 extern dtrace_nfsclient_attrcache_flush_probe_func_t
120     dtrace_nfscl_attrcache_flush_done_probe;
121 
122 typedef void (*dtrace_nfsclient_attrcache_get_hit_probe_func_t)(uint32_t,
123     struct vnode *, struct vattr *);
124 extern dtrace_nfsclient_attrcache_get_hit_probe_func_t
125     dtrace_nfsclient_attrcache_get_hit_probe;
126 extern dtrace_nfsclient_attrcache_get_hit_probe_func_t
127     dtrace_nfscl_attrcache_get_hit_probe;
128 
129 typedef void (*dtrace_nfsclient_attrcache_get_miss_probe_func_t)(uint32_t,
130     struct vnode *);
131 extern dtrace_nfsclient_attrcache_get_miss_probe_func_t
132     dtrace_nfsclient_attrcache_get_miss_probe;
133 extern dtrace_nfsclient_attrcache_get_miss_probe_func_t
134     dtrace_nfscl_attrcache_get_miss_probe;
135 
136 typedef void (*dtrace_nfsclient_attrcache_load_probe_func_t)(uint32_t,
137     struct vnode *, struct vattr *, int);
138 extern dtrace_nfsclient_attrcache_load_probe_func_t
139     dtrace_nfsclient_attrcache_load_done_probe;
140 extern dtrace_nfsclient_attrcache_load_probe_func_t
141     dtrace_nfscl_attrcache_load_done_probe;
142 
143 /* dtnfsclient NFSv[234] 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 extern dtrace_nfsclient_nfs23_start_probe_func_t
149     dtrace_nfscl_nfs234_start_probe;
150 
151 typedef void (*dtrace_nfsclient_nfs23_done_probe_func_t)(uint32_t,
152     struct vnode *, struct mbuf *, struct ucred *, int, int);
153 extern dtrace_nfsclient_nfs23_done_probe_func_t
154     dtrace_nfsclient_nfs23_done_probe;
155 extern dtrace_nfsclient_nfs23_done_probe_func_t
156     dtrace_nfscl_nfs234_done_probe;
157 
158 /*
159  * Functions which allow the dtrace module to check that the kernel
160  * hooks have been compiled with sufficient space for it's private
161  * structures.
162  */
163 size_t	kdtrace_proc_size(void);
164 size_t	kdtrace_thread_size(void);
165 
166 void	kdtrace_proc_ctor(struct proc *p);
167 void	kdtrace_proc_dtor(struct proc *p);
168 void	kdtrace_thread_ctor(struct thread *td);
169 void	kdtrace_thread_dtor(struct thread *td);
170 
171 /*
172  * OpenSolaris compatible time functions returning nanoseconds.
173  * On OpenSolaris these return hrtime_t which we define as uint64_t.
174  */
175 uint64_t	dtrace_gethrtime(void);
176 uint64_t	dtrace_gethrestime(void);
177 
178 #endif /* _SYS_DTRACE_BSD_H */
179