diff --git a/sys/amd64/amd64/exception.S b/sys/amd64/amd64/exception.S index d51078d..bb5fd56 100644 --- a/sys/amd64/amd64/exception.S +++ b/sys/amd64/amd64/exception.S @@ -228,7 +228,24 @@ alltraps_pushregs_no_rdi: .type calltrap,@function calltrap: movq %rsp,%rdi +#ifdef KDTRACE_HOOKS + /* + * Give DTrace a chance to vet this trap and skip the call to trap() if + * it turns out that it was caused by a DTrace probe. + */ + movq dtrace_trap_func,%rax + testq %rax,%rax + je skiphook + call *%rax + testq %rax,%rax + jne skiptrap + movq %rsp,%rdi +skiphook: +#endif call trap +#ifdef KDTRACE_HOOKS +skiptrap: +#endif MEXITCOUNT jmp doreti /* Handle any pending ASTs */ diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c index c56b99e..d9203bc 100644 --- a/sys/amd64/amd64/trap.c +++ b/sys/amd64/amd64/trap.c @@ -218,18 +218,6 @@ trap(struct trapframe *frame) goto out; } -#ifdef KDTRACE_HOOKS - /* - * A trap can occur while DTrace executes a probe. Before - * executing the probe, DTrace blocks re-scheduling and sets - * a flag in its per-cpu flags to indicate that it doesn't - * want to fault. On returning from the probe, the no-fault - * flag is cleared and finally re-scheduling is enabled. - */ - if (dtrace_trap_func != NULL && (*dtrace_trap_func)(frame, type)) - goto out; -#endif - if ((frame->tf_rflags & PSL_I) == 0) { /* * Buggy application or kernel code has disabled diff --git a/sys/cddl/dev/dtrace/amd64/dtrace_subr.c b/sys/cddl/dev/dtrace/amd64/dtrace_subr.c index bdd6fbe..e761f38 100644 --- a/sys/cddl/dev/dtrace/amd64/dtrace_subr.c +++ b/sys/cddl/dev/dtrace/amd64/dtrace_subr.c @@ -462,29 +462,27 @@ dtrace_gethrestime(void) return (current_time.tv_sec * 1000000000ULL + current_time.tv_nsec); } -/* Function to handle DTrace traps during probes. See amd64/amd64/trap.c */ +/* + * Function to handle DTrace traps during probes. See amd64/amd64/exception.S. + */ int -dtrace_trap(struct trapframe *frame, u_int type) +dtrace_trap(struct trapframe *frame) { /* * A trap can occur while DTrace executes a probe. Before * executing the probe, DTrace blocks re-scheduling and sets - * a flag in it's per-cpu flags to indicate that it doesn't + * a flag in its per-cpu flags to indicate that it doesn't * want to fault. On returning from the probe, the no-fault * flag is cleared and finally re-scheduling is enabled. * * Check if DTrace has enabled 'no-fault' mode: - * */ if ((cpu_core[curcpu].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT) != 0) { /* * There are only a couple of trap types that are expected. * All the rest will be handled in the usual way. */ - switch (type) { - /* Privilieged instruction fault. */ - case T_PRIVINFLT: - break; + switch (frame->tf_trapno) { /* General protection fault. */ case T_PROTFLT: /* Flag an illegal operation. */ diff --git a/sys/cddl/dev/dtrace/i386/dtrace_subr.c b/sys/cddl/dev/dtrace/i386/dtrace_subr.c index 49e5c76..0d2b259 100644 --- a/sys/cddl/dev/dtrace/i386/dtrace_subr.c +++ b/sys/cddl/dev/dtrace/i386/dtrace_subr.c @@ -471,26 +471,25 @@ dtrace_gethrestime(void) return (current_time.tv_sec * 1000000000ULL + current_time.tv_nsec); } -/* Function to handle DTrace traps during probes. See i386/i386/trap.c */ +/* Function to handle DTrace traps during probes. See i386/i386/exception.s */ int -dtrace_trap(struct trapframe *frame, u_int type) +dtrace_trap(struct trapframe *frame) { /* * A trap can occur while DTrace executes a probe. Before * executing the probe, DTrace blocks re-scheduling and sets - * a flag in it's per-cpu flags to indicate that it doesn't + * a flag in its per-cpu flags to indicate that it doesn't * want to fault. On returning from the probe, the no-fault * flag is cleared and finally re-scheduling is enabled. * * Check if DTrace has enabled 'no-fault' mode: - * */ if ((cpu_core[curcpu].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT) != 0) { /* * There are only a couple of trap types that are expected. * All the rest will be handled in the usual way. */ - switch (type) { + switch (frame->tf_trapno) { /* General protection fault. */ case T_PROTFLT: /* Flag an illegal operation. */ diff --git a/sys/cddl/dev/dtrace/mips/dtrace_subr.c b/sys/cddl/dev/dtrace/mips/dtrace_subr.c index a7ea375..5565a61 100644 --- a/sys/cddl/dev/dtrace/mips/dtrace_subr.c +++ b/sys/cddl/dev/dtrace/mips/dtrace_subr.c @@ -137,17 +137,20 @@ dtrace_gethrestime(void) /* Function to handle DTrace traps during probes. See amd64/amd64/trap.c */ int -dtrace_trap(struct trapframe *frame, u_int type) +dtrace_trap(struct trapframe *frame) { + u_int type; + + type = (trapframe->cause & MIPS_CR_EXC_CODE) >> MIPS_CR_EXC_CODE_SHIFT; + /* * A trap can occur while DTrace executes a probe. Before * executing the probe, DTrace blocks re-scheduling and sets - * a flag in it's per-cpu flags to indicate that it doesn't + * a flag in its per-cpu flags to indicate that it doesn't * want to fault. On returning from the probe, the no-fault * flag is cleared and finally re-scheduling is enabled. * * Check if DTrace has enabled 'no-fault' mode: - * */ if ((cpu_core[curcpu].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT) != 0) { /* diff --git a/sys/cddl/dev/dtrace/powerpc/dtrace_subr.c b/sys/cddl/dev/dtrace/powerpc/dtrace_subr.c index d58cf92..5411ece 100644 --- a/sys/cddl/dev/dtrace/powerpc/dtrace_subr.c +++ b/sys/cddl/dev/dtrace/powerpc/dtrace_subr.c @@ -262,24 +262,23 @@ dtrace_gethrestime(void) /* Function to handle DTrace traps during probes. See powerpc/powerpc/trap.c */ int -dtrace_trap(struct trapframe *frame, u_int type) +dtrace_trap(struct trapframe *frame) { /* * A trap can occur while DTrace executes a probe. Before * executing the probe, DTrace blocks re-scheduling and sets - * a flag in it's per-cpu flags to indicate that it doesn't + * a flag in its per-cpu flags to indicate that it doesn't * want to fault. On returning from the probe, the no-fault * flag is cleared and finally re-scheduling is enabled. * * Check if DTrace has enabled 'no-fault' mode: - * */ if ((cpu_core[curcpu].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT) != 0) { /* * There are only a couple of trap types that are expected. * All the rest will be handled in the usual way. */ - switch (type) { + switch (frame->exc) { /* Page fault. */ case EXC_DSI: case EXC_DSE: diff --git a/sys/i386/i386/trap.c b/sys/i386/i386/trap.c index 5285b1d..e7fb995 100644 --- a/sys/i386/i386/trap.c +++ b/sys/i386/i386/trap.c @@ -246,7 +246,7 @@ trap(struct trapframe *frame) * flag is cleared and finally re-scheduling is enabled. */ if ((type == T_PROTFLT || type == T_PAGEFLT) && - dtrace_trap_func != NULL && (*dtrace_trap_func)(frame, type)) + dtrace_trap_func != NULL && (*dtrace_trap_func)(frame)) goto out; #endif diff --git a/sys/mips/mips/trap.c b/sys/mips/mips/trap.c index f0df09c..df5efc0 100644 --- a/sys/mips/mips/trap.c +++ b/sys/mips/mips/trap.c @@ -605,7 +605,7 @@ trap(struct trapframe *trapframe) /* * A trap can occur while DTrace executes a probe. Before * executing the probe, DTrace blocks re-scheduling and sets - * a flag in it's per-cpu flags to indicate that it doesn't + * a flag in its per-cpu flags to indicate that it doesn't * want to fault. On returning from the probe, the no-fault * flag is cleared and finally re-scheduling is enabled. * @@ -618,7 +618,7 @@ trap(struct trapframe *trapframe) * XXXDTRACE: add pid probe handler here (if ever) */ if (!usermode) { - if (dtrace_trap_func != NULL && (*dtrace_trap_func)(trapframe, type)) + if (dtrace_trap_func != NULL && (*dtrace_trap_func)(trapframe)) return (trapframe->pc); } #endif diff --git a/sys/powerpc/aim/trap.c b/sys/powerpc/aim/trap.c index a3380e3..7f1be2d 100644 --- a/sys/powerpc/aim/trap.c +++ b/sys/powerpc/aim/trap.c @@ -167,7 +167,7 @@ trap(struct trapframe *frame) /* * A trap can occur while DTrace executes a probe. Before * executing the probe, DTrace blocks re-scheduling and sets - * a flag in it's per-cpu flags to indicate that it doesn't + * a flag in its per-cpu flags to indicate that it doesn't * want to fault. On returning from the probe, the no-fault * flag is cleared and finally re-scheduling is enabled. * @@ -176,7 +176,7 @@ trap(struct trapframe *frame) * handled the trap and modified the trap frame so that this * function can return normally. */ - if (dtrace_trap_func != NULL && (*dtrace_trap_func)(frame, type)) + if (dtrace_trap_func != NULL && (*dtrace_trap_func)(frame)) return; #endif diff --git a/sys/sys/dtrace_bsd.h b/sys/sys/dtrace_bsd.h index 6dd9024..b451022 100644 --- a/sys/sys/dtrace_bsd.h +++ b/sys/sys/dtrace_bsd.h @@ -48,15 +48,14 @@ extern cyclic_clock_func_t cyclic_clock_func; void clocksource_cyc_set(const struct bintime *t); +int dtrace_trap(struct trapframe *); + /* * The dtrace module handles traps that occur during a DTrace probe. * This type definition is used in the trap handler to provide a - * hook for the dtrace module to register it's handler with. + * hook for the dtrace module to register its handler with. */ -typedef int (*dtrace_trap_func_t)(struct trapframe *, u_int); - -int dtrace_trap(struct trapframe *, u_int); - +typedef int (*dtrace_trap_func_t)(struct trapframe *); extern dtrace_trap_func_t dtrace_trap_func; /*