systrace: track it like sdt probes

While here predict false.

Note the code is wrong (regardless of this change). Dereference of the
pointer can race with module unload. A fix would set the probe to a
nop stub instead of NULL.
This commit is contained in:
Mateusz Guzik 2018-04-27 15:16:34 +00:00
parent 715d1396d6
commit 9d68f7741f
4 changed files with 15 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 */