xref: /freebsd/sys/sys/dtrace_bsd.h (revision aa0a1e58)
1 /*-
2  * Copyright (c) 2007-2008 John Birrell (jb@freebsd.org)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
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 struct reg;
41 
42 /*
43  * Cyclic clock function type definition used to hook the cyclic
44  * subsystem into the appropriate timer interrupt.
45  */
46 typedef	void (*cyclic_clock_func_t)(struct trapframe *);
47 
48 /*
49  * These external variables are actually machine-dependent, so
50  * they might not actually exist.
51  *
52  * Defining them here avoids a proliferation of header files.
53  */
54 extern cyclic_clock_func_t     cyclic_clock_func[];
55 
56 /*
57  * The dtrace module handles traps that occur during a DTrace probe.
58  * This type definition is used in the trap handler to provide a
59  * hook for the dtrace module to register it's handler with.
60  */
61 typedef int (*dtrace_trap_func_t)(struct trapframe *, u_int);
62 
63 int	dtrace_trap(struct trapframe *, u_int);
64 
65 extern dtrace_trap_func_t	dtrace_trap_func;
66 
67 /* Used by the machine dependent trap() code. */
68 typedef	int (*dtrace_invop_func_t)(uintptr_t, uintptr_t *, uintptr_t);
69 typedef void (*dtrace_doubletrap_func_t)(void);
70 
71 /* Global variables in trap.c */
72 extern	dtrace_invop_func_t	dtrace_invop_func;
73 extern	dtrace_doubletrap_func_t	dtrace_doubletrap_func;
74 
75 /* Pid provider hooks */
76 typedef int (*dtrace_fasttrap_probe_ptr_t)(struct reg *);
77 extern	dtrace_fasttrap_probe_ptr_t	dtrace_fasttrap_probe_ptr;
78 typedef int (*dtrace_pid_probe_ptr_t)(struct reg *);
79 extern	dtrace_pid_probe_ptr_t	dtrace_pid_probe_ptr;
80 typedef int (*dtrace_return_probe_ptr_t)(struct reg *);
81 extern	dtrace_return_probe_ptr_t	dtrace_return_probe_ptr;
82 
83 /* Virtual time hook function type. */
84 typedef	void (*dtrace_vtime_switch_func_t)(struct thread *);
85 
86 extern int			dtrace_vtime_active;
87 extern dtrace_vtime_switch_func_t	dtrace_vtime_switch_func;
88 
89 /* The fasttrap module hooks into the fork, exit and exit. */
90 typedef void (*dtrace_fork_func_t)(struct proc *, struct proc *);
91 typedef void (*dtrace_execexit_func_t)(struct proc *);
92 
93 /* Global variable in kern_fork.c */
94 extern dtrace_fork_func_t	dtrace_fasttrap_fork;
95 
96 /* Global variable in kern_exec.c */
97 extern dtrace_execexit_func_t	dtrace_fasttrap_exec;
98 
99 /* Global variable in kern_exit.c */
100 extern dtrace_execexit_func_t	dtrace_fasttrap_exit;
101 
102 /* The dtmalloc provider hooks into malloc. */
103 typedef	void (*dtrace_malloc_probe_func_t)(u_int32_t, uintptr_t arg0,
104     uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4);
105 
106 extern dtrace_malloc_probe_func_t   dtrace_malloc_probe;
107 
108 /* dtnfsclient NFSv3 access cache provider hooks. */
109 typedef void (*dtrace_nfsclient_accesscache_flush_probe_func_t)(uint32_t,
110     struct vnode *);
111 extern dtrace_nfsclient_accesscache_flush_probe_func_t
112     dtrace_nfsclient_accesscache_flush_done_probe;
113 
114 typedef void (*dtrace_nfsclient_accesscache_get_probe_func_t)(uint32_t,
115     struct vnode *, uid_t, uint32_t);
116 extern dtrace_nfsclient_accesscache_get_probe_func_t
117     dtrace_nfsclient_accesscache_get_hit_probe,
118     dtrace_nfsclient_accesscache_get_miss_probe;
119 
120 typedef void (*dtrace_nfsclient_accesscache_load_probe_func_t)(uint32_t,
121     struct vnode *, uid_t, uint32_t, int);
122 extern dtrace_nfsclient_accesscache_load_probe_func_t
123     dtrace_nfsclient_accesscache_load_done_probe;
124 
125 /* dtnfsclient NFSv[23] attribute cache provider hooks. */
126 typedef void (*dtrace_nfsclient_attrcache_flush_probe_func_t)(uint32_t,
127     struct vnode *);
128 extern dtrace_nfsclient_attrcache_flush_probe_func_t
129     dtrace_nfsclient_attrcache_flush_done_probe;
130 
131 typedef void (*dtrace_nfsclient_attrcache_get_hit_probe_func_t)(uint32_t,
132     struct vnode *, struct vattr *);
133 extern dtrace_nfsclient_attrcache_get_hit_probe_func_t
134     dtrace_nfsclient_attrcache_get_hit_probe;
135 
136 typedef void (*dtrace_nfsclient_attrcache_get_miss_probe_func_t)(uint32_t,
137     struct vnode *);
138 extern dtrace_nfsclient_attrcache_get_miss_probe_func_t
139     dtrace_nfsclient_attrcache_get_miss_probe;
140 
141 typedef void (*dtrace_nfsclient_attrcache_load_probe_func_t)(uint32_t,
142     struct vnode *, struct vattr *, int);
143 extern dtrace_nfsclient_attrcache_load_probe_func_t
144     dtrace_nfsclient_attrcache_load_done_probe;
145 
146 /* dtnfsclient NFSv[23] RPC provider hooks. */
147 typedef void (*dtrace_nfsclient_nfs23_start_probe_func_t)(uint32_t,
148     struct vnode *, struct mbuf *, struct ucred *, int);
149 extern dtrace_nfsclient_nfs23_start_probe_func_t
150     dtrace_nfsclient_nfs23_start_probe;
151 
152 typedef void (*dtrace_nfsclient_nfs23_done_probe_func_t)(uint32_t,
153     struct vnode *, struct mbuf *, struct ucred *, int, int);
154 extern dtrace_nfsclient_nfs23_done_probe_func_t
155     dtrace_nfsclient_nfs23_done_probe;
156 
157 /*
158  * Functions which allow the dtrace module to check that the kernel
159  * hooks have been compiled with sufficient space for it's private
160  * structures.
161  */
162 size_t	kdtrace_proc_size(void);
163 size_t	kdtrace_thread_size(void);
164 
165 /*
166  * OpenSolaris compatible time functions returning nanoseconds.
167  * On OpenSolaris these return hrtime_t which we define as uint64_t.
168  */
169 uint64_t	dtrace_gethrtime(void);
170 uint64_t	dtrace_gethrestime(void);
171 
172 #endif /* _SYS_DTRACE_BSD_H */
173