PERFORCE change 143158 for review
John Birrell
jb at FreeBSD.org
Mon Jun 9 03:11:32 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=143158
Change 143158 by jb at freebsd3 on 2008/06/09 03:10:30
Add the hooks for the syscall (systrace) provider.
Note that this requires an ABI change, so a separate kernel option
is required to make it work. BREAK_SYSENT_ABI should be obvious.
Affected files ...
.. //depot/projects/dtrace6/src/sys/i386/i386/trap.c#2 edit
Differences ...
==== //depot/projects/dtrace6/src/sys/i386/i386/trap.c#2 (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 "opt_npx.h"
#include "opt_trap.h"
@@ -109,6 +110,26 @@
static void trap_fatal(struct trapframe *, vm_offset_t);
void dblfault_handler(void);
+#ifdef KDTRACE_HOOKS
+#include <sys/dtrace_bsd.h>
+
+/*
+ * 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
+
extern inthand_t IDTVEC(lcall_syscall);
#define MAX_TRAP_MSG 30
@@ -215,6 +236,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_eflags & PSL_I) == 0) {
/*
* Buggy application or kernel code has disabled
@@ -855,6 +895,10 @@
void
dblfault_handler()
{
+#ifdef KDTRACE_HOOKS
+ if (dtrace_doubletrap_func != NULL)
+ (*dtrace_doubletrap_func)();
+#endif
printf("\nFatal double fault:\n");
printf("eip = 0x%x\n", PCPU_GET(common_tss.tss_eip));
printf("esp = 0x%x\n", PCPU_GET(common_tss.tss_esp));
@@ -980,9 +1024,34 @@
PTRACESTOP_SC(p, td, S_PT_SCE);
+#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, args);
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
}
switch (error) {
More information about the p4-projects
mailing list