From owner-p4-projects@FreeBSD.ORG Mon Jun 9 07:00:29 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 7EA1B1065674; Mon, 9 Jun 2008 07:00:29 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3F9F41065673 for ; Mon, 9 Jun 2008 07:00:29 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 2B82F8FC13 for ; Mon, 9 Jun 2008 07:00:29 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m5970SWi082944 for ; Mon, 9 Jun 2008 07:00:28 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m5970Se0082942 for perforce@freebsd.org; Mon, 9 Jun 2008 07:00:28 GMT (envelope-from jb@freebsd.org) Date: Mon, 9 Jun 2008 07:00:28 GMT Message-Id: <200806090700.m5970Se0082942@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jb@freebsd.org using -f From: John Birrell To: Perforce Change Reviews Cc: Subject: PERFORCE change 143185 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Jun 2008 07:00:29 -0000 http://perforce.freebsd.org/chv.cgi?CH=143185 Change 143185 by jb@freebsd3 on 2008/06/09 07:00:10 Add the syscall hooks for DTrace. Affected files ... .. //depot/projects/dtrace6/src/sys/amd64/amd64/trap.c#3 edit Differences ... ==== //depot/projects/dtrace6/src/sys/amd64/amd64/trap.c#3 (text+ko) ==== @@ -49,6 +49,7 @@ #include "opt_hwpmc_hooks.h" #include "opt_isa.h" #include "opt_kdb.h" +#include "opt_kdtrace.h" #include "opt_ktrace.h" #include @@ -101,6 +102,26 @@ static int trap_pfault(struct trapframe *, int); static void trap_fatal(struct trapframe *, vm_offset_t); +#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; +#endif + #define MAX_TRAP_MSG 30 static char *trap_msg[] = { "", /* 0 unused */ @@ -196,6 +217,25 @@ goto out; #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 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. + */ + if ((type == T_PROTFLT || type == T_PAGEFLT) && + dtrace_trap_func != NULL) + if ((*dtrace_trap_func)(&frame, type)) + goto out; +#endif + if ((frame.tf_rflags & PSL_I) == 0) { /* * Buggy application or kernel code has disabled @@ -680,6 +720,10 @@ void dblfault_handler(struct trapframe frame) { +#ifdef KDTRACE_HOOKS + if (dtrace_doubletrap_func != NULL) + (*dtrace_doubletrap_func)(); +#endif printf("\nFatal double fault\n"); printf("rip = 0x%lx\n", frame.tf_rip); printf("rsp = 0x%lx\n", frame.tf_rsp); @@ -798,14 +842,62 @@ if ((callp->sy_narg & SYF_MPSAFE) == 0) { mtx_lock(&Giant); + +#if defined(KDTRACE_HOOKS) && defined(BREAK_SYSENT_ABI) + /* + * If the systrace module has registered it's probe + * callback and if there is a probe active for the + * syscall 'entry', process the probe. + */ + if (systrace_probe_func != NULL && callp->sy_entry != 0) + (*systrace_probe_func)(callp->sy_entry, code, callp, + args); +#endif + AUDIT_SYSCALL_ENTER(code, td); error = (*callp->sy_call)(td, argp); AUDIT_SYSCALL_EXIT(error, td); + +#if defined(KDTRACE_HOOKS) && defined(BREAK_SYSENT_ABI) + /* + * If the systrace module has registered it's probe + * callback and if there is a probe active for the + * syscall 'return', process the probe. + */ + if (systrace_probe_func != NULL && callp->sy_return != 0) + (*systrace_probe_func)(callp->sy_return, code, callp, + args); +#endif mtx_unlock(&Giant); } else { +#if defined(KDTRACE_HOOKS) && defined(BREAK_SYSENT_ABI) + /* + * If the systrace module has registered it's probe + * callback and if there is a probe active for the + * syscall 'entry', process the probe. + */ + if (systrace_probe_func != NULL && callp->sy_entry != 0) + (*systrace_probe_func)(callp->sy_entry, code, callp, + args); +#endif + AUDIT_SYSCALL_ENTER(code, td); error = (*callp->sy_call)(td, argp); AUDIT_SYSCALL_EXIT(error, td); + + /* Save the latest error return value. */ + td->td_errno = error; + +#if defined(KDTRACE_HOOKS) && defined(BREAK_SYSENT_ABI) + /* + * If the systrace module has registered it's probe + * callback and if there is a probe active for the + * syscall 'return', process the probe. + */ + if (systrace_probe_func != NULL && callp->sy_return != 0) + (*systrace_probe_func)(callp->sy_return, code, callp, + args); +#endif } }