aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2018-04-27 15:16:34 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2018-04-27 15:16:34 +0000
commit9d68f7741f72f3becdc8ec05edf32b58aef24a5e (patch)
treead3ee1a303350b7b5660605e475811ddc5177f7a
parent715d1396d6233158b94e85414b57520ee3e536cc (diff)
Notes
-rw-r--r--sys/cddl/dev/systrace/systrace.c8
-rw-r--r--sys/kern/kern_dtrace.c3
-rw-r--r--sys/kern/subr_syscall.c6
-rw-r--r--sys/sys/sysent.h1
4 files changed, 15 insertions, 3 deletions
diff --git a/sys/cddl/dev/systrace/systrace.c b/sys/cddl/dev/systrace/systrace.c
index 02b089b425269..2ef74cb15e0ad 100644
--- a/sys/cddl/dev/systrace/systrace.c
+++ b/sys/cddl/dev/systrace/systrace.c
@@ -135,6 +135,8 @@ extern const char *freebsd32_syscallnames[];
#error 1 << SYSTRACE_SHIFT must exceed number of system calls
#endif
+static int systrace_enabled_count;
+
static void systrace_load(void *);
static void systrace_unload(void *);
@@ -315,6 +317,9 @@ systrace_enable(void *arg, dtrace_id_t id, void *parg)
SYSENT[sysnum].sy_entry = id;
else
SYSENT[sysnum].sy_return = id;
+ systrace_enabled_count++;
+ if (systrace_enabled_count == 1)
+ systrace_enabled = true;
}
static void
@@ -324,6 +329,9 @@ systrace_disable(void *arg, dtrace_id_t id, void *parg)
SYSENT[sysnum].sy_entry = 0;
SYSENT[sysnum].sy_return = 0;
+ systrace_enabled_count--;
+ if (systrace_enabled_count == 0)
+ systrace_enabled = false;
}
static void
diff --git a/sys/kern/kern_dtrace.c b/sys/kern/kern_dtrace.c
index 7b13a52b3f3b5..cbe6bdf15fd8d 100644
--- a/sys/kern/kern_dtrace.c
+++ b/sys/kern/kern_dtrace.c
@@ -56,7 +56,8 @@ dtrace_doubletrap_func_t dtrace_doubletrap_func;
dtrace_pid_probe_ptr_t dtrace_pid_probe_ptr;
dtrace_return_probe_ptr_t dtrace_return_probe_ptr;
-systrace_probe_func_t __read_frequently systrace_probe_func;
+bool __read_frequently systrace_enabled;
+systrace_probe_func_t systrace_probe_func;
/* Return the DTrace process data size compiled in the kernel hooks. */
size_t
diff --git a/sys/kern/subr_syscall.c b/sys/kern/subr_syscall.c
index bca47edaf6134..6c70ddc9f789a 100644
--- a/sys/kern/subr_syscall.c
+++ b/sys/kern/subr_syscall.c
@@ -126,7 +126,8 @@ syscallenter(struct thread *td)
#ifdef KDTRACE_HOOKS
/* Give the syscall:::entry DTrace probe a chance to fire. */
- if (systrace_probe_func != NULL && sa->callp->sy_entry != 0)
+ if (__predict_false(systrace_enabled &&
+ sa->callp->sy_entry != 0))
(*systrace_probe_func)(sa, SYSTRACE_ENTRY, 0);
#endif
@@ -140,7 +141,8 @@ syscallenter(struct thread *td)
#ifdef KDTRACE_HOOKS
/* Give the syscall:::return DTrace probe a chance to fire. */
- if (systrace_probe_func != NULL && sa->callp->sy_return != 0)
+ if (__predict_false(systrace_enabled &&
+ sa->callp->sy_return != 0))
(*systrace_probe_func)(sa, SYSTRACE_RETURN,
error ? -1 : td->td_retval[0]);
#endif
diff --git a/sys/sys/sysent.h b/sys/sys/sysent.h
index c811a4a7f3bd4..9d85728e1593a 100644
--- a/sys/sys/sysent.h
+++ b/sys/sys/sysent.h
@@ -53,6 +53,7 @@ typedef void (*systrace_probe_func_t)(struct syscall_args *,
enum systrace_probe_t, int);
typedef void (*systrace_args_func_t)(int, void *, uint64_t *, int *);
+extern bool systrace_enabled;
extern systrace_probe_func_t systrace_probe_func;
struct sysent { /* system call table */