PERFORCE change 143185 for review
John Birrell
jb at FreeBSD.org
Mon Jun 9 07:00:29 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=143185
Change 143185 by jb at 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 <sys/param.h>
@@ -101,6 +102,26 @@
static int trap_pfault(struct trapframe *, int);
static void trap_fatal(struct trapframe *, vm_offset_t);
+#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
+
#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
}
}
More information about the p4-projects
mailing list