master
  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: */
 35struct mbuf;
 36struct trapframe;
 37struct thread;
 38struct vattr;
 39struct vnode;
 40
 41int 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 */
 48typedef int (*dtrace_trap_func_t)(struct trapframe *, u_int);
 49extern 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 */
 56typedef void (*dtrace_doubletrap_func_t)(void);
 57extern	dtrace_doubletrap_func_t	dtrace_doubletrap_func;
 58
 59/* Pid provider hooks */
 60typedef int (*dtrace_pid_probe_ptr_t)(struct trapframe *);
 61extern	dtrace_pid_probe_ptr_t	dtrace_pid_probe_ptr;
 62typedef int (*dtrace_return_probe_ptr_t)(struct trapframe *);
 63extern	dtrace_return_probe_ptr_t	dtrace_return_probe_ptr;
 64
 65/* Virtual time hook function type. */
 66typedef	void (*dtrace_vtime_switch_func_t)(struct thread *);
 67
 68extern int			dtrace_vtime_active;
 69extern dtrace_vtime_switch_func_t	dtrace_vtime_switch_func;
 70
 71/* The fasttrap module hooks into the fork, exit and exit. */
 72typedef void (*dtrace_fork_func_t)(struct proc *, struct proc *);
 73typedef void (*dtrace_execexit_func_t)(struct proc *);
 74
 75/* Global variable in kern_fork.c */
 76extern dtrace_fork_func_t	dtrace_fasttrap_fork;
 77
 78/* Global variable in kern_exec.c */
 79extern dtrace_execexit_func_t	dtrace_fasttrap_exec;
 80
 81/* Global variable in kern_exit.c */
 82extern dtrace_execexit_func_t	dtrace_fasttrap_exit;
 83
 84/* The dtmalloc provider hooks into malloc. */
 85typedef	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
 88extern dtrace_malloc_probe_func_t   dtrace_malloc_probe;
 89
 90/* dtnfsclient NFSv[34] access cache provider hooks. */
 91typedef void (*dtrace_nfsclient_accesscache_flush_probe_func_t)(uint32_t,
 92    struct vnode *);
 93extern dtrace_nfsclient_accesscache_flush_probe_func_t
 94    dtrace_nfsclient_accesscache_flush_done_probe;
 95extern dtrace_nfsclient_accesscache_flush_probe_func_t
 96    dtrace_nfscl_accesscache_flush_done_probe;
 97
 98typedef void (*dtrace_nfsclient_accesscache_get_probe_func_t)(uint32_t,
 99    struct vnode *, uid_t, uint32_t);
100extern dtrace_nfsclient_accesscache_get_probe_func_t
101    dtrace_nfsclient_accesscache_get_hit_probe,
102    dtrace_nfsclient_accesscache_get_miss_probe;
103extern dtrace_nfsclient_accesscache_get_probe_func_t
104    dtrace_nfscl_accesscache_get_hit_probe,
105    dtrace_nfscl_accesscache_get_miss_probe;
106
107typedef void (*dtrace_nfsclient_accesscache_load_probe_func_t)(uint32_t,
108    struct vnode *, uid_t, uint32_t, int);
109extern dtrace_nfsclient_accesscache_load_probe_func_t
110    dtrace_nfsclient_accesscache_load_done_probe;
111extern dtrace_nfsclient_accesscache_load_probe_func_t
112    dtrace_nfscl_accesscache_load_done_probe;
113
114/* dtnfsclient NFSv[234] attribute cache provider hooks. */
115typedef void (*dtrace_nfsclient_attrcache_flush_probe_func_t)(uint32_t,
116    struct vnode *);
117extern dtrace_nfsclient_attrcache_flush_probe_func_t
118    dtrace_nfsclient_attrcache_flush_done_probe;
119extern dtrace_nfsclient_attrcache_flush_probe_func_t
120    dtrace_nfscl_attrcache_flush_done_probe;
121
122typedef void (*dtrace_nfsclient_attrcache_get_hit_probe_func_t)(uint32_t,
123    struct vnode *, struct vattr *);
124extern dtrace_nfsclient_attrcache_get_hit_probe_func_t
125    dtrace_nfsclient_attrcache_get_hit_probe;
126extern dtrace_nfsclient_attrcache_get_hit_probe_func_t
127    dtrace_nfscl_attrcache_get_hit_probe;
128
129typedef void (*dtrace_nfsclient_attrcache_get_miss_probe_func_t)(uint32_t,
130    struct vnode *);
131extern dtrace_nfsclient_attrcache_get_miss_probe_func_t
132    dtrace_nfsclient_attrcache_get_miss_probe;
133extern dtrace_nfsclient_attrcache_get_miss_probe_func_t
134    dtrace_nfscl_attrcache_get_miss_probe;
135
136typedef void (*dtrace_nfsclient_attrcache_load_probe_func_t)(uint32_t,
137    struct vnode *, struct vattr *, int);
138extern dtrace_nfsclient_attrcache_load_probe_func_t
139    dtrace_nfsclient_attrcache_load_done_probe;
140extern dtrace_nfsclient_attrcache_load_probe_func_t
141    dtrace_nfscl_attrcache_load_done_probe;
142
143/* dtnfsclient NFSv[234] RPC provider hooks. */
144typedef void (*dtrace_nfsclient_nfs23_start_probe_func_t)(uint32_t,
145    struct vnode *, struct mbuf *, struct ucred *, int);
146extern dtrace_nfsclient_nfs23_start_probe_func_t
147    dtrace_nfsclient_nfs23_start_probe;
148extern dtrace_nfsclient_nfs23_start_probe_func_t
149    dtrace_nfscl_nfs234_start_probe;
150
151typedef void (*dtrace_nfsclient_nfs23_done_probe_func_t)(uint32_t,
152    struct vnode *, struct mbuf *, struct ucred *, int, int);
153extern dtrace_nfsclient_nfs23_done_probe_func_t
154    dtrace_nfsclient_nfs23_done_probe;
155extern 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 */
163size_t	kdtrace_proc_size(void);
164size_t	kdtrace_thread_size(void);
165
166void	kdtrace_proc_ctor(struct proc *p);
167void	kdtrace_proc_dtor(struct proc *p);
168void	kdtrace_thread_ctor(struct thread *td);
169void	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 */
175uint64_t	dtrace_gethrtime(void);
176uint64_t	dtrace_gethrestime(void);
177
178#endif /* _SYS_DTRACE_BSD_H */