1179064Sjb/*-
2179064Sjb * Copyright (c) 2007-2008 John Birrell (jb@freebsd.org)
3179064Sjb * All rights reserved.
4179064Sjb *
5179064Sjb * Redistribution and use in source and binary forms, with or without
6179064Sjb * modification, are permitted provided that the following conditions
7179064Sjb * are met:
8179064Sjb * 1. Redistributions of source code must retain the above copyright
9179064Sjb *    notice, this list of conditions and the following disclaimer.
10179064Sjb * 2. Redistributions in binary form must reproduce the above copyright
11179064Sjb *    notice, this list of conditions and the following disclaimer in the
12179064Sjb *    documentation and/or other materials provided with the distribution.
13179064Sjb *
14179064Sjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15179064Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16179064Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17179064Sjb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18179064Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19179064Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20179064Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21179064Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22179064Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23179064Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24179064Sjb * SUCH DAMAGE.
25179064Sjb *
26179064Sjb * $FreeBSD$
27179064Sjb *
28179064Sjb * This file contains BSD shims for Sun's DTrace code.
29179064Sjb */
30179064Sjb
31179064Sjb#ifndef _SYS_DTRACE_BSD_H
32179064Sjb#define	_SYS_DTRACE_BSD_H
33179064Sjb
34179064Sjb/* Forward definitions: */
35190293Srwatsonstruct mbuf;
36179064Sjbstruct trapframe;
37179064Sjbstruct thread;
38190380Srwatsonstruct vattr;
39190380Srwatsonstruct vnode;
40211813Srpaulostruct reg;
41238366Sgnnstruct devstat;
42238366Sgnnstruct bio;
43179064Sjb
44179064Sjb/*
45179064Sjb * The dtrace module handles traps that occur during a DTrace probe.
46179064Sjb * This type definition is used in the trap handler to provide a
47179064Sjb * hook for the dtrace module to register it's handler with.
48179064Sjb */
49179064Sjbtypedef int (*dtrace_trap_func_t)(struct trapframe *, u_int);
50179064Sjb
51179064Sjbint	dtrace_trap(struct trapframe *, u_int);
52179064Sjb
53179064Sjbextern dtrace_trap_func_t	dtrace_trap_func;
54179064Sjb
55269752Smarkj/*
56269752Smarkj * A hook which removes active FBT probes before executing the double fault
57269752Smarkj * handler. We want to ensure that DTrace doesn't trigger another trap, which
58269752Smarkj * would result in a reset.
59269752Smarkj */
60179064Sjbtypedef	int (*dtrace_invop_func_t)(uintptr_t, uintptr_t *, uintptr_t);
61179064Sjbtypedef void (*dtrace_doubletrap_func_t)(void);
62179064Sjbextern	dtrace_invop_func_t	dtrace_invop_func;
63179064Sjbextern	dtrace_doubletrap_func_t	dtrace_doubletrap_func;
64179064Sjb
65211813Srpaulo/* Pid provider hooks */
66211813Srpaulotypedef int (*dtrace_pid_probe_ptr_t)(struct reg *);
67211813Srpauloextern	dtrace_pid_probe_ptr_t	dtrace_pid_probe_ptr;
68211813Srpaulotypedef int (*dtrace_return_probe_ptr_t)(struct reg *);
69211813Srpauloextern	dtrace_return_probe_ptr_t	dtrace_return_probe_ptr;
70211813Srpaulo
71179064Sjb/* Virtual time hook function type. */
72179064Sjbtypedef	void (*dtrace_vtime_switch_func_t)(struct thread *);
73179064Sjb
74179064Sjbextern int			dtrace_vtime_active;
75179064Sjbextern dtrace_vtime_switch_func_t	dtrace_vtime_switch_func;
76179064Sjb
77179064Sjb/* The fasttrap module hooks into the fork, exit and exit. */
78179064Sjbtypedef void (*dtrace_fork_func_t)(struct proc *, struct proc *);
79179064Sjbtypedef void (*dtrace_execexit_func_t)(struct proc *);
80179064Sjb
81179064Sjb/* Global variable in kern_fork.c */
82179064Sjbextern dtrace_fork_func_t	dtrace_fasttrap_fork;
83179064Sjb
84179064Sjb/* Global variable in kern_exec.c */
85179064Sjbextern dtrace_execexit_func_t	dtrace_fasttrap_exec;
86179064Sjb
87179064Sjb/* Global variable in kern_exit.c */
88179064Sjbextern dtrace_execexit_func_t	dtrace_fasttrap_exit;
89179064Sjb
90179064Sjb/* The dtmalloc provider hooks into malloc. */
91179064Sjbtypedef	void (*dtrace_malloc_probe_func_t)(u_int32_t, uintptr_t arg0,
92179064Sjb    uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4);
93179064Sjb
94179064Sjbextern dtrace_malloc_probe_func_t   dtrace_malloc_probe;
95179064Sjb
96223280Srmacklem/* dtnfsclient NFSv[34] access cache provider hooks. */
97190380Srwatsontypedef void (*dtrace_nfsclient_accesscache_flush_probe_func_t)(uint32_t,
98190380Srwatson    struct vnode *);
99190380Srwatsonextern dtrace_nfsclient_accesscache_flush_probe_func_t
100190380Srwatson    dtrace_nfsclient_accesscache_flush_done_probe;
101223280Srmacklemextern dtrace_nfsclient_accesscache_flush_probe_func_t
102223280Srmacklem    dtrace_nfscl_accesscache_flush_done_probe;
103190380Srwatson
104190380Srwatsontypedef void (*dtrace_nfsclient_accesscache_get_probe_func_t)(uint32_t,
105190380Srwatson    struct vnode *, uid_t, uint32_t);
106190380Srwatsonextern dtrace_nfsclient_accesscache_get_probe_func_t
107190380Srwatson    dtrace_nfsclient_accesscache_get_hit_probe,
108190380Srwatson    dtrace_nfsclient_accesscache_get_miss_probe;
109223280Srmacklemextern dtrace_nfsclient_accesscache_get_probe_func_t
110223280Srmacklem    dtrace_nfscl_accesscache_get_hit_probe,
111223280Srmacklem    dtrace_nfscl_accesscache_get_miss_probe;
112190380Srwatson
113190380Srwatsontypedef void (*dtrace_nfsclient_accesscache_load_probe_func_t)(uint32_t,
114190380Srwatson    struct vnode *, uid_t, uint32_t, int);
115190380Srwatsonextern dtrace_nfsclient_accesscache_load_probe_func_t
116190380Srwatson    dtrace_nfsclient_accesscache_load_done_probe;
117223280Srmacklemextern dtrace_nfsclient_accesscache_load_probe_func_t
118223280Srmacklem    dtrace_nfscl_accesscache_load_done_probe;
119190380Srwatson
120223280Srmacklem/* dtnfsclient NFSv[234] attribute cache provider hooks. */
121190380Srwatsontypedef void (*dtrace_nfsclient_attrcache_flush_probe_func_t)(uint32_t,
122190380Srwatson    struct vnode *);
123190380Srwatsonextern dtrace_nfsclient_attrcache_flush_probe_func_t
124190380Srwatson    dtrace_nfsclient_attrcache_flush_done_probe;
125223280Srmacklemextern dtrace_nfsclient_attrcache_flush_probe_func_t
126223280Srmacklem    dtrace_nfscl_attrcache_flush_done_probe;
127190380Srwatson
128190380Srwatsontypedef void (*dtrace_nfsclient_attrcache_get_hit_probe_func_t)(uint32_t,
129190380Srwatson    struct vnode *, struct vattr *);
130190380Srwatsonextern dtrace_nfsclient_attrcache_get_hit_probe_func_t
131190380Srwatson    dtrace_nfsclient_attrcache_get_hit_probe;
132223280Srmacklemextern dtrace_nfsclient_attrcache_get_hit_probe_func_t
133223280Srmacklem    dtrace_nfscl_attrcache_get_hit_probe;
134190380Srwatson
135190380Srwatsontypedef void (*dtrace_nfsclient_attrcache_get_miss_probe_func_t)(uint32_t,
136190380Srwatson    struct vnode *);
137190380Srwatsonextern dtrace_nfsclient_attrcache_get_miss_probe_func_t
138190380Srwatson    dtrace_nfsclient_attrcache_get_miss_probe;
139223280Srmacklemextern dtrace_nfsclient_attrcache_get_miss_probe_func_t
140223280Srmacklem    dtrace_nfscl_attrcache_get_miss_probe;
141190380Srwatson
142190380Srwatsontypedef void (*dtrace_nfsclient_attrcache_load_probe_func_t)(uint32_t,
143190380Srwatson    struct vnode *, struct vattr *, int);
144190380Srwatsonextern dtrace_nfsclient_attrcache_load_probe_func_t
145190380Srwatson    dtrace_nfsclient_attrcache_load_done_probe;
146223280Srmacklemextern dtrace_nfsclient_attrcache_load_probe_func_t
147223280Srmacklem    dtrace_nfscl_attrcache_load_done_probe;
148190380Srwatson
149223280Srmacklem/* dtnfsclient NFSv[234] RPC provider hooks. */
150190380Srwatsontypedef void (*dtrace_nfsclient_nfs23_start_probe_func_t)(uint32_t,
151190293Srwatson    struct vnode *, struct mbuf *, struct ucred *, int);
152190293Srwatsonextern dtrace_nfsclient_nfs23_start_probe_func_t
153190293Srwatson    dtrace_nfsclient_nfs23_start_probe;
154223280Srmacklemextern dtrace_nfsclient_nfs23_start_probe_func_t
155223280Srmacklem    dtrace_nfscl_nfs234_start_probe;
156190380Srwatson
157190380Srwatsontypedef void (*dtrace_nfsclient_nfs23_done_probe_func_t)(uint32_t,
158190380Srwatson    struct vnode *, struct mbuf *, struct ucred *, int, int);
159190293Srwatsonextern dtrace_nfsclient_nfs23_done_probe_func_t
160190293Srwatson    dtrace_nfsclient_nfs23_done_probe;
161223280Srmacklemextern dtrace_nfsclient_nfs23_done_probe_func_t
162223280Srmacklem    dtrace_nfscl_nfs234_done_probe;
163190293Srwatson
164238366Sgnn/* IO Provider hooks, really hook into devstat */
165238366Sgnntypedef void (*dtrace_io_start_probe_func_t)(uint32_t, struct bio *,
166238366Sgnn					     struct devstat *);
167238366Sgnnextern dtrace_io_start_probe_func_t dtrace_io_start_probe;
168238366Sgnn
169238366Sgnntypedef void (*dtrace_io_done_probe_func_t)(uint32_t, struct bio *,
170238366Sgnn					    struct devstat *);
171238366Sgnnextern dtrace_io_done_probe_func_t dtrace_io_done_probe;
172238366Sgnn
173238366Sgnntypedef void (*dtrace_io_wait_start_probe_func_t)(uint32_t, uintptr_t *,
174238366Sgnn						  struct devstat *);
175238366Sgnnextern dtrace_io_wait_start_probe_func_t dtrace_io_wait_start_probe;
176238366Sgnn
177238366Sgnntypedef void (*dtrace_io_wait_done_probe_func_t)(uint32_t, uintptr_t *,
178238366Sgnn						 struct devstat *);
179238366Sgnnextern dtrace_io_wait_done_probe_func_t dtrace_io_wait_done_probe;
180238366Sgnn
181179064Sjb/*
182179064Sjb * Functions which allow the dtrace module to check that the kernel
183179064Sjb * hooks have been compiled with sufficient space for it's private
184179064Sjb * structures.
185179064Sjb */
186179064Sjbsize_t	kdtrace_proc_size(void);
187179064Sjbsize_t	kdtrace_thread_size(void);
188179064Sjb
189179064Sjb/*
190179064Sjb * OpenSolaris compatible time functions returning nanoseconds.
191179064Sjb * On OpenSolaris these return hrtime_t which we define as uint64_t.
192179064Sjb */
193179064Sjbuint64_t	dtrace_gethrtime(void);
194179064Sjbuint64_t	dtrace_gethrestime(void);
195179064Sjb
196179064Sjb#endif /* _SYS_DTRACE_BSD_H */
197