From 45fa45a9ccc39ab51aa7429912b55d8c7556bcf5 Mon Sep 17 00:00:00 2001 From: gonzo Date: Sat, 24 Mar 2012 05:17:38 +0000 Subject: Add DTrace-related part to machine-dependent code: - DTrace trap handler - invop-related variables (unused on MIPS but still referenced from dtrace) --- sys/mips/mips/exception.S | 21 ++++++++++++++++++ sys/mips/mips/trap.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) (limited to 'sys/mips') diff --git a/sys/mips/mips/exception.S b/sys/mips/mips/exception.S index 34cf564..50da30b 100644 --- a/sys/mips/mips/exception.S +++ b/sys/mips/mips/exception.S @@ -55,6 +55,7 @@ */ #include "opt_ddb.h" +#include "opt_kdtrace.h" #include #include #include @@ -65,6 +66,26 @@ .set noreorder # Noreorder is default style! +#ifdef KDTRACE_HOOKS + .data + .globl dtrace_invop_jump_addr + .align 4 + .type dtrace_invop_jump_addr, @object + .size dtrace_invop_jump_addr, 8 +dtrace_invop_jump_addr: + .word 0 + .word 0 + .globl dtrace_invop_calltrap_addr + .align 4 + .type dtrace_invop_calltrap_addr, @object + .size dtrace_invop_calltrap_addr, 8 +dtrace_invop_calltrap_addr: + .word 0 + .word 0 + + .text +#endif + /* * Reasonable limit */ diff --git a/sys/mips/mips/trap.c b/sys/mips/mips/trap.c index bfffd8b..f2b343a 100644 --- a/sys/mips/mips/trap.c +++ b/sys/mips/mips/trap.c @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include "opt_ddb.h" #include "opt_global.h" #include "opt_ktrace.h" +#include "opt_kdtrace.h" #define NO_REG_DEFS 1 /* Prevent asm.h from including regdef.h */ #include @@ -93,6 +94,33 @@ __FBSDID("$FreeBSD$"); #include #endif +#ifdef KDTRACE_HOOKS +#include + +/* + * This is a hook which is initialised by the dtrace module + * to handle traps which might occur during DTrace probe + * execution. + */ +dtrace_trap_func_t dtrace_trap_func; + +dtrace_doubletrap_func_t dtrace_doubletrap_func; + +/* + * This is a hook which is initialised by the systrace module + * when it is loaded. This keeps the DTrace syscall provider + * implementation opaque. + */ +systrace_probe_func_t systrace_probe_func; + +/* + * These hooks are necessary for the pid, usdt and fasttrap providers. + */ +dtrace_fasttrap_probe_ptr_t dtrace_fasttrap_probe_ptr; +dtrace_pid_probe_ptr_t dtrace_pid_probe_ptr; +dtrace_return_probe_ptr_t dtrace_return_probe_ptr; +#endif + #ifdef TRAP_DEBUG int trap_debug = 0; SYSCTL_INT(_machdep, OID_AUTO, trap_debug, CTLFLAG_RW, @@ -529,6 +557,29 @@ trap(struct trapframe *trapframe) } } #endif + +#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 it's 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 the DTrace kernel module has registered a trap handler, + * call it and if it returns non-zero, assume that it has + * handled the trap and modified the trap frame so that this + * function can return normally. + */ + /* + * XXXDTRACE: add fasttrap and pid probes handlers here (if ever) + */ + if (!usermode) { + if (dtrace_trap_func != NULL && (*dtrace_trap_func)(trapframe, type)) + return (trapframe->pc); + } +#endif + switch (type) { case T_MCHECK: #ifdef DDB @@ -633,6 +684,9 @@ dofault: PROC_LOCK(p); --p->p_lock; PROC_UNLOCK(p); + /* + * XXXDTRACE: add dtrace_doubletrap_func here? + */ #ifdef VMFAULT_TRACE printf("vm_fault(%p (pmap %p), %p (%p), %x, %d) -> %x at pc %p\n", map, &vm->vm_pmap, (void *)va, (void *)(intptr_t)trapframe->badvaddr, -- cgit v1.1