From owner-p4-projects@FreeBSD.ORG Sun Nov 5 00:44:19 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 5FCAB16A416; Sun, 5 Nov 2006 00:44:19 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 182C516A40F for ; Sun, 5 Nov 2006 00:44:19 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id D884A43D53 for ; Sun, 5 Nov 2006 00:44:18 +0000 (GMT) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id kA50iIhM092466 for ; Sun, 5 Nov 2006 00:44:18 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id kA50iI9w092463 for perforce@freebsd.org; Sun, 5 Nov 2006 00:44:18 GMT (envelope-from jb@freebsd.org) Date: Sun, 5 Nov 2006 00:44:18 GMT Message-Id: <200611050044.kA50iI9w092463@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 109251 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: Sun, 05 Nov 2006 00:44:19 -0000 http://perforce.freebsd.org/chv.cgi?CH=109251 Change 109251 by jb@jb_freebsd8 on 2006/11/05 00:43:18 Merge the DTrace stuff back in. Affected files ... .. //depot/projects/dtrace/src/sys/i386/i386/trap.c#15 edit Differences ... ==== //depot/projects/dtrace/src/sys/i386/i386/trap.c#15 (text+ko) ==== @@ -102,6 +102,35 @@ #include #endif +#ifdef KDTRACE +#include +#include + +/* + * These are hooks which are initialised by the dtrace module + * when it is loaded. This keeps the DTrace implementation + * opaque. + * + * All that the trap() function below needs to determine + * is how many instruction bytes to offset the instruction + * pointer before returning from a trap that occured durin a + * 'no-fault' DTrace probe. + */ +dtrace_instr_size_func_t dtrace_instr_size_func; + +/* + * This hook handles invalid opcodes. + */ +dtrace_invop_func_t dtrace_invop_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 + extern void trap(struct trapframe frame); extern void syscall(struct trapframe frame); @@ -216,6 +245,69 @@ goto out; #endif +#ifdef KDTRACE + /* + * If DTrace support is compiled into the kernel, a trap can + * occur while DTrace executes a probe. Before executing the + * probe, DTrace disables interrupts 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 interrupts are re-enabled. + * + * Check if DTrace has enabled 'no-fault' mode: + * + */ + if ((cpu_core[curcpu].cpuc_dtrace_flags & CPU_DTRACE_NOFAULT) != 0) { + /* + * When the dtrace module was loaded (or initialised + * if linked into the kernel), it should have set it's + * machine dependent instruction size function pointer + * for use here. If not, the trap will just end up + * being processed as a panic like any other. + */ + if (dtrace_instr_size_func != NULL) { + /* + * There are only a couple of trap types that + * are expected. All the rest will be handled + * in the usual way. + */ + switch (type) { + /* General protection fault. */ + case T_PROTFLT: + /* Flag an illegal operation. */ + cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_ILLOP; + + /* + * Offset the instruction pointer + * to the instruction following the + * one casing the fault. + */ + frame.tf_eip += (*dtrace_instr_size_func)((u_char *) frame.tf_eip); + goto out; + /* Page fault. */ + case T_PAGEFLT: + /* Flag a bad address. */ + cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_BADADDR; + cpu_core[curcpu].cpuc_dtrace_illval = rcr2(); + + /* + * Offset the instruction pointer + * to the instruction following the + * one casing the fault. + */ + frame.tf_eip += (*dtrace_instr_size_func)((u_char *) frame.tf_eip); + goto out; + default: + /* + * Handle all other traps in the usual + * way. + */ + break; + } + } + } +#endif + if ((frame.tf_eflags & PSL_I) == 0) { /* * Buggy application or kernel code has disabled @@ -1006,9 +1098,34 @@ PTRACESTOP_SC(p, td, S_PT_SCE); +#ifdef KDTRACE + /* + * 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, args); AUDIT_SYSCALL_EXIT(error, td); + +#ifdef KDTRACE + /* Save the error return variable for DTrace to reference. */ + td->td_errno = error; + + /* + * 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 } switch (error) {