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