]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
Initial commit of DTrace.
authorNick Alcock <nick.alcock@oracle.com>
Fri, 30 Sep 2011 17:55:09 +0000 (18:55 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Mon, 5 Dec 2011 18:27:52 +0000 (18:27 +0000)
Build via a simple 'make' if you're already running this kernel, or via 'make
KERNELDIR=/path/to/kernel/top/level' otherwise. Installed via 'make install'.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
48 files changed:
dtrace/Kbuild [new file with mode: 0644]
dtrace/Makefile [new file with mode: 0644]
dtrace/dt_test.h [new file with mode: 0644]
dtrace/dt_test_dev.c [new file with mode: 0644]
dtrace/dt_test_mod.c [new file with mode: 0644]
dtrace/dtrace_actdesc.c [new file with mode: 0644]
dtrace/dtrace_anon.c [new file with mode: 0644]
dtrace/dtrace_asm.S [new file with mode: 0644]
dtrace/dtrace_buffer.c [new file with mode: 0644]
dtrace/dtrace_dev.c [new file with mode: 0644]
dtrace/dtrace_dev.h [new file with mode: 0644]
dtrace/dtrace_dif.c [new file with mode: 0644]
dtrace/dtrace_dof.c [new file with mode: 0644]
dtrace/dtrace_ecb.c [new file with mode: 0644]
dtrace/dtrace_enable.c [new file with mode: 0644]
dtrace/dtrace_fmt.c [new file with mode: 0644]
dtrace/dtrace_hash.c [new file with mode: 0644]
dtrace/dtrace_helper.c [new file with mode: 0644]
dtrace/dtrace_isa.c [new file with mode: 0644]
dtrace/dtrace_match.c [new file with mode: 0644]
dtrace/dtrace_mod.c [new file with mode: 0644]
dtrace/dtrace_predicate.c [new file with mode: 0644]
dtrace/dtrace_priv.c [new file with mode: 0644]
dtrace/dtrace_probe.c [new file with mode: 0644]
dtrace/dtrace_probe_ctx.c [new file with mode: 0644]
dtrace/dtrace_ptofapi.c [new file with mode: 0644]
dtrace/dtrace_spec.c [new file with mode: 0644]
dtrace/dtrace_state.c [new file with mode: 0644]
dtrace/dtrace_util.c [new file with mode: 0644]
dtrace/fasttrap.h [new file with mode: 0644]
dtrace/fasttrap_dev.c [new file with mode: 0644]
dtrace/fasttrap_mod.c [new file with mode: 0644]
dtrace/fbt.h [new file with mode: 0644]
dtrace/fbt_dev.c [new file with mode: 0644]
dtrace/fbt_mod.c [new file with mode: 0644]
dtrace/lockstat.h [new file with mode: 0644]
dtrace/lockstat_dev.c [new file with mode: 0644]
dtrace/lockstat_mod.c [new file with mode: 0644]
dtrace/profile.h [new file with mode: 0644]
dtrace/profile_dev.c [new file with mode: 0644]
dtrace/profile_mod.c [new file with mode: 0644]
dtrace/sdt.h [new file with mode: 0644]
dtrace/sdt_dev.c [new file with mode: 0644]
dtrace/sdt_impl.h [new file with mode: 0644]
dtrace/sdt_mod.c [new file with mode: 0644]
dtrace/sdt_subr.c [new file with mode: 0644]
dtrace/systrace_dev.c [new file with mode: 0644]
dtrace/systrace_mod.c [new file with mode: 0644]

diff --git a/dtrace/Kbuild b/dtrace/Kbuild
new file mode 100644 (file)
index 0000000..93aeb0d
--- /dev/null
@@ -0,0 +1,34 @@
+#
+# Makefile for DTrace
+#
+
+GCOV_PROFILE := y
+
+EXTRA_CFLAGS                   := -Ikernel/dtrace
+
+obj-$(CONFIG_DT_CORE)          += dtrace.o
+obj-$(CONFIG_DT_FASTTRAP)      += fasttrap.o
+obj-$(CONFIG_DT_FBT)           += fbt.o
+obj-$(CONFIG_DT_LOCKSTAT)      += lockstat.o
+obj-$(CONFIG_DT_PROFILE)       += profile.o
+obj-$(CONFIG_DT_SDT)           += sdt.o
+obj-$(CONFIG_DT_SYSTRACE)      += systrace.o
+obj-$(CONFIG_DT_DT_TEST)       += dt_test.o
+
+dtrace-y                       := dtrace_mod.o dtrace_dev.o \
+                                  dtrace_asm.o dtrace_isa.o \
+                                  dtrace_actdesc.o dtrace_anon.o \
+                                  dtrace_buffer.o dtrace_dif.o dtrace_dof.o \
+                                  dtrace_ecb.o dtrace_enable.o \
+                                  dtrace_fmt.o dtrace_hash.o dtrace_helper.o \
+                                  dtrace_match.o dtrace_priv.o \
+                                  dtrace_probe.o dtrace_probe_ctx.o \
+                                  dtrace_ptofapi.o dtrace_predicate.o \
+                                  dtrace_spec.o dtrace_state.o dtrace_util.o
+fasttrap-y                     := fasttrap_mod.o fasttrap_dev.o
+fbt-y                          := fbt_mod.o fbt_dev.o
+lockstat-y                     := lockstat_mod.o lockstat_dev.o
+profile-y                      := profile_mod.o profile_dev.o
+sdt-y                          := sdt_mod.o sdt_dev.o sdt_subr.o
+systrace-y                     := systrace_mod.o systrace_dev.o
+dt_test-y                      := dt_test_mod.o dt_test_dev.o
diff --git a/dtrace/Makefile b/dtrace/Makefile
new file mode 100644 (file)
index 0000000..0adc58f
--- /dev/null
@@ -0,0 +1,12 @@
+#
+# Makefile for DTrace
+#
+
+KERNELDIR := /lib/modules/`uname -r`/build
+
+modules::
+
+install:: modules_install
+
+%::
+       $(MAKE) -C $(KERNELDIR) M=`pwd` $@
diff --git a/dtrace/dt_test.h b/dtrace/dt_test.h
new file mode 100644 (file)
index 0000000..86bd55a
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef _DT_TEST_H_
+#define _DT_TEST_H_
+
+extern void dt_test_provide(void *, const dtrace_probedesc_t *);
+extern int dt_test_enable(void *arg, dtrace_id_t, void *);
+extern void dt_test_disable(void *arg, dtrace_id_t, void *);
+extern void dt_test_destroy(void *, dtrace_id_t, void *);
+
+extern dtrace_provider_id_t    dt_test_id;
+
+extern int dt_test_dev_init(void);
+extern void dt_test_dev_exit(void);
+
+#endif /* _DT_TEST_H_ */
diff --git a/dtrace/dt_test_dev.c b/dtrace/dt_test_dev.c
new file mode 100644 (file)
index 0000000..55998ec
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * FILE:       dt_test_dev.c
+ * DESCRIPTION:        DTrace Test Probe: device file handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+#include <trace/syscall.h>
+#include <asm/unistd.h>
+
+#include "dtrace.h"
+#include "dtrace_dev.h"
+#include "dt_test.h"
+
+static dtrace_id_t     pid = 0;
+static int             enabled = 0;
+
+void dt_test_provide(void *arg, const dtrace_probedesc_t *desc)
+{
+       if (dtrace_probe_lookup(dt_test_id, "dt_test", NULL, "test") != 0)
+               return;
+
+       pid = dtrace_probe_create(dt_test_id,
+                                 "dt_test", NULL, "test", 0, NULL);
+}
+
+int dt_test_enable(void *arg, dtrace_id_t id, void *parg)
+{
+       enabled = 1;
+
+       return 0;
+}
+
+void dt_test_disable(void *arg, dtrace_id_t id, void *parg)
+{
+       enabled = 0;
+}
+
+void dt_test_destroy(void *arg, dtrace_id_t id, void *parg)
+{
+}
+
+static long dt_test_ioctl(struct file *file,
+                        unsigned int cmd, unsigned long arg)
+{
+       if (enabled) {
+               dtrace_probe(pid, cmd, arg, 2, 3, 4);
+
+               return 0;
+       }
+
+       return -EAGAIN;
+}
+
+static int dt_test_open(struct inode *inode, struct file *file)
+{
+       return 0;
+}
+
+static int dt_test_close(struct inode *inode, struct file *file)
+{
+       return 0;
+}
+
+static const struct file_operations dt_test_fops = {
+       .owner  = THIS_MODULE,
+        .unlocked_ioctl = dt_test_ioctl,
+        .open   = dt_test_open,
+        .release = dt_test_close,
+};
+
+static struct miscdevice dt_test_dev = {
+       .minor = DT_DEV_DT_TEST_MINOR,
+       .name = "dt_test",
+       .nodename = "dtrace/provider/dt_test",
+       .fops = &dt_test_fops,
+};
+
+int dt_test_dev_init(void)
+{
+       int     ret = 0;
+
+       ret = misc_register(&dt_test_dev);
+       if (ret)
+               pr_err("%s: Can't register misc device %d\n",
+                      dt_test_dev.name, dt_test_dev.minor);
+
+       return ret;
+}
+
+void dt_test_dev_exit(void)
+{
+       misc_deregister(&dt_test_dev);
+}
diff --git a/dtrace/dt_test_mod.c b/dtrace/dt_test_mod.c
new file mode 100644 (file)
index 0000000..822df2b
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * FILE:       dt_test_mod.c
+ * DESCRIPTION:        DTrace Test Probe: module handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/module.h>
+
+#include "dtrace.h"
+#include "dtrace_dev.h"
+#include "dt_test.h"
+
+MODULE_AUTHOR("Kris Van Hees (kris.van.hees@oracle.com)");
+MODULE_DESCRIPTION("DTrace Test Probe");
+MODULE_VERSION("v0.1");
+MODULE_LICENSE("Proprietary");
+
+static const dtrace_pattr_t dt_test_attr = {
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
+};
+
+static dtrace_pops_t dt_test_pops = {
+       dt_test_provide,
+       NULL,
+       dt_test_enable,
+       dt_test_disable,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       dt_test_destroy
+};
+
+DT_PROVIDER_MODULE(dt_test, DTRACE_PRIV_USER);
diff --git a/dtrace/dtrace_actdesc.c b/dtrace/dtrace_actdesc.c
new file mode 100644 (file)
index 0000000..5b84cf8
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * FILE:       dtrace_actdesc.c
+ * DESCRIPTION:        Dynamic Tracing: action description functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/slab.h>
+
+#include "dtrace.h"
+
+dtrace_actdesc_t *dtrace_actdesc_create(dtrace_actkind_t kind, uint32_t ntuple,
+                                       uint64_t uarg, uint64_t arg)
+{
+       dtrace_actdesc_t        *act;
+
+#ifdef FIXME
+       ASSERT(!DTRACEACT_ISPRINTFLIKE(kind) ||
+              (arg != 0 && (uintptr_t)arg >= KERNELBASE) ||
+              (arg == 0 && kind == DTRACEACT_PRINTA));
+#else
+       ASSERT(!DTRACEACT_ISPRINTFLIKE(kind) ||
+              (arg != 0) ||
+              (arg == 0 && kind == DTRACEACT_PRINTA));
+#endif
+
+       act = kzalloc(sizeof (dtrace_actdesc_t), GFP_KERNEL);
+       act->dtad_kind = kind;
+       act->dtad_ntuple = ntuple;
+       act->dtad_uarg = uarg;
+       act->dtad_arg = arg;
+       act->dtad_refcnt = 1;
+
+       return act;
+}
+
+void dtrace_actdesc_hold(dtrace_actdesc_t *act)
+{
+       ASSERT(act->dtad_refcnt >= 1);
+
+       act->dtad_refcnt++;
+}
+
+void dtrace_actdesc_release(dtrace_actdesc_t *act, dtrace_vstate_t *vstate)
+{
+       dtrace_actkind_t        kind = act->dtad_kind;
+       dtrace_difo_t           *dp;
+
+       ASSERT(act->dtad_refcnt >= 1);
+
+       if (--act->dtad_refcnt != 0)
+               return;
+
+       if ((dp = act->dtad_difo) != NULL)
+               dtrace_difo_release(dp, vstate);
+
+       if (DTRACEACT_ISPRINTFLIKE(kind)) {
+               char    *str = (char *)(uintptr_t)act->dtad_arg;
+
+#ifdef FIXME
+               ASSERT((str != NULL && (uintptr_t)str >= KERNELBASE) ||
+                      (str == NULL && act->dtad_kind == DTRACEACT_PRINTA));
+#else
+               ASSERT((str != NULL) ||
+                      (str == NULL && act->dtad_kind == DTRACEACT_PRINTA));
+#endif
+
+               if (str != NULL)
+                       kfree(str);
+       }
+
+       kfree(act);
+}
diff --git a/dtrace/dtrace_anon.c b/dtrace/dtrace_anon.c
new file mode 100644 (file)
index 0000000..57de888
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * FILE:       dtrace_anon.c
+ * DESCRIPTION:        Dynamic Tracing: anonymous enabling functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include "dtrace.h"
+
+dtrace_anon_t  dtrace_anon;
+
+dtrace_state_t *dtrace_anon_grab(void)
+{
+       dtrace_state_t  *state;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+
+       if ((state = dtrace_anon.dta_state) == NULL) {
+               ASSERT(dtrace_anon.dta_enabling == NULL);
+
+               return NULL;
+       }
+
+       ASSERT(dtrace_anon.dta_enabling != NULL);
+       ASSERT(dtrace_retained != NULL);
+
+       dtrace_enabling_destroy(dtrace_anon.dta_enabling);
+       dtrace_anon.dta_enabling = NULL;
+       dtrace_anon.dta_state = NULL;
+
+       return state;
+}
+
+void dtrace_anon_property(void)
+{
+       int             i, rv;
+       dtrace_state_t  *state;
+       dof_hdr_t       *dof;
+       char            c[32];             /* enough for "dof-data-" + digits */
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(mutex_is_locked(&cpu_lock));
+
+       for (i = 0; ; i++) {
+               snprintf(c, sizeof (c), "dof-data-%d", i);
+
+               dtrace_err_verbose = 1;
+
+               if ((dof = dtrace_dof_property(c)) == NULL) {
+                       dtrace_err_verbose = 0;
+                       break;
+               }
+
+#ifdef FIXME
+               /*
+                * We want to create anonymous state, so we need to transition
+                * the kernel debugger to indicate that DTrace is active.  If
+                * this fails (e.g. because the debugger has modified text in
+                * some way), we won't continue with the processing.
+                */
+               if (kdi_dtrace_set(KDI_DTSET_DTRACE_ACTIVATE) != 0) {
+                       pr_info("kernel debugger active; "
+                               "anonymous enabling ignored.");
+                       dtrace_dof_destroy(dof);
+                       break;
+               }
+#endif
+
+               /*
+                * If we haven't allocated an anonymous state, we'll do so now.
+               */
+               if ((state = dtrace_anon.dta_state) == NULL) {
+                       state = dtrace_state_create(NULL);
+                       dtrace_anon.dta_state = state;
+
+                       if (state == NULL) {
+                               /*
+                                * This basically shouldn't happen: there is no
+                                * failure mode from dtrace_state_create().
+                                * Still, the interface allows for a failure
+                                * mode, and we want to fail as gracefully as
+                                * possible: we'll emit an error message and
+                                * cease processing anonymous state in this
+                                * case.
+                                */
+                               pr_warning("failed to create anonymous state");
+                               dtrace_dof_destroy(dof);
+                               break;
+                       }
+               }
+
+               rv = dtrace_dof_slurp(dof, &state->dts_vstate, current_cred(),
+                                     &dtrace_anon.dta_enabling, 0, TRUE);
+
+               if (rv == 0)
+                       rv = dtrace_dof_options(dof, state);
+
+               dtrace_err_verbose = 0;
+               dtrace_dof_destroy(dof);
+
+               if (rv != 0) {
+                       /*
+                        * This is malformed DOF; chuck any anonymous state
+                        * that we created.
+                        */
+                       ASSERT(dtrace_anon.dta_enabling == NULL);
+                       dtrace_state_destroy(state);
+                       dtrace_anon.dta_state = NULL;
+                       break;
+               }
+
+               ASSERT(dtrace_anon.dta_enabling != NULL);
+       }
+
+       if (dtrace_anon.dta_enabling != NULL) {
+               int     rval;
+
+               /*
+                * dtrace_enabling_retain() can only fail because we are
+                * trying to retain more enablings than are allowed -- but
+                * we only have one anonymous enabling, and we are guaranteed
+                * to be allowed at least one retained enabling; we assert
+                * that dtrace_enabling_retain() returns success.
+                */
+               rval = dtrace_enabling_retain(dtrace_anon.dta_enabling);
+               ASSERT(rval == 0);
+
+               dtrace_enabling_dump(dtrace_anon.dta_enabling);
+       }
+}
diff --git a/dtrace/dtrace_asm.S b/dtrace/dtrace_asm.S
new file mode 100644 (file)
index 0000000..3aeb2c5
--- /dev/null
@@ -0,0 +1,328 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <linux/linkage.h>
+
+#define CPU_DTRACE_BADADDR     0x0004  /* DTrace fault: bad address */
+
+#if defined(__x86_64__)
+
+       ENTRY(dtrace_getfp)
+       movq    %rbp, %rax
+       ret
+       ENDPROC(dtrace_getfp)
+
+#elif defined(__i386__)
+
+       ENTRY(dtrace_getfp)
+       movl    %ebp, %eax
+       ret
+       ENDPROC(dtrace_getfp)
+
+#endif /* __i386__ */
+
+
+#if defined(__x86_64__)
+
+       ENTRY(dtrace_cas32)
+       movl    %esi, %eax
+       lock
+       cmpxchgl %edx, (%rdi)
+       ret
+       ENDPROC(dtrace_cas32)
+
+       ENTRY(dtrace_casptr)
+       movq    %rsi, %rax
+       lock
+       cmpxchgq %rdx, (%rdi)
+       ret
+       ENDPROC(dtrace_casptr)
+
+#elif defined(__i386__)
+
+       ENTRY(dtrace_cas32)
+       ENTRY(dtrace_casptr)
+       movl    4(%esp), %edx
+       movl    8(%esp), %eax
+       movl    12(%esp), %ecx
+       lock
+       cmpxchgl %ecx, (%edx)
+       ret
+       ENDPROC(dtrace_casptr)
+       ENDPROC(dtrace_cas32)
+
+#endif /* __i386__ */
+
+#if defined(__x86_64__)
+       ENTRY(dtrace_caller)
+       movq    $-1, %rax
+       ret
+       ENDPROC(dtrace_caller)
+
+#elif defined(__i386__)
+
+       ENTRY(dtrace_caller)
+       movl    $-1, %eax
+       ret
+       ENDPROC(dtrace_caller)
+
+#endif /* __i386__ */
+
+#if defined(__x86_64__)
+
+       ENTRY(dtrace_copy)
+       pushq   %rbp
+       movq    %rsp, %rbp
+
+       xchgq   %rdi, %rsi              # make %rsi source, %rdi dest
+       movq    %rdx, %rcx              # load count
+       repz                            # repeat for count ...
+       smovb                           #   move from %ds:rsi to %ed:rdi
+       leave
+       ret
+       ENDPROC(dtrace_copy)
+
+#elif defined(__i386__)
+
+       ENTRY(dtrace_copy)
+       pushl   %ebp
+       movl    %esp, %ebp
+       pushl   %esi
+       pushl   %edi
+
+       movl    8(%ebp), %esi           # Load source address
+       movl    12(%ebp), %edi          # Load destination address
+       movl    16(%ebp), %ecx          # Load count
+       repz                            # Repeat for count...
+       smovb                           #   move from %ds:si to %es:di
+
+       popl    %edi
+       popl    %esi
+       movl    %ebp, %esp
+       popl    %ebp
+       ret
+       ENDPROC(dtrace_copy)
+
+#endif /* __i386__ */
+
+#if defined(__x86_64__)
+
+       ENTRY(dtrace_copystr)
+       pushq   %rbp
+       movq    %rsp, %rbp
+
+0:
+       movb    (%rdi), %al             # load from source
+       movb    %al, (%rsi)             # store to destination
+       addq    $1, %rdi                # increment source pointer
+       addq    $1, %rsi                # increment destination pointer
+       subq    $1, %rdx                # decrement remaining count
+       cmpb    $0, %al
+       je      2f
+       testq   $0xfff, %rdx            # test if count is 4k-aligned
+       jnz     1f                      # if not, continue with copying
+       testq   $CPU_DTRACE_BADADDR, (%rcx) # load and test dtrace flags
+       jnz     2f
+1:
+       cmpq    $0, %rdx
+       jne     0b
+2:
+       leave
+       ret
+
+       ENDPROC(dtrace_copystr)
+
+#elif defined(__i386__)
+
+       ENTRY(dtrace_copystr)
+
+       pushl   %ebp                    # Setup stack frame
+       movl    %esp, %ebp
+       pushl   %ebx                    # Save registers
+
+       movl    8(%ebp), %ebx           # Load source address
+       movl    12(%ebp), %edx          # Load destination address
+       movl    16(%ebp), %ecx          # Load count
+
+0:
+       movb    (%ebx), %al             # Load from source
+       movb    %al, (%edx)             # Store to destination
+       incl    %ebx                    # Increment source pointer
+       incl    %edx                    # Increment destination pointer
+       decl    %ecx                    # Decrement remaining count
+       cmpb    $0, %al
+       je      2f
+       testl   $0xfff, %ecx            # Check if count is 4k-aligned
+       jnz     1f
+       movl    20(%ebp), %eax          # load flags pointer
+       testl   $CPU_DTRACE_BADADDR, (%eax) # load and test dtrace flags
+       jnz     2f
+1:
+       cmpl    $0, %ecx
+       jne     0b
+
+2:
+       popl    %ebx
+       movl    %ebp, %esp
+       popl    %ebp
+       ret
+
+       ENDPROC(dtrace_copystr)
+
+#endif /* __i386__ */
+
+#if defined(__x86_64__)
+
+       ENTRY(dtrace_fulword)
+       movq    (%rdi), %rax
+       ret
+       ENDPROC(dtrace_fulword)
+
+#elif defined(__i386__)
+
+       ENTRY(dtrace_fulword)
+       movl    4(%esp), %ecx
+       xorl    %eax, %eax
+       movl    (%ecx), %eax
+       ret
+       ENDPROC(dtrace_fulword)
+
+#endif /* __i386__ */
+
+#if defined(__x86_64__)
+
+       ENTRY(dtrace_fuword8_nocheck)
+       xorq    %rax, %rax
+       movb    (%rdi), %al
+       ret
+       ENDPROC(dtrace_fuword8_nocheck)
+
+#elif defined(__i386__)
+
+       ENTRY(dtrace_fuword8_nocheck)
+       movl    4(%esp), %ecx
+       xorl    %eax, %eax
+       movzbl  (%ecx), %eax
+       ret
+       ENDPROC(dtrace_fuword8_nocheck)
+
+#endif /* __i386__ */
+
+#if defined(__x86_64__)
+
+       ENTRY(dtrace_fuword16_nocheck)
+       xorq    %rax, %rax
+       movw    (%rdi), %ax
+       ret
+       ENDPROC(dtrace_fuword16_nocheck)
+
+#elif defined(__i386__)
+
+       ENTRY(dtrace_fuword16_nocheck)
+       movl    4(%esp), %ecx
+       xorl    %eax, %eax
+       movzwl  (%ecx), %eax
+       ret
+       ENDPROC(dtrace_fuword16_nocheck)
+
+#endif /* __i386__ */
+
+#if defined(__x86_64__)
+
+       ENTRY(dtrace_fuword32_nocheck)
+       xorq    %rax, %rax
+       movl    (%rdi), %eax
+       ret
+       ENDPROC(dtrace_fuword32_nocheck)
+
+#elif defined(__i386__)
+
+       ENTRY(dtrace_fuword32_nocheck)
+       movl    4(%esp), %ecx
+       xorl    %eax, %eax
+       movl    (%ecx), %eax
+       ret
+       ENDPROC(dtrace_fuword32_nocheck)
+
+#endif /* __i386__ */
+
+#if defined(__x86_64__)
+
+       ENTRY(dtrace_fuword64_nocheck)
+       movq    (%rdi), %rax
+       ret
+       ENDPROC(dtrace_fuword64_nocheck)
+
+#elif defined(__i386__)
+
+       ENTRY(dtrace_fuword64_nocheck)
+       movl    4(%esp), %ecx
+       xorl    %eax, %eax
+       xorl    %edx, %edx
+       movl    (%ecx), %eax
+       movl    4(%ecx), %edx
+       ret
+       ENDPROC(dtrace_fuword64_nocheck)
+
+#endif /* __i386__ */
+
+#if defined(__x86_64__)
+
+       ENTRY(dtrace_probe_error)
+       pushq   %rbp
+       movq    %rsp, %rbp
+       subq    $0x8, %rsp
+       movq    %r9, (%rsp)
+       movq    %r8, %r9
+       movq    %rcx, %r8
+       movq    %rdx, %rcx
+       movq    %rsi, %rdx
+       movq    %rdi, %rsi
+       movl    dtrace_probeid_error(%rip), %edi
+       call    dtrace_probe
+       addq    $0x8, %rsp
+       leave
+       ret
+       ENDPROC(dtrace_probe_error)
+
+#elif defined(__i386__)
+
+       ENTRY(dtrace_probe_error)
+       pushl   %ebp
+       movl    %esp, %ebp
+       pushl   0x1c(%ebp)
+       pushl   0x18(%ebp)
+       pushl   0x14(%ebp)
+       pushl   0x10(%ebp)
+       pushl   0xc(%ebp)
+       pushl   0x8(%ebp)
+       pushl   dtrace_probeid_error
+       call    dtrace_probe
+       movl    %ebp, %esp
+       popl    %ebp
+       ret
+       ENDPROC(dtrace_probe_error)
+
+#endif /* __i386__ */
diff --git a/dtrace/dtrace_buffer.c b/dtrace/dtrace_buffer.c
new file mode 100644 (file)
index 0000000..073cd59
--- /dev/null
@@ -0,0 +1,454 @@
+/*
+ * FILE:       dtrace_buffer.c
+ * DESCRIPTION:        Dynamic Tracing: buffer functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/vmalloc.h>
+
+#include "dtrace.h"
+
+dtrace_optval_t                dtrace_nonroot_maxsize = (16 * 1024 * 1024);
+
+/*
+ * Note:  called from cross call context.  This function switches the two
+ * buffers on a given CPU.  The atomicity of this operation is assured by
+ * disabling interrupts while the actual switch takes place; the disabling of
+ * interrupts serializes the execution with any execution of dtrace_probe() on
+ * the same CPU.
+ */
+void dtrace_buffer_switch(dtrace_buffer_t *buf)
+{
+       caddr_t                 tomax = buf->dtb_tomax;
+       caddr_t                 xamot = buf->dtb_xamot;
+       dtrace_icookie_t        cookie;
+
+       ASSERT(!(buf->dtb_flags & DTRACEBUF_NOSWITCH));
+       ASSERT(!(buf->dtb_flags & DTRACEBUF_RING));
+
+       local_irq_save(cookie);
+
+       buf->dtb_tomax = xamot;
+       buf->dtb_xamot = tomax;
+       buf->dtb_xamot_drops = buf->dtb_drops;
+       buf->dtb_xamot_offset = buf->dtb_offset;
+       buf->dtb_xamot_errors = buf->dtb_errors;
+       buf->dtb_xamot_flags = buf->dtb_flags;
+       buf->dtb_offset = 0;
+       buf->dtb_drops = 0;
+       buf->dtb_errors = 0;
+       buf->dtb_flags &= ~(DTRACEBUF_ERROR | DTRACEBUF_DROPPED);
+
+       local_irq_restore(cookie);
+}
+
+/*
+ * Note:  called from cross call context.  This function activates a buffer
+ * on a CPU.  As with dtrace_buffer_switch(), the atomicity of the operation
+ * is guaranteed by the disabling of interrupts.
+ */
+void dtrace_buffer_activate(dtrace_state_t *state)
+{
+       dtrace_buffer_t         *buf;
+       dtrace_icookie_t        cookie;
+
+       local_irq_save(cookie);
+
+       buf = &state->dts_buffer[smp_processor_id()];
+
+       if (buf->dtb_tomax != NULL) {
+               /*
+                * We might like to assert that the buffer is marked inactive,
+                * but this isn't necessarily true:  the buffer for the CPU
+                * that processes the BEGIN probe has its buffer activated
+                * manually.  In this case, we take the (harmless) action
+                * re-clearing the bit INACTIVE bit.
+                */
+                buf->dtb_flags &= ~DTRACEBUF_INACTIVE;
+       }
+
+       local_irq_restore(cookie);
+}
+
+int dtrace_buffer_alloc(dtrace_buffer_t *bufs, size_t size, int flags,
+                       processorid_t cpuid)
+{
+       processorid_t   cpu;
+       dtrace_buffer_t *buf;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(mutex_is_locked(&cpu_lock));
+
+#ifdef FIXME
+       if (size > dtrace_nonroot_maxsize &&
+           !PRIV_POLICY_CHOICE(current_cred(), PRIV_ALL, FALSE))
+               return -EFBIG;
+#endif
+
+       for_each_online_cpu(cpu) {
+               if (cpuid != DTRACE_CPUALL && cpuid != cpu)
+                       continue;
+
+               buf = &bufs[cpu];
+
+               /*
+                * If there is already a buffer allocated for this CPU, it
+                * is only possible that this is a DR event.  In this case,
+                * the buffer size must match our specified size.
+                */
+               if (buf->dtb_tomax != NULL) {
+                       ASSERT(buf->dtb_size == size);
+                       continue;
+               }
+
+               ASSERT(buf->dtb_xamot == NULL);
+
+               if ((buf->dtb_tomax = dtrace_vzalloc_try(size)) == NULL)
+                       goto err;
+
+               buf->dtb_size = size;
+               buf->dtb_flags = flags;
+               buf->dtb_offset = 0;
+               buf->dtb_drops = 0;
+
+               if (flags & DTRACEBUF_NOSWITCH)
+                       continue;
+
+               if ((buf->dtb_xamot = dtrace_vzalloc_try(size)) == NULL)
+                       goto err;
+       }
+
+       return 0;
+
+err:
+       for_each_online_cpu(cpu) {
+               if (cpuid != DTRACE_CPUALL && cpuid != cpu)
+                       continue;
+
+               buf = &bufs[cpu];
+
+               if (buf->dtb_xamot != NULL) {
+                       ASSERT(buf->dtb_tomax != NULL);
+                       ASSERT(buf->dtb_size == size);
+                       vfree(buf->dtb_xamot);
+               }
+
+               if (buf->dtb_tomax != NULL) {
+                       ASSERT(buf->dtb_size == size);
+                       vfree(buf->dtb_tomax);
+               }
+
+               buf->dtb_tomax = NULL;
+               buf->dtb_xamot = NULL;
+               buf->dtb_size = 0;
+       }
+
+       return -ENOMEM;
+}
+void dtrace_buffer_drop(dtrace_buffer_t *buf)
+{
+       buf->dtb_drops++;
+}
+
+intptr_t dtrace_buffer_reserve(dtrace_buffer_t *buf, size_t needed,
+                              size_t align, dtrace_state_t *state,
+                              dtrace_mstate_t *mstate)
+{
+       intptr_t        offs = buf->dtb_offset, soffs;
+       intptr_t        woffs;
+       caddr_t         tomax;
+       size_t          total;
+
+       if (buf->dtb_flags & DTRACEBUF_INACTIVE)
+               return -1;
+
+       if ((tomax = buf->dtb_tomax) == NULL) {
+               dtrace_buffer_drop(buf);
+               return -1;
+       }
+
+       if (!(buf->dtb_flags & (DTRACEBUF_RING | DTRACEBUF_FILL))) {
+               while (offs & (align - 1)) {
+                       /*
+                        * Assert that our alignment is off by a number which
+                        * is itself sizeof (uint32_t) aligned.
+                        */
+                       ASSERT(!((align - (offs & (align - 1))) &
+                               (sizeof (uint32_t) - 1)));
+                       DTRACE_STORE(uint32_t, tomax, offs, DTRACE_EPIDNONE);
+                       offs += sizeof (uint32_t);
+               }
+
+               if ((soffs = offs + needed) > buf->dtb_size) {
+                       dtrace_buffer_drop(buf);
+                       return -1;
+               }
+
+               if (mstate == NULL)
+                       return (offs);
+
+               mstate->dtms_scratch_base = (uintptr_t)tomax + soffs;
+               mstate->dtms_scratch_size = buf->dtb_size - soffs;
+               mstate->dtms_scratch_ptr = mstate->dtms_scratch_base;
+
+               return offs;
+       }
+
+       if (buf->dtb_flags & DTRACEBUF_FILL) {
+               if (state->dts_activity != DTRACE_ACTIVITY_COOLDOWN &&
+                   (buf->dtb_flags & DTRACEBUF_FULL))
+                       return -1;
+
+               goto out;
+       }
+
+       total = needed + (offs & (align - 1));
+
+       /*
+        * For a ring buffer, life is quite a bit more complicated.  Before
+        * we can store any padding, we need to adjust our wrapping offset.
+        * (If we've never before wrapped or we're not about to, no adjustment
+        * is required.)
+        */
+       if ((buf->dtb_flags & DTRACEBUF_WRAPPED) ||
+           offs + total > buf->dtb_size) {
+               woffs = buf->dtb_xamot_offset;
+
+               if (offs + total > buf->dtb_size) {
+                       /*
+                        * We can't fit in the end of the buffer.  First, a
+                        * sanity check that we can fit in the buffer at all.
+                        */
+                       if (total > buf->dtb_size) {
+                               dtrace_buffer_drop(buf);
+                               return -1;
+                       }
+
+                       /*
+                        * We're going to be storing at the top of the buffer,
+                        * so now we need to deal with the wrapped offset.  We
+                        * only reset our wrapped offset to 0 if it is
+                        * currently greater than the current offset.  If it
+                        * is less than the current offset, it is because a
+                        * previous allocation induced a wrap -- but the
+                        * allocation didn't subsequently take the space due
+                        * to an error or false predicate evaluation.  In this
+                        * case, we'll just leave the wrapped offset alone: if
+                        * the wrapped offset hasn't been advanced far enough
+                        * for this allocation, it will be adjusted in the
+                        * lower loop.
+                        */
+                       if (buf->dtb_flags & DTRACEBUF_WRAPPED) {
+                               if (woffs >= offs)
+                                       woffs = 0;
+                       } else
+                               woffs = 0;
+
+                       /*
+                        * Now we know that we're going to be storing to the
+                        * top of the buffer and that there is room for us
+                        * there.  We need to clear the buffer from the current
+                        * offset to the end (there may be old gunk there).
+                        */
+                       while (offs < buf->dtb_size)
+                               tomax[offs++] = 0;
+
+                       /*
+                        * We need to set our offset to zero.  And because we
+                        * are wrapping, we need to set the bit indicating as
+                        * much.  We can also adjust our needed space back
+                        * down to the space required by the ECB -- we know
+                        * that the top of the buffer is aligned.
+                        */
+                       offs = 0;
+                       total = needed;
+                       buf->dtb_flags |= DTRACEBUF_WRAPPED;
+               } else {
+                       /*
+                        * There is room for us in the buffer, so we simply
+                        * need to check the wrapped offset.
+                        */
+                       if (woffs < offs) {
+                               /*
+                                * The wrapped offset is less than the offset.
+                                * This can happen if we allocated buffer space
+                                * that induced a wrap, but then we didn't
+                                * subsequently take the space due to an error
+                                * or false predicate evaluation.  This is
+                                * okay; we know that _this_ allocation isn't
+                                * going to induce a wrap.  We still can't
+                                * reset the wrapped offset to be zero,
+                                * however: the space may have been trashed in
+                                * the previous failed probe attempt.  But at
+                                * least the wrapped offset doesn't need to
+                                * be adjusted at all...
+                                */
+                               goto out;
+                       }
+               }
+
+               while (offs + total > woffs) {
+                       dtrace_epid_t   epid = *(uint32_t *)(tomax + woffs);
+                       size_t          size;
+
+                       if (epid == DTRACE_EPIDNONE)
+                               size = sizeof (uint32_t);
+                       else {
+                               ASSERT(epid <= state->dts_necbs);
+                               ASSERT(state->dts_ecbs[epid - 1] != NULL);
+
+                               size = state->dts_ecbs[epid - 1]->dte_size;
+                       }
+
+                       ASSERT(woffs + size <= buf->dtb_size);
+                       ASSERT(size != 0);
+
+                       if (woffs + size == buf->dtb_size) {
+                               /*
+                                * We've reached the end of the buffer; we want
+                                * to set the wrapped offset to 0 and break
+                                * out.  However, if the offs is 0, then we're
+                                * in a strange edge-condition:  the amount of
+                                * space that we want to reserve plus the size
+                                * of the record that we're overwriting is
+                                * space but subsequently don't consume it (due
+                                * to a failed predicate or error) the wrapped
+                                * offset will be 0 -- yet the EPID at offset 0
+                                * will not be committed.  This situation is
+                                * relatively easy to deal with:  if we're in
+                                * this case, the buffer is indistinguishable
+                                * from one that hasn't wrapped; we need only
+                                * finish the job by clearing the wrapped bit,
+                                * explicitly setting the offset to be 0, and
+                                * zero'ing out the old data in the buffer.
+                                */
+                               if (offs == 0) {
+                                       buf->dtb_flags &= ~DTRACEBUF_WRAPPED;
+                                       buf->dtb_offset = 0;
+                                       woffs = total;
+
+                                       while (woffs < buf->dtb_size)
+                                               tomax[woffs++] = 0;
+                               }
+
+                               woffs = 0;
+                               break;
+                       }
+
+                       woffs += size;
+               }
+
+               /*
+                * We have a wrapped offset.  It may be that the wrapped offset
+                * has become zero -- that's okay.
+                */
+               buf->dtb_xamot_offset = woffs;
+       }
+
+out:
+       /*
+        * Now we can plow the buffer with any necessary padding.
+        */
+       while (offs & (align - 1)) {
+               /*
+                * Assert that our alignment is off by a number which
+                * is itself sizeof (uint32_t) aligned.
+                */
+               ASSERT(!((align - (offs & (align - 1))) &
+                       (sizeof (uint32_t) - 1)));
+               DTRACE_STORE(uint32_t, tomax, offs, DTRACE_EPIDNONE);
+               offs += sizeof (uint32_t);
+       }
+
+       if (buf->dtb_flags & DTRACEBUF_FILL) {
+               if (offs + needed > buf->dtb_size - state->dts_reserve) {
+                       buf->dtb_flags |= DTRACEBUF_FULL;
+                       return -1;
+               }
+       }
+
+       if (mstate == NULL)
+               return offs;
+
+       /*
+        * For ring buffers and fill buffers, the scratch space is always
+        * the inactive buffer.
+        */
+       mstate->dtms_scratch_base = (uintptr_t)buf->dtb_xamot;
+       mstate->dtms_scratch_size = buf->dtb_size;
+       mstate->dtms_scratch_ptr = mstate->dtms_scratch_base;
+
+       return offs;
+}
+
+void dtrace_buffer_polish(dtrace_buffer_t *buf)
+{
+       ASSERT(buf->dtb_flags & DTRACEBUF_RING);
+       ASSERT(mutex_is_locked(&dtrace_lock));
+
+       if (!(buf->dtb_flags & DTRACEBUF_WRAPPED))
+               return;
+
+       /*
+        * We need to polish the ring buffer.  There are three cases:
+        *
+        * - The first (and presumably most common) is that there is no gap
+        *   between the buffer offset and the wrapped offset.  In this case,
+        *   there is nothing in the buffer that isn't valid data; we can
+        *   mark the buffer as polished and return.
+        *
+        * - The second (less common than the first but still more common
+        *   than the third) is that there is a gap between the buffer offset
+        *   and the wrapped offset, and the wrapped offset is larger than the
+        *   buffer offset.  This can happen because of an alignment issue, or
+        *   can happen because of a call to dtrace_buffer_reserve() that
+        *   didn't subsequently consume the buffer space.  In this case,
+        *   we need to zero the data from the buffer offset to the wrapped
+        *   offset.
+        *
+        * - The third (and least common) is that there is a gap between the
+        *   buffer offset and the wrapped offset, but the wrapped offset is
+        *   _less_ than the buffer offset.  This can only happen because a
+        *   call to dtrace_buffer_reserve() induced a wrap, but the space
+        *   was not subsequently consumed.  In this case, we need to zero the
+        *   space from the offset to the end of the buffer _and_ from the
+        *   top of the buffer to the wrapped offset.
+        */
+       if (buf->dtb_offset < buf->dtb_xamot_offset)
+               memset(buf->dtb_tomax + buf->dtb_offset, 0,
+                      buf->dtb_xamot_offset - buf->dtb_offset);
+
+       if (buf->dtb_offset > buf->dtb_xamot_offset) {
+               memset(buf->dtb_tomax + buf->dtb_offset, 0,
+                      buf->dtb_size - buf->dtb_offset);
+               memset(buf->dtb_tomax, 0, buf->dtb_xamot_offset);
+       }
+}
+
+void dtrace_buffer_free(dtrace_buffer_t *bufs)
+{
+       int     cpu;
+
+       for_each_online_cpu(cpu) {
+               dtrace_buffer_t *buf = &bufs[cpu];
+
+               if (buf->dtb_tomax == NULL) {
+                       ASSERT(buf->dtb_xamot == NULL);
+                       ASSERT(buf->dtb_size == 0);
+
+                       continue;
+               }
+
+               if (buf->dtb_xamot != NULL) {
+                       ASSERT(!(buf->dtb_flags & DTRACEBUF_NOSWITCH));
+
+                       vfree(buf->dtb_xamot);
+                       buf->dtb_xamot = NULL;
+               }
+
+               vfree(buf->dtb_tomax);
+               buf->dtb_size = 0;
+               buf->dtb_tomax = NULL;
+       }
+}
diff --git a/dtrace/dtrace_dev.c b/dtrace/dtrace_dev.c
new file mode 100644 (file)
index 0000000..9dfe442
--- /dev/null
@@ -0,0 +1,1317 @@
+/*
+ * FILE:       dtrace_dev.c
+ * DESCRIPTION:        Dynamic Tracing: device file handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/delay.h>
+#include <linux/fs.h>
+#include <linux/jiffies.h>
+#include <linux/kernel.h>
+#include <linux/miscdevice.h>
+#include <linux/slab.h>
+#include <asm/uaccess.h>
+
+#include "ctf_api.h"
+#include "dtrace.h"
+#include "dtrace_dev.h"
+#include "dtrace_ioctl.h"
+
+uint32_t                       dtrace_helptrace_next = 0;
+uint32_t                       dtrace_helptrace_nlocals;
+char                           *dtrace_helptrace_buffer;
+int                            dtrace_helptrace_bufsize = 512 * 1024;
+
+#ifdef CONFIG_DT_DEBUG
+int                            dtrace_helptrace_enabled = 1;
+#else
+int                            dtrace_helptrace_enabled = 0;
+#endif
+
+int                            dtrace_opens;
+int                            dtrace_err_verbose;
+
+dtrace_pops_t                  dtrace_provider_ops = {
+       (void (*)(void *, const dtrace_probedesc_t *))dtrace_nullop,
+       (void (*)(void *, struct module *))dtrace_nullop,
+       (int (*)(void *, dtrace_id_t, void *))dtrace_enable_nullop,
+       (void (*)(void *, dtrace_id_t, void *))dtrace_nullop,
+       (void (*)(void *, dtrace_id_t, void *))dtrace_nullop,
+       (void (*)(void *, dtrace_id_t, void *))dtrace_nullop,
+       NULL,
+       NULL,
+       NULL,
+       (void (*)(void *, dtrace_id_t, void *))dtrace_nullop
+};
+
+dtrace_toxrange_t              *dtrace_toxrange;
+int                            dtrace_toxranges;
+
+static size_t                  dtrace_retain_max = 1024;
+
+static int                     dtrace_toxranges_max;
+
+static dtrace_pattr_t          dtrace_provider_attr = {
+{ DTRACE_STABILITY_STABLE, DTRACE_STABILITY_STABLE, DTRACE_CLASS_COMMON },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_STABLE, DTRACE_STABILITY_STABLE, DTRACE_CLASS_COMMON },
+{ DTRACE_STABILITY_STABLE, DTRACE_STABILITY_STABLE, DTRACE_CLASS_COMMON },
+};
+
+void (*dtrace_modload)(struct module *);
+void (*dtrace_modunload)(struct module *);
+
+void dtrace_nullop(void)
+{
+}
+
+int dtrace_enable_nullop(void)
+{
+       return 0;
+}
+
+static long dtrace_ioctl(struct file *file,
+                        unsigned int cmd, unsigned long arg)
+{
+       dtrace_state_t  *state = (dtrace_state_t *)file->private_data;
+       int             rval;
+       void __user     *argp = (void __user *)arg;
+
+       if (state->dts_anon) {
+               ASSERT(dtrace_anon.dta_state == NULL);
+               state = state->dts_anon;
+       }
+
+       switch (cmd) {
+       case DTRACEIOC_PROVIDER: {
+               dtrace_providerdesc_t   pvd;
+               dtrace_provider_t       *pvp;
+
+printk(KERN_INFO "IOCTL provider\n");
+               if (copy_from_user(&pvd, argp, sizeof(pvd)) != 0)
+                       return -EFAULT;
+
+               pvd.dtvd_name[DTRACE_PROVNAMELEN - 1] = '\0';
+               mutex_lock(&dtrace_provider_lock);
+
+               for (pvp = dtrace_provider; pvp != NULL; pvp = pvp->dtpv_next) {
+                       if (strcmp(pvp->dtpv_name, pvd.dtvd_name) == 0)
+                               break;
+               }
+
+               mutex_unlock(&dtrace_provider_lock);
+
+               if (pvp == NULL)
+                       return -ESRCH;
+
+               memcpy(&pvd.dtvd_priv, &pvp->dtpv_priv,
+                      sizeof(dtrace_ppriv_t));
+               memcpy(&pvd.dtvd_attr, &pvp->dtpv_attr,
+                      sizeof(dtrace_pattr_t));
+
+               if (copy_to_user(argp, &pvd, sizeof(pvd)) != 0)
+                       return -EFAULT;
+
+               return 0;
+       }
+
+       case DTRACEIOC_EPROBE: {
+               dtrace_eprobedesc_t     epdesc;
+               dtrace_ecb_t            *ecb;
+               dtrace_action_t         *act;
+               void                    *buf;
+               size_t                  size;
+               uint8_t                 *dest;
+               int                     nrecs;
+
+printk(KERN_INFO "IOCTL eprobe\n");
+               if (copy_from_user(&epdesc, argp, sizeof(epdesc)) != 0)
+                       return -EFAULT;
+
+               mutex_lock(&dtrace_lock);
+
+printk(KERN_INFO "    Looking for ECB %ld\n", epdesc.dtepd_epid);
+               if ((ecb = dtrace_epid2ecb(state, epdesc.dtepd_epid)) == NULL) {
+                       mutex_unlock(&dtrace_lock);
+printk(KERN_INFO "    ECB not found\n");
+                       return -EINVAL;
+               }
+
+               if (ecb->dte_probe == NULL) {
+                       mutex_unlock(&dtrace_lock);
+printk(KERN_INFO "    ECB has no probe\n");
+                       return -EINVAL;
+               }
+
+printk(KERN_INFO "    ECB has probe %ld\n", ecb->dte_probe->dtpr_id);
+               epdesc.dtepd_probeid = ecb->dte_probe->dtpr_id;
+               epdesc.dtepd_uarg = ecb->dte_uarg;
+               epdesc.dtepd_size = ecb->dte_size;
+
+               nrecs = epdesc.dtepd_nrecs;
+               epdesc.dtepd_nrecs = 0;
+               for (act = ecb->dte_action; act != NULL; act = act->dta_next) {
+                       if (DTRACEACT_ISAGG(act->dta_kind) || act->dta_intuple)
+                               continue;
+
+                       epdesc.dtepd_nrecs++;
+               }
+
+               /*
+                * Now that we have the size, we need to allocate a temporary
+                * buffer in which to store the complete description.  We need
+                * the temporary buffer to be able to drop dtrace_lock()
+                * across the copy_to_user(), below.
+                */
+               size = sizeof(dtrace_eprobedesc_t) +
+                      (epdesc.dtepd_nrecs * sizeof(dtrace_recdesc_t));
+
+               buf = kmalloc(size, GFP_KERNEL);
+               dest = buf;
+
+               memcpy(dest, &epdesc, sizeof(epdesc));
+               dest += offsetof(dtrace_eprobedesc_t, dtepd_rec[0]);
+
+               for (act = ecb->dte_action; act != NULL; act = act->dta_next) {
+                       if (DTRACEACT_ISAGG(act->dta_kind) || act->dta_intuple)
+                               continue;
+
+                       if (nrecs-- == 0)
+                               break;
+
+                       memcpy(dest, &act->dta_rec, sizeof(dtrace_recdesc_t));
+                       dest += sizeof(dtrace_recdesc_t);
+               }
+
+               mutex_unlock(&dtrace_lock);
+
+               if (copy_to_user(argp, buf,
+                                (uintptr_t)(dest - (uint8_t *)buf)) != 0) {
+                       kfree(buf);
+                       return -EFAULT;
+               }
+
+               kfree(buf);
+               return 0;
+       }
+
+       case DTRACEIOC_AGGDESC: {
+               dtrace_aggdesc_t        aggdesc;
+               dtrace_action_t         *act;
+               dtrace_aggregation_t    *agg;
+               int                     nrecs;
+               uint32_t                offs;
+               dtrace_recdesc_t        *lrec;
+               void                    *buf;
+               size_t                  size;
+               uint8_t                 *dest;
+
+printk(KERN_INFO "IOCTL aggdesc\n");
+               if (copy_from_user(&aggdesc, argp, sizeof(aggdesc)) != 0)
+                       return -EFAULT;
+
+               mutex_lock(&dtrace_lock);
+
+               if ((agg = dtrace_aggid2agg(state, aggdesc.dtagd_id)) == NULL) {
+                       mutex_unlock(&dtrace_lock);
+                       return -EINVAL;
+               }
+printk(KERN_INFO "IOCTL aggdesc: Found agg %lu, ECB %lu\n", agg->dtag_id, agg->dtag_ecb->dte_epid);
+
+               aggdesc.dtagd_epid = agg->dtag_ecb->dte_epid;
+
+               nrecs = aggdesc.dtagd_nrecs;
+               aggdesc.dtagd_nrecs = 0;
+
+               offs = agg->dtag_base;
+               lrec = &agg->dtag_action.dta_rec;
+               aggdesc.dtagd_size = lrec->dtrd_offset + lrec->dtrd_size -
+                                    offs;
+
+               for (act = agg->dtag_first; ; act = act->dta_next) {
+                       ASSERT(act->dta_intuple ||
+                              DTRACEACT_ISAGG(act->dta_kind));
+
+                       /*
+                        * If this action has a record size of zero, it
+                        * denotes an argument to the aggregating action.
+                        * Because the presence of this record doesn't (or
+                        * shouldn't) affect the way the data is interpreted,
+                        * we don't copy it out to save user-level the
+                        * confusion of dealing with a zero-length record.
+                        */
+                       if (act->dta_rec.dtrd_size == 0) {
+                               ASSERT(agg->dtag_hasarg);
+                               continue;
+                       }
+
+                       aggdesc.dtagd_nrecs++;
+
+                       if (act == &agg->dtag_action)
+                               break;
+               }
+
+               /*
+                * Now that we have the size, we need to allocate a temporary
+                * buffer in which to store the complete description.  We need
+                * the temporary buffer to be able to drop dtrace_lock()
+                * across the copyout(), below.
+                */
+               size = sizeof(dtrace_aggdesc_t) +
+                      (aggdesc.dtagd_nrecs * sizeof(dtrace_recdesc_t));
+
+               buf = kmalloc(size, GFP_KERNEL);
+               dest = buf;
+
+               memcpy(dest, &aggdesc, sizeof(aggdesc));
+               dest += offsetof(dtrace_aggdesc_t, dtagd_rec[0]);
+
+               for (act = agg->dtag_first; ; act = act->dta_next) {
+                       dtrace_recdesc_t        rec = act->dta_rec;
+
+                       /*
+                        * See the comment in the above loop for why we pass
+                        * over zero-length records.
+                        */
+                       if (rec.dtrd_size == 0) {
+                               ASSERT(agg->dtag_hasarg);
+                               continue;
+                       }
+
+                       if (nrecs-- == 0)
+                               break;
+
+                       rec.dtrd_offset -= offs;
+                       memcpy(dest, &rec, sizeof(rec));
+                       dest += sizeof(dtrace_recdesc_t);
+
+                       if (act == &agg->dtag_action)
+                               break;
+               }
+
+               mutex_unlock(&dtrace_lock);
+
+               if (copy_to_user(argp, buf,
+                                (uintptr_t)(dest - (uint8_t *)buf)) != 0) {
+                       kfree(buf);
+                       return -EFAULT;
+               }
+
+               kfree(buf);
+               return 0;
+       }
+
+       case DTRACEIOC_ENABLE: {
+               dof_hdr_t               *dof;
+               dtrace_enabling_t       *enab = NULL;
+               dtrace_vstate_t         *vstate;
+               int                     err = 0;
+               int                     rv;
+
+printk(KERN_INFO "IOCTL enable\n");
+               rv = 0;
+
+               /*
+                * If a NULL argument has been passed, we take this as our
+                * cue to reevaluate our enablings.
+                */
+               if (argp == NULL) {
+                       dtrace_enabling_matchall();
+
+                       return 0;
+               }
+
+               if ((dof = dtrace_dof_copyin(argp, &rval)) == NULL)
+                       return rval;
+
+               mutex_lock(&cpu_lock);
+               mutex_lock(&dtrace_lock);
+               vstate = &state->dts_vstate;
+
+               if (state->dts_activity != DTRACE_ACTIVITY_INACTIVE) {
+                       mutex_unlock(&dtrace_lock);
+                       mutex_unlock(&cpu_lock);
+                       dtrace_dof_destroy(dof);
+                       return -EBUSY;
+               }
+
+               if (dtrace_dof_slurp(dof, vstate, file->f_cred, &enab, 0,
+                                    TRUE) != 0) {
+                       mutex_unlock(&dtrace_lock);
+                       mutex_unlock(&cpu_lock);
+                       dtrace_dof_destroy(dof);
+                       return -EINVAL;
+               }
+
+               if ((rval = dtrace_dof_options(dof, state)) != 0) {
+                       dtrace_enabling_destroy(enab);
+                       mutex_unlock(&dtrace_lock);
+                       mutex_unlock(&cpu_lock);
+                       dtrace_dof_destroy(dof);
+                       return rval;
+               }
+
+               if ((err = dtrace_enabling_match(enab, &rv)) == 0)
+                       err = dtrace_enabling_retain(enab);
+               else
+                       dtrace_enabling_destroy(enab);
+
+               mutex_unlock(&dtrace_lock);
+               mutex_unlock(&cpu_lock);
+               dtrace_dof_destroy(dof);
+
+               return err == 0 ? rv : err;
+       }
+
+       case DTRACEIOC_REPLICATE: {
+               dtrace_repldesc_t       desc;
+               dtrace_probedesc_t      *match = &desc.dtrpd_match;
+               dtrace_probedesc_t      *create = &desc.dtrpd_create;
+               int                     err;
+
+printk(KERN_INFO "IOCTL replicate\n");
+               if (copy_from_user(&desc, argp, sizeof(desc)) != 0)
+                       return -EFAULT;
+
+               match->dtpd_provider[DTRACE_PROVNAMELEN - 1] = '\0';
+               match->dtpd_mod[DTRACE_MODNAMELEN - 1] = '\0';
+               match->dtpd_func[DTRACE_FUNCNAMELEN - 1] = '\0';
+               match->dtpd_name[DTRACE_NAMELEN - 1] = '\0';
+
+               create->dtpd_provider[DTRACE_PROVNAMELEN - 1] = '\0';
+               create->dtpd_mod[DTRACE_MODNAMELEN - 1] = '\0';
+               create->dtpd_func[DTRACE_FUNCNAMELEN - 1] = '\0';
+               create->dtpd_name[DTRACE_NAMELEN - 1] = '\0';
+
+               mutex_lock(&dtrace_lock);
+               err = dtrace_enabling_replicate(state, match, create);
+               mutex_unlock(&dtrace_lock);
+
+               return err;
+       }
+
+       case DTRACEIOC_PROBEMATCH:
+       case DTRACEIOC_PROBES: {
+               dtrace_probe_t          *probe = NULL;
+               dtrace_probedesc_t      desc;
+               dtrace_probekey_t       pkey;
+               uint32_t                priv;
+               uid_t                   uid;
+
+printk(KERN_INFO "IOCTL %s\n", cmd == DTRACEIOC_PROBEMATCH ? "probematch" : "probes");
+               if (copy_from_user(&desc, argp, sizeof(desc)) != 0)
+                       return -EFAULT;
+
+               desc.dtpd_provider[DTRACE_PROVNAMELEN - 1] = '\0';
+               desc.dtpd_mod[DTRACE_MODNAMELEN - 1] = '\0';
+               desc.dtpd_func[DTRACE_FUNCNAMELEN - 1] = '\0';
+               desc.dtpd_name[DTRACE_NAMELEN - 1] = '\0';
+
+               /*
+                * Before we attempt to match this probe, we want to give
+                * all providers the opportunity to provide it.
+                */
+               if (desc.dtpd_id == DTRACE_IDNONE) {
+                       mutex_lock(&dtrace_provider_lock);
+                       dtrace_probe_provide(&desc, NULL);
+                       mutex_unlock(&dtrace_provider_lock);
+               }
+
+               if (cmd == DTRACEIOC_PROBEMATCH)  {
+                       dtrace_probekey(&desc, &pkey);
+                       pkey.dtpk_id = DTRACE_IDNONE;
+               }
+printk(KERN_INFO "IOCTL %s: id[%d] p[%s] m[%s] f[%s] n[%s]\n", cmd == DTRACEIOC_PROBEMATCH ? "probematch" : "probes", desc.dtpd_id, desc.dtpd_provider, desc.dtpd_mod, desc.dtpd_func, desc.dtpd_name);
+
+               dtrace_cred2priv(file->f_cred, &priv, &uid);
+
+               mutex_lock(&dtrace_lock);
+
+               if (cmd == DTRACEIOC_PROBEMATCH)  {
+                       int     m = 0;
+
+                       while ((probe = dtrace_probe_get_next(desc.dtpd_id))
+                              != NULL) {
+                               if ((m = dtrace_match_probe(
+                                               probe, &pkey, priv, uid)))
+                                       break;
+
+                               desc.dtpd_id = probe->dtpr_id + 1;
+                       }
+
+                       if (m < 0) {
+                               mutex_unlock(&dtrace_lock);
+                               return -EINVAL;
+                       }
+               } else {
+                       while ((probe = dtrace_probe_get_next(desc.dtpd_id))
+                              != NULL) {
+                               if (dtrace_match_priv(probe, priv, uid))
+                                       break;
+
+                               desc.dtpd_id = probe->dtpr_id + 1;
+                       }
+               }
+
+               if (probe == NULL) {
+                       mutex_unlock(&dtrace_lock);
+                       return -ESRCH;
+               }
+
+               dtrace_probe_description(probe, &desc);
+               mutex_unlock(&dtrace_lock);
+
+printk(KERN_INFO "Returning probe [%s]\n", desc.dtpd_name);
+               if (copy_to_user(argp, &desc, sizeof(desc)) != 0)
+                       return -EFAULT;
+
+               return 0;
+       }
+
+       case DTRACEIOC_PROBEARG: {
+               dtrace_argdesc_t        desc;
+               dtrace_probe_t          *probe;
+               dtrace_provider_t       *prov;
+
+printk(KERN_INFO "IOCTL probearg\n");
+               if (copy_from_user(&desc, argp, sizeof(desc)) != 0)
+                       return -EFAULT;
+
+               if (desc.dtargd_id == DTRACE_IDNONE)
+                       return -EINVAL;
+
+               if (desc.dtargd_ndx == DTRACE_ARGNONE)
+                       return -EINVAL;
+
+               mutex_lock(&dtrace_provider_lock);
+//             mutex_lock(&module_mutex); /* FIXME */
+               mutex_lock(&dtrace_lock);
+
+               probe = dtrace_probe_lookup_id(desc.dtargd_id);
+               if (probe == NULL) {
+                       mutex_unlock(&dtrace_lock);
+//                     mutex_unlock(&module_mutex); /* FIXME */
+                       mutex_unlock(&dtrace_provider_lock);
+
+                       return -EINVAL;
+               }
+
+               mutex_unlock(&dtrace_lock);
+
+               prov = probe->dtpr_provider;
+
+               if (prov->dtpv_pops.dtps_getargdesc == NULL) {
+                       /*
+                        * There isn't any typed information for this probe.
+                        * Set the argument number to DTRACE_ARGNONE.
+                        */
+                       desc.dtargd_ndx = DTRACE_ARGNONE;
+               } else {
+                       desc.dtargd_native[0] = '\0';
+                       desc.dtargd_xlate[0] = '\0';
+                       desc.dtargd_mapping = desc.dtargd_ndx;
+
+                       prov->dtpv_pops.dtps_getargdesc(
+                               prov->dtpv_arg, probe->dtpr_id,
+                               probe->dtpr_arg, &desc);
+               }
+
+//             mutex_unlock(&module_mutex); /* FIXME */
+               mutex_unlock(&dtrace_provider_lock);
+
+               if (copy_to_user(argp, &desc, sizeof(desc)) != 0)
+                       return -EFAULT;
+
+               return 0;
+       }
+
+       case DTRACEIOC_GO: {
+               processorid_t   cpuid;
+
+printk(KERN_INFO "IOCTL go\n");
+               rval = dtrace_state_go(state, &cpuid);
+
+               if (rval != 0)
+                       return rval;
+
+               if (copy_to_user(argp, &cpuid, sizeof(cpuid)) != 0)
+                       return -EFAULT;
+
+               return 0;
+       }
+
+       case DTRACEIOC_STOP: {
+               processorid_t   cpuid;
+
+printk(KERN_INFO "IOCTL stop\n");
+               mutex_lock(&dtrace_lock);
+               rval = dtrace_state_stop(state, &cpuid);
+               mutex_unlock(&dtrace_lock);
+
+               if (rval != 0)
+                       return rval;
+
+               if (copy_to_user(argp, &cpuid, sizeof(cpuid)) != 0)
+                       return -EFAULT;
+
+               return 0;
+       }
+
+       case DTRACEIOC_DOFGET: {
+               dof_hdr_t       hdr, *dof;
+               uint64_t        len;
+
+printk(KERN_INFO "IOCTL dofget\n");
+               if (copy_from_user(&hdr, argp, sizeof(hdr)) != 0)
+                       return -EFAULT;
+
+               mutex_lock(&dtrace_lock);
+               dof = dtrace_dof_create(state);
+               mutex_unlock(&dtrace_lock);
+
+               len = min(hdr.dofh_loadsz, dof->dofh_loadsz);
+               rval = copy_to_user(argp, dof, len);
+               dtrace_dof_destroy(dof);
+
+               return rval == 0 ? 0 : -EFAULT;
+       }
+
+       case DTRACEIOC_AGGSNAP:
+       case DTRACEIOC_BUFSNAP: {
+               dtrace_bufdesc_t        desc;
+               caddr_t                 cached;
+               dtrace_buffer_t         *buf;
+
+printk(KERN_INFO "IOCTL %s\n", cmd == DTRACEIOC_AGGSNAP ? "aggsnap" : "bufsnap");
+               if (copy_from_user(&desc, argp, sizeof(desc)) != 0)
+                       return -EFAULT;
+
+               if (desc.dtbd_cpu < 0 || desc.dtbd_cpu >= NR_CPUS)
+                       return -EINVAL;
+
+               mutex_lock(&dtrace_lock);
+
+               if (cmd == DTRACEIOC_BUFSNAP)
+                       buf = &state->dts_buffer[desc.dtbd_cpu];
+               else
+                       buf = &state->dts_aggbuffer[desc.dtbd_cpu];
+
+               if (buf->dtb_flags & (DTRACEBUF_RING | DTRACEBUF_FILL)) {
+                       size_t  sz = buf->dtb_offset;
+
+                       if (state->dts_activity != DTRACE_ACTIVITY_STOPPED) {
+                               mutex_unlock(&dtrace_lock);
+                               return -EBUSY;
+                       }
+
+                       /*
+                        * If this buffer has already been consumed, we're
+                        * going to indicate that there's nothing left here
+                        * to consume.
+                        */
+                       if (buf->dtb_flags & DTRACEBUF_CONSUMED) {
+                               mutex_unlock(&dtrace_lock);
+
+                               desc.dtbd_size = 0;
+                               desc.dtbd_drops = 0;
+                               desc.dtbd_errors = 0;
+                               desc.dtbd_oldest = 0;
+                               sz = sizeof(desc);
+
+                               if (copy_to_user(argp, &desc, sz) != 0)
+                                       return -EFAULT;
+
+                               return 0;
+                       }
+
+                       /*
+                        * If this is a ring buffer that has wrapped, we want
+                        * to copy the whole thing out.
+                        */
+                       if (buf->dtb_flags & DTRACEBUF_WRAPPED) {
+                               dtrace_buffer_polish(buf);
+                               sz = buf->dtb_size;
+                       }
+
+                       if (copy_to_user(desc.dtbd_data, buf->dtb_tomax,
+                                        sz) != 0) {
+                               mutex_unlock(&dtrace_lock);
+                               return -EFAULT;
+                       }
+
+                       desc.dtbd_size = sz;
+                       desc.dtbd_drops = buf->dtb_drops;
+                       desc.dtbd_errors = buf->dtb_errors;
+                       desc.dtbd_oldest = buf->dtb_xamot_offset;
+
+                       mutex_unlock(&dtrace_lock);
+
+                       if (copy_to_user(argp, &desc, sizeof(desc)) != 0)
+                               return -EFAULT;
+
+                       buf->dtb_flags |= DTRACEBUF_CONSUMED;
+
+                       return 0;
+               }
+
+               if (buf->dtb_tomax == NULL) {
+                       ASSERT(buf->dtb_xamot == NULL);
+                       mutex_unlock(&dtrace_lock);
+                       return -ENOENT;
+               }
+
+               cached = buf->dtb_tomax;
+
+               dtrace_xcall(desc.dtbd_cpu,
+                            (dtrace_xcall_t)dtrace_buffer_switch, buf);
+
+               state->dts_errors += buf->dtb_xamot_errors;
+
+               /*
+                * If the buffers did not actually switch, then the cross call
+                * did not take place -- presumably because the given CPU is
+                * not in the ready set.  If this is the case, we'll return
+                * ENOENT.
+                */
+               if (buf->dtb_tomax == cached) {
+                       ASSERT(buf->dtb_xamot != cached);
+                       mutex_unlock(&dtrace_lock);
+                       return -ENOENT;
+               }
+
+               ASSERT(cached == buf->dtb_xamot);
+
+               /*
+                * We have our snapshot; now copy it out.
+                */
+               if (copy_to_user(desc.dtbd_data, buf->dtb_xamot,
+                                buf->dtb_xamot_offset) != 0) {
+                       mutex_unlock(&dtrace_lock);
+                       return -EFAULT;
+               }
+
+               desc.dtbd_size = buf->dtb_xamot_offset;
+               desc.dtbd_drops = buf->dtb_xamot_drops;
+               desc.dtbd_errors = buf->dtb_xamot_errors;
+               desc.dtbd_oldest = 0;
+
+               mutex_unlock(&dtrace_lock);
+
+               /*
+                * Finally, copy out the buffer description.
+                */
+               if (copy_to_user(argp, &desc, sizeof(desc)) != 0)
+                       return -EFAULT;
+
+               return 0;
+       }
+
+       case DTRACEIOC_CONF: {
+               dtrace_conf_t   conf;
+
+printk(KERN_INFO "IOCTL conf\n");
+               memset(&conf, 0, sizeof(conf));
+               conf.dtc_difversion = DIF_VERSION;
+               conf.dtc_difintregs = DIF_DIR_NREGS;
+               conf.dtc_diftupregs = DIF_DTR_NREGS;
+               conf.dtc_ctfmodel = CTF_MODEL_NATIVE;
+               conf.dtc_maxbufs = nr_cpu_ids;
+
+               if (copy_to_user(argp, &conf, sizeof(conf)) != 0)
+                       return -EFAULT;
+
+               return 0;
+       }
+
+       case DTRACEIOC_STATUS: {
+               dtrace_status_t stat;
+               dtrace_dstate_t *dstate;
+               int             i, j;
+               uint64_t        nerrs;
+
+printk(KERN_INFO "IOCTL status\n");
+               /*
+                * See the comment in dtrace_state_deadman() for the reason
+                * for setting dts_laststatus to INT64_MAX before setting
+                * it to the correct value.
+                */
+               state->dts_laststatus = ns_to_ktime(INT64_MAX);
+               dtrace_membar_producer();
+               state->dts_laststatus = dtrace_gethrtime();
+
+               memset(&stat, 0, sizeof(stat));
+
+               mutex_lock(&dtrace_lock);
+
+               if (state->dts_activity == DTRACE_ACTIVITY_INACTIVE) {
+                       mutex_unlock(&dtrace_lock);
+                       return -ENOENT;
+               }
+
+               if (state->dts_activity == DTRACE_ACTIVITY_DRAINING)
+                       stat.dtst_exiting = 1;
+
+               nerrs = state->dts_errors;
+               dstate = &state->dts_vstate.dtvs_dynvars;
+
+               for (i = 0; i < NR_CPUS; i++) {
+                       dtrace_dstate_percpu_t  *dcpu = &dstate->dtds_percpu[i];
+
+                       stat.dtst_dyndrops += dcpu->dtdsc_drops;
+                       stat.dtst_dyndrops_dirty += dcpu->dtdsc_dirty_drops;
+                       stat.dtst_dyndrops_rinsing += dcpu->dtdsc_rinsing_drops;
+
+                       if (state->dts_buffer[i].dtb_flags & DTRACEBUF_FULL)
+                               stat.dtst_filled++;
+
+                       nerrs += state->dts_buffer[i].dtb_errors;
+
+                       for (j = 0; j < state->dts_nspeculations; j++) {
+                               dtrace_speculation_t    *spec;
+                               dtrace_buffer_t         *buf;
+
+                               spec = &state->dts_speculations[j];
+                               buf = &spec->dtsp_buffer[i];
+                               stat.dtst_specdrops += buf->dtb_xamot_drops;
+                       }
+               }
+
+               stat.dtst_specdrops_busy = state->dts_speculations_busy;
+               stat.dtst_specdrops_unavail = state->dts_speculations_unavail;
+               stat.dtst_stkstroverflows = state->dts_stkstroverflows;
+               stat.dtst_dblerrors = state->dts_dblerrors;
+               stat.dtst_killed = (state->dts_activity ==
+                                   DTRACE_ACTIVITY_KILLED);
+               stat.dtst_errors = nerrs;
+
+               mutex_unlock(&dtrace_lock);
+
+               if (copy_to_user(argp, &stat, sizeof(stat)) != 0)
+                       return -EFAULT;
+
+               return 0;
+       }
+
+       case DTRACEIOC_FORMAT: {
+               dtrace_fmtdesc_t        fmt;
+               char                    *str;
+               int                     len;
+
+printk(KERN_INFO "IOCTL format\n");
+               if (copy_from_user(&fmt, argp, sizeof (fmt)) != 0)
+                       return -EFAULT;
+
+               mutex_lock(&dtrace_lock);
+
+               if (fmt.dtfd_format == 0 ||
+                   fmt.dtfd_format > state->dts_nformats) {
+                       mutex_unlock(&dtrace_lock);
+                       return -EINVAL;
+               }
+
+               /*
+                * Format strings are allocated contiguously and they are
+                * never freed; if a format index is less than the number
+                * of formats, we can assert that the format map is non-NULL
+                * and that the format for the specified index is non-NULL.
+                */
+               ASSERT(state->dts_formats != NULL);
+               str = state->dts_formats[fmt.dtfd_format - 1];
+               ASSERT(str != NULL);
+
+               len = strlen(str) + 1;
+
+               if (len > fmt.dtfd_length) {
+                       fmt.dtfd_length = len;
+
+                       if (copy_to_user(argp, &fmt, sizeof (fmt)) != 0) {
+                               mutex_unlock(&dtrace_lock);
+                               return -EINVAL;
+                       }
+               } else {
+                       if (copy_to_user(fmt.dtfd_string, str, len) != 0) {
+                               mutex_unlock(&dtrace_lock);
+                               return -EINVAL;
+                       }
+               }
+
+               mutex_unlock(&dtrace_lock);
+
+               return 0;
+       }
+
+       default:
+               break;
+       }
+
+       return -ENOTTY;
+}
+
+static int dtrace_open(struct inode *inode, struct file *file)
+{
+       dtrace_state_t  *state;
+       uint32_t        priv;
+       uid_t           uid;
+
+       dtrace_cred2priv(file->f_cred, &priv, &uid);
+       if (priv == DTRACE_PRIV_NONE)
+               return -EACCES;
+
+       mutex_lock(&dtrace_provider_lock);
+       dtrace_probe_provide(NULL, NULL);
+       mutex_unlock(&dtrace_provider_lock);
+
+       mutex_lock(&cpu_lock);
+       mutex_lock(&dtrace_lock);
+       dtrace_opens++;
+       dtrace_membar_producer();
+
+#ifdef FIXME
+       /*
+        * Is this relevant for Linux?  Is there an equivalent?
+        */
+       if (kdi_dtrace_set(KDI_DTSET_DTRACE_ACTIVATE) != 0) {
+               dtrace_opens--;
+               mutex_unlock(&cpu_lock);
+               mutex_unlock(&dtrace_lock);
+               return -EBUSY;
+       }
+#endif
+
+       state = dtrace_state_create(file);
+       mutex_unlock(&cpu_lock);
+
+       if (state == NULL) {
+#ifdef FIXME
+               if (--dtrace_opens == 0 && dtrace_anon.dta_enabling == NULL)
+                       (void)kdi_dtrace_set(KDI_DTSET_DTRACE_DEACTIVATE);
+#endif
+
+               mutex_unlock(&dtrace_lock);
+
+               return -EAGAIN;
+       }
+
+       file->private_data = state;
+
+       mutex_unlock(&dtrace_lock);
+
+       return 0;
+}
+
+static int dtrace_close(struct inode *inode, struct file *file)
+{
+       dtrace_state_t  *state;
+
+       mutex_lock(&cpu_lock);
+       mutex_lock(&dtrace_lock);
+
+       /*
+        * If there is anonymous state, destroy that first.
+        */
+       state = file->private_data;
+       if (state->dts_anon) {
+               ASSERT(dtrace_anon.dta_state == NULL);
+
+               dtrace_state_destroy(state->dts_anon);
+       }
+
+       dtrace_state_destroy(state);
+       ASSERT(dtrace_opens > 0);
+
+#ifdef FIXME
+       if (--dtrace_opens == 0 && dtrace_anon.dta_enabling == NULL)
+               (void)kdi_dtrace_set(KDI_DTSET_DTRACE_DEACTIVATE);
+#else
+       --dtrace_opens;
+#endif
+
+       mutex_unlock(&dtrace_lock);
+       mutex_unlock(&cpu_lock);
+
+       return 0;
+}
+
+static const struct file_operations dtrace_fops = {
+       .owner  = THIS_MODULE,
+        .unlocked_ioctl = dtrace_ioctl,
+        .open   = dtrace_open,
+        .release = dtrace_close,
+};
+
+static struct miscdevice dtrace_dev = {
+       .minor = DT_DEV_DTRACE_MINOR,
+       .name = "dtrace",
+       .nodename = "dtrace/dtrace",
+       .fops = &dtrace_fops,
+};
+
+static void
+dtrace_module_loaded(struct module *module)
+{
+       dtrace_provider_t *prv;
+
+       mutex_lock(&dtrace_provider_lock);
+       /* FIXME: mutex_lock(&mod_lock); */
+
+       //ASSERT(ctl->mod_busy);
+
+       /*
+        * We're going to call each providers per-module provide operation
+        * specifying only this module.
+        */
+       for (prv = dtrace_provider; prv != NULL; prv = prv->dtpv_next)
+               prv->dtpv_pops.dtps_provide_module(prv->dtpv_arg, module);
+
+       /* FIXME: mutex_unlock(&mod_lock); */
+       mutex_unlock(&dtrace_provider_lock);
+
+       /*
+        * If we have any retained enablings, we need to match against them.
+        * Enabling probes requires that cpu_lock be held, and we cannot hold
+        * cpu_lock here -- it is legal for cpu_lock to be held when loading a
+        * module.  (In particular, this happens when loading scheduling
+        * classes.)  So if we have any retained enablings, we need to dispatch
+        * our task queue to do the match for us.
+        */
+       mutex_lock(&dtrace_lock);
+
+       if (dtrace_retained == NULL) {
+               mutex_unlock(&dtrace_lock);
+               return;
+       }
+
+#ifdef FIXME
+       /* FIXME: maybe convert to a Linux workqueue */
+       (void) taskq_dispatch(dtrace_taskq,
+           (task_func_t *)dtrace_enabling_matchall, NULL, TQ_SLEEP);
+#else
+       dtrace_enabling_matchall();
+#endif
+
+       mutex_unlock(&dtrace_lock);
+
+       /*
+        * And now, for a little heuristic sleaze:  in general, we want to
+        * match modules as soon as they load.  However, we cannot guarantee
+        * this, because it would lead us to the lock ordering violation
+        * outlined above.  The common case, of course, is that cpu_lock is
+        * _not_ held -- so we delay here for a clock tick, hoping that that's
+        * long enough for the task queue to do its work.  If it's not, it's
+        * not a serious problem -- it just means that the module that we
+        * just loaded may not be immediately instrumentable.
+        */
+       udelay(jiffies_to_usecs(1));
+}
+
+static void
+dtrace_module_unloaded(struct module *module)
+{
+       dtrace_probe_t template, *probe, *first, *next;
+       dtrace_provider_t *prov;
+
+       template.dtpr_mod = module->name;
+
+       mutex_lock(&dtrace_provider_lock);
+       /* FIXME: mutex_lock(&mod_lock); */
+       mutex_lock(&dtrace_lock);
+
+       if (dtrace_bymod == NULL) {
+               /*
+                * The DTrace module is loaded (obviously) but not attached;
+                * we don't have any work to do.
+                */
+               mutex_unlock(&dtrace_provider_lock);
+               /* FIXME: mutex_unlock(&mod_lock); */
+               mutex_unlock(&dtrace_lock);
+               return;
+       }
+
+       for (probe = first = dtrace_hash_lookup(dtrace_bymod, &template);
+           probe != NULL; probe = probe->dtpr_nextmod) {
+               if (probe->dtpr_ecb != NULL) {
+                       mutex_unlock(&dtrace_provider_lock);
+                       /* FIXME: mutex_unlock(&mod_lock); */
+                       mutex_unlock(&dtrace_lock);
+
+                       /*
+                        * This shouldn't _actually_ be possible -- we're
+                        * unloading a module that has an enabled probe in it.
+                        * (It's normally up to the provider to make sure that
+                        * this can't happen.)  However, because dtps_enable()
+                        * doesn't have a failure mode, there can be an
+                        * enable/unload race.  Upshot:  we don't want to
+                        * assert, but we're not going to disable the
+                        * probe, either.
+                        */
+                       if (dtrace_err_verbose) {
+                               pr_warning("unloaded module '%s' had "
+                                   "enabled probes", module->name);
+                       }
+
+                       return;
+               }
+       }
+
+       probe = first;
+
+       for (first = NULL; probe != NULL; probe = next) {
+//TBD          ASSERT(dtrace_probes[probe->dtpr_id - 1] == probe);
+
+//TBD          dtrace_probes[probe->dtpr_id - 1] = NULL;
+
+               next = probe->dtpr_nextmod;
+               dtrace_hash_remove(dtrace_bymod, probe);
+               dtrace_hash_remove(dtrace_byfunc, probe);
+               dtrace_hash_remove(dtrace_byname, probe);
+
+               if (first == NULL) {
+                       first = probe;
+                       probe->dtpr_nextmod = NULL;
+               } else {
+                       probe->dtpr_nextmod = first;
+                       first = probe;
+               }
+       }
+
+       /*
+        * We've removed all of the module's probes from the hash chains and
+        * from the probe array.  Now issue a dtrace_sync() to be sure that
+        * everyone has cleared out from any probe array processing.
+        */
+       dtrace_sync();
+
+       for (probe = first; probe != NULL; probe = first) {
+               first = probe->dtpr_nextmod;
+               prov = probe->dtpr_provider;
+               prov->dtpv_pops.dtps_destroy(prov->dtpv_arg, probe->dtpr_id,
+                   probe->dtpr_arg);
+               kfree(probe->dtpr_mod);
+               kfree(probe->dtpr_func);
+               kfree(probe->dtpr_name);
+//FIXME                vmem_free(dtrace_arena, (void *)(uintptr_t)probe->dtpr_id, 1);
+               kfree(probe);
+       }
+
+       mutex_unlock(&dtrace_lock);
+       /* FIXME: mutex_unlock(&mod_lock); */
+       mutex_unlock(&dtrace_provider_lock);
+}
+
+/*
+ * Register a toxic range.
+ */
+static void dtrace_toxrange_add(uintptr_t base, uintptr_t limit)
+{
+       if (dtrace_toxranges >= dtrace_toxranges_max) {
+               int                     osize, nsize;
+               dtrace_toxrange_t       *range;
+
+               osize = dtrace_toxranges_max * sizeof(dtrace_toxrange_t);
+
+               if (osize == 0) {
+                       ASSERT(dtrace_toxrange == NULL);
+                       ASSERT(dtrace_toxranges_max == 0);
+
+                       dtrace_toxranges_max = 1;
+               } else
+                       dtrace_toxranges_max <<= 1;
+
+               nsize = dtrace_toxranges_max * sizeof(dtrace_toxrange_t);
+               range = kzalloc(nsize, GFP_KERNEL);
+
+               if (dtrace_toxrange != NULL) {
+                       ASSERT(osize != 0);
+
+                       memcpy(range, dtrace_toxrange, osize);
+                       kfree(dtrace_toxrange);
+               }
+
+               dtrace_toxrange = range;
+       }
+
+       ASSERT(dtrace_toxrange[dtrace_toxranges].dtt_base == (uintptr_t)NULL);
+       ASSERT(dtrace_toxrange[dtrace_toxranges].dtt_limit == (uintptr_t)NULL);
+
+       dtrace_toxrange[dtrace_toxranges].dtt_base = base;
+       dtrace_toxrange[dtrace_toxranges].dtt_limit = limit;
+       dtrace_toxranges++;
+}
+
+/*
+ * Check if an address falls within a toxic region.
+ */
+int dtrace_istoxic(uintptr_t kaddr, size_t size)
+{
+       uintptr_t       taddr, tsize;
+       int             i;
+
+       for (i = 0; i < dtrace_toxranges; i++) {
+               taddr = dtrace_toxrange[i].dtt_base;
+               tsize = dtrace_toxrange[i].dtt_limit - taddr;
+
+               if (kaddr - taddr < tsize) {
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR);
+                       cpu_core[smp_processor_id()].cpuc_dtrace_illval = kaddr;
+                       return 1;
+               }
+
+               if (taddr - kaddr < size) {
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR);
+                       cpu_core[smp_processor_id()].cpuc_dtrace_illval = taddr;
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
+/*
+ * Initialize the DTrace core.
+ *
+ * Equivalent to: dtrace_attach()
+ */
+int dtrace_dev_init(void)
+{
+       dtrace_provider_id_t    id;
+       int                     rc = 0;
+
+       mutex_lock(&cpu_lock);
+       mutex_lock(&dtrace_provider_lock);
+       mutex_lock(&dtrace_lock);
+
+       /*
+        * Register the device for the DTrace core.
+        */
+       rc = misc_register(&dtrace_dev);
+       if (rc) {
+               pr_err("%s: Can't register misc device %d\n",
+                      dtrace_dev.name, dtrace_dev.minor);
+
+               mutex_unlock(&cpu_lock);
+               mutex_unlock(&dtrace_provider_lock);
+               mutex_unlock(&dtrace_lock);
+
+               return rc;
+       }
+
+       dtrace_modload = dtrace_module_loaded;
+       dtrace_modunload = dtrace_module_unloaded;
+#ifdef FIXME
+       dtrace_cpu_init = dtrace_cpu_setup_initial;
+       dtrace_helpers_cleanup = dtrace_helpers_destroy;
+       dtrace_helpers_fork = dtrace_helpers_duplicate;
+       dtrace_cpustart_init = dtrace_suspend;
+       dtrace_cpustart_fini = dtrace_resume;
+       dtrace_debugger_init = dtrace_suspend;
+       dtrace_debugger_fini = dtrace_resume;
+
+       register_cpu_setup_func((cpu_setup_func_t *)dtrace_cpu_setup, NULL);
+#endif
+
+       dtrace_probe_init();
+
+#ifdef FIXME
+       dtrace_taskq = taskq_create("dtrace_taskq", 1, maxclsyspri, 1, INT_MAX,
+                                   0);
+#endif
+
+       dtrace_state_cache = kmem_cache_create("dtrace_state_cache",
+                               sizeof(dtrace_dstate_percpu_t) * NR_CPUS,
+                               __alignof__(dtrace_dstate_percpu_t),
+                               SLAB_PANIC, NULL);
+
+       /*
+        * Create the probe hashtables.
+        */
+       dtrace_bymod = dtrace_hash_create(
+                               offsetof(dtrace_probe_t, dtpr_mod),
+                               offsetof(dtrace_probe_t, dtpr_nextmod),
+                               offsetof(dtrace_probe_t, dtpr_prevmod));
+       dtrace_byfunc = dtrace_hash_create(
+                               offsetof(dtrace_probe_t, dtpr_func),
+                               offsetof(dtrace_probe_t, dtpr_nextfunc),
+                               offsetof(dtrace_probe_t, dtpr_prevfunc));
+       dtrace_byname = dtrace_hash_create(
+                               offsetof(dtrace_probe_t, dtpr_name),
+                               offsetof(dtrace_probe_t, dtpr_nextname),
+                               offsetof(dtrace_probe_t, dtpr_prevname));
+
+       /*
+        * Ensure that the X configuration parameter has a legal value.
+        */
+       if (dtrace_retain_max < 1) {
+               pr_warning("Illegal value (%lu) for dtrace_retain_max; "
+                          "setting to 1", (unsigned long)dtrace_retain_max);
+
+               dtrace_retain_max = 1;
+       }
+
+       /*
+        * Discover our toxic ranges.
+        */
+       dtrace_toxic_ranges(dtrace_toxrange_add);
+
+       /*
+        * Register ourselves as a provider.
+        */
+       dtrace_register("dtrace", &dtrace_provider_attr, DTRACE_PRIV_NONE, 0,
+                       &dtrace_provider_ops, NULL, &id);
+
+       ASSERT(dtrace_provider != NULL);
+       ASSERT((dtrace_provider_id_t)dtrace_provider == id);
+
+       /*
+        * Create BEGIN, END, and ERROR probes.
+        */
+       dtrace_probeid_begin = dtrace_probe_create(
+                               (dtrace_provider_id_t)dtrace_provider, NULL,
+                               NULL, "BEGIN", 0, NULL);
+       dtrace_probeid_end = dtrace_probe_create(
+                               (dtrace_provider_id_t)dtrace_provider, NULL,
+                               NULL, "END", 0, NULL);
+       dtrace_probeid_error = dtrace_probe_create(
+                               (dtrace_provider_id_t)dtrace_provider, NULL,
+                               NULL, "ERROR", 1, NULL);
+
+       dtrace_anon_property();
+       mutex_unlock(&cpu_lock);
+
+       /*
+        * If DTrace helper tracing is enabled, we need to allocate a trace
+        * buffer.
+        */
+       if (dtrace_helptrace_enabled) {
+               ASSERT(dtrace_helptrace_buffer == NULL);
+
+               dtrace_helptrace_buffer = dtrace_vzalloc(
+                                               dtrace_helptrace_bufsize);
+               dtrace_helptrace_next = 0;
+       }
+
+#ifdef FIXME
+       /*
+        * There is usually code here to handle the case where there already
+        * are providers when we get to this code.  On Linux, that does not
+        * seem to be possible since the DTrace core module (this code) is
+        * loaded as a dependency for each provider, and thus this
+        * initialization code is executed prior to the initialization code of
+        * the first provider causing the core to be loaded.
+        */
+#endif
+
+       mutex_unlock(&dtrace_provider_lock);
+       mutex_unlock(&dtrace_lock);
+
+       return 0;
+}
+
+void dtrace_dev_exit(void)
+{
+       kmem_cache_destroy(dtrace_state_cache);
+       misc_deregister(&dtrace_dev);
+
+       dtrace_probe_exit();
+}
diff --git a/dtrace/dtrace_dev.h b/dtrace/dtrace_dev.h
new file mode 100644 (file)
index 0000000..4e614f3
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef _DTRACE_DEV_H_
+#define _DTRACE_DEV_H_
+
+#define DT_DEV_DTRACE_MINOR    (16)
+#define DT_DEV_HELPER_MINOR    (DT_DEV_DTRACE_MINOR + 1)
+#define DT_DEV_PROFILE_MINOR   (DT_DEV_HELPER_MINOR + 1)
+#define DT_DEV_SYSTRACE_MINOR  (DT_DEV_PROFILE_MINOR + 1)
+#define DT_DEV_FBT_MINOR       (DT_DEV_SYSTRACE_MINOR + 1)
+#define DT_DEV_SDT_MINOR       (DT_DEV_FBT_MINOR + 1)
+#define DT_DEV_FASTTRAP_MINOR  (DT_DEV_SDT_MINOR + 1)
+#define DT_DEV_LOCKSTAT_MINOR  (DT_DEV_FASTTRAP_MINOR + 1)
+#define DT_DEV_DT_TEST_MINOR   (DT_DEV_LOCKSTAT_MINOR + 1)
+
+extern int dtrace_dev_init(void);
+extern void dtrace_dev_exit(void);
+
+#endif /* _DTRACE_DEV_H_ */
diff --git a/dtrace/dtrace_dif.c b/dtrace/dtrace_dif.c
new file mode 100644 (file)
index 0000000..2bb4c84
--- /dev/null
@@ -0,0 +1,4473 @@
+/*
+ * FILE:       dtrace_dif.c
+ * DESCRIPTION:        Dynamic Tracing: DIF object functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/hardirq.h>
+#include <linux/in6.h>
+#include <linux/inet.h>
+#include <linux/kdev_t.h>
+#include <linux/slab.h>
+#include <linux/socket.h>
+#include <net/ipv6.h>
+
+#include "dtrace.h"
+
+size_t                         dtrace_global_maxsize = 16 * 1024;
+
+static uint64_t                        dtrace_vtime_references;
+
+static int dtrace_difo_err(uint_t pc, const char *format, ...)
+{
+       char    buf[256];
+
+       if (dtrace_err_verbose) {
+               va_list alist;
+               size_t  len = strlen(format);
+
+               pr_err("dtrace DIF object error: [%u]: ", pc);
+
+               if (len >= 256 - sizeof(KERN_ERR)) {
+                       pr_err("<invalid format string>");
+                       return 1;
+               }
+
+               memcpy(buf, KERN_ERR, sizeof(KERN_ERR));
+               memcpy(buf + sizeof(KERN_ERR), format, len);
+
+               va_start(alist, format);
+               vprintk(buf, alist);
+               va_end(alist);
+       }
+
+       return 1;
+}
+
+/*
+ * Validate a DTrace DIF object by checking the IR instructions.  The following
+ * rules are currently enforced by dtrace_difo_validate():
+ *
+ * 1. Each instruction must have a valid opcode
+ * 2. Each register, string, variable, or subroutine reference must be valid
+ * 3. No instruction can modify register %r0 (must be zero)
+ * 4. All instruction reserved bits must be set to zero
+ * 5. The last instruction must be a "ret" instruction
+ * 6. All branch targets must reference a valid instruction _after_ the branch
+ */
+int dtrace_difo_validate(dtrace_difo_t *dp, dtrace_vstate_t *vstate,
+                        uint_t nregs, const cred_t *cr)
+{
+       int     err = 0, i;
+       int     (*efunc)(uint_t pc, const char *, ...) = dtrace_difo_err;
+       int     kcheckload = 0;
+       uint_t  pc;
+
+       kcheckload = cr == NULL ||
+                    (vstate->dtvs_state->dts_cred.dcr_visible &
+                     DTRACE_CRV_KERNEL) == 0;
+
+       dp->dtdo_destructive = 0;
+
+       for (pc = 0; pc < dp->dtdo_len && err == 0; pc++) {
+               dif_instr_t     instr = dp->dtdo_buf[pc];
+               uint_t          r1 = DIF_INSTR_R1(instr);
+               uint_t          r2 = DIF_INSTR_R2(instr);
+               uint_t          rd = DIF_INSTR_RD(instr);
+               uint_t          rs = DIF_INSTR_RS(instr);
+               uint_t          label = DIF_INSTR_LABEL(instr);
+               uint_t          v = DIF_INSTR_VAR(instr);
+               uint_t          subr = DIF_INSTR_SUBR(instr);
+               uint_t          type = DIF_INSTR_TYPE(instr);
+               uint_t          op = DIF_INSTR_OP(instr);
+
+               switch (op) {
+               case DIF_OP_OR:
+               case DIF_OP_XOR:
+               case DIF_OP_AND:
+               case DIF_OP_SLL:
+               case DIF_OP_SRL:
+               case DIF_OP_SRA:
+               case DIF_OP_SUB:
+               case DIF_OP_ADD:
+               case DIF_OP_MUL:
+               case DIF_OP_SDIV:
+               case DIF_OP_UDIV:
+               case DIF_OP_SREM:
+               case DIF_OP_UREM:
+               case DIF_OP_COPYS:
+                       if (r1 >= nregs)
+                               err += efunc(pc, "invalid register %u\n", r1);
+                       if (r2 >= nregs)
+                               err += efunc(pc, "invalid register %u\n", r2);
+                       if (rd >= nregs)
+                               err += efunc(pc, "invalid register %u\n", rd);
+                       if (rd == 0)
+                               err += efunc(pc, "cannot write to %r0\n");
+                       break;
+               case DIF_OP_NOT:
+               case DIF_OP_MOV:
+               case DIF_OP_ALLOCS:
+                       if (r1 >= nregs)
+                               err += efunc(pc, "invalid register %u\n", r1);
+                       if (r2 != 0)
+                               err += efunc(pc, "non-zero reserved bits\n");
+                       if (rd >= nregs)
+                               err += efunc(pc, "invalid register %u\n", rd);
+                       if (rd == 0)
+                               err += efunc(pc, "cannot write to %r0\n");
+                       break;
+               case DIF_OP_LDSB:
+               case DIF_OP_LDSH:
+               case DIF_OP_LDSW:
+               case DIF_OP_LDUB:
+               case DIF_OP_LDUH:
+               case DIF_OP_LDUW:
+               case DIF_OP_LDX:
+                       if (r1 >= nregs)
+                               err += efunc(pc, "invalid register %u\n", r1);
+                       if (r2 != 0)
+                               err += efunc(pc, "non-zero reserved bits\n");
+                       if (rd >= nregs)
+                               err += efunc(pc, "invalid register %u\n", rd);
+                       if (rd == 0)
+                               err += efunc(pc, "cannot write to %r0\n");
+                       if (kcheckload)
+                               dp->dtdo_buf[pc] = DIF_INSTR_LOAD(
+                                                       op + DIF_OP_RLDSB -
+                                                            DIF_OP_LDSB,
+                                                       r1, rd);
+                       break;
+               case DIF_OP_RLDSB:
+               case DIF_OP_RLDSH:
+               case DIF_OP_RLDSW:
+               case DIF_OP_RLDUB:
+               case DIF_OP_RLDUH:
+               case DIF_OP_RLDUW:
+               case DIF_OP_RLDX:
+                       if (r1 >= nregs)
+                               err += efunc(pc, "invalid register %u\n", r1);
+                       if (r2 != 0)
+                               err += efunc(pc, "non-zero reserved bits\n");
+                       if (rd >= nregs)
+                               err += efunc(pc, "invalid register %u\n", rd);
+                       if (rd == 0)
+                               err += efunc(pc, "cannot write to %r0\n");
+                       break;
+               case DIF_OP_ULDSB:
+               case DIF_OP_ULDSH:
+               case DIF_OP_ULDSW:
+               case DIF_OP_ULDUB:
+               case DIF_OP_ULDUH:
+               case DIF_OP_ULDUW:
+               case DIF_OP_ULDX:
+                       if (r1 >= nregs)
+                               err += efunc(pc, "invalid register %u\n", r1);
+                       if (r2 != 0)
+                               err += efunc(pc, "non-zero reserved bits\n");
+                       if (rd >= nregs)
+                               err += efunc(pc, "invalid register %u\n", rd);
+                       if (rd == 0)
+                               err += efunc(pc, "cannot write to %r0\n");
+                       break;
+               case DIF_OP_STB:
+               case DIF_OP_STH:
+               case DIF_OP_STW:
+               case DIF_OP_STX:
+                       if (r1 >= nregs)
+                               err += efunc(pc, "invalid register %u\n", r1);
+                       if (r2 != 0)
+                               err += efunc(pc, "non-zero reserved bits\n");
+                       if (rd >= nregs)
+                               err += efunc(pc, "invalid register %u\n", rd);
+                       if (rd == 0)
+                               err += efunc(pc, "cannot write to 0 address\n");
+                       break;
+               case DIF_OP_CMP:
+               case DIF_OP_SCMP:
+                       if (r1 >= nregs)
+                               err += efunc(pc, "invalid register %u\n", r1);
+                       if (r2 >= nregs)
+                               err += efunc(pc, "invalid register %u\n", r2);
+                       if (rd != 0)
+                               err += efunc(pc, "non-zero reserved bits\n");
+                       break;
+               case DIF_OP_TST:
+                       if (r1 >= nregs)
+                               err += efunc(pc, "invalid register %u\n", r1);
+                       if (r2 != 0 || rd != 0)
+                               err += efunc(pc, "non-zero reserved bits\n");
+                       break;
+               case DIF_OP_BA:
+               case DIF_OP_BE:
+               case DIF_OP_BNE:
+               case DIF_OP_BG:
+               case DIF_OP_BGU:
+               case DIF_OP_BGE:
+               case DIF_OP_BGEU:
+               case DIF_OP_BL:
+               case DIF_OP_BLU:
+               case DIF_OP_BLE:
+               case DIF_OP_BLEU:
+                       if (label >= dp->dtdo_len)
+                               err += efunc(pc, "invalid branch target %u\n",
+                                            label);
+                       if (label <= pc)
+                               err += efunc(pc, "backward branch to %u\n",
+                                            label);
+                       break;
+               case DIF_OP_RET:
+                       if (r1 != 0 || r2 != 0)
+                               err += efunc(pc, "non-zero reserved bits\n");
+                       if (rd >= nregs)
+                               err += efunc(pc, "invalid register %u\n", rd);
+                       break;
+               case DIF_OP_NOP:
+               case DIF_OP_POPTS:
+               case DIF_OP_FLUSHTS:
+                       if (r1 != 0 || r2 != 0 || rd != 0)
+                               err += efunc(pc, "non-zero reserved bits\n");
+                       break;
+               case DIF_OP_SETX:
+                       if (DIF_INSTR_INTEGER(instr) >= dp->dtdo_intlen)
+                               err += efunc(pc, "invalid integer ref %u\n",
+                                            DIF_INSTR_INTEGER(instr));
+                       if (rd >= nregs)
+                               err += efunc(pc, "invalid register %u\n", rd);
+                       if (rd == 0)
+                               err += efunc(pc, "cannot write to %r0\n");
+                       break;
+               case DIF_OP_SETS:
+                       if (DIF_INSTR_STRING(instr) >= dp->dtdo_strlen)
+                               err += efunc(pc, "invalid string ref %u\n",
+                                            DIF_INSTR_STRING(instr));
+                       if (rd >= nregs)
+                               err += efunc(pc, "invalid register %u\n", rd);
+                       if (rd == 0)
+                               err += efunc(pc, "cannot write to %r0\n");
+                       break;
+               case DIF_OP_LDGA:
+               case DIF_OP_LDTA:
+                       if (r1 > DIF_VAR_ARRAY_MAX)
+                               err += efunc(pc, "invalid array %u\n", r1);
+                       if (r2 >= nregs)
+                               err += efunc(pc, "invalid register %u\n", r2);
+                       if (rd >= nregs)
+                               err += efunc(pc, "invalid register %u\n", rd);
+                       if (rd == 0)
+                               err += efunc(pc, "cannot write to %r0\n");
+                       break;
+               case DIF_OP_LDGS:
+               case DIF_OP_LDTS:
+               case DIF_OP_LDLS:
+               case DIF_OP_LDGAA:
+               case DIF_OP_LDTAA:
+                       if (v < DIF_VAR_OTHER_MIN || v > DIF_VAR_OTHER_MAX)
+                               err += efunc(pc, "invalid variable %u\n", v);
+                       if (rd >= nregs)
+                               err += efunc(pc, "invalid register %u\n", rd);
+                       if (rd == 0)
+                               err += efunc(pc, "cannot write to %r0\n");
+                       break;
+               case DIF_OP_STGS:
+               case DIF_OP_STTS:
+               case DIF_OP_STLS:
+               case DIF_OP_STGAA:
+               case DIF_OP_STTAA:
+                       if (v < DIF_VAR_OTHER_UBASE || v > DIF_VAR_OTHER_MAX)
+                               err += efunc(pc, "invalid variable %u\n", v);
+                       if (rs >= nregs)
+                               err += efunc(pc, "invalid register %u\n", rd);
+                       break;
+               case DIF_OP_CALL:
+                       if (subr > DIF_SUBR_MAX)
+                               err += efunc(pc, "invalid subr %u\n", subr);
+                       if (rd >= nregs)
+                               err += efunc(pc, "invalid register %u\n", rd);
+                       if (rd == 0)
+                               err += efunc(pc, "cannot write to %r0\n");
+
+                       if (subr == DIF_SUBR_COPYOUT ||
+                           subr == DIF_SUBR_COPYOUTSTR)
+                               dp->dtdo_destructive = 1;
+                       break;
+               case DIF_OP_PUSHTR:
+                       if (type != DIF_TYPE_STRING && type != DIF_TYPE_CTF)
+                               err += efunc(pc, "invalid ref type %u\n", type);
+                       if (r2 >= nregs)
+                               err += efunc(pc, "invalid register %u\n", r2);
+                       if (rs >= nregs)
+                               err += efunc(pc, "invalid register %u\n", rs);
+                       break;
+               case DIF_OP_PUSHTV:
+                       if (type != DIF_TYPE_CTF)
+                               err += efunc(pc, "invalid val type %u\n", type);
+                       if (r2 >= nregs)
+                               err += efunc(pc, "invalid register %u\n", r2);
+                       if (rs >= nregs)
+                               err += efunc(pc, "invalid register %u\n", rs);
+                       break;
+               default:
+                       err += efunc(pc, "invalid opcode %u\n",
+                                    DIF_INSTR_OP(instr));
+               }
+       }
+
+       if (dp->dtdo_len != 0 &&
+           DIF_INSTR_OP(dp->dtdo_buf[dp->dtdo_len - 1]) != DIF_OP_RET) {
+               err += efunc(dp->dtdo_len - 1,
+                            "expected 'ret' as last DIF instruction\n");
+       }
+
+       if (!(dp->dtdo_rtype.dtdt_flags & DIF_TF_BYREF)) {
+               /*
+                * If we're not returning by reference, the size must be either
+                * 0 or the size of one of the base types.
+                */
+               switch (dp->dtdo_rtype.dtdt_size) {
+               case 0:
+               case sizeof(uint8_t):
+               case sizeof(uint16_t):
+               case sizeof(uint32_t):
+               case sizeof(uint64_t):
+                       break;
+
+               default:
+                       err += efunc(dp->dtdo_len - 1, "bad return size\n");
+               }
+       }
+
+       for (i = 0; i < dp->dtdo_varlen && err == 0; i++) {
+               dtrace_difv_t           *v = &dp->dtdo_vartab[i],
+                                       *existing = NULL;
+               dtrace_diftype_t        *vt, *et;
+               uint_t                  id, ndx;
+
+               if (v->dtdv_scope != DIFV_SCOPE_GLOBAL &&
+                   v->dtdv_scope != DIFV_SCOPE_THREAD &&
+                   v->dtdv_scope != DIFV_SCOPE_LOCAL) {
+                       err += efunc(i, "unrecognized variable scope %d\n",
+                                    v->dtdv_scope);
+                       break;
+               }
+
+               if (v->dtdv_kind != DIFV_KIND_ARRAY &&
+                   v->dtdv_kind != DIFV_KIND_SCALAR) {
+                       err += efunc(i, "unrecognized variable type %d\n",
+                                    v->dtdv_kind);
+                       break;
+               }
+
+               if ((id = v->dtdv_id) > DIF_VARIABLE_MAX) {
+                       err += efunc(i, "%d exceeds variable id limit\n", id);
+                       break;
+               }
+
+               if (id < DIF_VAR_OTHER_UBASE)
+                       continue;
+
+               /*
+                * For user-defined variables, we need to check that this
+                * definition is identical to any previous definition that we
+                * encountered.
+                */
+               ndx = id - DIF_VAR_OTHER_UBASE;
+
+               switch (v->dtdv_scope) {
+               case DIFV_SCOPE_GLOBAL:
+                       if (ndx < vstate->dtvs_nglobals) {
+                               dtrace_statvar_t        *svar;
+
+                               if ((svar = vstate->dtvs_globals[ndx]) != NULL)
+                                       existing = &svar->dtsv_var;
+                       }
+
+                       break;
+
+               case DIFV_SCOPE_THREAD:
+                       if (ndx < vstate->dtvs_ntlocals)
+                               existing = &vstate->dtvs_tlocals[ndx];
+                       break;
+
+               case DIFV_SCOPE_LOCAL:
+                       if (ndx < vstate->dtvs_nlocals) {
+                               dtrace_statvar_t        *svar;
+
+                               if ((svar = vstate->dtvs_locals[ndx]) != NULL)
+                                       existing = &svar->dtsv_var;
+                       }
+
+                       break;
+               }
+
+               vt = &v->dtdv_type;
+
+               if (vt->dtdt_flags & DIF_TF_BYREF) {
+                       if (vt->dtdt_size == 0) {
+                               err += efunc(i, "zero-sized variable\n");
+                               break;
+                       }
+
+                       if (v->dtdv_scope == DIFV_SCOPE_GLOBAL &&
+                           vt->dtdt_size > dtrace_global_maxsize) {
+                               err += efunc(i, "oversized by-ref global\n");
+                               break;
+                       }
+               }
+
+               if (existing == NULL || existing->dtdv_id == 0)
+                       continue;
+
+               ASSERT(existing->dtdv_id == v->dtdv_id);
+               ASSERT(existing->dtdv_scope == v->dtdv_scope);
+
+               if (existing->dtdv_kind != v->dtdv_kind)
+                       err += efunc(i, "%d changed variable kind\n", id);
+
+               et = &existing->dtdv_type;
+
+               if (vt->dtdt_flags != et->dtdt_flags) {
+                       err += efunc(i, "%d changed variable type flags\n", id);
+                       break;
+               }
+
+               if (vt->dtdt_size != 0 && vt->dtdt_size != et->dtdt_size) {
+                       err += efunc(i, "%d changed variable type size\n", id);
+                       break;
+               }
+       }
+
+       return err;
+}
+
+/*
+ * Returns 1 if the expression in the DIF object can be cached on a per-thread
+ * basis; 0 if not.
+ */
+int dtrace_difo_cacheable(dtrace_difo_t *dp)
+{
+       int     i;
+
+       if (dp == NULL)
+               return 0;
+
+       for (i = 0; i < dp->dtdo_varlen; i++) {
+               dtrace_difv_t   *v = &dp->dtdo_vartab[i];
+
+               if (v->dtdv_scope != DIFV_SCOPE_GLOBAL)
+                       continue;
+
+               switch (v->dtdv_id) {
+               case DIF_VAR_CURTHREAD:
+               case DIF_VAR_PID:
+               case DIF_VAR_TID:
+               case DIF_VAR_EXECNAME:
+               case DIF_VAR_ZONENAME:
+                       break;
+
+               default:
+                       return 0;
+               }
+       }
+
+       /*
+        * This DIF object may be cacheable.  Now we need to look for any
+        * array loading instructions, any memory loading instructions, or
+        * any stores to thread-local variables.
+        */
+       for (i = 0; i < dp->dtdo_len; i++) {
+               uint_t  op = DIF_INSTR_OP(dp->dtdo_buf[i]);
+
+               if ((op >= DIF_OP_LDSB && op <= DIF_OP_LDX) ||
+                   (op >= DIF_OP_ULDSB && op <= DIF_OP_ULDX) ||
+                   (op >= DIF_OP_RLDSB && op <= DIF_OP_RLDX) ||
+                   op == DIF_OP_LDGA || op == DIF_OP_STTS)
+                       return 0;
+       }
+
+       return 1;
+}
+
+/*
+ * This routine calculates the dynamic variable chunksize for a given DIF
+ * object.  The calculation is not fool-proof, and can probably be tricked by
+ * malicious DIF -- but it works for all compiler-generated DIF.  Because this
+ * calculation is likely imperfect, dtrace_dynvar() is able to gracefully fail
+ * if a dynamic variable size exceeds the chunksize.
+ */
+static void dtrace_difo_chunksize(dtrace_difo_t *dp, dtrace_vstate_t *vstate)
+{
+       uint64_t                sval;
+       dtrace_key_t            tupregs[DIF_DTR_NREGS + 2]; /* + thread + id */
+       const dif_instr_t       *text = dp->dtdo_buf;
+       uint_t                  pc, srd = 0;
+       uint_t                  ttop = 0;
+       size_t                  size, ksize;
+       uint_t                  id, i;
+
+       for (pc = 0; pc < dp->dtdo_len; pc++) {
+               dif_instr_t     instr = text[pc];
+               uint_t          op = DIF_INSTR_OP(instr);
+               uint_t          rd = DIF_INSTR_RD(instr);
+               uint_t          r1 = DIF_INSTR_R1(instr);
+               uint_t          nkeys = 0;
+               uchar_t         scope;
+               dtrace_key_t    *key = tupregs;
+
+               switch (op) {
+               case DIF_OP_SETX:
+                       sval = dp->dtdo_inttab[DIF_INSTR_INTEGER(instr)];
+                       srd = rd;
+                       continue;
+
+               case DIF_OP_STTS:
+                       key = &tupregs[DIF_DTR_NREGS];
+                       key[0].dttk_size = 0;
+                       key[1].dttk_size = 0;
+                       nkeys = 2;
+                       scope = DIFV_SCOPE_THREAD;
+                       break;
+
+               case DIF_OP_STGAA:
+               case DIF_OP_STTAA:
+                       nkeys = ttop;
+
+                       if (DIF_INSTR_OP(instr) == DIF_OP_STTAA)
+                               key[nkeys++].dttk_size = 0;
+
+                       key[nkeys++].dttk_size = 0;
+
+                       if (op == DIF_OP_STTAA)
+                               scope = DIFV_SCOPE_THREAD;
+                       else
+                               scope = DIFV_SCOPE_GLOBAL;
+
+                       break;
+
+               case DIF_OP_PUSHTR:
+                       if (ttop == DIF_DTR_NREGS)
+                               return;
+
+                       /*
+                        * If the register for the size of the "pushtr" is %r0
+                        * (or the value is 0) and the type is a string, we'll
+                        * use the system-wide default string size.
+                        */
+                       if ((srd == 0 || sval == 0) && r1 == DIF_TYPE_STRING)
+                               tupregs[ttop++].dttk_size =
+                                               dtrace_strsize_default;
+                       else {
+                               if (srd == 0)
+                                       return;
+
+                               tupregs[ttop++].dttk_size = sval;
+                       }
+
+                       break;
+
+               case DIF_OP_PUSHTV:
+                       if (ttop == DIF_DTR_NREGS)
+                               return;
+
+                       tupregs[ttop++].dttk_size = 0;
+                       break;
+
+               case DIF_OP_FLUSHTS:
+                       ttop = 0;
+                       break;
+
+               case DIF_OP_POPTS:
+                       if (ttop != 0)
+                               ttop--;
+                       break;
+               }
+
+               sval = 0;
+               srd = 0;
+
+               if (nkeys == 0)
+                       continue;
+
+               /*
+                * We have a dynamic variable allocation; calculate its size.
+                */
+               for (ksize = 0, i = 0; i < nkeys; i++)
+                       ksize += P2ROUNDUP(key[i].dttk_size, sizeof(uint64_t));
+
+               size = sizeof(dtrace_dynvar_t);
+               size += sizeof(dtrace_key_t) * (nkeys - 1);
+               size += ksize;
+
+               /*
+                * Now we need to determine the size of the stored data.
+               */
+               id = DIF_INSTR_VAR(instr);
+
+               for (i = 0; i < dp->dtdo_varlen; i++) {
+                       dtrace_difv_t   *v = &dp->dtdo_vartab[i];
+
+                       if (v->dtdv_id == id && v->dtdv_scope == scope) {
+                               size += v->dtdv_type.dtdt_size;
+                               break;
+                       }
+               }
+
+               if (i == dp->dtdo_varlen)
+                       return;
+
+               /*
+                * We have the size.  If this is larger than the chunk size
+                * for our dynamic variable state, reset the chunk size.
+                */
+               size = P2ROUNDUP(size, sizeof(uint64_t));
+
+               if (size > vstate->dtvs_dynvars.dtds_chunksize)
+                       vstate->dtvs_dynvars.dtds_chunksize = size;
+       }
+}
+
+void dtrace_difo_hold(dtrace_difo_t *dp)
+{
+       int     i;
+
+       dp->dtdo_refcnt++;
+       ASSERT(dp->dtdo_refcnt != 0);
+
+       for (i = 0; i < dp->dtdo_varlen; i++) {
+               dtrace_difv_t   *v = &dp->dtdo_vartab[i];
+
+               if (v->dtdv_id != DIF_VAR_VTIMESTAMP)
+                       continue;
+
+               if (dtrace_vtime_references++ == 0)
+                       dtrace_vtime_enable();
+       }
+}
+
+void dtrace_difo_init(dtrace_difo_t *dp, dtrace_vstate_t *vstate)
+{
+       int     i, oldsvars, osz, nsz, otlocals, ntlocals;
+       uint_t  id;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(dp->dtdo_buf != NULL && dp->dtdo_len != 0);
+
+       for (i = 0; i < dp->dtdo_varlen; i++) {
+               dtrace_difv_t           *v = &dp->dtdo_vartab[i];
+               dtrace_statvar_t        *svar, ***svarp;
+               size_t                  dsize = 0;
+               uint8_t                 scope = v->dtdv_scope;
+               int                     *np;
+
+               if ((id = v->dtdv_id) < DIF_VAR_OTHER_UBASE)
+                       continue;
+
+               id -= DIF_VAR_OTHER_UBASE;
+
+               switch (scope) {
+               case DIFV_SCOPE_THREAD:
+                       while (id >= (otlocals = vstate->dtvs_ntlocals)) {
+                               dtrace_difv_t   *tlocals;
+
+                               if ((ntlocals = (otlocals << 1)) == 0)
+                                       ntlocals = 1;
+
+                               osz = otlocals * sizeof(dtrace_difv_t);
+                               nsz = ntlocals * sizeof(dtrace_difv_t);
+
+                               tlocals = kzalloc(nsz, GFP_KERNEL);
+
+                               if (osz != 0) {
+                                       memcpy(tlocals, vstate->dtvs_tlocals,
+                                              osz);
+                                       kfree(vstate->dtvs_tlocals);
+                               }
+
+                               vstate->dtvs_tlocals = tlocals;
+                               vstate->dtvs_ntlocals = ntlocals;
+                       }
+
+                       vstate->dtvs_tlocals[id] = *v;
+                       continue;
+
+               case DIFV_SCOPE_LOCAL:
+                       np = &vstate->dtvs_nlocals;
+                       svarp = &vstate->dtvs_locals;
+
+                       if (v->dtdv_type.dtdt_flags & DIF_TF_BYREF)
+                               dsize = NR_CPUS *
+                                       (v->dtdv_type.dtdt_size +
+                                        sizeof(uint64_t));
+                       else
+                               dsize = NR_CPUS * sizeof(uint64_t);
+
+                       break;
+
+               case DIFV_SCOPE_GLOBAL:
+                       np = &vstate->dtvs_nglobals;
+                       svarp = &vstate->dtvs_globals;
+
+                       if (v->dtdv_type.dtdt_flags & DIF_TF_BYREF)
+                               dsize = v->dtdv_type.dtdt_size +
+                                       sizeof(uint64_t);
+
+                       break;
+
+               default:
+                       ASSERT(0);
+                       continue; /* not reached */
+               }
+
+               while (id >= (oldsvars = *np)) {
+                       dtrace_statvar_t        **statics;
+                       int                     newsvars, oldsize, newsize;
+
+                       if ((newsvars = (oldsvars << 1)) == 0)
+                               newsvars = 1;
+
+                       oldsize = oldsvars * sizeof(dtrace_statvar_t *);
+                       newsize = newsvars * sizeof(dtrace_statvar_t *);
+
+                       statics = kzalloc(newsize, GFP_KERNEL);
+
+                       if (oldsize != 0) {
+                               memcpy(statics, *svarp, oldsize);
+                               kfree(*svarp);
+                       }
+
+                       *svarp = statics;
+                       *np = newsvars;
+               }
+
+               if ((svar = (*svarp)[id]) == NULL) {
+                       svar = kzalloc(sizeof(dtrace_statvar_t), GFP_KERNEL);
+                       svar->dtsv_var = *v;
+
+                       if ((svar->dtsv_size = dsize) != 0) {
+                               svar->dtsv_data =
+                                       (uint64_t)(uintptr_t)kzalloc(
+                                                       dsize, GFP_KERNEL);
+                       }
+
+                       (*svarp)[id] = svar;
+               }
+
+               svar->dtsv_refcnt++;
+       }
+
+       dtrace_difo_chunksize(dp, vstate);
+       dtrace_difo_hold(dp);
+}
+
+void dtrace_difo_destroy(dtrace_difo_t *dp, dtrace_vstate_t *vstate)
+{
+       int     i;
+
+       ASSERT(dp->dtdo_refcnt == 0);
+
+       for (i = 0; i < dp->dtdo_varlen; i++) {
+               dtrace_difv_t           *v = &dp->dtdo_vartab[i];
+               dtrace_statvar_t        *svar, **svarp;
+               uint_t                  id;
+               uint8_t                 scope = v->dtdv_scope;
+               int                     *np;
+
+               switch (scope) {
+               case DIFV_SCOPE_THREAD:
+                       continue;
+
+               case DIFV_SCOPE_LOCAL:
+                       np = &vstate->dtvs_nlocals;
+                       svarp = vstate->dtvs_locals;
+                       break;
+
+               case DIFV_SCOPE_GLOBAL:
+                       np = &vstate->dtvs_nglobals;
+                       svarp = vstate->dtvs_globals;
+                       break;
+
+               default:
+                       BUG();
+               }
+
+               if ((id = v->dtdv_id) < DIF_VAR_OTHER_UBASE)
+                       continue;
+
+               id -= DIF_VAR_OTHER_UBASE;
+               ASSERT(id < *np);
+
+               svar = svarp[id];
+               ASSERT(svar != NULL);
+               ASSERT(svar->dtsv_refcnt > 0);
+
+               if (--svar->dtsv_refcnt > 0)
+                       continue;
+
+               if (svar->dtsv_size != 0) {
+                       ASSERT((void *)(uintptr_t)svar->dtsv_data != NULL);
+                       kfree((void *)(uintptr_t)svar->dtsv_data);
+               }
+
+               kfree(svar);
+               svarp[id] = NULL;
+       }
+
+       kfree(dp->dtdo_buf);
+        kfree(dp->dtdo_inttab);
+        kfree(dp->dtdo_strtab);
+        kfree(dp->dtdo_vartab);
+        kfree(dp);
+}
+
+void dtrace_difo_release(dtrace_difo_t *dp, dtrace_vstate_t *vstate)
+{
+       int     i;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(dp->dtdo_refcnt != 0);
+
+       for (i = 0; i < dp->dtdo_varlen; i++) {
+               dtrace_difv_t *v = &dp->dtdo_vartab[i];
+
+               if (v->dtdv_id != DIF_VAR_VTIMESTAMP)
+                       continue;
+
+               ASSERT(dtrace_vtime_references > 0);
+
+               if (--dtrace_vtime_references == 0)
+                       dtrace_vtime_disable();
+       }
+
+       if (--dp->dtdo_refcnt == 0)
+               dtrace_difo_destroy(dp, vstate);
+}
+
+/*
+ * The key for a thread-local variable consists of the lower 63 bits of the
+ * task pid, prefixed by a bit indicating whether an interrupt is active (1) or
+ * not (0).
+ * We add DIF_VARIABLE_MAX to the pid to assure that the thread key is never
+ * equal to a variable identifier.  This is necessary (but not sufficient) to
+ * assure that global associative arrays never collide with thread-local
+ * variables.  To guarantee that they cannot collide, we must also define the
+ * order for keying dynamic variables.  That order is:
+ *
+ *   [ key0 ] ... [ keyn ] [ variable-key ] [ tls-key ]
+ *
+ * Because the variable-key and the tls-key are in orthogonal spaces, there is
+ * no way for a global variable key signature to match a thread-local key
+ * signature.
+ */
+#define DTRACE_TLS_THRKEY(where)                                       \
+       {                                                               \
+               uint_t  intr = in_interrupt() ? 1 : 0;                  \
+                                                                       \
+               (where) = ((current->pid + DIF_VARIABLE_MAX) &          \
+                          (((uint64_t)1 << 63) - 1)) |                 \
+                         ((uint64_t)intr << 63);                       \
+       }
+
+#ifndef FIXME
+# define DTRACE_ALIGNCHECK(addr, size, flags)
+#endif
+
+/*
+ * Test whether a range of memory starting at testaddr of size testsz falls
+ * within the range of memory described by addr, sz.  We take care to avoid
+ * problems with overflow and underflow of the unsigned quantities, and
+ * disallow all negative sizes.  Ranges of size 0 are allowed.
+ */
+#define DTRACE_INRANGE(testaddr, testsz, baseaddr, basesz) \
+       ((testaddr) - (baseaddr) < (basesz) && \
+        (testaddr) + (testsz) - (baseaddr) <= (basesz) && \
+        (testaddr) + (testsz) >= (testaddr))
+
+#define DTRACE_LOADFUNC(bits)                                          \
+       uint##bits##_t dtrace_load##bits(uintptr_t addr)                \
+       {                                                               \
+               size_t                  size = bits / NBBY;             \
+               uint##bits##_t          rval;                           \
+               int                     i;                              \
+               int                     cpu = smp_processor_id();       \
+               volatile uint16_t       *flags = (volatile uint16_t *)  \
+                           &cpu_core[cpu].cpuc_dtrace_flags;           \
+                                                                       \
+               /*                                                      \
+                * Deviation from the OpenSolaris code...  Protect      \
+                * against dereferencing the NULL pointer since that    \
+                * really causes us a lot of grief (crash).             \
+                */                                                     \
+               if (addr == 0) {                                        \
+                       *flags |= CPU_DTRACE_BADADDR;                   \
+                       cpu_core[cpu].cpuc_dtrace_illval = addr;        \
+                       return 0;                                       \
+               }                                                       \
+                                                                       \
+               DTRACE_ALIGNCHECK(addr, size, flags);                   \
+                                                                       \
+               for (i = 0; i < dtrace_toxranges; i++) {                \
+                       if (addr >= dtrace_toxrange[i].dtt_limit)       \
+                               continue;                               \
+                                                                       \
+                       if (addr + size <= dtrace_toxrange[i].dtt_base) \
+                               continue;                               \
+                                                               \
+                       /*                                              \
+                        * This address falls within a toxic region.    \
+                        */                                             \
+                       *flags |= CPU_DTRACE_BADADDR;                   \
+                       cpu_core[cpu].cpuc_dtrace_illval = addr;        \
+                       return 0;                                       \
+               }                                                       \
+                                                                       \
+               *flags |= CPU_DTRACE_NOFAULT;                           \
+               rval = *((volatile uint##bits##_t *)addr);              \
+               *flags &= ~CPU_DTRACE_NOFAULT;                          \
+                                                                       \
+               return !(*flags & CPU_DTRACE_FAULT) ? rval : 0;         \
+       }
+
+#ifdef CONFIG_64BIT
+# define dtrace_loadptr        dtrace_load64
+#else
+# define dtrace_loadptr        dtrace_load32
+#endif
+
+/*
+ * Use the DTRACE_LOADFUNC macro to define functions for each of loading a
+ * uint8_t, a uint16_t, a uint32_t and a uint64_t.
+ */
+DTRACE_LOADFUNC(8)
+DTRACE_LOADFUNC(16)
+DTRACE_LOADFUNC(32)
+DTRACE_LOADFUNC(64)
+
+#define DT_BSWAP_8(x)  ((x) & 0xff)
+#define DT_BSWAP_16(x) ((DT_BSWAP_8(x) << 8) | DT_BSWAP_8((x) >> 8))
+#define DT_BSWAP_32(x) ((DT_BSWAP_16(x) << 16) | DT_BSWAP_16((x) >> 16))
+#define DT_BSWAP_64(x) ((DT_BSWAP_32(x) << 32) | DT_BSWAP_32((x) >> 32))
+
+static int dtrace_inscratch(uintptr_t dest, size_t size,
+                           dtrace_mstate_t *mstate)
+{
+       if (dest < mstate->dtms_scratch_base)
+               return 0;
+
+       if (dest + size < dest)
+               return 0;
+
+       if (dest + size > mstate->dtms_scratch_ptr)
+               return 0;
+
+       return 1;
+}
+
+static int dtrace_canstore_statvar(uint64_t addr, size_t sz,
+                                  dtrace_statvar_t **svars, int nsvars)
+{
+       int i;
+
+       for (i = 0; i < nsvars; i++) {
+               dtrace_statvar_t        *svar = svars[i];
+
+               if (svar == NULL || svar->dtsv_size == 0)
+                       continue;
+
+               if (DTRACE_INRANGE(addr, sz, svar->dtsv_data, svar->dtsv_size))
+                       return 1;
+       }
+
+       return 0;
+}
+
+/*
+ * Check to see if the address is within a memory region to which a store may
+ * be issued.  This includes the DTrace scratch areas, and any DTrace variable
+ * region.  The caller of dtrace_canstore() is responsible for performing any
+ * alignment checks that are needed before stores are actually executed.
+ */
+static int dtrace_canstore(uint64_t addr, size_t sz, dtrace_mstate_t *mstate,
+                          dtrace_vstate_t *vstate)
+{
+       /*
+        * First, check to see if the address is in scratch space...
+        */
+       if (DTRACE_INRANGE(addr, sz, mstate->dtms_scratch_base,
+                          mstate->dtms_scratch_size))
+               return 1;
+
+       /*
+        * Now check to see if it's a dynamic variable.  This check will pick
+        * up both thread-local variables and any global dynamically-allocated
+        * variables.
+        */
+       if (DTRACE_INRANGE(addr, sz, (uintptr_t)vstate->dtvs_dynvars.dtds_base,
+                          vstate->dtvs_dynvars.dtds_size)) {
+               dtrace_dstate_t *dstate = &vstate->dtvs_dynvars;
+               uintptr_t       base = (uintptr_t)dstate->dtds_base +
+                                      (dstate->dtds_hashsize *
+                                       sizeof(dtrace_dynhash_t));
+               uintptr_t       chunkoffs;
+               uint64_t        num;
+
+               /*
+                * Before we assume that we can store here, we need to make
+                * sure that it isn't in our metadata -- storing to our
+                * dynamic variable metadata would corrupt our state.  For
+                * the range to not include any dynamic variable metadata,
+                * it must:
+                *
+                *      (1) Start above the hash table that is at the base of
+                *      the dynamic variable space
+                *
+                *      (2) Have a starting chunk offset that is beyond the
+                *      dtrace_dynvar_t that is at the base of every chunk
+                *
+                *      (3) Not span a chunk boundary
+                */
+               if (addr < base)
+                       return 0;
+
+               num = addr - base;
+               chunkoffs = do_div(num, dstate->dtds_chunksize);
+
+               if (chunkoffs < sizeof(dtrace_dynvar_t))
+                       return 0;
+
+               if (chunkoffs + sz > dstate->dtds_chunksize)
+                       return 0;
+
+               return 1;
+       }
+
+       /*
+        * Finally, check the static local and global variables.  These checks
+        * take the longest, so we perform them last.
+        */
+       if (dtrace_canstore_statvar(addr, sz, vstate->dtvs_locals,
+                                   vstate->dtvs_nlocals))
+               return 1;
+
+       if (dtrace_canstore_statvar(addr, sz, vstate->dtvs_globals,
+                                   vstate->dtvs_nglobals))
+               return 1;
+
+       return 0;
+}
+
+/*
+ * Convenience routine to check to see if the address is within a memory
+ * region in which a load may be issued given the user's privilege level;
+ * if not, it sets the appropriate error flags and loads 'addr' into the
+ * illegal value slot.
+ *
+ * DTrace subroutines (DIF_SUBR_*) should use this helper to implement
+ * appropriate memory access protection.
+ */
+static int
+dtrace_canload(uint64_t addr, size_t sz, dtrace_mstate_t *mstate,
+    dtrace_vstate_t *vstate)
+{
+       int                     cpu = smp_processor_id();
+       volatile uintptr_t      *illval = &cpu_core[cpu].cpuc_dtrace_illval;
+
+       /*
+        * If we hold the privilege to read from kernel memory, then
+        * everything is readable.
+        */
+       if ((mstate->dtms_access & DTRACE_ACCESS_KERNEL) != 0)
+               return 1;
+
+       /*
+        * You can obviously read that which you can store.
+        */
+       if (dtrace_canstore(addr, sz, mstate, vstate))
+               return 1;
+
+       /*
+        * We're allowed to read from our own string table.
+        */
+       if (DTRACE_INRANGE(addr, sz, (uintptr_t)mstate->dtms_difo->dtdo_strtab,
+                          mstate->dtms_difo->dtdo_strlen))
+               return 1;
+
+       DTRACE_CPUFLAG_SET(CPU_DTRACE_KPRIV);
+       *illval = addr;
+
+       return 0;
+}
+
+/*
+ * Convenience routine to check to see if a given string is within a memory
+ * region in which a load may be issued given the user's privilege level;
+ * this exists so that we don't need to issue unnecessary dtrace_strlen()
+ * calls in the event that the user has all privileges.
+ */
+static int
+dtrace_strcanload(uint64_t addr, size_t sz, dtrace_mstate_t *mstate,
+    dtrace_vstate_t *vstate)
+{
+       size_t  strsz;
+
+       /*
+        * If we hold the privilege to read from kernel memory, then
+        * everything is readable.
+        */
+       if ((mstate->dtms_access & DTRACE_ACCESS_KERNEL) != 0)
+               return 1;
+
+       strsz = 1 + dtrace_strlen((char *)(uintptr_t)addr, sz);
+       if (dtrace_canload(addr, strsz, mstate, vstate))
+               return 1;
+
+       return 0;
+}
+
+/*
+ * Convenience routine to check to see if a given variable is within a memory
+ * region in which a load may be issued given the user's privilege level.
+ */
+int dtrace_vcanload(void *src, dtrace_diftype_t *type, dtrace_mstate_t *mstate,
+                   dtrace_vstate_t *vstate)
+{
+       size_t  sz;
+
+       ASSERT(type->dtdt_flags & DIF_TF_BYREF);
+
+       /*
+        * If we hold the privilege to read from kernel memory, then
+        * everything is readable.
+        */
+       if ((mstate->dtms_access & DTRACE_ACCESS_KERNEL) != 0)
+               return 1;
+
+       if (type->dtdt_kind == DIF_TYPE_STRING)
+               sz = dtrace_strlen(
+                       src,
+                       vstate->dtvs_state->dts_options[DTRACEOPT_STRSIZE]
+                    ) + 1;
+       else
+               sz = type->dtdt_size;
+
+       return dtrace_canload((uintptr_t)src, sz, mstate, vstate);
+}
+
+/*
+ * Copy src to dst using safe memory accesses.  The src is assumed to be unsafe
+ * memory specified by the DIF program.  The dst is assumed to be safe memory
+ * that we can store to directly because it is managed by DTrace.  As with
+ * standard bcopy, overlapping copies are handled properly.
+ */
+static void dtrace_bcopy(const void *src, void *dst, size_t len)
+{
+       if (len != 0) {
+               uint8_t         *s1 = dst;
+               const uint8_t   *s2 = src;
+
+               if (s1 <= s2) {
+                       do {
+                               *s1++ = dtrace_load8((uintptr_t)s2++);
+                       } while (--len != 0);
+               } else {
+                       s2 += len;
+                       s1 += len;
+
+                       do {
+                               *--s1 = dtrace_load8((uintptr_t)--s2);
+                       } while (--len != 0);
+               }
+       }
+}
+
+/*
+ * Copy src to dst using safe memory accesses, up to either the specified
+ * length, or the point that a nul byte is encountered.  The src is assumed to
+ * be unsafe memory specified by the DIF program.  The dst is assumed to be
+ * safe memory that we can store to directly because it is managed by DTrace.
+ * Unlike dtrace_bcopy(), overlapping regions are not handled.
+ */
+static void dtrace_strcpy(const void *src, void *dst, size_t len)
+{
+       if (len != 0) {
+               uint8_t         *s1 = dst, c;
+               const uint8_t   *s2 = src;
+
+               do {
+                       *s1++ = c = dtrace_load8((uintptr_t)s2++);
+               } while (--len != 0 && c != '\0');
+       }
+}
+/*
+ * Copy src to dst, deriving the size and type from the specified (BYREF)
+ * variable type.  The src is assumed to be unsafe memory specified by the DIF
+ * program.  The dst is assumed to be DTrace variable memory that is of the
+ * specified type; we assume that we can store to directly.
+ */
+static void dtrace_vcopy(void *src, void *dst, dtrace_diftype_t *type)
+{
+       ASSERT(type->dtdt_flags & DIF_TF_BYREF);
+
+       if (type->dtdt_kind == DIF_TYPE_STRING)
+               dtrace_strcpy(src, dst, type->dtdt_size);
+       else
+               dtrace_bcopy(src, dst, type->dtdt_size);
+}
+
+/*
+ * Compare s1 to s2 using safe memory accesses.  The s1 data is assumed to be
+ * unsafe memory specified by the DIF program.  The s2 data is assumed to be
+ * safe memory that we can access directly because it is managed by DTrace.
+ */
+static int dtrace_bcmp(const void *s1, const void *s2, size_t len)
+{
+       volatile uint16_t       *flags;
+
+       flags = (volatile uint16_t *)&cpu_core[
+                                       smp_processor_id()].cpuc_dtrace_flags;
+
+       if (s1 == s2)
+               return 0;
+
+       if (s1 == NULL || s2 == NULL)
+               return 1;
+
+       if (s1 != s2 && len != 0) {
+               const uint8_t   *ps1 = s1;
+               const uint8_t   *ps2 = s2;
+
+               do {
+                       if (dtrace_load8((uintptr_t)ps1++) != *ps2++)
+                               return 1;
+               } while (--len != 0 && !(*flags & CPU_DTRACE_FAULT));
+       }
+
+       return 0;
+}
+
+/*
+ * Zero the specified region using a simple byte-by-byte loop.  Note that this
+ * is for safe DTrace-managed memory only.
+ */
+void dtrace_bzero(void *dst, size_t len)
+{
+       uchar_t *cp;
+
+       for (cp = dst; len != 0; len--)
+               *cp++ = 0;
+}
+
+#define DTRACE_DYNHASH_FREE    0
+#define DTRACE_DYNHASH_SINK    1
+#define DTRACE_DYNHASH_VALID   2
+
+/*
+ * Depending on the value of the op parameter, this function looks-up,
+ * allocates or deallocates an arbitrarily-keyed dynamic variable.  If an
+ * allocation is requested, this function will return a pointer to a
+ * dtrace_dynvar_t corresponding to the allocated variable -- or NULL if no
+ * variable can be allocated.  If NULL is returned, the appropriate counter
+ * will be incremented.
+ */
+static dtrace_dynvar_t *dtrace_dynvar(dtrace_dstate_t *dstate, uint_t nkeys,
+                                     dtrace_key_t *key, size_t dsize,
+                                     dtrace_dynvar_op_t op,
+                                     dtrace_mstate_t *mstate,
+                                     dtrace_vstate_t *vstate)
+{
+       uint64_t                hashval = DTRACE_DYNHASH_VALID;
+       dtrace_dynhash_t        *hash = dstate->dtds_hash;
+       dtrace_dynvar_t         *free, *new_free, *next, *dvar, *start,
+                               *prev = NULL;
+       processorid_t           me = smp_processor_id(), cpu = me;
+       dtrace_dstate_percpu_t  *dcpu = &dstate->dtds_percpu[me];
+       size_t                  bucket, ksize;
+       size_t                  chunksize = dstate->dtds_chunksize;
+       uintptr_t               kdata, lock, nstate;
+       uint_t                  i;
+
+        ASSERT(nkeys != 0);
+
+       /*
+        * Hash the key.  As with aggregations, we use Jenkins' "One-at-a-time"
+        * algorithm.  For the by-value portions, we perform the algorithm in
+        * 16-bit chunks (as opposed to 8-bit chunks).  This speeds things up a
+        * bit, and seems to have only a minute effect on distribution.  For
+        * the by-reference data, we perform "One-at-a-time" iterating (safely)
+        * over each referenced byte.  It's painful to do this, but it's much
+        * better than pathological hash distribution.  The efficacy of the
+        * hashing algorithm (and a comparison with other algorithms) may be
+        * found by running the ::dtrace_dynstat MDB dcmd.
+        */
+       for (i = 0; i < nkeys; i++) {
+               if (key[i].dttk_size == 0) {
+                       uint64_t        val = key[i].dttk_value;
+
+                       hashval += (val >> 48) & 0xffff;
+                       hashval += (hashval << 10);
+                       hashval ^= (hashval >> 6);
+
+                       hashval += (val >> 32) & 0xffff;
+                       hashval += (hashval << 10);
+                       hashval ^= (hashval >> 6);
+
+                       hashval += (val >> 16) & 0xffff;
+                       hashval += (hashval << 10);
+                       hashval ^= (hashval >> 6);
+
+                       hashval += val & 0xffff;
+                       hashval += (hashval << 10);
+                       hashval ^= (hashval >> 6);
+               } else {
+                       /*
+                        * This is incredibly painful, but it beats the hell
+                        * out of the alternative.
+                        */
+                       uint64_t        j, size = key[i].dttk_size;
+                       uintptr_t       base = (uintptr_t)key[i].dttk_value;
+
+                       if (!dtrace_canload(base, size, mstate, vstate))
+                               break;
+
+                       for (j = 0; j < size; j++) {
+                               hashval += dtrace_load8(base + j);
+                               hashval += (hashval << 10);
+                               hashval ^= (hashval >> 6);
+                       }
+               }
+       }
+
+       if (DTRACE_CPUFLAG_ISSET(CPU_DTRACE_FAULT))
+               return NULL;
+
+       hashval += (hashval << 3);
+       hashval ^= (hashval >> 11);
+       hashval += (hashval << 15);
+
+       /*
+        * There is a remote chance (ideally, 1 in 2^31) that our hashval
+        * comes out to be one of our two sentinel hash values.  If this
+        * actually happens, we set the hashval to be a value known to be a
+        * non-sentinel value.
+        */
+       if (hashval == DTRACE_DYNHASH_FREE || hashval == DTRACE_DYNHASH_SINK)
+               hashval = DTRACE_DYNHASH_VALID;
+
+       /*
+        * Yes, it's painful to do a divide here.  If the cycle count becomes
+        * important here, tricks can be pulled to reduce it.  (However, it's
+        * critical that hash collisions be kept to an absolute minimum;
+        * they're much more painful than a divide.)  It's better to have a
+        * solution that generates few collisions and still keeps things
+        * relatively simple.
+        *
+        * Linux cannot do a straight 64-bit divide without gcc requiring
+        * linking in code that the kernel doesn't link, so we need to use an
+        * alternative.
+        *
+        *      bucket = hashval % dstate->dtds_hashsize;
+        */
+       {
+           uint64_t    num;
+
+           num = hashval;
+           bucket = do_div(num, dstate->dtds_hashsize);
+       }
+
+       if (op == DTRACE_DYNVAR_DEALLOC) {
+               volatile uintptr_t      *lockp = &hash[bucket].dtdh_lock;
+
+               for (;;) {
+                       while ((lock = *lockp) & 1)
+                               continue;
+
+                       if (cmpxchg(lockp, lock, (lock + 1)) == lock)
+                               break;
+               }
+
+               dtrace_membar_producer();
+       }
+
+top:
+       prev = NULL;
+       lock = hash[bucket].dtdh_lock;
+
+       dtrace_membar_consumer();
+
+       start = hash[bucket].dtdh_chain;
+       ASSERT(start != NULL && (start->dtdv_hashval == DTRACE_DYNHASH_SINK ||
+              start->dtdv_hashval != DTRACE_DYNHASH_FREE ||
+              op != DTRACE_DYNVAR_DEALLOC));
+
+       for (dvar = start; dvar != NULL; dvar = dvar->dtdv_next) {
+               dtrace_tuple_t  *dtuple = &dvar->dtdv_tuple;
+               dtrace_key_t    *dkey = &dtuple->dtt_key[0];
+
+               if (dvar->dtdv_hashval != hashval) {
+                       if (dvar->dtdv_hashval == DTRACE_DYNHASH_SINK) {
+                               /*
+                                * We've reached the sink, and therefore the
+                                * end of the hash chain; we can kick out of
+                                * the loop knowing that we have seen a valid
+                                * snapshot of state.
+                                */
+                               ASSERT(dvar->dtdv_next == NULL);
+                               ASSERT(dvar == &dtrace_dynhash_sink);
+                               break;
+                       }
+
+                       if (dvar->dtdv_hashval == DTRACE_DYNHASH_FREE) {
+                               /*
+                                * We've gone off the rails:  somewhere along
+                                * the line, one of the members of this hash
+                                * chain was deleted.  Note that we could also
+                                * detect this by simply letting this loop run
+                                * to completion, as we would eventually hit
+                                * the end of the dirty list.  However, we
+                                * want to avoid running the length of the
+                                * dirty list unnecessarily (it might be quite
+                                * long), so we catch this as early as
+                                * possible by detecting the hash marker.  In
+                                * this case, we simply set dvar to NULL and
+                                * break; the conditional after the loop will
+                                * send us back to top.
+                                */
+                               dvar = NULL;
+                               break;
+                       }
+
+                       goto next;
+               }
+
+               if (dtuple->dtt_nkeys != nkeys)
+                       goto next;
+
+               for (i = 0; i < nkeys; i++, dkey++) {
+                       if (dkey->dttk_size != key[i].dttk_size)
+                               goto next;      /* size or type mismatch */
+
+                       if (dkey->dttk_size != 0) {
+                               if (dtrace_bcmp(
+                                         (void *)(uintptr_t)key[i].dttk_value,
+                                         (void *)(uintptr_t)dkey->dttk_value,
+                                         dkey->dttk_size))
+                                       goto next;
+                       } else {
+                               if (dkey->dttk_value != key[i].dttk_value)
+                                       goto next;
+                       }
+               }
+
+               if (op != DTRACE_DYNVAR_DEALLOC)
+                       return dvar;
+
+               ASSERT(dvar->dtdv_next == NULL ||
+               dvar->dtdv_next->dtdv_hashval != DTRACE_DYNHASH_FREE);
+
+               if (prev != NULL) {
+                       ASSERT(hash[bucket].dtdh_chain != dvar);
+                       ASSERT(start != dvar);
+                       ASSERT(prev->dtdv_next == dvar);
+                       prev->dtdv_next = dvar->dtdv_next;
+               } else {
+                       if (cmpxchg(&hash[bucket].dtdh_chain, start,
+                                   dvar->dtdv_next) != start) {
+                               /*
+                                * We have failed to atomically swing the
+                                * hash table head pointer, presumably because
+                                * of a conflicting allocation on another CPU.
+                                * We need to reread the hash chain and try
+                                * again.
+                                */
+                               goto top;
+                       }
+               }
+
+               dtrace_membar_producer();
+
+               /*
+                * Now set the hash value to indicate that it's free.
+                */
+               ASSERT(hash[bucket].dtdh_chain != dvar);
+               dvar->dtdv_hashval = DTRACE_DYNHASH_FREE;
+
+               dtrace_membar_producer();
+
+               /*
+                * Set the next pointer to point at the dirty list, and
+                * atomically swing the dirty pointer to the newly freed dvar.
+                */
+               do {
+                       next = dcpu->dtdsc_dirty;
+                       dvar->dtdv_next = next;
+               } while (cmpxchg(&dcpu->dtdsc_dirty, next, dvar) != next);
+
+               /*
+                * Finally, unlock this hash bucket.
+                */
+               ASSERT(hash[bucket].dtdh_lock == lock);
+               ASSERT(lock & 1);
+               hash[bucket].dtdh_lock++;
+
+               return NULL;
+next:
+               prev = dvar;
+               continue;
+       }
+
+       if (dvar == NULL) {
+               /*
+                * If dvar is NULL, it is because we went off the rails:
+                * one of the elements that we traversed in the hash chain
+                * was deleted while we were traversing it.  In this case,
+                * we assert that we aren't doing a dealloc (deallocs lock
+                * the hash bucket to prevent themselves from racing with
+                * one another), and retry the hash chain traversal.
+                */
+               ASSERT(op != DTRACE_DYNVAR_DEALLOC);
+               goto top;
+       }
+
+       if (op != DTRACE_DYNVAR_ALLOC) {
+               /*
+                * If we are not to allocate a new variable, we want to
+                * return NULL now.  Before we return, check that the value
+                * of the lock word hasn't changed.  If it has, we may have
+                * seen an inconsistent snapshot.
+                */
+               if (op == DTRACE_DYNVAR_NOALLOC) {
+                       if (hash[bucket].dtdh_lock != lock)
+                               goto top;
+               } else {
+                       ASSERT(op == DTRACE_DYNVAR_DEALLOC);
+                       ASSERT(hash[bucket].dtdh_lock == lock);
+                       ASSERT(lock & 1);
+                       hash[bucket].dtdh_lock++;
+               }
+
+               return NULL;
+       }
+
+       /*
+        * We need to allocate a new dynamic variable.  The size we need is the
+        * size of dtrace_dynvar plus the size of nkeys dtrace_key_t's plus the
+        * size of any auxiliary key data (rounded up to 8-byte alignment) plus
+        * the size of any referred-to data (dsize).  We then round the final
+        * size up to the chunksize for allocation.
+        */
+       for (ksize = 0, i = 0; i < nkeys; i++)
+               ksize += P2ROUNDUP(key[i].dttk_size, sizeof(uint64_t));
+
+       /*
+        * This should be pretty much impossible, but could happen if, say,
+        * strange DIF specified the tuple.  Ideally, this should be an
+        * assertion and not an error condition -- but that requires that the
+        * chunksize calculation in dtrace_difo_chunksize() be absolutely
+        * bullet-proof.  (That is, it must not be able to be fooled by
+        * malicious DIF.)  Given the lack of backwards branches in DIF,
+        * solving this would presumably not amount to solving the Halting
+        * Problem -- but it still seems awfully hard.
+        */
+       if (sizeof(dtrace_dynvar_t) + sizeof(dtrace_key_t) * (nkeys - 1) +
+           ksize + dsize > chunksize) {
+               dcpu->dtdsc_drops++;
+               return NULL;
+       }
+
+       nstate = DTRACE_DSTATE_EMPTY;
+
+       do {
+retry:
+               free = dcpu->dtdsc_free;
+
+               if (free == NULL) {
+                       dtrace_dynvar_t *clean = dcpu->dtdsc_clean;
+                       void            *rval;
+
+                       if (clean == NULL) {
+                               /*
+                                * We're out of dynamic variable space on
+                                * this CPU.  Unless we have tried all CPUs,
+                                * we'll try to allocate from a different
+                                * CPU.
+                                */
+                               switch (dstate->dtds_state) {
+                               case DTRACE_DSTATE_CLEAN: {
+                                       uintptr_t       *sp =
+                                                       (uintptr_t *)
+                                                       &dstate->dtds_state;
+
+                                       if (++cpu >= NR_CPUS)
+                                               cpu = 0;
+
+                                       if (dcpu->dtdsc_dirty != NULL &&
+                                           nstate == DTRACE_DSTATE_EMPTY)
+                                               nstate = DTRACE_DSTATE_DIRTY;
+
+                                       if (dcpu->dtdsc_rinsing != NULL)
+                                               nstate = DTRACE_DSTATE_RINSING;
+
+                                       dcpu = &dstate->dtds_percpu[cpu];
+
+                                       if (cpu != me)
+                                               goto retry;
+
+                                       cmpxchg(sp, DTRACE_DSTATE_CLEAN,
+                                               nstate);
+
+                                       /*
+                                        * To increment the correct bean
+                                        * counter, take another lap.
+                                        */
+                                       goto retry;
+                               }
+
+                               case DTRACE_DSTATE_DIRTY:
+                                       dcpu->dtdsc_dirty_drops++;
+                                       break;
+
+                               case DTRACE_DSTATE_RINSING:
+                                       dcpu->dtdsc_rinsing_drops++;
+                                       break;
+
+                               case DTRACE_DSTATE_EMPTY:
+                                       dcpu->dtdsc_drops++;
+                                       break;
+                               }
+
+                               DTRACE_CPUFLAG_SET(CPU_DTRACE_DROP);
+                               return NULL;
+                       }
+
+                       /*
+                        * The clean list appears to be non-empty.  We want to
+                        * move the clean list to the free list; we start by
+                        * moving the clean pointer aside.
+                        */
+                       if (cmpxchg(&dcpu->dtdsc_clean, clean, NULL) != clean)
+                               /*
+                                * We are in one of two situations:
+                                *
+                                *  (a) The clean list was switched to the
+                                *      free list by another CPU.
+                                *
+                                *  (b) The clean list was added to by the
+                                *      cleansing cyclic.
+                                *
+                                * In either of these situations, we can
+                                * just reattempt the free list allocation.
+                                */
+                               goto retry;
+
+                       ASSERT(clean->dtdv_hashval == DTRACE_DYNHASH_FREE);
+
+                       /*
+                        * Now we'll move the clean list to the free list.
+                        * It's impossible for this to fail:  the only way
+                        * the free list can be updated is through this
+                        * code path, and only one CPU can own the clean list.
+                        * Thus, it would only be possible for this to fail if
+                        * this code were racing with dtrace_dynvar_clean().
+                        * (That is, if dtrace_dynvar_clean() updated the clean
+                        * list, and we ended up racing to update the free
+                        * list.)  This race is prevented by the dtrace_sync()
+                        * in dtrace_dynvar_clean() -- which flushes the
+                        * owners of the clean lists out before resetting
+                        * the clean lists.
+                        */
+                       rval = cmpxchg(&dcpu->dtdsc_free, NULL, clean);
+                       ASSERT(rval == NULL);
+
+                       goto retry;
+               }
+
+               dvar = free;
+               new_free = dvar->dtdv_next;
+       } while (cmpxchg(&dcpu->dtdsc_free, free, new_free) != free);
+
+       /*
+        * We have now allocated a new chunk.  We copy the tuple keys into the
+        * tuple array and copy any referenced key data into the data space
+        * following the tuple array.  As we do this, we relocate dttk_value
+        * in the final tuple to point to the key data address in the chunk.
+        */
+       kdata = (uintptr_t)&dvar->dtdv_tuple.dtt_key[nkeys];
+       dvar->dtdv_data = (void *)(kdata + ksize);
+       dvar->dtdv_tuple.dtt_nkeys = nkeys;
+
+       for (i = 0; i < nkeys; i++) {
+               dtrace_key_t    *dkey = &dvar->dtdv_tuple.dtt_key[i];
+               size_t          kesize = key[i].dttk_size;
+
+               if (kesize != 0) {
+                       dtrace_bcopy(
+                               (const void *)(uintptr_t)key[i].dttk_value,
+                               (void *)kdata, kesize);
+                       dkey->dttk_value = kdata;
+                       kdata += P2ROUNDUP(kesize, sizeof(uint64_t));
+               } else
+                       dkey->dttk_value = key[i].dttk_value;
+
+               dkey->dttk_size = kesize;
+       }
+
+       ASSERT(dvar->dtdv_hashval == DTRACE_DYNHASH_FREE);
+       dvar->dtdv_hashval = hashval;
+       dvar->dtdv_next = start;
+
+       if (cmpxchg(&hash[bucket].dtdh_chain, start, dvar) == start)
+               return dvar;
+
+       /*
+        * The cas has failed.  Either another CPU is adding an element to
+        * this hash chain, or another CPU is deleting an element from this
+        * hash chain.  The simplest way to deal with both of these cases
+        * (though not necessarily the most efficient) is to free our
+        * allocated block and tail-call ourselves.  Note that the free is
+        * to the dirty list and _not_ to the free list.  This is to prevent
+        * races with allocators, above.
+        */
+       dvar->dtdv_hashval = DTRACE_DYNHASH_FREE;
+
+       dtrace_membar_producer();
+
+       do {
+               free = dcpu->dtdsc_dirty;
+               dvar->dtdv_next = free;
+       } while (cmpxchg(&dcpu->dtdsc_dirty, free, dvar) != free);
+
+       return dtrace_dynvar(dstate, nkeys, key, dsize, op, mstate, vstate);
+}
+
+/*
+ * Return a string.  In the event that the user lacks the privilege to access
+ * arbitrary kernel memory, we copy the string out to scratch memory so that we
+ * don't fail access checking.
+ *
+ * dtrace_dif_variable() uses this routine as a helper for various
+ * builtin values such as 'execname' and 'probefunc.'
+ */
+static uintptr_t dtrace_dif_varstr(uintptr_t addr, dtrace_state_t *state,
+                                  dtrace_mstate_t *mstate)
+{
+       uint64_t        size = state->dts_options[DTRACEOPT_STRSIZE];
+       uintptr_t       ret;
+       size_t          strsz;
+
+       /*
+        * The easy case: this probe is allowed to read all of memory, so
+        * we can just return this as a vanilla pointer.
+        */
+       if ((mstate->dtms_access & DTRACE_ACCESS_KERNEL) != 0)
+               return addr;
+
+       /*
+        * This is the tougher case: we copy the string in question from
+        * kernel memory into scratch memory and return it that way: this
+        * ensures that we won't trip up when access checking tests the
+        * BYREF return value.
+        */
+       strsz = dtrace_strlen((char *)addr, size) + 1;
+
+       if (mstate->dtms_scratch_ptr + strsz >
+           mstate->dtms_scratch_base + mstate->dtms_scratch_size) {
+               DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+               return (uintptr_t)NULL;
+       }
+
+       dtrace_strcpy((const void *)addr, (void *)mstate->dtms_scratch_ptr,
+                     strsz);
+       ret = mstate->dtms_scratch_ptr;
+       mstate->dtms_scratch_ptr += strsz;
+
+       return ret;
+}
+
+/*
+ * This function implements the DIF emulator's variable lookups.  The emulator
+ * passes a reserved variable identifier and optional built-in array index.
+ */
+static uint64_t dtrace_dif_variable(dtrace_mstate_t *mstate,
+                                   dtrace_state_t *state, uint64_t v,
+                                   uint64_t ndx)
+{
+       /*
+        * If we're accessing one of the uncached arguments, we'll turn this
+        * into a reference in the args array.
+        */
+       if (v >= DIF_VAR_ARG0 && v <= DIF_VAR_ARG9) {
+               ndx = v - DIF_VAR_ARG0;
+               v = DIF_VAR_ARGS;
+       }
+
+       switch (v) {
+       case DIF_VAR_ARGS:
+               ASSERT(mstate->dtms_present & DTRACE_MSTATE_ARGS);
+
+               if (ndx >=
+                   sizeof(mstate->dtms_arg) / sizeof(mstate->dtms_arg[0])) {
+                       int                     aframes =
+                                       mstate->dtms_probe->dtpr_aframes + 2;
+                       dtrace_provider_t       *pv;
+                       uint64_t                val;
+
+                       pv = mstate->dtms_probe->dtpr_provider;
+                       if (pv->dtpv_pops.dtps_getargval != NULL)
+                               val = pv->dtpv_pops.dtps_getargval(
+                                       pv->dtpv_arg,
+                                       mstate->dtms_probe->dtpr_id,
+                                       mstate->dtms_probe->dtpr_arg,
+                                       ndx, aframes);
+                       else
+                               val = dtrace_getarg(ndx, aframes);
+
+                       /*
+                        * This is regrettably required to keep the compiler
+                        * from tail-optimizing the call to dtrace_getarg().
+                        * The condition always evaluates to true, but the
+                        * compiler has no way of figuring that out a priori.
+                        * (None of this would be necessary if the compiler
+                        * could be relied upon to _always_ tail-optimize
+                        * the call to dtrace_getarg() -- but it can't.)
+                        */
+                       if (mstate->dtms_probe != NULL)
+                               return val;
+
+                       ASSERT(0);
+               }
+
+               return mstate->dtms_arg[ndx];
+
+       case DIF_VAR_UREGS: {
+               struct pt_regs  *regs = task_pt_regs(current);
+
+               if (!dtrace_priv_proc(state))
+                       return 0;
+
+               return dtrace_getreg(regs, ndx);
+       }
+
+       case DIF_VAR_CURTHREAD:
+               if (!dtrace_priv_kernel(state))
+                       return 0;
+
+               return (uint64_t)(uintptr_t)current;
+
+       case DIF_VAR_TIMESTAMP:
+               if (!(mstate->dtms_present & DTRACE_MSTATE_TIMESTAMP)) {
+                       mstate->dtms_timestamp = dtrace_gethrtime();
+                       mstate->dtms_present |= DTRACE_MSTATE_TIMESTAMP;
+               }
+
+               return ktime_to_ns(mstate->dtms_timestamp);
+
+       case DIF_VAR_VTIMESTAMP:
+               ASSERT(dtrace_vtime_references != 0);
+
+               return ktime_to_ns(current->dtrace_vtime);
+
+       case DIF_VAR_WALLTIMESTAMP:
+               return ktime_to_ns(dtrace_getwalltime());
+
+       case DIF_VAR_IPL:
+               if (!dtrace_priv_kernel(state))
+                       return 0;
+
+               if (!(mstate->dtms_present & DTRACE_MSTATE_IPL)) {
+                       mstate->dtms_ipl = dtrace_getipl();
+                       mstate->dtms_present |= DTRACE_MSTATE_IPL;
+               }
+
+               return mstate->dtms_ipl;
+
+       case DIF_VAR_EPID:
+               ASSERT(mstate->dtms_present & DTRACE_MSTATE_EPID);
+               ASSERT(mstate->dtms_present & DTRACE_MSTATE_EPID);
+
+               return mstate->dtms_epid;
+
+       case DIF_VAR_ID:
+               ASSERT(mstate->dtms_present & DTRACE_MSTATE_PROBE);
+               return mstate->dtms_probe->dtpr_id;
+
+       case DIF_VAR_STACKDEPTH:
+               if (!dtrace_priv_kernel(state))
+                       return 0;
+               if (!(mstate->dtms_present & DTRACE_MSTATE_STACKDEPTH)) {
+                       int     aframes = mstate->dtms_probe->dtpr_aframes + 2;
+
+                       mstate->dtms_stackdepth = dtrace_getstackdepth(aframes);
+                       mstate->dtms_present |= DTRACE_MSTATE_STACKDEPTH;
+               }
+
+               return mstate->dtms_stackdepth;
+
+       case DIF_VAR_USTACKDEPTH:
+               if (!dtrace_priv_proc(state))
+                       return 0;
+
+               if (!(mstate->dtms_present & DTRACE_MSTATE_USTACKDEPTH)) {
+                       /*
+                        * See comment in DIF_VAR_PID.
+                        */
+                       if (DTRACE_ANCHORED(mstate->dtms_probe) &&
+                           in_interrupt())
+                               mstate->dtms_ustackdepth = 0;
+                       else {
+                               DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+                               mstate->dtms_ustackdepth =
+                                               dtrace_getustackdepth();
+                               DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
+                       }
+
+                       mstate->dtms_present |= DTRACE_MSTATE_USTACKDEPTH;
+               }
+
+               return mstate->dtms_ustackdepth;
+
+       case DIF_VAR_CALLER:
+               if (!dtrace_priv_kernel(state))
+                       return 0;
+
+               if (!(mstate->dtms_present & DTRACE_MSTATE_CALLER)) {
+                       int     aframes = mstate->dtms_probe->dtpr_aframes + 2;
+
+                       if (!DTRACE_ANCHORED(mstate->dtms_probe)) {
+                               /*
+                                * If this is an unanchored probe, we are
+                                * required to go through the slow path:
+                                * dtrace_caller() only guarantees correct
+                                * results for anchored probes.
+                                */
+                               uint64_t        caller[2];
+
+                               dtrace_getpcstack(caller, 2, aframes,
+                                       (uint32_t *)(uintptr_t)
+                                                       mstate->dtms_arg[0]);
+                               mstate->dtms_caller = caller[1];
+                       } else if ((mstate->dtms_caller =
+                                       dtrace_caller(aframes)) == -1) {
+                               /*
+                                * We have failed to do this the quick way;
+                                * we must resort to the slower approach of
+                                * calling dtrace_getpcstack().
+                                */
+                               uint64_t        caller;
+
+                               dtrace_getpcstack(&caller, 1, aframes, NULL);
+                               mstate->dtms_caller = caller;
+                       }
+
+                       mstate->dtms_present |= DTRACE_MSTATE_CALLER;
+               }
+
+               return mstate->dtms_caller;
+
+       case DIF_VAR_UCALLER:
+               if (!dtrace_priv_proc(state))
+                       return 0;
+
+               if (!(mstate->dtms_present & DTRACE_MSTATE_UCALLER)) {
+                       uint64_t        ustack[3];
+
+                       /*
+                        * dtrace_getupcstack() fills in the first uint64_t
+                        * with the current PID.  The second uint64_t will
+                        * be the program counter at user-level.  The third
+                        * uint64_t will contain the caller, which is what
+                        * we're after.
+                        */
+                       ustack[2] = 0;
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+                       dtrace_getupcstack(ustack, 3);
+                       DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
+                       mstate->dtms_ucaller = ustack[2];
+                       mstate->dtms_present |= DTRACE_MSTATE_UCALLER;
+               }
+
+               return mstate->dtms_ucaller;
+
+       case DIF_VAR_PROBEPROV:
+               ASSERT(mstate->dtms_present & DTRACE_MSTATE_PROBE);
+
+               return dtrace_dif_varstr(
+                       (uintptr_t)mstate->dtms_probe->dtpr_provider->dtpv_name,
+                       state, mstate);
+
+       case DIF_VAR_PROBEMOD:
+               ASSERT(mstate->dtms_present & DTRACE_MSTATE_PROBE);
+               return dtrace_dif_varstr(
+                       (uintptr_t)mstate->dtms_probe->dtpr_mod, state,
+                       mstate);
+
+       case DIF_VAR_PROBEFUNC:
+               ASSERT(mstate->dtms_present & DTRACE_MSTATE_PROBE);
+
+               return dtrace_dif_varstr(
+                       (uintptr_t)mstate->dtms_probe->dtpr_func, state,
+                       mstate);
+
+       case DIF_VAR_PROBENAME:
+               ASSERT(mstate->dtms_present & DTRACE_MSTATE_PROBE);
+
+               return dtrace_dif_varstr(
+                       (uintptr_t)mstate->dtms_probe->dtpr_name, state,
+                       mstate);
+
+       case DIF_VAR_PID:
+               if (!dtrace_priv_proc(state))
+                       return 0;
+
+               /*
+                * Note that we are assuming that an unanchored probe is
+                * always due to a high-level interrupt.  (And we're assuming
+                * that there is only a single high level interrupt.)
+                */
+               if (DTRACE_ANCHORED(mstate->dtms_probe) && in_interrupt())
+                       return init_task.pid;
+
+               /*
+                * It is always safe to dereference current, it always points
+                * to a valid task_struct.
+                */
+               return (uint64_t)current->pid;
+
+       case DIF_VAR_PPID:
+               if (!dtrace_priv_proc(state))
+                       return 0;
+
+               /*
+                * See comment in DIF_VAR_PID.
+                */
+               if (DTRACE_ANCHORED(mstate->dtms_probe) && in_interrupt())
+                       return init_task.real_parent->pid;
+
+               /*
+                * It is always safe to dereference current, it always points
+                * to a valid task_struct.
+                *
+                * Additionally, it is safe to dereference one's parent, since
+                * it is never NULL after process birth.
+                */
+               return (uint64_t)current->real_parent->pid;
+
+       case DIF_VAR_TID:
+               /*
+                * See comment in DIF_VAR_PID.
+                */
+               if (DTRACE_ANCHORED(mstate->dtms_probe) && in_interrupt())
+                       return init_task.pid;
+
+               return (uint64_t)current->pid;
+
+       case DIF_VAR_EXECNAME:
+               if (!dtrace_priv_proc(state))
+                       return 0;
+
+               /*
+                * See comment in DIF_VAR_PID.
+                */
+               if (DTRACE_ANCHORED(mstate->dtms_probe) && in_interrupt())
+                       return (uint64_t)(uintptr_t)init_task.comm;
+
+               /*
+                * It is always safe to dereference current, it always points
+                * to a valid task_struct.
+                */
+               return dtrace_dif_varstr((uintptr_t)current->comm, state,
+                                        mstate);
+
+       case DIF_VAR_ZONENAME:
+               return 0;
+
+       case DIF_VAR_UID:
+               if (!dtrace_priv_proc(state))
+                       return 0;
+
+               /*
+                * See comment in DIF_VAR_PID.
+                */
+               if (DTRACE_ANCHORED(mstate->dtms_probe) && in_interrupt())
+                       return (uint64_t)init_task.real_cred->uid;
+
+               /*
+                * It is always safe to dereference current, it always points
+                * to a valid task_struct.
+                *
+                * Additionally, it is safe to dereference one's own process
+                * credential, since this is never NULL after process birth.
+                */
+               return (uint64_t)current->real_cred->uid;
+
+       case DIF_VAR_GID:
+               if (!dtrace_priv_proc(state))
+                       return 0;
+
+               /*
+                * See comment in DIF_VAR_PID.
+                */
+               if (DTRACE_ANCHORED(mstate->dtms_probe) && in_interrupt())
+                       return (uint64_t)init_task.real_cred->gid;
+
+               /*
+                * It is always safe to dereference current, it always points
+                * to a valid task_struct.
+                *
+                * Additionally, it is safe to dereference one's own process
+                * credential, since this is never NULL after process birth.
+                */
+               return (uint64_t)current->real_cred->gid;
+
+       case DIF_VAR_ERRNO:
+               if (!dtrace_priv_proc(state))
+                       return 0;
+
+               /*
+                * See comment in DIF_VAR_PID.
+                */
+               if (DTRACE_ANCHORED(mstate->dtms_probe) && in_interrupt())
+                       return 0;
+
+               /*
+                * It is always safe to dereference current, it always points
+                * to a valid task_struct.
+                */
+               return (uint64_t)current->thread.error_code;
+
+       default:
+               DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
+               return 0;
+       }
+}
+
+#define DTRACE_V4MAPPED_OFFSET (sizeof (uint32_t) * 3)
+
+/*
+ * Emulate the execution of DTrace ID subroutines invoked by the call opcode.
+ * Notice that we don't bother validating the proper number of arguments or
+ * their types in the tuple stack.  This isn't needed because all argument
+ * interpretation is safe because of our load safety -- the worst that can
+ * happen is that a bogus program can obtain bogus results.
+ */
+static void dtrace_dif_subr(uint_t subr, uint_t rd, uint64_t *regs,
+                           dtrace_key_t *tupregs, int nargs,
+                           dtrace_mstate_t *mstate, dtrace_state_t *state)
+{
+       volatile uint16_t       *flags = &cpu_core[
+                                               smp_processor_id()
+                                         ].cpuc_dtrace_flags;
+       volatile uintptr_t      *illval = &cpu_core[
+                                               smp_processor_id()
+                                          ].cpuc_dtrace_illval;
+       dtrace_vstate_t         *vstate = &state->dts_vstate;
+
+       union {
+               struct mutex mi;
+               uint64_t mx;
+       } m;
+
+       union {
+               rwlock_t ri;
+               uintptr_t rw;
+       } r;
+
+       switch (subr) {
+       case DIF_SUBR_RAND:
+               regs[rd] = ktime_to_ns(dtrace_gethrtime()) * 2416 + 374441;
+               regs[rd] = do_div(regs[rd], 1771875);
+               break;
+
+       case DIF_SUBR_MUTEX_OWNED:
+               if (!dtrace_canload(tupregs[0].dttk_value,
+                                   sizeof(struct mutex), mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               m.mx = dtrace_load64(tupregs[0].dttk_value);
+#ifdef CONFIG_SMP
+               regs[rd] = m.mi.owner != NULL;
+#else
+               regs[rd] = mutex_is_locked(&m.mi);
+#endif
+               break;
+
+       case DIF_SUBR_MUTEX_OWNER:
+               if (!dtrace_canload(tupregs[0].dttk_value,
+                                   sizeof(struct mutex), mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               m.mx = dtrace_load64(tupregs[0].dttk_value);
+#ifdef CONFIG_SMP
+               regs[rd] = (uintptr_t)m.mi.owner;
+#else
+               regs[rd] = 0;
+#endif
+               break;
+
+       case DIF_SUBR_MUTEX_TYPE_ADAPTIVE:
+               if (!dtrace_canload(tupregs[0].dttk_value,
+                                   sizeof(struct mutex), mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               m.mx = dtrace_load64(tupregs[0].dttk_value);
+               /*
+                * On Linux, all mutexes are adaptive.
+                */
+               regs[rd] = 1;
+               break;
+
+       case DIF_SUBR_MUTEX_TYPE_SPIN:
+               if (!dtrace_canload(tupregs[0].dttk_value,
+                                   sizeof(struct mutex), mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               m.mx = dtrace_load64(tupregs[0].dttk_value);
+               /*
+                * On Linux, all mutexes are adaptive.
+                */
+               regs[rd] = 0;
+               break;
+
+       case DIF_SUBR_RW_READ_HELD: {
+               if (!dtrace_canload(tupregs[0].dttk_value, sizeof(uintptr_t),
+                   mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               r.rw = dtrace_loadptr(tupregs[0].dttk_value);
+               regs[rd] = !write_can_lock(&r.ri) && read_can_lock(&r.ri);
+               break;
+       }
+
+       case DIF_SUBR_RW_WRITE_HELD:
+               if (!dtrace_canload(tupregs[0].dttk_value, sizeof(rwlock_t),
+                   mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               r.rw = dtrace_loadptr(tupregs[0].dttk_value);
+               regs[rd] = !write_can_lock(&r.ri);
+               break;
+
+       case DIF_SUBR_RW_ISWRITER:
+               if (!dtrace_canload(tupregs[0].dttk_value, sizeof(rwlock_t),
+                   mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               r.rw = dtrace_loadptr(tupregs[0].dttk_value);
+               /*
+                * On Linux there is no way to determine whether someone is
+                * trying to acquire a write lock.
+                */
+               regs[rd] = !write_can_lock(&r.ri);
+               break;
+
+       case DIF_SUBR_BCOPY: {
+               /*
+                * We need to be sure that the destination is in the scratch
+                * region -- no other region is allowed.
+                */
+               uintptr_t       src = tupregs[0].dttk_value;
+               uintptr_t       dest = tupregs[1].dttk_value;
+               size_t          size = tupregs[2].dttk_value;
+
+               if (!dtrace_inscratch(dest, size, mstate)) {
+                       *flags |= CPU_DTRACE_BADADDR;
+                       *illval = regs[rd];
+                       break;
+               }
+
+               if (!dtrace_canload(src, size, mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               dtrace_bcopy((void *)src, (void *)dest, size);
+               break;
+       }
+
+       case DIF_SUBR_ALLOCA:
+       case DIF_SUBR_COPYIN: {
+               uintptr_t       dest = P2ROUNDUP(mstate->dtms_scratch_ptr, 8);
+               uint64_t        size = tupregs[
+                                       subr == DIF_SUBR_ALLOCA ? 0 : 1
+                                      ].dttk_value;
+               size_t          scratch_size = (dest -
+                                               mstate->dtms_scratch_ptr) +
+                                              size;
+
+               /*
+                * This action doesn't require any credential checks since
+                * probes will not activate in user contexts to which the
+                * enabling user does not have permissions.
+                */
+
+               /*
+                * Rounding up the user allocation size could have overflowed
+                * a large, bogus allocation (like -1ULL) to 0.
+                */
+               if (scratch_size < size ||
+                   !DTRACE_INSCRATCH(mstate, scratch_size)) {
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+                       regs[rd] = 0;
+                       break;
+               }
+
+               if (subr == DIF_SUBR_COPYIN) {
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+                       dtrace_copyin(tupregs[0].dttk_value, dest, size, flags);
+                       DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
+               }
+
+               mstate->dtms_scratch_ptr += scratch_size;
+               regs[rd] = dest;
+               break;
+       }
+
+       case DIF_SUBR_COPYINTO: {
+               uint64_t        size = tupregs[1].dttk_value;
+               uintptr_t       dest = tupregs[2].dttk_value;
+
+               /*
+                * This action doesn't require any credential checks since
+                * probes will not activate in user contexts to which the
+                * enabling user does not have permissions.
+                */
+               if (!dtrace_inscratch(dest, size, mstate)) {
+                       *flags |= CPU_DTRACE_BADADDR;
+                       *illval = regs[rd];
+                       break;
+               }
+
+               DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+               dtrace_copyin(tupregs[0].dttk_value, dest, size, flags);
+               DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
+               break;
+       }
+
+       case DIF_SUBR_COPYINSTR: {
+               uintptr_t       dest = mstate->dtms_scratch_ptr;
+               uint64_t        size = state->dts_options[DTRACEOPT_STRSIZE];
+
+               if (nargs > 1 && tupregs[1].dttk_value < size)
+                       size = tupregs[1].dttk_value + 1;
+
+               /*
+                * This action doesn't require any credential checks since
+                * probes will not activate in user contexts to which the
+                * enabling user does not have permissions.
+                */
+               if (!DTRACE_INSCRATCH(mstate, size)) {
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+                       regs[rd] = 0;
+                       break;
+               }
+
+               DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+               dtrace_copyinstr(tupregs[0].dttk_value, dest, size, flags);
+               DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
+
+               ((char *)dest)[size - 1] = '\0';
+               mstate->dtms_scratch_ptr += size;
+               regs[rd] = dest;
+               break;
+       }
+
+#if 0 /* FIXME */
+       case DIF_SUBR_MSGSIZE:
+       case DIF_SUBR_MSGDSIZE: {
+               uintptr_t       baddr = tupregs[0].dttk_value, daddr;
+               uintptr_t       wptr, rptr;
+               size_t          count = 0;
+               int             cont = 0;
+
+               while (baddr != NULL && !(*flags & CPU_DTRACE_FAULT)) {
+
+                       if (!dtrace_canload(baddr, sizeof(mblk_t), mstate,
+                           vstate)) {
+                               regs[rd] = 0;
+                               break;
+                       }
+
+                       wptr = dtrace_loadptr(baddr +
+                           offsetof(mblk_t, b_wptr));
+
+                       rptr = dtrace_loadptr(baddr +
+                           offsetof(mblk_t, b_rptr));
+
+                       if (wptr < rptr) {
+                               *flags |= CPU_DTRACE_BADADDR;
+                               *illval = tupregs[0].dttk_value;
+                               break;
+                       }
+
+                       daddr = dtrace_loadptr(baddr +
+                           offsetof(mblk_t, b_datap));
+
+                       baddr = dtrace_loadptr(baddr +
+                           offsetof(mblk_t, b_cont));
+
+                       /*
+                        * We want to prevent against denial-of-service here,
+                        * so we're only going to search the list for
+                        * dtrace_msgdsize_max mblks.
+                        */
+                       if (cont++ > dtrace_msgdsize_max) {
+                               *flags |= CPU_DTRACE_ILLOP;
+                               break;
+                       }
+
+                       if (subr == DIF_SUBR_MSGDSIZE) {
+                               if (dtrace_load8(daddr +
+                                   offsetof(dblk_t, db_type)) != M_DATA)
+                                       continue;
+                       }
+
+                       count += wptr - rptr;
+               }
+
+               if (!(*flags & CPU_DTRACE_FAULT))
+                       regs[rd] = count;
+
+               break;
+       }
+#endif
+
+       case DIF_SUBR_PROGENYOF: {
+               pid_t                   pid = tupregs[0].dttk_value;
+               struct task_struct      *p;
+               int                     rval = 0;
+
+               DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+
+               for (p = current; p != NULL; p = p->real_parent) {
+                       if (p->pid == pid) {
+                               rval = 1;
+                               break;
+                       }
+               }
+
+               DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
+
+               regs[rd] = rval;
+               break;
+       }
+
+       case DIF_SUBR_SPECULATION:
+               regs[rd] = dtrace_speculation(state);
+               break;
+
+       case DIF_SUBR_COPYOUT: {
+               uintptr_t       kaddr = tupregs[0].dttk_value;
+               uintptr_t       uaddr = tupregs[1].dttk_value;
+               uint64_t        size = tupregs[2].dttk_value;
+
+               if (!dtrace_destructive_disallow &&
+                   dtrace_priv_proc_control(state) &&
+                   !dtrace_istoxic(kaddr, size)) {
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+                       dtrace_copyout(kaddr, uaddr, size, flags);
+                       DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
+               }
+               break;
+       }
+
+       case DIF_SUBR_COPYOUTSTR: {
+               uintptr_t       kaddr = tupregs[0].dttk_value;
+               uintptr_t       uaddr = tupregs[1].dttk_value;
+               uint64_t        size = tupregs[2].dttk_value;
+
+               if (!dtrace_destructive_disallow &&
+                   dtrace_priv_proc_control(state) &&
+                   !dtrace_istoxic(kaddr, size)) {
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+                       dtrace_copyoutstr(kaddr, uaddr, size, flags);
+                       DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
+               }
+               break;
+       }
+
+       case DIF_SUBR_STRLEN: {
+               size_t          sz;
+               uintptr_t       addr = (uintptr_t)tupregs[0].dttk_value;
+
+               sz = dtrace_strlen((char *)addr,
+                                  state->dts_options[DTRACEOPT_STRSIZE]);
+
+               if (!dtrace_canload(addr, sz + 1, mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               regs[rd] = sz;
+
+               break;
+       }
+
+       case DIF_SUBR_STRCHR:
+       case DIF_SUBR_STRRCHR: {
+               /*
+                * We're going to iterate over the string looking for the
+                * specified character.  We will iterate until we have reached
+                * the string length or we have found the character.  If this
+                * is DIF_SUBR_STRRCHR, we will look for the last occurrence
+                * of the specified character instead of the first.
+                */
+               uintptr_t       saddr = tupregs[0].dttk_value;
+               uintptr_t       addr = tupregs[0].dttk_value;
+               uintptr_t       limit = addr +
+                                       state->dts_options[DTRACEOPT_STRSIZE];
+               char            c, target = (char)tupregs[1].dttk_value;
+
+               for (regs[rd] = 0; addr < limit; addr++) {
+                       if ((c = dtrace_load8(addr)) == target) {
+                               regs[rd] = addr;
+
+                               if (subr == DIF_SUBR_STRCHR)
+                                       break;
+                       }
+
+                       if (c == '\0')
+                               break;
+               }
+
+               if (!dtrace_canload(saddr, addr - saddr, mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               break;
+       }
+
+       case DIF_SUBR_STRSTR:
+       case DIF_SUBR_INDEX:
+       case DIF_SUBR_RINDEX: {
+               /*
+                * We're going to iterate over the string looking for the
+                * specified string.  We will iterate until we have reached
+                * the string length or we have found the string.  (Yes, this
+                * is done in the most naive way possible -- but considering
+                * that the string we're searching for is likely to be
+                * relatively short, the complexity of Rabin-Karp or similar
+                * hardly seems merited.)
+                */
+               char            *addr = (char *)(uintptr_t)
+                                                       tupregs[0].dttk_value;
+               char            *substr = (char *)(uintptr_t)
+                                                       tupregs[1].dttk_value;
+               uint64_t        size = state->dts_options[DTRACEOPT_STRSIZE];
+               size_t          len = dtrace_strlen(addr, size);
+               size_t          sublen = dtrace_strlen(substr, size);
+               char            *limit = addr + len, *orig = addr;
+               int             notfound = subr == DIF_SUBR_STRSTR ? 0 : -1;
+               int             inc = 1;
+
+               regs[rd] = notfound;
+
+               if (!dtrace_canload((uintptr_t)addr, len + 1, mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               if (!dtrace_canload((uintptr_t)substr, sublen + 1, mstate,
+                                   vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               /*
+                * strstr() and index()/rindex() have similar semantics if
+                * both strings are the empty string: strstr() returns a
+                * pointer to the (empty) string, and index() and rindex()
+                * both return index 0 (regardless of any position argument).
+                */
+               if (sublen == 0 && len == 0) {
+                       if (subr == DIF_SUBR_STRSTR)
+                               regs[rd] = (uintptr_t)addr;
+                       else
+                               regs[rd] = 0;
+                       break;
+               }
+
+               if (subr != DIF_SUBR_STRSTR) {
+                       if (subr == DIF_SUBR_RINDEX) {
+                               limit = orig - 1;
+                               addr += len;
+                               inc = -1;
+                       }
+
+                       /*
+                        * Both index() and rindex() take an optional position
+                        * argument that denotes the starting position.
+                        */
+                       if (nargs == 3) {
+                               int64_t pos = (int64_t)tupregs[2].dttk_value;
+
+                               /*
+                                * If the position argument to index() is
+                                * negative, Perl implicitly clamps it at
+                                * zero.  This semantic is a little surprising
+                                * given the special meaning of negative
+                                * positions to similar Perl functions like
+                                * substr(), but it appears to reflect a
+                                * notion that index() can start from a
+                                * negative index and increment its way up to
+                                * the string.  Given this notion, Perl's
+                                * rindex() is at least self-consistent in
+                                * that it implicitly clamps positions greater
+                                * than the string length to be the string
+                                * length.  Where Perl completely loses
+                                * coherence, however, is when the specified
+                                * substring is the empty string ("").  In
+                                * this case, even if the position is
+                                * negative, rindex() returns 0 -- and even if
+                                * the position is greater than the length,
+                                * index() returns the string length.  These
+                                * semantics violate the notion that index()
+                                * should never return a value less than the
+                                * specified position and that rindex() should
+                                * never return a value greater than the
+                                * specified position.  (One assumes that
+                                * these semantics are artifacts of Perl's
+                                * implementation and not the results of
+                                * deliberate design -- it beggars belief that
+                                * even Larry Wall could desire such oddness.)
+                                * While in the abstract one would wish for
+                                * consistent position semantics across
+                                * substr(), index() and rindex() -- or at the
+                                * very least self-consistent position
+                                * semantics for index() and rindex() -- we
+                                * instead opt to keep with the extant Perl
+                                * semantics, in all their broken glory.  (Do
+                                * we have more desire to maintain Perl's
+                                * semantics than Perl does?  Probably.)
+                                */
+                               if (subr == DIF_SUBR_RINDEX) {
+                                       if (pos < 0) {
+                                               if (sublen == 0)
+                                                       regs[rd] = 0;
+                                               break;
+                                       }
+
+                                       if (pos > len)
+                                               pos = len;
+                               } else {
+                                       if (pos < 0)
+                                               pos = 0;
+
+                                       if (pos >= len) {
+                                               if (sublen == 0)
+                                                       regs[rd] = len;
+                                               break;
+                                       }
+                               }
+
+                               addr = orig + pos;
+                       }
+               }
+
+               for (regs[rd] = notfound; addr != limit; addr += inc) {
+                       if (dtrace_strncmp(addr, substr, sublen) == 0) {
+                               if (subr != DIF_SUBR_STRSTR) {
+                                       /*
+                                        * As D index() and rindex() are
+                                        * modeled on Perl (and not on awk),
+                                        * we return a zero-based (and not a
+                                        * one-based) index.  (For you Perl
+                                        * weenies: no, we're not going to add
+                                        * $[ -- and shouldn't you be at a con
+                                        * or something?)
+                                        */
+                                       regs[rd] = (uintptr_t)(addr - orig);
+                                       break;
+                               }
+
+                               ASSERT(subr == DIF_SUBR_STRSTR);
+                               regs[rd] = (uintptr_t)addr;
+                               break;
+                       }
+               }
+
+               break;
+       }
+
+       case DIF_SUBR_STRTOK: {
+               uintptr_t       addr = tupregs[0].dttk_value;
+               uintptr_t       tokaddr = tupregs[1].dttk_value;
+               uint64_t        size = state->dts_options[DTRACEOPT_STRSIZE];
+               uintptr_t       limit, toklimit = tokaddr + size;
+               uint8_t         c, tokmap[32];  /* 256 / 8 */
+               char            *dest = (char *)mstate->dtms_scratch_ptr;
+               int             i;
+
+               /*
+                * Check both the token buffer and (later) the input buffer,
+                * since both could be non-scratch addresses.
+                */
+               if (!dtrace_strcanload(tokaddr, size, mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               if (!DTRACE_INSCRATCH(mstate, size)) {
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+                       regs[rd] = 0;
+                       break;
+               }
+
+               if (addr == (uintptr_t)NULL) {
+                       /*
+                        * If the address specified is NULL, we use our saved
+                        * strtok pointer from the mstate.  Note that this
+                        * means that the saved strtok pointer is _only_
+                        * valid within multiple enablings of the same probe --
+                        * it behaves like an implicit clause-local variable.
+                        */
+                       addr = mstate->dtms_strtok;
+               } else {
+                       /*
+                        * If the user-specified address is non-NULL we must
+                        * access check it.  This is the only time we have
+                        * a chance to do so, since this address may reside
+                        * in the string table of this clause-- future calls
+                        * (when we fetch addr from mstate->dtms_strtok)
+                        * would fail this access check.
+                        */
+                       if (!dtrace_strcanload(addr, size, mstate, vstate)) {
+                               regs[rd] = 0;
+                               break;
+                       }
+               }
+
+               /*
+                * First, zero the token map, and then process the token
+                * string -- setting a bit in the map for every character
+                * found in the token string.
+                */
+               for (i = 0; i < sizeof(tokmap); i++)
+                       tokmap[i] = 0;
+
+               for (; tokaddr < toklimit; tokaddr++) {
+                       if ((c = dtrace_load8(tokaddr)) == '\0')
+                               break;
+
+                       ASSERT((c >> 3) < sizeof(tokmap));
+                       tokmap[c >> 3] |= (1 << (c & 0x7));
+               }
+
+               for (limit = addr + size; addr < limit; addr++) {
+                       /*
+                        * We're looking for a character that is _not_ contained
+                        * in the token string.
+                        */
+                       if ((c = dtrace_load8(addr)) == '\0')
+                               break;
+
+                       if (!(tokmap[c >> 3] & (1 << (c & 0x7))))
+                               break;
+               }
+
+               if (c == '\0') {
+                       /*
+                        * We reached the end of the string without finding
+                        * any character that was not in the token string.
+                        * We return NULL in this case, and we set the saved
+                        * address to NULL as well.
+                        */
+                       regs[rd] = 0;
+                       mstate->dtms_strtok = (uintptr_t)NULL;
+                       break;
+               }
+
+               /*
+                * From here on, we're copying into the destination string.
+                */
+               for (i = 0; addr < limit && i < size - 1; addr++) {
+                       if ((c = dtrace_load8(addr)) == '\0')
+                               break;
+
+                       if (tokmap[c >> 3] & (1 << (c & 0x7)))
+                               break;
+
+                       ASSERT(i < size);
+                       dest[i++] = c;
+               }
+
+               ASSERT(i < size);
+               dest[i] = '\0';
+               regs[rd] = (uintptr_t)dest;
+               mstate->dtms_scratch_ptr += size;
+               mstate->dtms_strtok = addr;
+               break;
+       }
+
+       case DIF_SUBR_SUBSTR: {
+               uintptr_t       s = tupregs[0].dttk_value;
+               uint64_t        size = state->dts_options[DTRACEOPT_STRSIZE];
+               char            *d = (char *)mstate->dtms_scratch_ptr;
+               int64_t         index = (int64_t)tupregs[1].dttk_value;
+               int64_t         remaining = (int64_t)tupregs[2].dttk_value;
+               size_t          len = dtrace_strlen((char *)s, size);
+               int64_t         i = 0;
+
+               if (!dtrace_canload(s, len + 1, mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               if (!DTRACE_INSCRATCH(mstate, size)) {
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+                       regs[rd] = 0;
+                       break;
+               }
+
+               if (nargs <= 2)
+                       remaining = (int64_t)size;
+
+               if (index < 0) {
+                       index += len;
+
+                       if (index < 0 && index + remaining > 0) {
+                               remaining += index;
+                               index = 0;
+                       }
+               }
+
+               if (index >= len || index < 0) {
+                       remaining = 0;
+               } else if (remaining < 0) {
+                       remaining += len - index;
+               } else if (index + remaining > size) {
+                       remaining = size - index;
+               }
+
+               for (i = 0; i < remaining; i++) {
+                       if ((d[i] = dtrace_load8(s + index + i)) == '\0')
+                               break;
+               }
+
+               d[i] = '\0';
+
+               mstate->dtms_scratch_ptr += size;
+               regs[rd] = (uintptr_t)d;
+               break;
+       }
+
+       case DIF_SUBR_GETMAJOR:
+               regs[rd] = MAJOR(tupregs[0].dttk_value);
+               break;
+
+       case DIF_SUBR_GETMINOR:
+               regs[rd] = MINOR(tupregs[0].dttk_value);
+               break;
+
+#if 0 /* FIXME */
+       case DIF_SUBR_DDI_PATHNAME: {
+               /*
+                * This one is a galactic mess.  We are going to roughly
+                * emulate ddi_pathname(), but it's made more complicated
+                * by the fact that we (a) want to include the minor name and
+                * (b) must proceed iteratively instead of recursively.
+                */
+               uintptr_t dest = mstate->dtms_scratch_ptr;
+               uint64_t size = state->dts_options[DTRACEOPT_STRSIZE];
+               char *start = (char *)dest, *end = start + size - 1;
+               uintptr_t daddr = tupregs[0].dttk_value;
+               int64_t minor = (int64_t)tupregs[1].dttk_value;
+               char *s;
+               int i, len, depth = 0;
+
+               /*
+                * Due to all the pointer jumping we do and context we must
+                * rely upon, we just mandate that the user must have kernel
+                * read privileges to use this routine.
+                */
+               if ((mstate->dtms_access & DTRACE_ACCESS_KERNEL) == 0) {
+                       *flags |= CPU_DTRACE_KPRIV;
+                       *illval = daddr;
+                       regs[rd] = 0;
+               }
+
+               if (!DTRACE_INSCRATCH(mstate, size)) {
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+                       regs[rd] = 0;
+                       break;
+               }
+
+               *end = '\0';
+
+               /*
+                * We want to have a name for the minor.  In order to do this,
+                * we need to walk the minor list from the devinfo.  We want
+                * to be sure that we don't infinitely walk a circular list,
+                * so we check for circularity by sending a scout pointer
+                * ahead two elements for every element that we iterate over;
+                * if the list is circular, these will ultimately point to the
+                * same element.  You may recognize this little trick as the
+                * answer to a stupid interview question -- one that always
+                * seems to be asked by those who had to have it laboriously
+                * explained to them, and who can't even concisely describe
+                * the conditions under which one would be forced to resort to
+                * this technique.  Needless to say, those conditions are
+                * found here -- and probably only here.  Is this the only use
+                * of this infamous trick in shipping, production code?  If it
+                * isn't, it probably should be...
+                */
+               if (minor != -1) {
+                       uintptr_t maddr = dtrace_loadptr(daddr +
+                           offsetof(struct dev_info, devi_minor));
+
+                       uintptr_t next = offsetof(struct ddi_minor_data, next);
+                       uintptr_t name = offsetof(struct ddi_minor_data,
+                           d_minor) + offsetof(struct ddi_minor, name);
+                       uintptr_t dev = offsetof(struct ddi_minor_data,
+                           d_minor) + offsetof(struct ddi_minor, dev);
+                       uintptr_t scout;
+
+                       if (maddr != NULL)
+                               scout = dtrace_loadptr(maddr + next);
+
+                       while (maddr != NULL && !(*flags & CPU_DTRACE_FAULT)) {
+                               uint64_t m;
+#ifdef _LP64
+                               m = dtrace_load64(maddr + dev) & MAXMIN64;
+#else
+                               m = dtrace_load32(maddr + dev) & MAXMIN;
+#endif
+                               if (m != minor) {
+                                       maddr = dtrace_loadptr(maddr + next);
+
+                                       if (scout == NULL)
+                                               continue;
+
+                                       scout = dtrace_loadptr(scout + next);
+
+                                       if (scout == NULL)
+                                               continue;
+
+                                       scout = dtrace_loadptr(scout + next);
+
+                                       if (scout == NULL)
+                                               continue;
+
+                                       if (scout == maddr) {
+                                               *flags |= CPU_DTRACE_ILLOP;
+                                               break;
+                                       }
+
+                                       continue;
+                               }
+
+                               /*
+                                * We have the minor data.  Now we need to
+                                * copy the minor's name into the end of the
+                                * pathname.
+                                */
+                               s = (char *)dtrace_loadptr(maddr + name);
+                               len = dtrace_strlen(s, size);
+
+                               if (*flags & CPU_DTRACE_FAULT)
+                                       break;
+
+                               if (len != 0) {
+                                       if ((end -= (len + 1)) < start)
+                                               break;
+
+                                       *end = ':';
+                               }
+
+                               for (i = 1; i <= len; i++)
+                                       end[i] = dtrace_load8((uintptr_t)s++);
+                               break;
+                       }
+               }
+
+               while (daddr != NULL && !(*flags & CPU_DTRACE_FAULT)) {
+                       ddi_node_state_t devi_state;
+
+                       devi_state = dtrace_load32(daddr +
+                           offsetof(struct dev_info, devi_node_state));
+
+                       if (*flags & CPU_DTRACE_FAULT)
+                               break;
+
+                       if (devi_state >= DS_INITIALIZED) {
+                               s = (char *)dtrace_loadptr(daddr +
+                                   offsetof(struct dev_info, devi_addr));
+                               len = dtrace_strlen(s, size);
+
+                               if (*flags & CPU_DTRACE_FAULT)
+                                       break;
+
+                               if (len != 0) {
+                                       if ((end -= (len + 1)) < start)
+                                               break;
+
+                                       *end = '@';
+                               }
+
+                               for (i = 1; i <= len; i++)
+                                       end[i] = dtrace_load8((uintptr_t)s++);
+                       }
+
+                       /*
+                        * Now for the node name...
+                        */
+                       s = (char *)dtrace_loadptr(daddr +
+                           offsetof(struct dev_info, devi_node_name));
+
+                       daddr = dtrace_loadptr(daddr +
+                           offsetof(struct dev_info, devi_parent));
+
+                       /*
+                        * If our parent is NULL (that is, if we're the root
+                        * node), we're going to use the special path
+                        * "devices".
+                        */
+                       if (daddr == NULL)
+                               s = "devices";
+
+                       len = dtrace_strlen(s, size);
+                       if (*flags & CPU_DTRACE_FAULT)
+                               break;
+
+                       if ((end -= (len + 1)) < start)
+                               break;
+
+                       for (i = 1; i <= len; i++)
+                               end[i] = dtrace_load8((uintptr_t)s++);
+                       *end = '/';
+
+                       if (depth++ > dtrace_devdepth_max) {
+                               *flags |= CPU_DTRACE_ILLOP;
+                               break;
+                       }
+               }
+
+               if (end < start)
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+
+               if (daddr == NULL) {
+                       regs[rd] = (uintptr_t)end;
+                       mstate->dtms_scratch_ptr += size;
+               }
+
+               break;
+       }
+#endif
+
+       case DIF_SUBR_STRJOIN: {
+               char            *d = (char *)mstate->dtms_scratch_ptr;
+               uint64_t        size = state->dts_options[DTRACEOPT_STRSIZE];
+               uintptr_t       s1 = tupregs[0].dttk_value;
+               uintptr_t       s2 = tupregs[1].dttk_value;
+               int             i = 0;
+
+               if (!dtrace_strcanload(s1, size, mstate, vstate) ||
+                   !dtrace_strcanload(s2, size, mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               if (!DTRACE_INSCRATCH(mstate, size)) {
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+                       regs[rd] = 0;
+                       break;
+               }
+
+               for (;;) {
+                       if (i >= size) {
+                               DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+                               regs[rd] = 0;
+                               break;
+                       }
+
+                       if ((d[i++] = dtrace_load8(s1++)) == '\0') {
+                               i--;
+                               break;
+                       }
+               }
+
+               for (;;) {
+                       if (i >= size) {
+                               DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+                               regs[rd] = 0;
+                               break;
+                       }
+
+                       if ((d[i++] = dtrace_load8(s2++)) == '\0')
+                               break;
+               }
+
+               if (i < size) {
+                       mstate->dtms_scratch_ptr += i;
+                       regs[rd] = (uintptr_t)d;
+               }
+
+               break;
+       }
+
+       case DIF_SUBR_LLTOSTR: {
+               int64_t         i = (int64_t)tupregs[0].dttk_value;
+               int64_t         val = i < 0 ? i * -1 : i;
+               uint64_t        size = 22;      /* room for 2^64 in dec */
+               char            *end = (char *)mstate->dtms_scratch_ptr + size
+                                                                       - 1;
+
+               if (!DTRACE_INSCRATCH(mstate, size)) {
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+                       regs[rd] = 0;
+                       break;
+               }
+
+               /*
+                * GCC on Linux introduces calls to functions that are not
+                * linked into the kernel image, so we need to use the do_div()
+                * function instead.  It modifies the first argument in place
+                * (replaces it with the quotient), and returns the remainder.
+                *
+                * Was:
+                *      for (*end-- = '\0'; val; val /= 10)
+                *              *end-- = '0' + (val % 10);
+                */
+               for (*end-- = '\0'; val; )
+                       *end-- = '0' + do_div(val, 10);
+
+               if (i == 0)
+                       *end-- = '0';
+
+               if (i < 0)
+                       *end-- = '-';
+
+               regs[rd] = (uintptr_t)end + 1;
+               mstate->dtms_scratch_ptr += size;
+               break;
+       }
+
+       case DIF_SUBR_HTONS:
+       case DIF_SUBR_NTOHS:
+#ifdef _BIG_ENDIAN
+               regs[rd] = (uint16_t)tupregs[0].dttk_value;
+#else
+               regs[rd] = DT_BSWAP_16((uint16_t)tupregs[0].dttk_value);
+#endif
+               break;
+
+
+       case DIF_SUBR_HTONL:
+       case DIF_SUBR_NTOHL:
+#ifdef _BIG_ENDIAN
+               regs[rd] = (uint32_t)tupregs[0].dttk_value;
+#else
+               regs[rd] = DT_BSWAP_32((uint32_t)tupregs[0].dttk_value);
+#endif
+               break;
+
+
+       case DIF_SUBR_HTONLL:
+       case DIF_SUBR_NTOHLL:
+#ifdef _BIG_ENDIAN
+               regs[rd] = (uint64_t)tupregs[0].dttk_value;
+#else
+               regs[rd] = DT_BSWAP_64((uint64_t)tupregs[0].dttk_value);
+#endif
+               break;
+
+
+       case DIF_SUBR_DIRNAME:
+       case DIF_SUBR_BASENAME: {
+               char            *dest = (char *)mstate->dtms_scratch_ptr;
+               uint64_t        size = state->dts_options[DTRACEOPT_STRSIZE];
+               uintptr_t       src = tupregs[0].dttk_value;
+               int             i, j, len = dtrace_strlen((char *)src, size);
+               int             lastbase = -1, firstbase = -1, lastdir = -1;
+               int             start, end;
+
+               if (!dtrace_canload(src, len + 1, mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               if (!DTRACE_INSCRATCH(mstate, size)) {
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+                       regs[rd] = 0;
+                       break;
+               }
+
+               /*
+                * The basename and dirname for a zero-length string is
+                * defined to be "."
+                */
+               if (len == 0) {
+                       len = 1;
+                       src = (uintptr_t)".";
+               }
+
+               /*
+                * Start from the back of the string, moving back toward the
+                * front until we see a character that isn't a slash.  That
+                * character is the last character in the basename.
+                */
+               for (i = len - 1; i >= 0; i--) {
+                       if (dtrace_load8(src + i) != '/')
+                               break;
+               }
+
+               if (i >= 0)
+                       lastbase = i;
+
+               /*
+                * Starting from the last character in the basename, move
+                * towards the front until we find a slash.  The character
+                * that we processed immediately before that is the first
+                * character in the basename.
+                */
+               for (; i >= 0; i--) {
+                       if (dtrace_load8(src + i) == '/')
+                               break;
+               }
+
+               if (i >= 0)
+                       firstbase = i + 1;
+
+               /*
+                * Now keep going until we find a non-slash character.  That
+                * character is the last character in the dirname.
+                */
+               for (; i >= 0; i--) {
+                       if (dtrace_load8(src + i) != '/')
+                               break;
+               }
+
+               if (i >= 0)
+                       lastdir = i;
+
+               ASSERT(!(lastbase == -1 && firstbase != -1));
+               ASSERT(!(firstbase == -1 && lastdir != -1));
+
+               if (lastbase == -1) {
+                       /*
+                        * We didn't find a non-slash character.  We know that
+                        * the length is non-zero, so the whole string must be
+                        * slashes.  In either the dirname or the basename
+                        * case, we return '/'.
+                        */
+                       ASSERT(firstbase == -1);
+                       firstbase = lastbase = lastdir = 0;
+               }
+
+               if (firstbase == -1) {
+                       /*
+                        * The entire string consists only of a basename
+                        * component.  If we're looking for dirname, we need
+                        * to change our string to be just "."; if we're
+                        * looking for a basename, we'll just set the first
+                        * character of the basename to be 0.
+                        */
+                       if (subr == DIF_SUBR_DIRNAME) {
+                               ASSERT(lastdir == -1);
+                               src = (uintptr_t)".";
+                               lastdir = 0;
+                       } else {
+                               firstbase = 0;
+                       }
+               }
+
+               if (subr == DIF_SUBR_DIRNAME) {
+                       if (lastdir == -1) {
+                               /*
+                                * We know that we have a slash in the name --
+                                * or lastdir would be set to 0, above.  And
+                                * because lastdir is -1, we know that this
+                                * slash must be the first character.  (That
+                                * is, the full string must be of the form
+                                * "/basename".)  In this case, the last
+                                * character of the directory name is 0.
+                                */
+                               lastdir = 0;
+                       }
+
+                       start = 0;
+                       end = lastdir;
+               } else {
+                       ASSERT(subr == DIF_SUBR_BASENAME);
+                       ASSERT(firstbase != -1 && lastbase != -1);
+                       start = firstbase;
+                       end = lastbase;
+               }
+
+               for (i = start, j = 0; i <= end && j < size - 1; i++, j++)
+                       dest[j] = dtrace_load8(src + i);
+
+               dest[j] = '\0';
+               regs[rd] = (uintptr_t)dest;
+               mstate->dtms_scratch_ptr += size;
+               break;
+       }
+
+       case DIF_SUBR_CLEANPATH: {
+               char            *dest = (char *)mstate->dtms_scratch_ptr, c;
+               uint64_t        size = state->dts_options[DTRACEOPT_STRSIZE];
+               uintptr_t       src = tupregs[0].dttk_value;
+               int             i = 0, j = 0;
+
+               if (!dtrace_strcanload(src, size, mstate, vstate)) {
+                       regs[rd] = 0;
+                       break;
+               }
+
+               if (!DTRACE_INSCRATCH(mstate, size)) {
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+                       regs[rd] = 0;
+                       break;
+               }
+
+               /*
+                * Move forward, loading each character.
+                */
+               do {
+                       c = dtrace_load8(src + i++);
+next:
+                       if (j + 5 >= size)      /* 5 = strlen("/..c\0") */
+                               break;
+
+                       if (c != '/') {
+                               dest[j++] = c;
+                               continue;
+                       }
+
+                       c = dtrace_load8(src + i++);
+
+                       if (c == '/') {
+                               /*
+                                * We have two slashes -- we can just advance
+                                * to the next character.
+                                */
+                               goto next;
+                       }
+
+                       if (c != '.') {
+                               /*
+                                * This is not "." and it's not ".." -- we can
+                                * just store the "/" and this character and
+                                * drive on.
+                                */
+                               dest[j++] = '/';
+                               dest[j++] = c;
+                               continue;
+                       }
+
+                       c = dtrace_load8(src + i++);
+
+                       if (c == '/') {
+                               /*
+                                * This is a "/./" component.  We're not going
+                                * to store anything in the destination buffer;
+                                * we're just going to go to the next component.
+                                */
+                               goto next;
+                       }
+
+                       if (c != '.') {
+                               /*
+                                * This is not ".." -- we can just store the
+                                * "/." and this character and continue
+                                * processing.
+                                */
+                               dest[j++] = '/';
+                               dest[j++] = '.';
+                               dest[j++] = c;
+                               continue;
+                       }
+
+                       c = dtrace_load8(src + i++);
+
+                       if (c != '/' && c != '\0') {
+                               /*
+                                * This is not ".." -- it's "..[mumble]".
+                                * We'll store the "/.." and this character
+                                * and continue processing.
+                                */
+                               dest[j++] = '/';
+                               dest[j++] = '.';
+                               dest[j++] = '.';
+                               dest[j++] = c;
+                               continue;
+                       }
+
+                       /*
+                        * This is "/../" or "/..\0".  We need to back up
+                        * our destination pointer until we find a "/".
+                        */
+                       i--;
+                       while (j != 0 && dest[--j] != '/')
+                               continue;
+
+                       if (c == '\0')
+                               dest[++j] = '/';
+               } while (c != '\0');
+
+               dest[j] = '\0';
+               regs[rd] = (uintptr_t)dest;
+               mstate->dtms_scratch_ptr += size;
+               break;
+       }
+
+       case DIF_SUBR_INET_NTOA:
+       case DIF_SUBR_INET_NTOA6:
+       case DIF_SUBR_INET_NTOP: {
+               size_t  size;
+               int     af, argi, i;
+               char    *base, *end;
+
+               if (subr == DIF_SUBR_INET_NTOP) {
+                       af = (int)tupregs[0].dttk_value;
+                       argi = 1;
+               } else {
+                       af = subr == DIF_SUBR_INET_NTOA ? AF_INET: AF_INET6;
+                       argi = 0;
+               }
+
+               if (af == AF_INET) {
+                       ipaddr_t        ip4;
+                       uint8_t         *ptr8, val;
+
+                       /*
+                        * Safely load the IPv4 address.
+                        */
+                       ip4 = dtrace_load32(tupregs[argi].dttk_value);
+
+                       /*
+                        * Check an IPv4 string will fit in scratch.
+                        */
+                       size = INET_ADDRSTRLEN;
+                       if (!DTRACE_INSCRATCH(mstate, size)) {
+                               DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+                               regs[rd] = 0;
+                               break;
+                       }
+                       base = (char *)mstate->dtms_scratch_ptr;
+                       end = (char *)mstate->dtms_scratch_ptr + size - 1;
+
+                       /*
+                        * Stringify as a dotted decimal quad.
+                        */
+                       *end-- = '\0';
+                       ptr8 = (uint8_t *)&ip4;
+                       for (i = 3; i >= 0; i--) {
+                               val = ptr8[i];
+
+                               if (val == 0) {
+                                       *end-- = '0';
+                               } else {
+                                       for (; val; val /= 10) {
+                                               *end-- = '0' + (val % 10);
+                                       }
+                               }
+
+                               if (i > 0)
+                                       *end-- = '.';
+                       }
+                       ASSERT(end + 1 >= base);
+#ifdef CONFIG_IPV6
+               } else if (af == AF_INET6) {
+                       struct in6_addr ip6;
+                       int             firstzero, tryzero, numzero, v6end;
+                       uint16_t        val;
+                       const char      digits[] = "0123456789abcdef";
+
+                       /*
+                        * Stringify using RFC 1884 convention 2 - 16 bit
+                        * hexadecimal values with a zero-run compression.
+                        * Lower case hexadecimal digits are used.
+                        *      eg, fe80::214:4fff:fe0b:76c8.
+                        * The IPv4 embedded form is returned for inet_ntop,
+                        * just the IPv4 string is returned for inet_ntoa6.
+                        */
+
+                       /*
+                        * Safely load the IPv6 address.
+                        */
+                       dtrace_bcopy(
+                           (void *)(uintptr_t)tupregs[argi].dttk_value,
+                           (void *)(uintptr_t)&ip6, sizeof(struct in6_addr));
+
+                       /*
+                        * Check an IPv6 string will fit in scratch.
+                        */
+                       size = INET6_ADDRSTRLEN;
+                       if (!DTRACE_INSCRATCH(mstate, size)) {
+                               DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+                               regs[rd] = 0;
+                               break;
+                       }
+                       base = (char *)mstate->dtms_scratch_ptr;
+                       end = (char *)mstate->dtms_scratch_ptr + size - 1;
+                       *end-- = '\0';
+
+                       /*
+                        * Find the longest run of 16 bit zero values
+                        * for the single allowed zero compression - "::".
+                        */
+                       firstzero = -1;
+                       tryzero = -1;
+                       numzero = 1;
+                       for (i = 0; i < sizeof(struct in6_addr); i++) {
+                               if (ip6.s6_addr[i] == 0 &&
+                                   tryzero == -1 && i % 2 == 0) {
+                                       tryzero = i;
+                                       continue;
+                               }
+
+                               if (tryzero != -1 &&
+                                   (ip6.s6_addr[i] != 0 ||
+                                   i == sizeof(struct in6_addr) - 1)) {
+
+                                       if (i - tryzero <= numzero) {
+                                               tryzero = -1;
+                                               continue;
+                                       }
+
+                                       firstzero = tryzero;
+                                       numzero = i - i % 2 - tryzero;
+                                       tryzero = -1;
+
+                                       if (ip6.s6_addr[i] == 0 &&
+                                           i == sizeof(struct in6_addr) - 1)
+                                               numzero += 2;
+                               }
+                       }
+                       ASSERT(firstzero + numzero <= sizeof(struct in6_addr));
+
+                       /*
+                        * Check for an IPv4 embedded address.
+                        */
+                       v6end = sizeof(struct in6_addr) - 2;
+                       if (ipv6_addr_type(&ip6) |
+                           (IPV6_ADDR_COMPATv4 | IPV6_ADDR_MAPPED)) {
+                               for (i = sizeof(struct in6_addr) - 1;
+                                   i >= DTRACE_V4MAPPED_OFFSET; i--) {
+                                       ASSERT(end >= base);
+
+                                       val = ip6.s6_addr[i];
+
+                                       if (val == 0) {
+                                               *end-- = '0';
+                                       } else {
+                                               for (; val; val /= 10) {
+                                                       *end-- = '0' + val % 10;
+                                               }
+                                       }
+
+                                       if (i > DTRACE_V4MAPPED_OFFSET)
+                                               *end-- = '.';
+                               }
+
+                               if (subr == DIF_SUBR_INET_NTOA6)
+                                       goto inetout;
+
+                               /*
+                                * Set v6end to skip the IPv4 address that
+                                * we have already stringified.
+                                */
+                               v6end = 10;
+                       }
+
+                       /*
+                        * Build the IPv6 string by working through the
+                        * address in reverse.
+                        */
+                       for (i = v6end; i >= 0; i -= 2) {
+                               ASSERT(end >= base);
+
+                               if (i == firstzero + numzero - 2) {
+                                       *end-- = ':';
+                                       *end-- = ':';
+                                       i -= numzero - 2;
+                                       continue;
+                               }
+
+                               if (i < 14 && i != firstzero - 2)
+                                       *end-- = ':';
+
+                               val = (ip6.s6_addr[i] << 8) +
+                                   ip6.s6_addr[i + 1];
+
+                               if (val == 0) {
+                                       *end-- = '0';
+                               } else {
+                                       for (; val; val /= 16) {
+                                               *end-- = digits[val % 16];
+                                       }
+                               }
+                       }
+                       ASSERT(end + 1 >= base);
+#endif
+               } else {
+                       /*
+                        * The user didn't use AH_INET or AH_INET6.
+                        */
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
+                       regs[rd] = 0;
+                       break;
+               }
+
+#ifdef CONFIG_IPV6
+inetout:
+#endif
+               regs[rd] = (uintptr_t)end + 1;
+               mstate->dtms_scratch_ptr += size;
+               break;
+       }
+
+       }
+}
+
+/*
+ * Emulate the execution of DTrace IR instructions specified by the given DIF
+ * object.  This function is deliberately void fo assertions as all of the
+ * necessary checks are handled by a call to dtrace_difo_validate().
+ */
+uint64_t dtrace_dif_emulate(dtrace_difo_t *difo, dtrace_mstate_t *mstate,
+                           dtrace_vstate_t *vstate, dtrace_state_t *state)
+{
+       const dif_instr_t       *text = difo->dtdo_buf;
+       const uint_t            textlen = difo->dtdo_len;
+       const char              *strtab = difo->dtdo_strtab;
+       const uint64_t          *inttab = difo->dtdo_inttab;
+
+       int                     cpu = smp_processor_id();
+       uint64_t                rval = 0;
+       dtrace_statvar_t        *svar;
+       dtrace_dstate_t         *dstate = &vstate->dtvs_dynvars;
+       dtrace_difv_t           *v;
+       volatile uint16_t       *flags = &cpu_core[cpu].cpuc_dtrace_flags;
+       volatile uintptr_t      *illval = &cpu_core[cpu].cpuc_dtrace_illval;
+
+       dtrace_key_t            tupregs[DIF_DTR_NREGS + 2];
+                                               /* +2 for thread and id */
+       uint64_t                regs[DIF_DIR_NREGS];
+       uint64_t                *tmp;
+
+       uint8_t                 cc_n = 0, cc_z = 0, cc_v = 0, cc_c = 0;
+       int64_t                 cc_r;
+       uint_t                  pc = 0, id, opc = 0;
+       uint8_t                 ttop = 0;
+       dif_instr_t             instr;
+       uint_t                  r1, r2, rd;
+
+       /*
+        * We stash the current DIF object into the machine state: we need it
+        * for subsequent access checking.
+        */
+       mstate->dtms_difo = difo;
+
+       regs[DIF_REG_R0] = 0;                   /* %r0 is fixed at zero */
+
+       while (pc < textlen && !(*flags & CPU_DTRACE_FAULT)) {
+               opc = pc;
+
+               instr = text[pc++];
+               r1 = DIF_INSTR_R1(instr);
+               r2 = DIF_INSTR_R2(instr);
+               rd = DIF_INSTR_RD(instr);
+
+               switch (DIF_INSTR_OP(instr)) {
+               case DIF_OP_OR:
+                       regs[rd] = regs[r1] | regs[r2];
+                       break;
+               case DIF_OP_XOR:
+                       regs[rd] = regs[r1] ^ regs[r2];
+                       break;
+               case DIF_OP_AND:
+                       regs[rd] = regs[r1] & regs[r2];
+                       break;
+               case DIF_OP_SLL:
+                       regs[rd] = regs[r1] << regs[r2];
+                       break;
+               case DIF_OP_SRL:
+                       regs[rd] = regs[r1] >> regs[r2];
+                       break;
+               case DIF_OP_SUB:
+                       regs[rd] = regs[r1] - regs[r2];
+                       break;
+               case DIF_OP_ADD:
+                       regs[rd] = regs[r1] + regs[r2];
+                       break;
+               case DIF_OP_MUL:
+                       regs[rd] = regs[r1] * regs[r2];
+                       break;
+               case DIF_OP_SDIV:
+                       if (regs[r2] == 0) {
+                               regs[rd] = 0;
+                               *flags |= CPU_DTRACE_DIVZERO;
+                       } else {
+                               /*
+                                * We cannot simply do a 64-bit division, since
+                                * gcc translates it into a call to a function
+                                * that is not linked into the kernel.
+                                *
+                                * regs[rd] = (int64_t)regs[r1] /
+                                *            (int64_t)regs[r2];
+                                */
+                               regs[rd] = (int64_t)regs[r1];
+                               do_div(regs[rd], (int64_t)regs[r2]);
+                       }
+                       break;
+
+               case DIF_OP_UDIV:
+                       if (regs[r2] == 0) {
+                               regs[rd] = 0;
+                               *flags |= CPU_DTRACE_DIVZERO;
+                       } else {
+                               /*
+                                * We cannot simply do a 64-bit division, since
+                                * gcc translates it into a call to a function
+                                * that is not linked into the kernel.
+                                *
+                                * regs[rd] = regs[r1] / regs[r2];
+                                */
+                               regs[rd] = regs[r1];
+                               do_div(regs[rd], regs[r2]);
+                       }
+                       break;
+
+               case DIF_OP_SREM:
+                       if (regs[r2] == 0) {
+                               regs[rd] = 0;
+                               *flags |= CPU_DTRACE_DIVZERO;
+                       } else {
+                               /*
+                                * We cannot simply do a 64-bit division, since
+                                * gcc translates it into a call to a function
+                                * that is not linked into the kernel.
+                                *
+                                * regs[rd] = (int64_t)regs[r1] %
+                                *            (int64_t)regs[r2];
+                                */
+                               regs[rd] = (int64_t)regs[r1];
+                               regs[rd] = do_div(regs[rd], (int64_t)regs[r2]);
+                       }
+                       break;
+
+               case DIF_OP_UREM:
+                       if (regs[r2] == 0) {
+                               regs[rd] = 0;
+                               *flags |= CPU_DTRACE_DIVZERO;
+                       } else {
+                               /*
+                                * We cannot simply do a 64-bit division, since
+                                * gcc translates it into a call to a function
+                                * that is not linked into the kernel.
+                                *
+                                * regs[rd] = regs[r1] % regs[r2];
+                                */
+                               regs[rd] = regs[r1];
+                               regs[rd] = do_div(regs[rd], regs[r2]);
+                       }
+                       break;
+
+               case DIF_OP_NOT:
+                       regs[rd] = ~regs[r1];
+                       break;
+               case DIF_OP_MOV:
+                       regs[rd] = regs[r1];
+                       break;
+               case DIF_OP_CMP:
+                       cc_r = regs[r1] - regs[r2];
+                       cc_n = cc_r < 0;
+                       cc_z = cc_r == 0;
+                       cc_v = 0;
+                       cc_c = regs[r1] < regs[r2];
+                       break;
+               case DIF_OP_TST:
+                       cc_n = cc_v = cc_c = 0;
+                       cc_z = regs[r1] == 0;
+                       break;
+               case DIF_OP_BA:
+                       pc = DIF_INSTR_LABEL(instr);
+                       break;
+               case DIF_OP_BE:
+                       if (cc_z)
+                               pc = DIF_INSTR_LABEL(instr);
+                       break;
+               case DIF_OP_BNE:
+                       if (cc_z == 0)
+                               pc = DIF_INSTR_LABEL(instr);
+                       break;
+               case DIF_OP_BG:
+                       if ((cc_z | (cc_n ^ cc_v)) == 0)
+                               pc = DIF_INSTR_LABEL(instr);
+                       break;
+               case DIF_OP_BGU:
+                       if ((cc_c | cc_z) == 0)
+                               pc = DIF_INSTR_LABEL(instr);
+                       break;
+               case DIF_OP_BGE:
+                       if ((cc_n ^ cc_v) == 0)
+                               pc = DIF_INSTR_LABEL(instr);
+                       break;
+               case DIF_OP_BGEU:
+                       if (cc_c == 0)
+                               pc = DIF_INSTR_LABEL(instr);
+                       break;
+               case DIF_OP_BL:
+                       if (cc_n ^ cc_v)
+                               pc = DIF_INSTR_LABEL(instr);
+                       break;
+               case DIF_OP_BLU:
+                       if (cc_c)
+                               pc = DIF_INSTR_LABEL(instr);
+                       break;
+               case DIF_OP_BLE:
+                       if (cc_z | (cc_n ^ cc_v))
+                               pc = DIF_INSTR_LABEL(instr);
+                       break;
+               case DIF_OP_BLEU:
+                       if (cc_c | cc_z)
+                               pc = DIF_INSTR_LABEL(instr);
+                       break;
+               case DIF_OP_RLDSB:
+#ifdef FIXME_OPENSOLARIS_BUG
+                       if (!dtrace_canstore(regs[r1], 1, mstate, vstate)) {
+#else
+                       if (!dtrace_canload(regs[r1], 1, mstate, vstate)) {
+#endif
+                               *flags |= CPU_DTRACE_KPRIV;
+                               *illval = regs[r1];
+                               break;
+                       }
+                       /*FALLTHROUGH*/
+               case DIF_OP_LDSB:
+                       regs[rd] = (int8_t)dtrace_load8(regs[r1]);
+                       break;
+               case DIF_OP_RLDSH:
+                       if (!dtrace_canstore(regs[r1], 2, mstate, vstate)) {
+                               *flags |= CPU_DTRACE_KPRIV;
+                               *illval = regs[r1];
+                               break;
+                       }
+                       /*FALLTHROUGH*/
+               case DIF_OP_LDSH:
+                       regs[rd] = (int16_t)dtrace_load16(regs[r1]);
+                       break;
+               case DIF_OP_RLDSW:
+                       if (!dtrace_canstore(regs[r1], 4, mstate, vstate)) {
+                               *flags |= CPU_DTRACE_KPRIV;
+                               *illval = regs[r1];
+                               break;
+                       }
+                       /*FALLTHROUGH*/
+               case DIF_OP_LDSW:
+                       regs[rd] = (int32_t)dtrace_load32(regs[r1]);
+                       break;
+               case DIF_OP_RLDUB:
+                       if (!dtrace_canstore(regs[r1], 1, mstate, vstate)) {
+                               *flags |= CPU_DTRACE_KPRIV;
+                               *illval = regs[r1];
+                               break;
+                       }
+                       /*FALLTHROUGH*/
+               case DIF_OP_LDUB:
+                       regs[rd] = dtrace_load8(regs[r1]);
+                       break;
+               case DIF_OP_RLDUH:
+                       if (!dtrace_canstore(regs[r1], 2, mstate, vstate)) {
+                               *flags |= CPU_DTRACE_KPRIV;
+                               *illval = regs[r1];
+                               break;
+                       }
+                       /*FALLTHROUGH*/
+               case DIF_OP_LDUH:
+                       regs[rd] = dtrace_load16(regs[r1]);
+                       break;
+               case DIF_OP_RLDUW:
+                       if (!dtrace_canstore(regs[r1], 4, mstate, vstate)) {
+                               *flags |= CPU_DTRACE_KPRIV;
+                               *illval = regs[r1];
+                               break;
+                       }
+                       /*FALLTHROUGH*/
+               case DIF_OP_LDUW:
+                       regs[rd] = dtrace_load32(regs[r1]);
+                       break;
+               case DIF_OP_RLDX:
+                       if (!dtrace_canstore(regs[r1], 8, mstate, vstate)) {
+                               *flags |= CPU_DTRACE_KPRIV;
+                               *illval = regs[r1];
+                               break;
+                       }
+                       /*FALLTHROUGH*/
+               case DIF_OP_LDX:
+                       regs[rd] = dtrace_load64(regs[r1]);
+                       break;
+               case DIF_OP_ULDSB:
+                       regs[rd] = (int8_t)dtrace_fuword8(
+                                               (void *)(uintptr_t)regs[r1]);
+                       break;
+               case DIF_OP_ULDSH:
+                       regs[rd] = (int16_t)dtrace_fuword16(
+                                               (void *)(uintptr_t)regs[r1]);
+                       break;
+               case DIF_OP_ULDSW:
+                       regs[rd] = (int32_t)dtrace_fuword32(
+                                               (void *)(uintptr_t)regs[r1]);
+                       break;
+               case DIF_OP_ULDUB:
+                       regs[rd] = dtrace_fuword8((void *)(uintptr_t)regs[r1]);
+                       break;
+               case DIF_OP_ULDUH:
+                       regs[rd] = dtrace_fuword16(
+                                               (void *)(uintptr_t)regs[r1]);
+                       break;
+               case DIF_OP_ULDUW:
+                       regs[rd] = dtrace_fuword32(
+                                               (void *)(uintptr_t)regs[r1]);
+                       break;
+               case DIF_OP_ULDX:
+                       regs[rd] = dtrace_fuword64(
+                                               (void *)(uintptr_t)regs[r1]);
+                       break;
+               case DIF_OP_RET:
+                       rval = regs[rd];
+                       pc = textlen;
+                       break;
+               case DIF_OP_NOP:
+                       break;
+               case DIF_OP_SETX:
+                       regs[rd] = inttab[DIF_INSTR_INTEGER(instr)];
+                       break;
+               case DIF_OP_SETS:
+                       regs[rd] = (uint64_t)(uintptr_t)
+                                       (strtab + DIF_INSTR_STRING(instr));
+                       break;
+               case DIF_OP_SCMP: {
+                       size_t          sz = state->dts_options[
+                                                       DTRACEOPT_STRSIZE];
+                       uintptr_t       s1 = regs[r1];
+                       uintptr_t       s2 = regs[r2];
+
+                       if (s1 != (uintptr_t)NULL &&
+                           !dtrace_strcanload(s1, sz, mstate, vstate))
+                               break;
+                       if (s2 != (uintptr_t)NULL &&
+                           !dtrace_strcanload(s2, sz, mstate, vstate))
+                               break;
+
+                       cc_r = dtrace_strncmp((char *)s1, (char *)s2, sz);
+
+                       cc_n = cc_r < 0;
+                       cc_z = cc_r == 0;
+                       cc_v = cc_c = 0;
+                       break;
+               }
+               case DIF_OP_LDGA:
+                   regs[rd] = dtrace_dif_variable(mstate, state, r1,
+                                                  regs[r2]);
+                       break;
+               case DIF_OP_LDGS:
+                       id = DIF_INSTR_VAR(instr);
+
+                       if (id >= DIF_VAR_OTHER_UBASE) {
+                               uintptr_t       a;
+
+                               id -= DIF_VAR_OTHER_UBASE;
+                               svar = vstate->dtvs_globals[id];
+                               ASSERT(svar != NULL);
+                               v = &svar->dtsv_var;
+
+                               if (!(v->dtdv_type.dtdt_flags & DIF_TF_BYREF)) {
+                                       regs[rd] = svar->dtsv_data;
+                                       break;
+                               }
+
+                               a = (uintptr_t)svar->dtsv_data;
+
+                               /*
+                                * If the 0th byte is set to UINT8_MAX then
+                                * this is to be treated as a reference to a
+                                * NULL variable.
+                                */
+                               if (*(uint8_t *)a == UINT8_MAX)
+                                       regs[rd] = 0;
+                               else
+                                       regs[rd] = a + sizeof(uint64_t);
+
+                               break;
+                       }
+
+                       regs[rd] = dtrace_dif_variable(mstate, state, id, 0);
+                       break;
+
+               case DIF_OP_STGS:
+                       id = DIF_INSTR_VAR(instr);
+
+                       ASSERT(id >= DIF_VAR_OTHER_UBASE);
+                       id -= DIF_VAR_OTHER_UBASE;
+
+                       svar = vstate->dtvs_globals[id];
+                       ASSERT(svar != NULL);
+                       v = &svar->dtsv_var;
+
+                       if (v->dtdv_type.dtdt_flags & DIF_TF_BYREF) {
+                               uintptr_t       a = (uintptr_t)svar->dtsv_data;
+
+                               ASSERT(a != 0);
+                               ASSERT(svar->dtsv_size != 0);
+
+                               if (regs[rd] == 0) {
+                                       *(uint8_t *)a = UINT8_MAX;
+                                       break;
+                               } else {
+                                       *(uint8_t *)a = 0;
+                                       a += sizeof(uint64_t);
+                               }
+
+                               if (!dtrace_vcanload(
+                                       (void *)(uintptr_t)regs[rd],
+                                       &v->dtdv_type, mstate, vstate))
+                                       break;
+
+                               dtrace_vcopy((void *)(uintptr_t)regs[rd],
+                                            (void *)a, &v->dtdv_type);
+                               break;
+                       }
+
+                       svar->dtsv_data = regs[rd];
+                       break;
+
+               case DIF_OP_LDTA:
+                       /*
+                        * There are no DTrace built-in thread-local arrays at
+                        * present.  This opcode is saved for future work.
+                        */
+                       *flags |= CPU_DTRACE_ILLOP;
+                       regs[rd] = 0;
+                       break;
+
+               case DIF_OP_LDLS:
+                       id = DIF_INSTR_VAR(instr);
+
+                       if (id < DIF_VAR_OTHER_UBASE) {
+                               /*
+                                * For now, this has no meaning.
+                                */
+                               regs[rd] = 0;
+                               break;
+                       }
+
+                       id -= DIF_VAR_OTHER_UBASE;
+
+                       ASSERT(id < vstate->dtvs_nlocals);
+                       ASSERT(vstate->dtvs_locals != NULL);
+
+                       svar = vstate->dtvs_locals[id];
+                       ASSERT(svar != NULL);
+                       v = &svar->dtsv_var;
+
+                       if (v->dtdv_type.dtdt_flags & DIF_TF_BYREF) {
+                               uintptr_t       a = (uintptr_t)svar->dtsv_data;
+                               size_t          sz = v->dtdv_type.dtdt_size;
+
+                               sz += sizeof(uint64_t);
+                               ASSERT(svar->dtsv_size == NR_CPUS * sz);
+                               a += smp_processor_id() * sz;
+
+                               if (*(uint8_t *)a == UINT8_MAX) {
+                                       /*
+                                        * If the 0th byte is set to UINT8_MAX
+                                        * then this is to be treated as a
+                                        * reference to a NULL variable.
+                                        */
+                                       regs[rd] = 0;
+                               } else
+                                       regs[rd] = a + sizeof(uint64_t);
+
+                               break;
+                       }
+
+                       ASSERT(svar->dtsv_size == NR_CPUS * sizeof(uint64_t));
+                       tmp = (uint64_t *)(uintptr_t)svar->dtsv_data;
+                       regs[rd] = tmp[smp_processor_id()];
+                       break;
+
+               case DIF_OP_STLS:
+                       id = DIF_INSTR_VAR(instr);
+
+                       ASSERT(id >= DIF_VAR_OTHER_UBASE);
+                       id -= DIF_VAR_OTHER_UBASE;
+                       ASSERT(id < vstate->dtvs_nlocals);
+
+                       ASSERT(vstate->dtvs_locals != NULL);
+                       svar = vstate->dtvs_locals[id];
+                       ASSERT(svar != NULL);
+                       v = &svar->dtsv_var;
+
+                       if (v->dtdv_type.dtdt_flags & DIF_TF_BYREF) {
+                               uintptr_t       a = (uintptr_t)svar->dtsv_data;
+                               size_t          sz = v->dtdv_type.dtdt_size;
+
+                               sz += sizeof(uint64_t);
+                               ASSERT(svar->dtsv_size == NR_CPUS * sz);
+                               a += smp_processor_id() * sz;
+
+                               if (regs[rd] == 0) {
+                                       *(uint8_t *)a = UINT8_MAX;
+                                       break;
+                               } else {
+                                       *(uint8_t *)a = 0;
+                                       a += sizeof(uint64_t);
+                               }
+
+                               if (!dtrace_vcanload(
+                                               (void *)(uintptr_t)regs[rd],
+                                               &v->dtdv_type, mstate, vstate))
+                                       break;
+
+                               dtrace_vcopy((void *)(uintptr_t)regs[rd],
+                                            (void *)a, &v->dtdv_type);
+                               break;
+                       }
+
+                       ASSERT(svar->dtsv_size == NR_CPUS * sizeof(uint64_t));
+                       tmp = (uint64_t *)(uintptr_t)svar->dtsv_data;
+                       tmp[smp_processor_id()] = regs[rd];
+                       break;
+
+               case DIF_OP_LDTS: {
+                       dtrace_dynvar_t *dvar;
+                       dtrace_key_t    *key;
+
+                       id = DIF_INSTR_VAR(instr);
+                       ASSERT(id >= DIF_VAR_OTHER_UBASE);
+                       id -= DIF_VAR_OTHER_UBASE;
+                       v = &vstate->dtvs_tlocals[id];
+
+                       key = &tupregs[DIF_DTR_NREGS];
+                       key[0].dttk_value = (uint64_t)id;
+                       key[0].dttk_size = 0;
+                       DTRACE_TLS_THRKEY(key[1].dttk_value);
+                       key[1].dttk_size = 0;
+
+                       dvar = dtrace_dynvar(dstate, 2, key, sizeof(uint64_t),
+                                            DTRACE_DYNVAR_NOALLOC, mstate,
+                                            vstate);
+
+                       if (dvar == NULL) {
+                               regs[rd] = 0;
+                               break;
+                       }
+
+                       if (v->dtdv_type.dtdt_flags & DIF_TF_BYREF)
+                               regs[rd] = (uint64_t)(uintptr_t)dvar->dtdv_data;
+                       else
+                               regs[rd] = *((uint64_t *)dvar->dtdv_data);
+
+                       break;
+               }
+
+               case DIF_OP_STTS: {
+                       dtrace_dynvar_t *dvar;
+                       dtrace_key_t    *key;
+
+                       id = DIF_INSTR_VAR(instr);
+                       ASSERT(id >= DIF_VAR_OTHER_UBASE);
+                       id -= DIF_VAR_OTHER_UBASE;
+
+                       key = &tupregs[DIF_DTR_NREGS];
+                       key[0].dttk_value = (uint64_t)id;
+                       key[0].dttk_size = 0;
+                       DTRACE_TLS_THRKEY(key[1].dttk_value);
+                       key[1].dttk_size = 0;
+                       v = &vstate->dtvs_tlocals[id];
+
+                       dvar = dtrace_dynvar(dstate, 2, key,
+                               v->dtdv_type.dtdt_size > sizeof(uint64_t)
+                                       ?  v->dtdv_type.dtdt_size
+                                       : sizeof(uint64_t),
+                               regs[rd]
+                                       ? DTRACE_DYNVAR_ALLOC
+                                       : DTRACE_DYNVAR_DEALLOC,
+                               mstate, vstate);
+
+                       /*
+                        * Given that we're storing to thread-local data,
+                        * we need to flush our predicate cache.
+                        */
+                       current->predcache = 0;
+
+                       if (dvar == NULL)
+                               break;
+
+                       if (v->dtdv_type.dtdt_flags & DIF_TF_BYREF) {
+                               if (!dtrace_vcanload(
+                                               (void *)(uintptr_t)regs[rd],
+                                               &v->dtdv_type, mstate, vstate))
+                                       break;
+
+                               dtrace_vcopy((void *)(uintptr_t)regs[rd],
+                                            dvar->dtdv_data, &v->dtdv_type);
+                       } else
+                               *((uint64_t *)dvar->dtdv_data) = regs[rd];
+
+                       break;
+               }
+
+               case DIF_OP_SRA:
+                       regs[rd] = (int64_t)regs[r1] >> regs[r2];
+                       break;
+
+               case DIF_OP_CALL:
+                       dtrace_dif_subr(DIF_INSTR_SUBR(instr), rd, regs,
+                                       tupregs, ttop, mstate, state);
+                       break;
+
+               case DIF_OP_PUSHTR:
+                       if (ttop == DIF_DTR_NREGS) {
+                               *flags |= CPU_DTRACE_TUPOFLOW;
+                               break;
+                       }
+
+                       if (r1 == DIF_TYPE_STRING)
+                               /*
+                                * If this is a string type and the size is 0,
+                                * we'll use the system-wide default string
+                                * size.  Note that we are _not_ looking at
+                                * the value of the DTRACEOPT_STRSIZE option;
+                                * had this been set, we would expect to have
+                                * a non-zero size value in the "pushtr".
+                                */
+                               tupregs[ttop].dttk_size =
+                                       dtrace_strlen(
+                                               (char *)(uintptr_t)regs[rd],
+                                               regs[r2]
+                                                   ? regs[r2]
+                                                   : dtrace_strsize_default
+                                       ) + 1;
+                       else
+                               tupregs[ttop].dttk_size = regs[r2];
+
+                       tupregs[ttop++].dttk_value = regs[rd];
+                       break;
+
+               case DIF_OP_PUSHTV:
+                       if (ttop == DIF_DTR_NREGS) {
+                               *flags |= CPU_DTRACE_TUPOFLOW;
+                               break;
+                       }
+
+                       tupregs[ttop].dttk_value = regs[rd];
+                       tupregs[ttop++].dttk_size = 0;
+                       break;
+
+               case DIF_OP_POPTS:
+                       if (ttop != 0)
+                               ttop--;
+                       break;
+
+               case DIF_OP_FLUSHTS:
+                       ttop = 0;
+                       break;
+
+               case DIF_OP_LDGAA:
+               case DIF_OP_LDTAA: {
+                       dtrace_dynvar_t *dvar;
+                       dtrace_key_t    *key = tupregs;
+                       uint_t          nkeys = ttop;
+
+                       id = DIF_INSTR_VAR(instr);
+                       ASSERT(id >= DIF_VAR_OTHER_UBASE);
+                       id -= DIF_VAR_OTHER_UBASE;
+
+                       key[nkeys].dttk_value = (uint64_t)id;
+                       key[nkeys++].dttk_size = 0;
+
+                       if (DIF_INSTR_OP(instr) == DIF_OP_LDTAA) {
+                               DTRACE_TLS_THRKEY(key[nkeys].dttk_value);
+                               key[nkeys++].dttk_size = 0;
+                               v = &vstate->dtvs_tlocals[id];
+                       } else
+                               v = &vstate->dtvs_globals[id]->dtsv_var;
+
+                       dvar = dtrace_dynvar(dstate, nkeys, key,
+                       v->dtdv_type.dtdt_size > sizeof(uint64_t) ?
+                       v->dtdv_type.dtdt_size : sizeof(uint64_t),
+                       DTRACE_DYNVAR_NOALLOC, mstate, vstate);
+
+                       if (dvar == NULL) {
+                               regs[rd] = 0;
+                               break;
+                       }
+
+                       if (v->dtdv_type.dtdt_flags & DIF_TF_BYREF)
+                               regs[rd] = (uint64_t)(uintptr_t)dvar->dtdv_data;
+                       else
+                               regs[rd] = *((uint64_t *)dvar->dtdv_data);
+
+                       break;
+               }
+
+               case DIF_OP_STGAA:
+               case DIF_OP_STTAA: {
+                       dtrace_dynvar_t *dvar;
+                       dtrace_key_t    *key = tupregs;
+                       uint_t          nkeys = ttop;
+
+                       id = DIF_INSTR_VAR(instr);
+                       ASSERT(id >= DIF_VAR_OTHER_UBASE);
+                       id -= DIF_VAR_OTHER_UBASE;
+
+                       key[nkeys].dttk_value = (uint64_t)id;
+                       key[nkeys++].dttk_size = 0;
+
+                       if (DIF_INSTR_OP(instr) == DIF_OP_STTAA) {
+                               DTRACE_TLS_THRKEY(key[nkeys].dttk_value);
+                               key[nkeys++].dttk_size = 0;
+                               v = &vstate->dtvs_tlocals[id];
+                       } else
+                               v = &vstate->dtvs_globals[id]->dtsv_var;
+
+                       dvar = dtrace_dynvar(dstate, nkeys, key,
+                               v->dtdv_type.dtdt_size > sizeof(uint64_t)
+                                       ?  v->dtdv_type.dtdt_size
+                                       : sizeof(uint64_t),
+                               regs[rd] ? DTRACE_DYNVAR_ALLOC
+                                        : DTRACE_DYNVAR_DEALLOC,
+                               mstate, vstate);
+
+                       if (dvar == NULL)
+                               break;
+
+                       if (v->dtdv_type.dtdt_flags & DIF_TF_BYREF) {
+                               if (!dtrace_vcanload(
+                                               (void *)(uintptr_t)regs[rd],
+                                               &v->dtdv_type, mstate, vstate))
+                                       break;
+
+                               dtrace_vcopy((void *)(uintptr_t)regs[rd],
+                                            dvar->dtdv_data, &v->dtdv_type);
+                       } else
+                               *((uint64_t *)dvar->dtdv_data) = regs[rd];
+
+                       break;
+               }
+
+               case DIF_OP_ALLOCS: {
+                       uintptr_t       ptr =
+                                       P2ROUNDUP(mstate->dtms_scratch_ptr, 8);
+                       size_t          size = ptr - mstate->dtms_scratch_ptr +
+                                              regs[r1];
+
+                       /*
+                        * Rounding up the user allocation size could have
+                        * overflowed large, bogus allocations (like -1ULL) to
+                        * 0.
+                        */
+                       if (size < regs[r1] ||
+                           !DTRACE_INSCRATCH(mstate, size)) {
+                               DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+                               regs[rd] = 0;
+                               break;
+                       }
+
+                       dtrace_bzero((void *) mstate->dtms_scratch_ptr, size);
+                       mstate->dtms_scratch_ptr += size;
+                       regs[rd] = ptr;
+                       break;
+               }
+
+               case DIF_OP_COPYS:
+                       if (!dtrace_canstore(regs[rd], regs[r2], mstate,
+                                            vstate)) {
+                               *flags |= CPU_DTRACE_BADADDR;
+                               *illval = regs[rd];
+                               break;
+                       }
+
+                       if (!dtrace_canload(regs[r1], regs[r2], mstate, vstate))
+                               break;
+
+                       dtrace_bcopy((void *)(uintptr_t)regs[r1],
+                                    (void *)(uintptr_t)regs[rd],
+                                    (size_t)regs[r2]);
+                       break;
+
+               case DIF_OP_STB:
+                       if (!dtrace_canstore(regs[rd], 1, mstate, vstate)) {
+                               *flags |= CPU_DTRACE_BADADDR;
+                               *illval = regs[rd];
+                               break;
+                       }
+
+                       *((uint8_t *)(uintptr_t)regs[rd]) = (uint8_t)regs[r1];
+                       break;
+
+               case DIF_OP_STH:
+                       if (!dtrace_canstore(regs[rd], 2, mstate, vstate)) {
+                               *flags |= CPU_DTRACE_BADADDR;
+                               *illval = regs[rd];
+                               break;
+                       }
+
+                       if (regs[rd] & 1) {
+                               *flags |= CPU_DTRACE_BADALIGN;
+                               *illval = regs[rd];
+                               break;
+                       }
+
+                       *((uint16_t *)(uintptr_t)regs[rd]) = (uint16_t)regs[r1];
+                       break;
+
+               case DIF_OP_STW:
+                       if (!dtrace_canstore(regs[rd], 4, mstate, vstate)) {
+                               *flags |= CPU_DTRACE_BADADDR;
+                               *illval = regs[rd];
+                               break;
+                       }
+
+                       if (regs[rd] & 3) {
+                               *flags |= CPU_DTRACE_BADALIGN;
+                               *illval = regs[rd];
+                               break;
+                       }
+
+                       *((uint32_t *)(uintptr_t)regs[rd]) = (uint32_t)regs[r1];
+                       break;
+
+               case DIF_OP_STX:
+                       if (!dtrace_canstore(regs[rd], 8, mstate, vstate)) {
+                               *flags |= CPU_DTRACE_BADADDR;
+                               *illval = regs[rd];
+                               break;
+                       }
+
+                       if (regs[rd] & 7) {
+                               *flags |= CPU_DTRACE_BADALIGN;
+                               *illval = regs[rd];
+                               break;
+                       }
+
+                       *((uint64_t *)(uintptr_t)regs[rd]) = regs[r1];
+                       break;
+               }
+       }
+
+       if (!(*flags & CPU_DTRACE_FAULT))
+               return rval;
+
+       mstate->dtms_fltoffs = opc * sizeof(dif_instr_t);
+       mstate->dtms_present |= DTRACE_MSTATE_FLTOFFS;
+
+       return 0;
+}
diff --git a/dtrace/dtrace_dof.c b/dtrace/dtrace_dof.c
new file mode 100644 (file)
index 0000000..805b2dc
--- /dev/null
@@ -0,0 +1,1053 @@
+/*
+ * FILE:       dtrace_dof.c
+ * DESCRIPTION:        Dynamic Tracing: DOF object functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/slab.h>
+#include <linux/types.h>
+#include <asm/uaccess.h>
+
+#include "dtrace.h"
+
+size_t         dtrace_difo_maxsize = 256 * 1024;
+dtrace_optval_t        dtrace_dof_maxsize = 256 * 1024;
+size_t         dtrace_actions_max = 16 * 1024;
+
+static void dtrace_dof_error(dof_hdr_t *dof, const char *str)
+{
+       if (dtrace_err_verbose)
+               pr_warning("failed to process DOF: %s", str);
+
+#ifdef DTRACE_ERRDEBUG
+       dtrace_errdebug(str);
+#endif
+}
+
+/*
+ * Create DOF out of a currently enabled state.  Right now, we only create
+ * DOF containing the run-time options -- but this could be expanded to create
+ * complete DOF representing the enabled state.
+ */
+dof_hdr_t *dtrace_dof_create(dtrace_state_t *state)
+{
+       dof_hdr_t       *dof;
+       dof_sec_t       *sec;
+       dof_optdesc_t   *opt;
+       int             i, len = sizeof(dof_hdr_t) +
+                                roundup(sizeof(dof_sec_t), sizeof(uint64_t)) +
+                                sizeof(dof_optdesc_t) * DTRACEOPT_MAX;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+
+       dof = kmalloc(len, GFP_KERNEL);
+       dof->dofh_ident[DOF_ID_MAG0] = DOF_MAG_MAG0;
+       dof->dofh_ident[DOF_ID_MAG1] = DOF_MAG_MAG1;
+       dof->dofh_ident[DOF_ID_MAG2] = DOF_MAG_MAG2;
+       dof->dofh_ident[DOF_ID_MAG3] = DOF_MAG_MAG3;
+
+       dof->dofh_ident[DOF_ID_MODEL] = DOF_MODEL_NATIVE;
+       dof->dofh_ident[DOF_ID_ENCODING] = DOF_ENCODE_NATIVE;
+       dof->dofh_ident[DOF_ID_VERSION] = DOF_VERSION;
+       dof->dofh_ident[DOF_ID_DIFVERS] = DIF_VERSION;
+       dof->dofh_ident[DOF_ID_DIFIREG] = DIF_DIR_NREGS;
+       dof->dofh_ident[DOF_ID_DIFTREG] = DIF_DTR_NREGS;
+
+       dof->dofh_flags = 0;
+       dof->dofh_hdrsize = sizeof(dof_hdr_t);
+       dof->dofh_secsize = sizeof(dof_sec_t);
+       dof->dofh_secnum = 1;   /* only DOF_SECT_OPTDESC */
+       dof->dofh_secoff = sizeof(dof_hdr_t);
+       dof->dofh_loadsz = len;
+       dof->dofh_filesz = len;
+       dof->dofh_pad = 0;
+
+       /*
+        * Fill in the option section header...
+        */
+       sec = (dof_sec_t *)((uintptr_t)dof + sizeof(dof_hdr_t));
+       sec->dofs_type = DOF_SECT_OPTDESC;
+       sec->dofs_align = sizeof(uint64_t);
+       sec->dofs_flags = DOF_SECF_LOAD;
+       sec->dofs_entsize = sizeof(dof_optdesc_t);
+
+       opt = (dof_optdesc_t *)((uintptr_t)sec +
+                               roundup(sizeof(dof_sec_t), sizeof(uint64_t)));
+
+       sec->dofs_offset = (uintptr_t)opt - (uintptr_t)dof;
+       sec->dofs_size = sizeof(dof_optdesc_t) * DTRACEOPT_MAX;
+
+       for (i = 0; i < DTRACEOPT_MAX; i++) {
+               opt[i].dofo_option = i;
+               opt[i].dofo_strtab = DOF_SECIDX_NONE;
+               opt[i].dofo_value = state->dts_options[i];
+       }
+
+       return dof;
+}
+
+dof_hdr_t *dtrace_dof_copyin(void __user *argp, int *errp)
+{
+       dof_hdr_t       hdr, *dof;
+
+#ifdef FIXME
+       /* This seems to be unnecessary and actually wrong). */
+       ASSERT(!mutex_is_locked(&dtrace_lock));
+#endif
+
+       /*
+        * First, we're going to copyin() the sizeof(dof_hdr_t).
+        */
+       if (copy_from_user(&hdr, argp, sizeof(hdr)) != 0) {
+               dtrace_dof_error(NULL, "failed to copyin DOF header");
+               *errp = -EFAULT;
+               return NULL;
+       }
+
+       /*
+        * Now we'll allocate the entire DOF and copy it in -- provided
+        * that the length isn't outrageous.
+        */
+       if (hdr.dofh_loadsz >= dtrace_dof_maxsize) {
+               dtrace_dof_error(&hdr, "load size exceeds maximum");
+               *errp = -E2BIG;
+               return NULL;
+       }
+
+       if (hdr.dofh_loadsz < sizeof(hdr)) {
+               dtrace_dof_error(&hdr, "invalid load size");
+               *errp = -EINVAL;
+               return NULL;
+       }
+
+       dof = kmalloc(hdr.dofh_loadsz, GFP_KERNEL);
+
+       if (copy_from_user(dof, argp, hdr.dofh_loadsz) != 0 ||
+               dof->dofh_loadsz != hdr.dofh_loadsz) {
+               kfree(dof);
+               *errp = -EFAULT;
+               return NULL;
+       }
+
+       return dof;
+}
+
+dof_hdr_t *dtrace_dof_property(const char *name)
+{
+       uchar_t         *buf;
+       uint64_t        loadsz;
+       unsigned int    len, i;
+       dof_hdr_t       *dof;
+
+       /*
+        * Unfortunately, array of values in .conf files are always (and
+        * only) interpreted to be integer arrays.  We must read our DOF
+        * as an integer array, and then squeeze it into a byte array.
+        */
+#ifdef FIXME
+       if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dtrace_devi, 0,
+                                     (char *)name, (int **)&buf, &len) !=
+           DDI_PROP_SUCCESS)
+               return NULL;
+#else
+       return NULL;
+#endif
+
+       for (i = 0; i < len; i++)
+               buf[i] = (uchar_t)(((int *)buf)[i]);
+
+       if (len < sizeof(dof_hdr_t)) {
+#ifdef FIXME
+               ddi_prop_free(buf);
+#endif
+               dtrace_dof_error(NULL, "truncated header");
+               return NULL;
+       }
+
+       if (len < (loadsz = ((dof_hdr_t *)buf)->dofh_loadsz)) {
+#ifdef FIXME
+               ddi_prop_free(buf);
+#endif
+               dtrace_dof_error(NULL, "truncated DOF");
+               return NULL;
+       }
+
+       if (loadsz >= dtrace_dof_maxsize) {
+#ifdef FIXME
+               ddi_prop_free(buf);
+#endif
+               dtrace_dof_error(NULL, "oversized DOF");
+               return NULL;
+       }
+
+       dof = kmalloc(loadsz, GFP_KERNEL);
+       memcpy(dof, buf, loadsz);
+#ifdef FIXME
+       ddi_prop_free(buf);
+#endif
+
+       return dof;
+}
+
+void dtrace_dof_destroy(dof_hdr_t *dof)
+{
+       kfree(dof);
+}
+
+/*
+ * Return the dof_sec_t pointer corresponding to a given section index.  If the
+ * index is not valid, dtrace_dof_error() is called and NULL is returned.  If
+ * a type other than DOF_SECT_NONE is specified, the header is checked against
+ * this type and NULL is returned if the types do not match.
+ */
+static dof_sec_t *dtrace_dof_sect(dof_hdr_t *dof, uint32_t type,
+                                 dof_secidx_t i)
+{
+       dof_sec_t       *sec = (dof_sec_t *)(uintptr_t)((uintptr_t)dof +
+                                                       dof->dofh_secoff +
+                                                       i * dof->dofh_secsize);
+
+       if (i >= dof->dofh_secnum) {
+               dtrace_dof_error(dof, "referenced section index is invalid");
+               return NULL;
+       }
+
+       if (!(sec->dofs_flags & DOF_SECF_LOAD)) {
+               dtrace_dof_error(dof, "referenced section is not loadable");
+               return NULL;
+       }
+
+       if (type != DOF_SECT_NONE && type != sec->dofs_type) {
+               dtrace_dof_error(dof, "referenced section is the wrong type");
+               return NULL;
+       }
+
+       return sec;
+}
+
+static dtrace_probedesc_t *dtrace_dof_probedesc(dof_hdr_t *dof, dof_sec_t *sec,
+                                               dtrace_probedesc_t *desc)
+{
+       dof_probedesc_t *probe;
+       dof_sec_t       *strtab;
+       uintptr_t       daddr = (uintptr_t)dof;
+       uintptr_t       str;
+       size_t          size;
+
+       if (sec->dofs_type != DOF_SECT_PROBEDESC) {
+               dtrace_dof_error(dof, "invalid probe section");
+               return NULL;
+       }
+
+       if (sec->dofs_align != sizeof(dof_secidx_t)) {
+               dtrace_dof_error(dof, "bad alignment in probe description");
+               return NULL;
+       }
+
+       if (sec->dofs_offset + sizeof(dof_probedesc_t) > dof->dofh_loadsz) {
+               dtrace_dof_error(dof, "truncated probe description");
+               return NULL;
+       }
+
+       probe = (dof_probedesc_t *)(uintptr_t)(daddr + sec->dofs_offset);
+       strtab = dtrace_dof_sect(dof, DOF_SECT_STRTAB, probe->dofp_strtab);
+
+       if (strtab == NULL)
+               return NULL;
+
+       str = daddr + strtab->dofs_offset;
+       size = strtab->dofs_size;
+
+       if (probe->dofp_provider >= strtab->dofs_size) {
+               dtrace_dof_error(dof, "corrupt probe provider");
+               return NULL;
+       }
+
+       strncpy(desc->dtpd_provider, (char *)(str + probe->dofp_provider),
+               min((size_t)DTRACE_PROVNAMELEN - 1,
+                   size - probe->dofp_provider));
+
+       if (probe->dofp_mod >= strtab->dofs_size) {
+               dtrace_dof_error(dof, "corrupt probe module");
+               return NULL;
+       }
+
+       strncpy(desc->dtpd_mod, (char *)(str + probe->dofp_mod),
+               min((size_t)DTRACE_MODNAMELEN - 1, size - probe->dofp_mod));
+
+       if (probe->dofp_func >= strtab->dofs_size) {
+               dtrace_dof_error(dof, "corrupt probe function");
+               return NULL;
+       }
+
+       strncpy(desc->dtpd_func, (char *)(str + probe->dofp_func),
+               min((size_t)DTRACE_FUNCNAMELEN - 1, size - probe->dofp_func));
+
+       if (probe->dofp_name >= strtab->dofs_size) {
+               dtrace_dof_error(dof, "corrupt probe name");
+               return NULL;
+       }
+
+       strncpy(desc->dtpd_name, (char *)(str + probe->dofp_name),
+               min((size_t)DTRACE_NAMELEN - 1, size - probe->dofp_name));
+
+       return desc;
+}
+
+static dtrace_difo_t *dtrace_dof_difo(dof_hdr_t *dof, dof_sec_t *sec,
+                                     dtrace_vstate_t *vstate,
+                                     const cred_t *cr)
+{
+       dtrace_difo_t   *dp;
+       size_t          ttl = 0;
+       dof_difohdr_t   *dofd;
+       uintptr_t       daddr = (uintptr_t)dof;
+       size_t          max = dtrace_difo_maxsize;
+       int             i, l, n;
+
+       static const struct {
+               int section;
+               int bufoffs;
+               int lenoffs;
+               int entsize;
+               int align;
+               const char *msg;
+       } difo[] = {
+               {
+                       DOF_SECT_DIF,
+                       offsetof(dtrace_difo_t, dtdo_buf),
+                       offsetof(dtrace_difo_t, dtdo_len),
+                       sizeof(dif_instr_t),
+                       sizeof(dif_instr_t),
+                       "multiple DIF sections"
+               },
+               {
+                       DOF_SECT_INTTAB,
+                       offsetof(dtrace_difo_t, dtdo_inttab),
+                       offsetof(dtrace_difo_t, dtdo_intlen),
+                       sizeof(uint64_t),
+                       sizeof(uint64_t),
+                       "multiple integer tables"
+               },
+               {
+                       DOF_SECT_STRTAB,
+                       offsetof(dtrace_difo_t, dtdo_strtab),
+                       offsetof(dtrace_difo_t, dtdo_strlen),
+                       0,
+                       sizeof(char),
+                       "multiple string tables"
+               },
+               {
+                       DOF_SECT_VARTAB,
+                       offsetof(dtrace_difo_t, dtdo_vartab),
+                       offsetof(dtrace_difo_t, dtdo_varlen),
+                       sizeof(dtrace_difv_t),
+                       sizeof(uint_t),
+                       "multiple variable tables"
+               },
+               {
+                       DOF_SECT_NONE,
+                       0,
+                       0,
+                       0,
+                       0,
+                       NULL
+               }
+       };
+
+       if (sec->dofs_type != DOF_SECT_DIFOHDR) {
+               dtrace_dof_error(dof, "invalid DIFO header section");
+               return NULL;
+       }
+
+       if (sec->dofs_align != sizeof(dof_secidx_t)) {
+               dtrace_dof_error(dof, "bad alignment in DIFO header");
+               return NULL;
+       }
+
+       if (sec->dofs_size < sizeof(dof_difohdr_t) ||
+           sec->dofs_size % sizeof(dof_secidx_t)) {
+               dtrace_dof_error(dof, "bad size in DIFO header");
+               return NULL;
+       }
+
+       dofd = (dof_difohdr_t *)(uintptr_t)(daddr + sec->dofs_offset);
+       n = (sec->dofs_size - sizeof(*dofd)) / sizeof(dof_secidx_t) + 1;
+
+       dp = kzalloc(sizeof(dtrace_difo_t), GFP_KERNEL);
+       dp->dtdo_rtype = dofd->dofd_rtype;
+
+       for (l = 0; l < n; l++) {
+               dof_sec_t       *subsec;
+               void            **bufp;
+               uint32_t        *lenp;
+
+               if ((subsec =
+                    dtrace_dof_sect(dof, DOF_SECT_NONE, dofd->dofd_links[l]))
+                   == NULL)
+                       goto err; /* invalid section link */
+
+               if (ttl + subsec->dofs_size > max) {
+                       dtrace_dof_error(dof, "exceeds maximum size");
+                       goto err;
+               }
+
+               ttl += subsec->dofs_size;
+
+               for (i = 0; difo[i].section != DOF_SECT_NONE; i++) {
+                       if (subsec->dofs_type != difo[i].section)
+                               continue;
+
+                       if (!(subsec->dofs_flags & DOF_SECF_LOAD)) {
+                               dtrace_dof_error(dof, "section not loaded");
+                               goto err;
+                       }
+
+                       if (subsec->dofs_align != difo[i].align) {
+                               dtrace_dof_error(dof, "bad alignment");
+                               goto err;
+                       }
+
+                       bufp = (void **)((uintptr_t)dp + difo[i].bufoffs);
+                       lenp = (uint32_t *)((uintptr_t)dp + difo[i].lenoffs);
+
+                       if (*bufp != NULL) {
+                               dtrace_dof_error(dof, difo[i].msg);
+                               goto err;
+                       }
+
+                       if (difo[i].entsize != subsec->dofs_entsize) {
+                               dtrace_dof_error(dof, "entry size mismatch");
+                               goto err;
+                       }
+
+                       if (subsec->dofs_entsize != 0) {
+                               uint64_t        n = subsec->dofs_size;
+
+                               if (do_div(n, subsec->dofs_entsize) != 0) {
+                                       dtrace_dof_error(dof,
+                                                        "corrupt entry size");
+                                       goto err;
+                               }
+                       }
+
+                       *lenp = subsec->dofs_size;
+                       *bufp = kmalloc(subsec->dofs_size, GFP_KERNEL);
+                       memcpy(*bufp,
+                              (char *)(uintptr_t)(daddr + subsec->dofs_offset),
+                              subsec->dofs_size);
+
+                       if (subsec->dofs_entsize != 0)
+                               *lenp /= subsec->dofs_entsize;
+
+                       break;
+               }
+
+               /*
+                * If we encounter a loadable DIFO sub-section that is not
+                * known to us, assume this is a broken program and fail.
+                */
+               if (difo[i].section == DOF_SECT_NONE &&
+                   (subsec->dofs_flags & DOF_SECF_LOAD)) {
+                       dtrace_dof_error(dof, "unrecognized DIFO subsection");
+                       goto err;
+               }
+       }
+
+       if (dp->dtdo_buf == NULL) {
+               /*
+                * We can't have a DIF object without DIF text.
+                */
+               dtrace_dof_error(dof, "missing DIF text");
+               goto err;
+       }
+
+       /*
+        * Before we validate the DIF object, run through the variable table
+        * looking for the strings -- if any of their size are under, we'll set
+        * their size to be the system-wide default string size.  Note that
+        * this should _not_ happen if the "strsize" option has been set --
+        * in this case, the compiler should have set the size to reflect the
+        * setting of the option.
+        */
+       for (i = 0; i < dp->dtdo_varlen; i++) {
+               dtrace_difv_t           *v = &dp->dtdo_vartab[i];
+               dtrace_diftype_t        *t = &v->dtdv_type;
+
+               if (v->dtdv_id < DIF_VAR_OTHER_UBASE)
+                       continue;
+
+               if (t->dtdt_kind == DIF_TYPE_STRING && t->dtdt_size == 0)
+                       t->dtdt_size = dtrace_strsize_default;
+       }
+
+       if (dtrace_difo_validate(dp, vstate, DIF_DIR_NREGS, cr) != 0)
+               goto err;
+
+       dtrace_difo_init(dp, vstate);
+       return dp;
+
+err:
+       kfree(dp->dtdo_buf);
+       kfree(dp->dtdo_inttab);
+       kfree(dp->dtdo_strtab);
+       kfree(dp->dtdo_vartab);
+
+       kfree(dp);
+       return NULL;
+}
+
+static dtrace_predicate_t *dtrace_dof_predicate(dof_hdr_t *dof, dof_sec_t *sec,
+                                               dtrace_vstate_t *vstate,
+                                               const cred_t *cr)
+{
+        dtrace_difo_t *dp;
+
+        if ((dp = dtrace_dof_difo(dof, sec, vstate, cr)) == NULL)
+                return NULL;
+
+        return dtrace_predicate_create(dp);
+}
+
+static dtrace_actdesc_t *dtrace_dof_actdesc(dof_hdr_t *dof, dof_sec_t *sec,
+                                           dtrace_vstate_t *vstate,
+                                           const cred_t *cr)
+{
+       dtrace_actdesc_t        *act, *first = NULL, *last = NULL, *next;
+       dof_actdesc_t           *desc;
+       dof_sec_t               *difosec;
+       size_t                  offs;
+       uintptr_t               daddr = (uintptr_t)dof;
+       uint64_t                arg;
+       dtrace_actkind_t        kind;
+
+       if (sec->dofs_type != DOF_SECT_ACTDESC) {
+               dtrace_dof_error(dof, "invalid action section");
+               return NULL;
+       }
+
+       if (sec->dofs_offset + sizeof(dof_actdesc_t) > dof->dofh_loadsz) {
+               dtrace_dof_error(dof, "truncated action description");
+               return NULL;
+       }
+
+       if (sec->dofs_align != sizeof(uint64_t)) {
+               dtrace_dof_error(dof, "bad alignment in action description");
+               return NULL;
+       }
+
+       if (sec->dofs_size < sec->dofs_entsize) {
+               dtrace_dof_error(dof, "section entry size exceeds total size");
+               return NULL;
+       }
+
+       if (sec->dofs_entsize != sizeof(dof_actdesc_t)) {
+               dtrace_dof_error(dof, "bad entry size in action description");
+               return NULL;
+       }
+
+       /*
+        * Was: sec->dofs_size / sec->dofs_entsize > dtrace_actions_max
+        * but it is safer to simply avoid the division (it requires use of
+        * a macro in Linux to cover 64-bit division in a 32-bit kernel.
+        */
+       if (sec->dofs_size > sec->dofs_entsize * dtrace_actions_max) {
+               dtrace_dof_error(dof, "actions exceed dtrace_actions_max");
+               return NULL;
+       }
+
+       for (offs = 0; offs < sec->dofs_size; offs += sec->dofs_entsize) {
+               desc = (dof_actdesc_t *)(daddr +
+                                        (uintptr_t)sec->dofs_offset + offs);
+               kind = (dtrace_actkind_t)desc->dofa_kind;
+
+               if (DTRACEACT_ISPRINTFLIKE(kind) &&
+                   (kind != DTRACEACT_PRINTA ||
+                    desc->dofa_strtab != DOF_SECIDX_NONE)) {
+                       dof_sec_t       *strtab;
+                       char            *str, *fmt;
+                       uint64_t        i;
+
+                       /*
+                        * The printf()-like actions must have a format string.
+                        */
+                       if ((strtab =
+                            dtrace_dof_sect(dof, DOF_SECT_STRTAB,
+                                            desc->dofa_strtab)) == NULL)
+                               goto err;
+
+                       str = (char *)((uintptr_t)dof +
+                                      (uintptr_t)strtab->dofs_offset);
+       
+                       for (i = desc->dofa_arg; i < strtab->dofs_size; i++) {
+                               if (str[i] == '\0')
+                                       break;
+                       }
+
+                       if (i >= strtab->dofs_size) {
+                               dtrace_dof_error(dof, "bogus format string");
+                               goto err;
+                       }
+
+                       if (i == desc->dofa_arg) {
+                               dtrace_dof_error(dof, "empty format string");
+                               goto err;
+                       }
+
+                       i -= desc->dofa_arg;
+                       fmt = kmalloc(i + 1, GFP_KERNEL);
+                       memcpy(fmt, &str[desc->dofa_arg], i + 1);
+                       arg = (uint64_t)(uintptr_t)fmt;
+               } else {
+                       if (kind == DTRACEACT_PRINTA) {
+                               ASSERT(desc->dofa_strtab == DOF_SECIDX_NONE);
+                               arg = 0;
+                       } else
+                               arg = desc->dofa_arg;
+               }
+
+               act = dtrace_actdesc_create(kind, desc->dofa_ntuple,
+                                           desc->dofa_uarg, arg);
+
+               if (last != NULL)
+                       last->dtad_next = act;
+               else
+                       first = act;
+
+               last = act;
+
+               if (desc->dofa_difo == DOF_SECIDX_NONE)
+                       continue;
+
+               if ((difosec = dtrace_dof_sect(dof, DOF_SECT_DIFOHDR,
+                                              desc->dofa_difo)) == NULL)
+                       goto err;
+
+               act->dtad_difo = dtrace_dof_difo(dof, difosec, vstate, cr);
+
+               if (act->dtad_difo == NULL)
+                       goto err;
+       }
+
+       ASSERT(first != NULL);
+       return first;
+
+err:
+       for (act = first; act != NULL; act = next) {
+               next = act->dtad_next;
+               dtrace_actdesc_release(act, vstate);
+       }
+
+       return NULL;
+}
+
+static dtrace_ecbdesc_t *dtrace_dof_ecbdesc(dof_hdr_t *dof, dof_sec_t *sec,
+                                           dtrace_vstate_t *vstate,
+                                           const cred_t *cr)
+{
+       dtrace_ecbdesc_t        *ep;
+       dof_ecbdesc_t           *ecb;
+       dtrace_probedesc_t      *desc;
+       dtrace_predicate_t      *pred = NULL;
+
+       if (sec->dofs_size < sizeof(dof_ecbdesc_t)) {
+               dtrace_dof_error(dof, "truncated ECB description");
+               return NULL;
+       }
+
+       if (sec->dofs_align != sizeof(uint64_t)) {
+               dtrace_dof_error(dof, "bad alignment in ECB description");
+               return NULL;
+       }
+
+       ecb = (dof_ecbdesc_t *)((uintptr_t)dof + (uintptr_t)sec->dofs_offset);
+       sec = dtrace_dof_sect(dof, DOF_SECT_PROBEDESC, ecb->dofe_probes);
+
+       if (sec == NULL)
+               return NULL;
+
+       ep = kzalloc(sizeof(dtrace_ecbdesc_t), GFP_KERNEL);
+       ep->dted_uarg = ecb->dofe_uarg;
+       desc = &ep->dted_probe;
+
+       if (dtrace_dof_probedesc(dof, sec, desc) == NULL)
+               goto err;
+
+       if (ecb->dofe_pred != DOF_SECIDX_NONE) {
+               if ((sec = dtrace_dof_sect(dof, DOF_SECT_DIFOHDR,
+                                          ecb->dofe_pred)) == NULL)
+                       goto err;
+
+               if ((pred = dtrace_dof_predicate(dof, sec, vstate, cr)) == NULL)
+                       goto err;
+
+               ep->dted_pred.dtpdd_predicate = pred;
+       }
+
+       if (ecb->dofe_actions != DOF_SECIDX_NONE) {
+               if ((sec = dtrace_dof_sect(dof, DOF_SECT_ACTDESC,
+                                          ecb->dofe_actions)) == NULL)
+                       goto err;
+
+               ep->dted_action = dtrace_dof_actdesc(dof, sec, vstate, cr);
+
+               if (ep->dted_action == NULL)
+                       goto err;
+       }
+
+       return ep;
+
+err:
+       if (pred != NULL)
+               dtrace_predicate_release(pred, vstate);
+       kfree(ep);
+       return NULL;
+}
+
+/*
+ * Apply the relocations from the specified 'sec' (a DOF_SECT_URELHDR) to the
+ * specified DOF.  At present, this amounts to simply adding 'ubase' to the
+ * site of any user SETX relocations to account for load object base address.
+ * In the future, if we need other relocations, this function can be extended.
+ */
+static int dtrace_dof_relocate(dof_hdr_t *dof, dof_sec_t *sec, uint64_t ubase)
+{
+       uintptr_t       daddr = (uintptr_t)dof;
+       dof_relohdr_t   *dofr = (dof_relohdr_t *)(uintptr_t)(daddr +
+                                                            sec->dofs_offset);
+       dof_sec_t       *ss, *rs, *ts;
+       dof_relodesc_t  *r;
+       uint_t          i, n;
+
+       if (sec->dofs_size < sizeof(dof_relohdr_t) ||
+           sec->dofs_align != sizeof(dof_secidx_t)) {
+               dtrace_dof_error(dof, "invalid relocation header");
+               return -1;
+       }
+
+       ss = dtrace_dof_sect(dof, DOF_SECT_STRTAB, dofr->dofr_strtab);
+       rs = dtrace_dof_sect(dof, DOF_SECT_RELTAB, dofr->dofr_relsec);
+       ts = dtrace_dof_sect(dof, DOF_SECT_NONE, dofr->dofr_tgtsec);
+
+       if (ss == NULL || rs == NULL || ts == NULL)
+               return -1; /* dtrace_dof_error() has been called already */
+
+       if (rs->dofs_entsize < sizeof(dof_relodesc_t) ||
+           rs->dofs_align != sizeof(uint64_t)) {
+               dtrace_dof_error(dof, "invalid relocation section");
+               return -1;
+       }
+
+       r = (dof_relodesc_t *)(uintptr_t)(daddr + rs->dofs_offset);
+       /*
+        * Was: n = rs->dofs_size / rs->dofs_entsize;
+        * but on Linux we need to use a macro for the division to handle the
+        * possible case of 64-bit division on a 32-bit kernel.
+        */
+       n = rs->dofs_size;
+       do_div(n, rs->dofs_entsize);
+
+       for (i = 0; i < n; i++) {
+               uintptr_t       taddr = daddr + ts->dofs_offset +
+                                               r->dofr_offset;
+
+               switch (r->dofr_type) {
+               case DOF_RELO_NONE:
+                       break;
+               case DOF_RELO_SETX:
+                       if (r->dofr_offset >= ts->dofs_size ||
+                           r->dofr_offset + sizeof(uint64_t) >
+                               ts->dofs_size) {
+                               dtrace_dof_error(dof, "bad relocation offset");
+                               return -1;
+                       }
+
+                       if (!IS_ALIGNED(taddr, sizeof(uint64_t))) {
+                               dtrace_dof_error(dof, "misaligned setx relo");
+                               return -1;
+                       }
+
+                       *(uint64_t *)taddr += ubase;
+                       break;
+               default:
+                       dtrace_dof_error(dof, "invalid relocation type");
+                       return -1;
+               }
+
+               r = (dof_relodesc_t *)((uintptr_t)r + rs->dofs_entsize);
+       }
+
+       return 0;
+}
+
+/*
+ * The dof_hdr_t passed to dtrace_dof_slurp() should be a partially validated
+ * header:  it should be at the front of a memory region that is at least
+ * sizeof(dof_hdr_t) in size -- and then at least dof_hdr.dofh_loadsz in
+ * size.  It need not be validated in any other way.
+ */
+int dtrace_dof_slurp(dof_hdr_t *dof, dtrace_vstate_t *vstate, const cred_t *cr,
+                    dtrace_enabling_t **enabp, uint64_t ubase, int noprobes)
+{
+       uint64_t                len = dof->dofh_loadsz, seclen;
+       uintptr_t               daddr = (uintptr_t)dof;
+       dtrace_ecbdesc_t        *ep;
+       dtrace_enabling_t       *enab;
+       uint_t                  i;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(dof->dofh_loadsz >= sizeof(dof_hdr_t));
+
+       /*
+        * Check the DOF header identification bytes.  In addition to checking
+        * valid settings, we also verify that unused bits/bytes are zeroed so
+        * we can use them later without fear of regressing existing binaries.
+        */
+       if (memcmp(&dof->dofh_ident[DOF_ID_MAG0], DOF_MAG_STRING,
+                  DOF_MAG_STRLEN) != 0) {
+               dtrace_dof_error(dof, "DOF magic string mismatch");
+               return -1;
+       }
+
+       if (dof->dofh_ident[DOF_ID_MODEL] != DOF_MODEL_ILP32 &&
+           dof->dofh_ident[DOF_ID_MODEL] != DOF_MODEL_LP64) {
+               dtrace_dof_error(dof, "DOF has invalid data model");
+               return -1;
+       }
+
+       if (dof->dofh_ident[DOF_ID_ENCODING] != DOF_ENCODE_NATIVE) {
+               dtrace_dof_error(dof, "DOF encoding mismatch");
+               return -1;
+       }
+
+       if (dof->dofh_ident[DOF_ID_VERSION] != DOF_VERSION_1 &&
+           dof->dofh_ident[DOF_ID_VERSION] != DOF_VERSION_2) {
+               dtrace_dof_error(dof, "DOF version mismatch");
+               return -1;
+       }
+
+       if (dof->dofh_ident[DOF_ID_DIFVERS] != DIF_VERSION_2) {
+               dtrace_dof_error(dof, "DOF uses unsupported instruction set");
+               return -1;
+       }
+
+       if (dof->dofh_ident[DOF_ID_DIFIREG] > DIF_DIR_NREGS) {
+               dtrace_dof_error(dof, "DOF uses too many integer registers");
+               return -1;
+       }
+
+       if (dof->dofh_ident[DOF_ID_DIFTREG] > DIF_DTR_NREGS) {
+               dtrace_dof_error(dof, "DOF uses too many tuple registers");
+               return -1;
+       }
+
+       for (i = DOF_ID_PAD; i < DOF_ID_SIZE; i++) {
+               if (dof->dofh_ident[i] != 0) {
+                       dtrace_dof_error(dof, "DOF has invalid ident byte set");                        return -1;
+               }
+       }
+
+       if (dof->dofh_flags & ~DOF_FL_VALID) {
+               dtrace_dof_error(dof, "DOF has invalid flag bits set");
+               return -1;
+       }
+
+       if (dof->dofh_secsize == 0) {
+               dtrace_dof_error(dof, "zero section header size");
+               return -1;
+       }
+
+       /*
+        * Check that the section headers don't exceed the amount of DOF
+        * data.  Note that we cast the section size and number of sections
+        * to uint64_t's to prevent possible overflow in the multiplication.
+        */
+       seclen = (uint64_t)dof->dofh_secnum * (uint64_t)dof->dofh_secsize;
+
+       if (dof->dofh_secoff > len || seclen > len ||
+           dof->dofh_secoff + seclen > len) {
+               dtrace_dof_error(dof, "truncated section headers");
+               return -1;
+       }
+
+       if (!IS_ALIGNED(dof->dofh_secoff, sizeof(uint64_t))) {
+               dtrace_dof_error(dof, "misaligned section headers");
+               return -1;
+       }
+
+       if (!IS_ALIGNED(dof->dofh_secsize, sizeof(uint64_t))) {
+               dtrace_dof_error(dof, "misaligned section size");
+               return -1;
+       }
+
+       /*
+        * Take an initial pass through the section headers to be sure that
+        * the headers don't have stray offsets.  If the 'noprobes' flag is
+        * set, do not permit sections relating to providers, probes, or args.
+        */
+       for (i = 0; i < dof->dofh_secnum; i++) {
+               dof_sec_t       *sec =
+                               (dof_sec_t *)(daddr +
+                                             (uintptr_t)dof->dofh_secoff +
+                                             i * dof->dofh_secsize);
+
+               if (noprobes) {
+                       switch (sec->dofs_type) {
+                       case DOF_SECT_PROVIDER:
+                       case DOF_SECT_PROBES:
+                       case DOF_SECT_PRARGS:
+                       case DOF_SECT_PROFFS:
+                               dtrace_dof_error(
+                                       dof, "illegal sections for enabling");
+                               return -1;
+                       }
+               }
+
+               if (DOF_SEC_ISLOADABLE(sec->dofs_type) &&
+                   !(sec->dofs_flags & DOF_SECF_LOAD)) {
+                       dtrace_dof_error(
+                               dof, "loadable section with load flag unset");
+                       return -1;
+               }
+
+               /*
+                * Just ignore non-loadable sections.
+                */
+               if (!(sec->dofs_flags & DOF_SECF_LOAD))
+                       continue;
+
+               if (sec->dofs_align & (sec->dofs_align - 1)) {
+                       dtrace_dof_error(dof, "bad section alignment");
+                       return -1;
+               }
+
+               if (sec->dofs_offset & (sec->dofs_align - 1)) {
+                       dtrace_dof_error(dof, "misaligned section");
+                       return -1;
+               }
+
+               if (sec->dofs_offset > len || sec->dofs_size > len ||
+                   sec->dofs_offset + sec->dofs_size > len) {
+                       dtrace_dof_error(dof, "corrupt section header");
+                       return -1;
+               }
+
+               if (sec->dofs_type == DOF_SECT_STRTAB && *((char *)daddr +
+                   sec->dofs_offset + sec->dofs_size - 1) != '\0') {
+                       dtrace_dof_error(dof, "non-terminating string table");
+                       return -1;
+               }
+       }
+
+       /*
+        * Take a second pass through the sections and locate and perform any
+        * relocations that are present.  We do this after the first pass to
+        * be sure that all sections have had their headers validated.
+        */
+       for (i = 0; i < dof->dofh_secnum; i++) {
+               dof_sec_t       *sec =
+                               (dof_sec_t *)(daddr +
+                                             (uintptr_t)dof->dofh_secoff +
+                                             i * dof->dofh_secsize);
+
+               /*
+                * Skip sections that are not loadable.
+                */
+               if (!(sec->dofs_flags & DOF_SECF_LOAD))
+                       continue;
+
+               switch (sec->dofs_type) {
+               case DOF_SECT_URELHDR:
+                       if (dtrace_dof_relocate(dof, sec, ubase) != 0)
+                               return -1;
+                       break;
+               }
+       }
+
+       if ((enab = *enabp) == NULL)
+               enab = *enabp = dtrace_enabling_create(vstate);
+
+       for (i = 0; i < dof->dofh_secnum; i++) {
+               dof_sec_t       *sec =
+                               (dof_sec_t *)(daddr +
+                                             (uintptr_t)dof->dofh_secoff +
+                                             i * dof->dofh_secsize);
+
+               if (sec->dofs_type != DOF_SECT_ECBDESC)
+                       continue;
+
+               if ((ep = dtrace_dof_ecbdesc(dof, sec, vstate, cr)) == NULL) {
+                       dtrace_enabling_destroy(enab);
+                       *enabp = NULL;
+                       return -1;
+               }
+
+               dtrace_enabling_add(enab, ep);
+       }
+
+       return 0;
+}
+
+/*
+ * Process DOF for any options.  This should be called after the DOF has been
+ * processed by dtrace_dof_slurp().
+ */
+int dtrace_dof_options(dof_hdr_t *dof, dtrace_state_t *state)
+{
+       int             i, rval;
+       uint32_t        entsize;
+       size_t          offs;
+       dof_optdesc_t   *desc;
+
+       for (i = 0; i < dof->dofh_secnum; i++) {
+               dof_sec_t       *sec = (dof_sec_t *)((uintptr_t)dof +
+                                      (uintptr_t)dof->dofh_secoff +
+                                      i * dof->dofh_secsize);
+
+               if (sec->dofs_type != DOF_SECT_OPTDESC)
+                       continue;
+
+               if (sec->dofs_align != sizeof(uint64_t)) {
+                       dtrace_dof_error(
+                               dof, "bad alignment in option description");
+                       return -EINVAL;
+               }
+
+               if ((entsize = sec->dofs_entsize) == 0) {
+                       dtrace_dof_error(dof, "zeroed option entry size");
+                       return -EINVAL;
+               }
+
+               if (entsize < sizeof(dof_optdesc_t)) {
+                       dtrace_dof_error(dof, "bad option entry size");
+                       return -EINVAL;
+               }
+
+               for (offs = 0; offs < sec->dofs_size; offs += entsize) {
+                       desc = (dof_optdesc_t *)((uintptr_t)dof +
+                                                (uintptr_t)sec->dofs_offset +
+                                                offs);
+
+                       if (desc->dofo_strtab != DOF_SECIDX_NONE) {
+                               dtrace_dof_error(
+                                       dof, "non-zero option string");
+                               return -EINVAL;
+                       }
+
+                       if (desc->dofo_value == DTRACEOPT_UNSET) {
+                               dtrace_dof_error(dof, "unset option");
+                               return -EINVAL;
+                       }
+
+                       if ((rval = dtrace_state_option(
+                                       state, desc->dofo_option,
+                                       desc->dofo_value)) != 0) {
+                               dtrace_dof_error(dof, "rejected option");
+                               return rval;
+                       }
+               }
+       }
+
+       return 0;
+}
diff --git a/dtrace/dtrace_ecb.c b/dtrace/dtrace_ecb.c
new file mode 100644 (file)
index 0000000..a9950cd
--- /dev/null
@@ -0,0 +1,845 @@
+/*
+ * FILE:       dtrace_ecb.c
+ * DESCRIPTION:        Dynamic Tracing: ECB functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/slab.h>
+
+#include "dtrace.h"
+
+dtrace_ecb_t   *dtrace_ecb_create_cache;
+
+static dtrace_action_t *dtrace_ecb_aggregation_create(dtrace_ecb_t *ecb,
+                                                     dtrace_actdesc_t *desc)
+{
+       dtrace_aggregation_t    *agg;
+       size_t                  size = sizeof(uint64_t);
+       int                     ntuple = desc->dtad_ntuple;
+       dtrace_action_t         *act;
+       dtrace_recdesc_t        *frec;
+       dtrace_aggid_t          aggid;
+       dtrace_state_t          *state = ecb->dte_state;
+       int                     err;
+
+       agg = kzalloc(sizeof(dtrace_aggregation_t), GFP_KERNEL);
+       agg->dtag_ecb = ecb;
+
+       ASSERT(DTRACEACT_ISAGG(desc->dtad_kind));
+
+       switch (desc->dtad_kind) {
+       case DTRACEAGG_MIN:
+               agg->dtag_initial = UINT64_MAX;
+               agg->dtag_aggregate = dtrace_aggregate_min;
+               break;
+
+       case DTRACEAGG_MAX:
+               agg->dtag_initial = UINT64_MIN;
+               agg->dtag_aggregate = dtrace_aggregate_max;
+               break;
+
+       case DTRACEAGG_COUNT:
+               agg->dtag_aggregate = dtrace_aggregate_count;
+               break;
+
+       case DTRACEAGG_QUANTIZE:
+               agg->dtag_aggregate = dtrace_aggregate_quantize;
+               size = (((sizeof(uint64_t) * NBBY) - 1) * 2 + 1) *
+                      sizeof(uint64_t);
+               break;
+
+       case DTRACEAGG_LQUANTIZE: {
+               uint16_t        step = DTRACE_LQUANTIZE_STEP(desc->dtad_arg);
+               uint16_t        levels =
+                               DTRACE_LQUANTIZE_LEVELS(desc->dtad_arg);
+
+               agg->dtag_initial = desc->dtad_arg;
+               agg->dtag_aggregate = dtrace_aggregate_lquantize;
+
+               if (step == 0 || levels == 0)
+                       goto err;
+
+               size = levels * sizeof(uint64_t) + 3 * sizeof(uint64_t);
+               break;
+       }
+
+       case DTRACEAGG_AVG:
+               agg->dtag_aggregate = dtrace_aggregate_avg;
+               size = sizeof(uint64_t) * 2;
+               break;
+
+       case DTRACEAGG_STDDEV:
+               agg->dtag_aggregate = dtrace_aggregate_stddev;
+               size = sizeof(uint64_t) * 4;
+               break;
+
+       case DTRACEAGG_SUM:
+               agg->dtag_aggregate = dtrace_aggregate_sum;
+               break;
+
+       default:
+               goto err;
+       }
+
+       agg->dtag_action.dta_rec.dtrd_size = size;
+
+       if (ntuple == 0)
+               goto err;
+
+       for (act = ecb->dte_action_last; act != NULL; act = act->dta_prev) {
+               if (DTRACEACT_ISAGG(act->dta_kind))
+                       break;
+
+               if (--ntuple == 0) {
+                       agg->dtag_first = act;
+                       goto success;
+               }
+       }
+
+       ASSERT(ntuple != 0);
+err:
+       kfree(agg);
+       return NULL;
+
+success:
+       ASSERT(ecb->dte_action_last != NULL);
+       act = ecb->dte_action_last;
+
+       if (act->dta_kind == DTRACEACT_DIFEXPR) {
+               ASSERT(act->dta_difo != NULL);
+
+               if (act->dta_difo->dtdo_rtype.dtdt_size == 0)
+                       agg->dtag_hasarg = 1;
+       }
+
+       /*
+        * Get an ID for the aggregation (add it to the idr).
+        */
+       mutex_unlock(&dtrace_lock);
+again:
+       idr_pre_get(&state->dts_agg_idr, __GFP_NOFAIL);
+       mutex_lock(&dtrace_lock);
+
+       err = idr_get_new(&state->dts_agg_idr, agg, &aggid);
+       if (err == -EAGAIN) {
+               mutex_unlock(&dtrace_lock);
+               goto again;
+       }
+
+       agg->dtag_id = aggid;
+printk(KERN_INFO "New aggregation: %u (for ECB %u)\n", aggid, ecb->dte_epid);
+
+       frec = &agg->dtag_first->dta_rec;
+       if (frec->dtrd_alignment < sizeof(dtrace_aggid_t))
+               frec->dtrd_alignment = sizeof(dtrace_aggid_t);
+
+       for (act = agg->dtag_first; act != NULL; act = act->dta_next) {
+               ASSERT(!act->dta_intuple);
+
+               act->dta_intuple = 1;
+       }
+
+       return &agg->dtag_action;
+}
+
+void dtrace_ecb_aggregation_destroy(dtrace_ecb_t *ecb, dtrace_action_t *act)
+{
+       dtrace_aggregation_t    *agg = (dtrace_aggregation_t *)act;
+       dtrace_state_t          *state = ecb->dte_state;
+
+       ASSERT(DTRACEACT_ISAGG(act->dta_kind));
+
+       idr_remove(&state->dts_agg_idr, agg->dtag_id);
+
+       kfree(agg);
+}
+
+static int dtrace_ecb_action_add(dtrace_ecb_t *ecb, dtrace_actdesc_t *desc)
+{
+       dtrace_action_t         *action, *last;
+       dtrace_difo_t           *dp = desc->dtad_difo;
+       uint32_t                size = 0, align = sizeof(uint8_t), mask;
+       uint16_t                format = 0;
+       dtrace_recdesc_t        *rec;
+       dtrace_state_t          *state = ecb->dte_state;
+       dtrace_optval_t         *opt = state->dts_options, nframes, strsize;
+       uint64_t                arg = desc->dtad_arg;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(ecb->dte_action == NULL || ecb->dte_action->dta_refcnt == 1);
+
+       if (DTRACEACT_ISAGG(desc->dtad_kind)) {
+               dtrace_action_t *act;
+
+               for (act = ecb->dte_action; act != NULL; act = act->dta_next) {
+                       if (act->dta_kind == DTRACEACT_COMMIT)
+                               return -EINVAL;
+
+                       if (act->dta_kind == DTRACEACT_SPECULATE)
+                               return -EINVAL;
+               }
+
+               action = dtrace_ecb_aggregation_create(ecb, desc);
+               if (action == NULL)
+                       return -EINVAL;
+       } else {
+               if (DTRACEACT_ISDESTRUCTIVE(desc->dtad_kind) ||
+                   (desc->dtad_kind == DTRACEACT_DIFEXPR &&
+                    dp != NULL && dp->dtdo_destructive))
+                       state->dts_destructive = 1;
+
+               switch (desc->dtad_kind) {
+               case DTRACEACT_PRINTF:
+               case DTRACEACT_PRINTA:
+               case DTRACEACT_SYSTEM:
+               case DTRACEACT_FREOPEN:
+                       if ((void *)(uintptr_t)arg == NULL) {
+                               ASSERT(desc->dtad_kind == DTRACEACT_PRINTA);
+       
+                               format = 0;
+                       } else {
+                               ASSERT((void *)(uintptr_t)arg != NULL);
+#ifdef FIXME
+                               ASSERT(arg > KERNELBASE);
+#endif
+
+                               format = dtrace_format_add(
+                                               state, (char *)(uintptr_t)arg);
+                       }
+
+               case DTRACEACT_LIBACT:
+               case DTRACEACT_DIFEXPR:
+                       if (dp == NULL)
+                               return -EINVAL;
+
+                       if ((size = dp->dtdo_rtype.dtdt_size) != 0)
+                               break;
+
+                       if (dp->dtdo_rtype.dtdt_kind == DIF_TYPE_STRING) {
+                               if (!(dp->dtdo_rtype.dtdt_flags & DIF_TF_BYREF))
+                                       return -EINVAL;
+
+                               size = opt[DTRACEOPT_STRSIZE];
+                       }
+
+                       break;
+
+               case DTRACEACT_STACK:
+                       if ((nframes = arg) == 0) {
+                               nframes = opt[DTRACEOPT_STACKFRAMES];
+
+                               ASSERT(nframes > 0);
+
+                               arg = nframes;
+                       }
+
+                       size = nframes * sizeof(uint64_t);
+                       break;
+
+               case DTRACEACT_JSTACK:
+                       if ((strsize = DTRACE_USTACK_STRSIZE(arg)) == 0)
+                               strsize = opt[DTRACEOPT_JSTACKSTRSIZE];
+
+                       if ((nframes = DTRACE_USTACK_NFRAMES(arg)) == 0)
+                               nframes = opt[DTRACEOPT_JSTACKFRAMES];
+
+                       arg = DTRACE_USTACK_ARG(nframes, strsize);
+
+               case DTRACEACT_USTACK:
+                       if (desc->dtad_kind != DTRACEACT_JSTACK &&
+                           (nframes = DTRACE_USTACK_NFRAMES(arg)) == 0) {
+                               strsize = DTRACE_USTACK_STRSIZE(arg);
+                               nframes = opt[DTRACEOPT_USTACKFRAMES];
+
+                               ASSERT(nframes > 0);
+
+                               arg = DTRACE_USTACK_ARG(nframes, strsize);
+                       }
+
+                       size = (nframes + 1) * sizeof(uint64_t);
+                       size += DTRACE_USTACK_STRSIZE(arg);
+                       size = P2ROUNDUP(size, (uint32_t)(sizeof(uintptr_t)));
+
+                       break;
+
+               case DTRACEACT_SYM:
+               case DTRACEACT_MOD:
+                       if (dp == NULL || ((size = dp->dtdo_rtype.dtdt_size) !=
+                                          sizeof(uint64_t)) ||
+                           (dp->dtdo_rtype.dtdt_flags & DIF_TF_BYREF))
+                               return -EINVAL;
+
+                       break;
+
+               case DTRACEACT_USYM:
+               case DTRACEACT_UMOD:
+               case DTRACEACT_UADDR:
+                       if (dp == NULL ||
+                           (dp->dtdo_rtype.dtdt_size != sizeof(uint64_t)) ||
+                           (dp->dtdo_rtype.dtdt_flags & DIF_TF_BYREF))
+                               return -EINVAL;
+
+                       size = 2 * sizeof(uint64_t);
+
+                       break;
+
+               case DTRACEACT_STOP:
+               case DTRACEACT_BREAKPOINT:
+               case DTRACEACT_PANIC:
+                       break;
+
+               case DTRACEACT_CHILL:
+               case DTRACEACT_DISCARD:
+               case DTRACEACT_RAISE:
+                       if (dp == NULL)
+                               return -EINVAL;
+
+                       break;
+
+               case DTRACEACT_EXIT:
+                       if (dp == NULL || (size = dp->dtdo_rtype.dtdt_size) !=
+                                          sizeof(int) ||
+                           (dp->dtdo_rtype.dtdt_flags & DIF_TF_BYREF))
+                               return -EINVAL;
+
+                       break;
+
+               case DTRACEACT_SPECULATE:
+                       if (ecb->dte_size > sizeof(dtrace_epid_t))
+                               return -EINVAL;
+
+                       if (dp == NULL)
+                               return -EINVAL;
+
+                       state->dts_speculates = 1;
+
+                       break;
+
+               case DTRACEACT_COMMIT: {
+                       dtrace_action_t *act = ecb->dte_action;
+
+                       for (; act != NULL; act = act->dta_next) {
+                               if (act->dta_kind == DTRACEACT_COMMIT)
+                                       return -EINVAL;
+                       }
+
+                       if (dp == NULL)
+                               return -EINVAL;
+
+                       break;
+               }
+
+               default:
+                       return -EINVAL;
+               }
+
+               if (size != 0 || desc->dtad_kind == DTRACEACT_SPECULATE) {
+                       dtrace_action_t *act = ecb->dte_action;
+
+                       for (; act != NULL; act = act->dta_next) {
+                               if (act->dta_kind == DTRACEACT_COMMIT)
+                                       return -EINVAL;
+                       }
+               }
+
+               action = kzalloc(sizeof(dtrace_action_t), GFP_KERNEL);
+               action->dta_rec.dtrd_size = size;
+       }
+
+       action->dta_refcnt = 1;
+       rec = &action->dta_rec;
+       size = rec->dtrd_size;
+
+       for (mask = sizeof(uint64_t) - 1; size != 0 && mask > 0; mask >>= 1) {
+               if (!(size & mask)) {
+                       align = mask + 1;
+
+                       break;
+               }
+       }
+
+       action->dta_kind = desc->dtad_kind;
+
+       if ((action->dta_difo = dp) != NULL)
+               dtrace_difo_hold(dp);
+
+       rec->dtrd_action = action->dta_kind;
+       rec->dtrd_arg = arg;
+       rec->dtrd_uarg = desc->dtad_uarg;
+       rec->dtrd_alignment = (uint16_t)align;
+       rec->dtrd_format = format;
+
+       if ((last = ecb->dte_action_last) != NULL) {
+               ASSERT(ecb->dte_action != NULL);
+
+               action->dta_prev = last;
+               last->dta_next = action;
+       } else {
+               ASSERT(ecb->dte_action == NULL);
+
+               ecb->dte_action = action;
+       }
+
+       ecb->dte_action_last = action;
+
+       return 0;
+}
+
+static void dtrace_ecb_action_remove(dtrace_ecb_t *ecb)
+{
+       dtrace_action_t *act = ecb->dte_action, *next;
+       dtrace_vstate_t *vstate = &ecb->dte_state->dts_vstate;
+       dtrace_difo_t   *dp;
+       uint16_t        format;
+
+       if (act != NULL && act->dta_refcnt > 1) {
+               ASSERT(act->dta_next == NULL || act->dta_next->dta_refcnt == 1);
+
+               act->dta_refcnt--;
+       } else {
+               for (; act != NULL; act = next) {
+                       next = act->dta_next;
+                       ASSERT(next != NULL || act == ecb->dte_action_last);
+                       ASSERT(act->dta_refcnt == 1);
+
+                       if ((format = act->dta_rec.dtrd_format) != 0)
+                               dtrace_format_remove(ecb->dte_state, format);
+
+                       if ((dp = act->dta_difo) != NULL)
+                               dtrace_difo_release(dp, vstate);
+
+                       if (DTRACEACT_ISAGG(act->dta_kind))
+                               dtrace_ecb_aggregation_destroy(ecb, act);
+                       else
+                               kfree(act);
+               }
+       }
+
+       ecb->dte_action = NULL;
+       ecb->dte_action_last = NULL;
+       ecb->dte_size = sizeof(dtrace_epid_t);
+}
+
+/*
+ * Disable the ECB by removing it from its probe.
+ */
+void dtrace_ecb_disable(dtrace_ecb_t *ecb)
+{
+       dtrace_ecb_t    *pecb, *prev = NULL;
+       dtrace_probe_t  *probe = ecb->dte_probe;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+
+       if (probe == NULL)
+               return;
+
+       for (pecb = probe->dtpr_ecb; pecb != NULL; pecb = pecb->dte_next) {
+               if (pecb == ecb)
+                       break;
+
+               prev = pecb;
+       }
+
+       ASSERT(pecb != NULL);
+
+       if (prev == NULL)
+               probe->dtpr_ecb = ecb->dte_next;
+       else
+               prev->dte_next = ecb->dte_next;
+
+       if (ecb == probe->dtpr_ecb_last) {
+               ASSERT(ecb->dte_next == NULL);
+               probe->dtpr_ecb_last = prev;
+       }
+
+       /*
+        * The ECB has been disconnected from the probe; now sync to assure
+        * that all CPUs have seen the change before returning.
+        */
+       dtrace_sync();
+
+       if (probe->dtpr_ecb == NULL) {
+               /*
+                * That was the last ECB on the probe; clear the predicate
+                * cache ID for the probe, disable it and sync one more time
+                * to assure that we'll never hit it again.
+                */
+               dtrace_provider_t       *prov = probe->dtpr_provider;
+
+               ASSERT(ecb->dte_next == NULL);
+               ASSERT(probe->dtpr_ecb_last == NULL);
+
+               probe->dtpr_predcache = DTRACE_CACHEIDNONE;
+               prov->dtpv_pops.dtps_disable(prov->dtpv_arg,
+                                            probe->dtpr_id, probe->dtpr_arg);
+
+               dtrace_sync();
+       } else {
+               /*
+                * There is at least one ECB remaining on the probe.  If there
+                * is _exactly_ one, set the probe's predicate cache ID to be
+                * the predicate cache ID of the remaining ECB.
+                */
+               ASSERT(probe->dtpr_ecb_last != NULL);
+               ASSERT(probe->dtpr_predcache == DTRACE_CACHEIDNONE);
+
+               if (probe->dtpr_ecb == probe->dtpr_ecb_last) {
+                       dtrace_predicate_t      *p =
+                                               probe->dtpr_ecb->dte_predicate;
+
+                       ASSERT(probe->dtpr_ecb->dte_next == NULL);
+
+                       if (p != NULL)
+                               probe->dtpr_predcache = p->dtp_cacheid;
+               }
+
+               ecb->dte_next = NULL;
+       }
+}
+
+static dtrace_ecb_t *dtrace_ecb_add(dtrace_state_t *state,
+                                   dtrace_probe_t *probe)
+{
+       dtrace_ecb_t    *ecb;
+       dtrace_epid_t   epid;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+
+       ecb = kzalloc(sizeof(dtrace_ecb_t), GFP_KERNEL);
+       ecb->dte_predicate = NULL;
+       ecb->dte_probe = probe;
+       ecb->dte_size = ecb->dte_needed = sizeof(dtrace_epid_t);
+       ecb->dte_alignment = sizeof(dtrace_epid_t);
+
+       epid = state->dts_epid++;
+
+       if (epid - 1 >= state->dts_necbs) {
+               dtrace_ecb_t    **oecbs = state->dts_ecbs, **ecbs;
+               int             necbs = state->dts_necbs << 1;
+
+               ASSERT(epid == state->dts_necbs + 1);
+
+               if (necbs == 0) {
+                       ASSERT(oecbs == NULL);
+
+                       necbs = 1;
+               }
+
+               ecbs = kcalloc(necbs, sizeof(*ecbs), GFP_KERNEL);
+               if (oecbs != NULL)
+                       memcpy(ecbs, oecbs, state->dts_necbs * sizeof(*ecbs));
+
+               dtrace_membar_producer();
+
+               state->dts_ecbs = ecbs;
+
+               if (oecbs != NULL) {
+                       if (state->dts_activity != DTRACE_ACTIVITY_INACTIVE)
+                               dtrace_sync();
+
+                       kfree(oecbs);
+               }
+
+               dtrace_membar_producer();
+
+               state->dts_necbs = necbs;
+       }
+
+       ecb->dte_state = state;
+
+       ASSERT(state->dts_ecbs[epid - 1] == NULL);
+
+       dtrace_membar_producer();
+
+       state->dts_ecbs[(ecb->dte_epid = epid) - 1] = ecb;
+
+printk(KERN_INFO "ecb_add: ECB %u for probe ID %u\n", epid, probe ? probe->dtpr_id : 0xffff);
+       return ecb;
+}
+
+static dtrace_ecb_t *dtrace_ecb_create(dtrace_state_t *state,
+                                      dtrace_probe_t *probe,
+                                      dtrace_enabling_t *enab)
+{
+       dtrace_ecb_t            *ecb;
+       dtrace_predicate_t      *pred;
+       dtrace_actdesc_t        *act;
+       dtrace_provider_t       *prov;
+       dtrace_ecbdesc_t        *desc = enab->dten_current;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(state != NULL);
+
+       ecb = dtrace_ecb_add(state, probe);
+       ecb->dte_uarg = desc->dted_uarg;
+
+       if ((pred = desc->dted_pred.dtpdd_predicate) != NULL) {
+               dtrace_predicate_hold(pred);
+               ecb->dte_predicate = pred;
+       }
+
+       if (probe != NULL) {
+               prov = probe->dtpr_provider;
+
+               if (!(state->dts_cred.dcr_visible & DTRACE_CRV_ALLPROC) &&
+                   (prov->dtpv_priv.dtpp_flags & DTRACE_PRIV_USER))
+                       ecb->dte_cond |= DTRACE_COND_OWNER;
+
+               if (!(state->dts_cred.dcr_visible & DTRACE_CRV_KERNEL) &&
+                   (prov->dtpv_priv.dtpp_flags & DTRACE_PRIV_KERNEL))
+                       ecb->dte_cond |= DTRACE_COND_USERMODE;
+       }
+
+       if (dtrace_ecb_create_cache != NULL) {
+               dtrace_ecb_t    *cached = dtrace_ecb_create_cache;
+               dtrace_action_t *act = cached->dte_action;
+
+               if (act != NULL) {
+                       ASSERT(act->dta_refcnt > 0);
+
+                       act->dta_refcnt++;
+                       ecb->dte_action = act;
+                       ecb->dte_action_last = cached->dte_action_last;
+                       ecb->dte_needed = cached->dte_needed;
+                       ecb->dte_size = cached->dte_size;
+                       ecb->dte_alignment = cached->dte_alignment;
+               }
+
+               return ecb;
+       }
+
+       for (act = desc->dted_action; act != NULL; act = act->dtad_next) {
+               if ((enab->dten_error = dtrace_ecb_action_add(ecb, act)) != 0) {
+                       dtrace_ecb_destroy(ecb);
+                       return NULL;
+               }
+       }
+
+       dtrace_ecb_resize(ecb);
+
+       return (dtrace_ecb_create_cache = ecb);
+}
+
+int dtrace_ecb_create_enable(dtrace_probe_t *probe, void *arg)
+{
+       dtrace_ecb_t            *ecb;
+       dtrace_enabling_t       *enab = arg;
+       dtrace_state_t          *state = enab->dten_vstate->dtvs_state;
+
+       ASSERT(state != NULL);
+
+       if (probe != NULL && probe->dtpr_gen < enab->dten_probegen)
+               return DTRACE_MATCH_NEXT;
+
+       if ((ecb = dtrace_ecb_create(state, probe, enab)) == NULL)
+               return DTRACE_MATCH_DONE;
+
+       if (dtrace_ecb_enable(ecb) < 0)
+               return DTRACE_MATCH_FAIL;
+
+       return DTRACE_MATCH_NEXT;
+}
+
+void dtrace_ecb_destroy(dtrace_ecb_t *ecb)
+{
+       dtrace_state_t          *state = ecb->dte_state;
+       dtrace_vstate_t         *vstate = &state->dts_vstate;
+       dtrace_predicate_t      *pred;
+       dtrace_epid_t           epid = ecb->dte_epid;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(ecb->dte_next == NULL);
+       ASSERT(ecb->dte_probe == NULL || ecb->dte_probe->dtpr_ecb != ecb);
+
+       if ((pred = ecb->dte_predicate) != NULL)
+               dtrace_predicate_release(pred, vstate);
+
+       dtrace_ecb_action_remove(ecb);
+
+       ASSERT(state->dts_ecbs[epid - 1] == ecb);
+       state->dts_ecbs[epid - 1] = NULL;
+
+       kfree(ecb);
+}
+
+void dtrace_ecb_resize(dtrace_ecb_t *ecb)
+{
+       uint32_t        maxalign = sizeof(dtrace_epid_t);
+       uint32_t        align = sizeof(uint8_t), offs, diff;
+       dtrace_action_t *act;
+       int             wastuple = 0;
+       uint32_t        aggbase = UINT32_MAX;
+       dtrace_state_t  *state = ecb->dte_state;
+
+       /*
+        * If we record anything, we always record the epid.  (And we always
+        * record it first.)
+        */
+       offs = sizeof(dtrace_epid_t);
+       ecb->dte_size = ecb->dte_needed = sizeof(dtrace_epid_t);
+
+       for (act = ecb->dte_action; act != NULL; act = act->dta_next) {
+               dtrace_recdesc_t        *rec = &act->dta_rec;
+
+               if ((align = rec->dtrd_alignment) > maxalign)
+                       maxalign = align;
+
+               if (!wastuple && act->dta_intuple) {
+                       /*
+                        * This is the first record in a tuple.  Align the
+                        * offset to be at offset 4 in an 8-byte aligned
+                        * block.
+                        */
+                       diff = offs + sizeof(dtrace_aggid_t);
+
+                       if ((diff = (diff & (sizeof(uint64_t) - 1))))
+                               offs += sizeof(uint64_t) - diff;
+
+                       aggbase = offs - sizeof(dtrace_aggid_t);
+                       ASSERT(!(aggbase & (sizeof(uint64_t) - 1)));
+               }
+
+               if (rec->dtrd_size != 0 && (diff = (offs & (align - 1)))) {
+                       /*
+                        * The current offset is not properly aligned; align it.
+                        */
+                       offs += align - diff;
+               }
+
+               rec->dtrd_offset = offs;
+
+               if (offs + rec->dtrd_size > ecb->dte_needed) {
+                       ecb->dte_needed = offs + rec->dtrd_size;
+
+                       if (ecb->dte_needed > state->dts_needed)
+                               state->dts_needed = ecb->dte_needed;
+               }
+
+               if (DTRACEACT_ISAGG(act->dta_kind)) {
+                       dtrace_aggregation_t    *agg =
+                                               (dtrace_aggregation_t *)act;
+                       dtrace_action_t         *first = agg->dtag_first,
+                                               *prev;
+
+                       ASSERT(rec->dtrd_size != 0 && first != NULL);
+                       ASSERT(wastuple);
+                       ASSERT(aggbase != UINT32_MAX);
+
+                       agg->dtag_base = aggbase;
+
+                       while ((prev = first->dta_prev) != NULL &&
+                              DTRACEACT_ISAGG(prev->dta_kind)) {
+                               agg = (dtrace_aggregation_t *)prev;
+                               first = agg->dtag_first;
+                       }
+
+                       if (prev != NULL) {
+                               offs = prev->dta_rec.dtrd_offset +
+                               prev->dta_rec.dtrd_size;
+                       } else
+                               offs = sizeof(dtrace_epid_t);
+
+                       wastuple = 0;
+               } else {
+                       if (!act->dta_intuple)
+                               ecb->dte_size = offs + rec->dtrd_size;
+
+                       offs += rec->dtrd_size;
+               }
+
+               wastuple = act->dta_intuple;
+       }
+
+       if ((act = ecb->dte_action) != NULL &&
+           !(act->dta_kind == DTRACEACT_SPECULATE && act->dta_next == NULL) &&
+           ecb->dte_size == sizeof(dtrace_epid_t)) {
+               /*
+                * If the size is still sizeof(dtrace_epid_t), then all
+                * actions store no data; set the size to 0.
+                */
+               ecb->dte_alignment = maxalign;
+               ecb->dte_size = 0;
+
+               /*
+                * If the needed space is still sizeof(dtrace_epid_t), then
+                * all actions need no additional space; set the needed
+                * size to 0.
+                */
+               if (ecb->dte_needed == sizeof(dtrace_epid_t))
+                       ecb->dte_needed = 0;
+
+               return;
+       }
+
+       /*
+        * Set our alignment, and make sure that the dte_size and dte_needed
+        * are aligned to the size of an EPID.
+        */
+       ecb->dte_alignment = maxalign;
+       ecb->dte_size = (ecb->dte_size + (sizeof(dtrace_epid_t) - 1)) &
+                       ~(sizeof(dtrace_epid_t) - 1);
+       ecb->dte_needed = (ecb->dte_needed + (sizeof(dtrace_epid_t) - 1)) &
+                         ~(sizeof(dtrace_epid_t) - 1);
+       ASSERT(ecb->dte_size <= ecb->dte_needed);
+}
+
+int dtrace_ecb_enable(dtrace_ecb_t *ecb)
+{
+       dtrace_probe_t  *probe = ecb->dte_probe;
+
+       ASSERT(mutex_is_locked(&cpu_lock));
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(ecb->dte_next == NULL);
+
+       if (probe == NULL)
+               return 0;
+
+       if (probe->dtpr_ecb == NULL) {
+               dtrace_provider_t       *prov = probe->dtpr_provider;
+
+               probe->dtpr_ecb = probe->dtpr_ecb_last = ecb;
+
+
+               if (ecb->dte_predicate != NULL)
+                       probe->dtpr_predcache = ecb->dte_predicate->dtp_cacheid;
+
+               return prov->dtpv_pops.dtps_enable(prov->dtpv_arg,
+                                                  probe->dtpr_id,
+                                                  probe->dtpr_arg);
+       } else {
+               ASSERT(probe->dtpr_ecb_last != NULL);
+
+               probe->dtpr_ecb_last->dte_next = ecb;
+               probe->dtpr_ecb_last = ecb;
+               probe->dtpr_predcache = 0;
+
+               dtrace_sync();
+
+               return 0;
+       }
+}
+
+dtrace_ecb_t *dtrace_epid2ecb(dtrace_state_t *state, dtrace_epid_t id)
+{
+       dtrace_ecb_t *ecb;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+
+       if (id == 0 || id > state->dts_necbs)
+               return NULL;
+
+       ASSERT(state->dts_necbs > 0 && state->dts_ecbs != NULL);
+       ecb = state->dts_ecbs[id - 1];
+       ASSERT(ecb == NULL || ecb->dte_epid == id);
+
+       return ecb;
+}
+
+dtrace_aggregation_t *dtrace_aggid2agg(dtrace_state_t *state,
+                                      dtrace_aggid_t id)
+{
+       ASSERT(mutex_is_locked(&dtrace_lock));
+
+       return idr_find(&state->dts_agg_idr, id);
+}
diff --git a/dtrace/dtrace_enable.c b/dtrace/dtrace_enable.c
new file mode 100644 (file)
index 0000000..38355c2
--- /dev/null
@@ -0,0 +1,414 @@
+/*
+ * FILE:       dtrace_enable.c
+ * DESCRIPTION:        Dynamic Tracing: enabling functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/kernel.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+
+#include "dtrace.h"
+
+size_t                 dtrace_retain_max = 1024;
+dtrace_enabling_t      *dtrace_retained;
+dtrace_genid_t         dtrace_retained_gen;
+
+dtrace_enabling_t *dtrace_enabling_create(dtrace_vstate_t *vstate)
+{
+       dtrace_enabling_t       *enab;
+
+       enab = kzalloc(sizeof (dtrace_enabling_t), GFP_KERNEL);
+       enab->dten_vstate = vstate;
+
+       return enab;
+}
+
+void dtrace_enabling_add(dtrace_enabling_t *enab, dtrace_ecbdesc_t *ecb)
+{
+       dtrace_ecbdesc_t        **ndesc;
+       size_t                  osize, nsize;
+
+       /*
+        * We can't add to enablings after we've enabled them, or after we've
+        * retained them.
+        */
+       ASSERT(enab->dten_probegen == 0);
+       ASSERT(enab->dten_next == NULL && enab->dten_prev == NULL);
+
+       if (enab->dten_ndesc < enab->dten_maxdesc) {
+               enab->dten_desc[enab->dten_ndesc++] = ecb;
+               return;
+       }
+
+       osize = enab->dten_maxdesc * sizeof (dtrace_enabling_t *);
+
+       if (enab->dten_maxdesc == 0)
+               enab->dten_maxdesc = 1;
+       else
+               enab->dten_maxdesc <<= 1;
+
+       ASSERT(enab->dten_ndesc < enab->dten_maxdesc);
+
+       nsize = enab->dten_maxdesc * sizeof (dtrace_enabling_t *);
+       ndesc = kzalloc(nsize, GFP_KERNEL);
+       memcpy(ndesc, enab->dten_desc, osize);
+       kfree(enab->dten_desc);
+
+       enab->dten_desc = ndesc;
+       enab->dten_desc[enab->dten_ndesc++] = ecb;
+}
+
+static void dtrace_enabling_addlike(dtrace_enabling_t *enab,
+                                   dtrace_ecbdesc_t *ecb,
+                                   dtrace_probedesc_t *pd)
+{
+       dtrace_ecbdesc_t *new;
+       dtrace_predicate_t      *pred;
+       dtrace_actdesc_t        *act;
+
+       /*
+        * We're going to create a new ECB description that matches the
+        * specified ECB in every way, but has the specified probe description.
+        */
+       new = kzalloc(sizeof (dtrace_ecbdesc_t), GFP_KERNEL);
+
+       if ((pred = ecb->dted_pred.dtpdd_predicate) != NULL)
+               dtrace_predicate_hold(pred);
+
+       for (act = ecb->dted_action; act != NULL; act = act->dtad_next)
+               dtrace_actdesc_hold(act);
+
+       new->dted_action = ecb->dted_action;
+       new->dted_pred = ecb->dted_pred;
+       new->dted_probe = *pd;
+       new->dted_uarg = ecb->dted_uarg;
+
+       dtrace_enabling_add(enab, new);
+}
+
+void dtrace_enabling_dump(dtrace_enabling_t *enab)
+{
+       int     i;
+
+       for (i = 0; i < enab->dten_ndesc; i++) {
+               dtrace_probedesc_t      *desc =
+                                       &enab->dten_desc[i]->dted_probe;
+
+               pr_info("enabling probe %d (%s:%s:%s:%s)",
+                       i, desc->dtpd_provider, desc->dtpd_mod,
+                       desc->dtpd_func, desc->dtpd_name);
+       }
+}
+
+void dtrace_enabling_destroy(dtrace_enabling_t *enab)
+{
+       int                     i;
+       dtrace_ecbdesc_t        *ep;
+       dtrace_vstate_t         *vstate = enab->dten_vstate;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+
+       for (i = 0; i < enab->dten_ndesc; i++) {
+               dtrace_actdesc_t        *act, *next;
+               dtrace_predicate_t      *pred;
+
+               ep = enab->dten_desc[i];
+
+               if ((pred = ep->dted_pred.dtpdd_predicate) != NULL)
+                       dtrace_predicate_release(pred, vstate);
+
+               for (act = ep->dted_action; act != NULL; act = next) {
+                       next = act->dtad_next;
+                       dtrace_actdesc_release(act, vstate);
+               }
+
+               kfree(ep);
+       }
+
+       kfree(enab->dten_desc);
+
+       /*
+        * If this was a retained enabling, decrement the dts_nretained count
+        * and remove it from the dtrace_retained list.
+        */
+       if (enab->dten_prev != NULL || enab->dten_next != NULL ||
+           dtrace_retained == enab) {
+               ASSERT(enab->dten_vstate->dtvs_state != NULL);
+               ASSERT(enab->dten_vstate->dtvs_state->dts_nretained > 0);
+               enab->dten_vstate->dtvs_state->dts_nretained--;
+               dtrace_retained_gen++;
+       }
+
+       if (enab->dten_prev == NULL) {
+               if (dtrace_retained == enab) {
+                       dtrace_retained = enab->dten_next;
+
+                       if (dtrace_retained != NULL)
+                               dtrace_retained->dten_prev = NULL;
+               }
+       } else {
+               ASSERT(enab != dtrace_retained);
+               ASSERT(dtrace_retained != NULL);
+               enab->dten_prev->dten_next = enab->dten_next;
+       }
+
+       if (enab->dten_next != NULL) {
+               ASSERT(dtrace_retained != NULL);
+               enab->dten_next->dten_prev = enab->dten_prev;
+       }
+
+       kfree(enab);
+}
+
+int dtrace_enabling_retain(dtrace_enabling_t *enab)
+{
+       dtrace_state_t  *state;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(enab->dten_next == NULL && enab->dten_prev == NULL);
+       ASSERT(enab->dten_vstate != NULL);
+
+       state = enab->dten_vstate->dtvs_state;
+       ASSERT(state != NULL);
+
+       /*
+        * We only allow each state to retain dtrace_retain_max enablings.
+        */
+       if (state->dts_nretained >= dtrace_retain_max)
+               return -ENOSPC;
+
+       state->dts_nretained++;
+       dtrace_retained_gen++;
+
+       if (dtrace_retained == NULL) {
+               dtrace_retained = enab;
+               return 0;
+       }
+
+       enab->dten_next = dtrace_retained;
+       dtrace_retained->dten_prev = enab;
+       dtrace_retained = enab;
+
+       return 0;
+}
+
+int dtrace_enabling_replicate(dtrace_state_t *state, dtrace_probedesc_t *match,
+                             dtrace_probedesc_t *create)
+{
+       dtrace_enabling_t       *new, *enab;
+       int                     found = 0, err = -ENOENT;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(strlen(match->dtpd_provider) < DTRACE_PROVNAMELEN);
+       ASSERT(strlen(match->dtpd_mod) < DTRACE_MODNAMELEN);
+       ASSERT(strlen(match->dtpd_func) < DTRACE_FUNCNAMELEN);
+       ASSERT(strlen(match->dtpd_name) < DTRACE_NAMELEN);
+
+       new = dtrace_enabling_create(&state->dts_vstate);
+
+       /*
+        * Iterate over all retained enablings, looking for enablings that
+        * match the specified state.
+        */
+       for (enab = dtrace_retained; enab != NULL; enab = enab->dten_next) {
+               int     i;
+
+               /*
+                * dtvs_state can only be NULL for helper enablings -- and
+                * helper enablings can't be retained.
+                */
+               ASSERT(enab->dten_vstate->dtvs_state != NULL);
+
+               if (enab->dten_vstate->dtvs_state != state)
+                       continue;
+
+               /*
+                * Now iterate over each probe description; we're looking for
+                * an exact match to the specified probe description.
+                */
+               for (i = 0; i < enab->dten_ndesc; i++) {
+                       dtrace_ecbdesc_t        *ep = enab->dten_desc[i];
+                       dtrace_probedesc_t      *pd = &ep->dted_probe;
+
+                       if (strcmp(pd->dtpd_provider, match->dtpd_provider))
+                               continue;
+
+                       if (strcmp(pd->dtpd_mod, match->dtpd_mod))
+                               continue;
+
+                       if (strcmp(pd->dtpd_func, match->dtpd_func))
+                               continue;
+
+                       if (strcmp(pd->dtpd_name, match->dtpd_name))
+                               continue;
+
+                       /*
+                        * We have a winning probe!  Add it to our growing
+                        * enabling.
+                        */
+                       found = 1;
+                       dtrace_enabling_addlike(new, ep, create);
+               }
+       }
+
+       if (!found || (err = dtrace_enabling_retain(new)) != 0) {
+               dtrace_enabling_destroy(new);
+               return err;
+       }
+
+       return 0;
+}
+
+void dtrace_enabling_retract(dtrace_state_t *state)
+{
+       dtrace_enabling_t       *enab, *next;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+
+       /*
+        * Iterate over all retained enablings, destroy the enablings retained
+        * for the specified state.
+        */
+       for (enab = dtrace_retained; enab != NULL; enab = next) {
+               next = enab->dten_next;
+
+               /*
+                * dtvs_state can only be NULL for helper enablings, and helper
+                * enablings can't be retained.
+                */
+               ASSERT(enab->dten_vstate->dtvs_state != NULL);
+
+               if (enab->dten_vstate->dtvs_state == state) {
+                       ASSERT(state->dts_nretained > 0);
+                       dtrace_enabling_destroy(enab);
+               }
+       }
+
+       ASSERT(state->dts_nretained == 0);
+}
+
+int dtrace_enabling_match(dtrace_enabling_t *enab, int *nmatched)
+{
+       int     i;
+       int     total_matched = 0, matched = 0;
+
+       for (i = 0; i < enab->dten_ndesc; i++) {
+               dtrace_ecbdesc_t        *ep = enab->dten_desc[i];
+
+               enab->dten_current = ep;
+               enab->dten_error = 0;
+
+               if ((matched = dtrace_probe_enable(&ep->dted_probe, enab)) < 0)
+                       return -EBUSY;
+
+               total_matched += matched;
+
+               if (enab->dten_error != 0) {
+                       if (nmatched == NULL)
+                               pr_warning("dtrace_enabling_match() error on %p: %d\n", (void *)ep, enab->dten_error);
+
+                       return enab->dten_error;
+               }
+       }
+
+       enab->dten_probegen = dtrace_probegen;
+       if (nmatched != NULL)
+               *nmatched = total_matched;
+
+       return 0;
+}
+
+void dtrace_enabling_matchall(void)
+{
+       dtrace_enabling_t       *enab;
+
+       mutex_lock(&cpu_lock);
+       mutex_lock(&dtrace_lock);
+
+       for (enab = dtrace_retained; enab != NULL; enab = enab->dten_next)
+               (void) dtrace_enabling_match(enab, NULL);
+
+       mutex_unlock(&dtrace_lock);
+       mutex_unlock(&cpu_lock);
+}
+
+/*
+ * If an enabling is to be enabled without having matched probes (that is, if
+ * dtrace_state_go() is to be called on the underlying dtrace_state_t), the
+ * enabling must be _primed_ by creating an ECB for every ECB description.
+ * This must be done to assure that we know the number of speculations, the
+ * number of aggregations, the minimum buffer size needed, etc. before we
+ * transition out of DTRACE_ACTIVITY_INACTIVE.  To do this without actually
+ * enabling any probes, we create ECBs for every ECB decription, but with a
+ * NULL probe -- which is exactly what this function does.
+ */
+void dtrace_enabling_prime(dtrace_state_t *state)
+{
+       dtrace_enabling_t       *enab;
+       int                     i;
+
+       for (enab = dtrace_retained; enab != NULL; enab = enab->dten_next) {
+               ASSERT(enab->dten_vstate->dtvs_state != NULL);
+
+               if (enab->dten_vstate->dtvs_state != state)
+                       continue;
+
+               /*
+                * We don't want to prime an enabling more than once, lest
+                * we allow a malicious user to induce resource exhaustion.
+                * (The ECBs that result from priming an enabling aren't
+                * leaked -- but they also aren't deallocated until the
+                * consumer state is destroyed.)
+                */
+               if (enab->dten_primed)
+                       continue;
+
+               for (i = 0; i < enab->dten_ndesc; i++) {
+                       enab->dten_current = enab->dten_desc[i];
+                       dtrace_probe_enable(NULL, enab);
+               }
+
+               enab->dten_primed = 1;
+       }
+}
+
+void dtrace_enabling_provide(dtrace_provider_t *prv)
+{
+       int             all = 0;
+       dtrace_genid_t  gen;
+
+       if (prv == NULL) {
+               all = 1;
+               prv = dtrace_provider;
+       }
+
+       do {
+               dtrace_enabling_t       *enab;
+               void                    *parg = prv->dtpv_arg;
+
+retry:
+               gen = dtrace_retained_gen;
+               for (enab = dtrace_retained; enab != NULL;
+                    enab = enab->dten_next) {
+                       int     i;
+
+                       for (i = 0; i < enab->dten_ndesc; i++) {
+                               dtrace_probedesc_t      desc;
+
+                               desc = enab->dten_desc[i]->dted_probe;
+                               mutex_unlock(&dtrace_lock);
+                               prv->dtpv_pops.dtps_provide(parg, &desc);
+                               mutex_lock(&dtrace_lock);
+
+                               if (gen != dtrace_retained_gen)
+                                       goto retry;
+                       }
+               }
+       } while (all && (prv = prv->dtpv_next) != NULL);
+
+       mutex_unlock(&dtrace_lock);
+       dtrace_probe_provide(NULL, all ? NULL : prv);
+       mutex_lock(&dtrace_lock);
+}
diff --git a/dtrace/dtrace_fmt.c b/dtrace/dtrace_fmt.c
new file mode 100644 (file)
index 0000000..a4bef75
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * FILE:       dtrace_fmt.c
+ * DESCRIPTION:        Dynamic Tracing: format functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/slab.h>
+
+#include "dtrace.h"
+
+uint16_t dtrace_format_add(dtrace_state_t *state, char *str)
+{
+       char            *fmt, **new;
+       uint16_t        ndx;
+
+       fmt = dtrace_strdup(str);
+
+       for (ndx = 0; ndx < state->dts_nformats; ndx++) {
+               if (state->dts_formats[ndx] == NULL) {
+                       state->dts_formats[ndx] = fmt;
+
+                       return ndx + 1;
+               }
+       }
+
+       if (state->dts_nformats == UINT16_MAX) {
+               kfree(fmt);
+
+               return 0;
+       }
+
+       ndx = state->dts_nformats++;
+       new = kmalloc((ndx + 1) * sizeof (char *), GFP_KERNEL);
+
+       if (state->dts_formats != NULL) {
+               ASSERT(ndx != 0);
+               memcpy(new, state->dts_formats, ndx * sizeof (char *));
+               kfree(state->dts_formats);
+       }
+
+       state->dts_formats = new;
+       state->dts_formats[ndx] = fmt;
+
+       return ndx + 1;
+}
+
+void dtrace_format_remove(dtrace_state_t *state, uint16_t format)
+{
+       char    *fmt;
+
+       ASSERT(state->dts_formats != NULL);
+       ASSERT(format <= state->dts_nformats);
+       ASSERT(state->dts_formats[format - 1] != NULL);
+
+       fmt = state->dts_formats[format - 1];
+       kfree(fmt);
+       state->dts_formats[format - 1] = NULL;
+}
+
+void dtrace_format_destroy(dtrace_state_t *state)
+{
+       int     i;
+
+       if (state->dts_nformats == 0) {
+               ASSERT(state->dts_formats == NULL);
+               return;
+       }
+
+       ASSERT(state->dts_formats != NULL);
+
+       for (i = 0; i < state->dts_nformats; i++) {
+               char    *fmt = state->dts_formats[i];
+
+               if (fmt == NULL)
+                       continue;
+
+               kfree(fmt);
+       }
+
+       kfree(state->dts_formats);
+       state->dts_nformats = 0;
+       state->dts_formats = NULL;
+}
diff --git a/dtrace/dtrace_hash.c b/dtrace/dtrace_hash.c
new file mode 100644 (file)
index 0000000..9becd58
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * FILE:       dtrace_hash.c
+ * DESCRIPTION:        Dynamic Tracing: probe hashing functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/slab.h>
+
+#include "dtrace.h"
+
+#define DTRACE_HASHSTR(hash, probe)    \
+       dtrace_hash_str(*((char **)((uintptr_t)(probe) + (hash)->dth_stroffs)))
+#define DTRACE_HASHEQ(hash, lhs, rhs)  \
+       (strcmp(*((char **)((uintptr_t)(lhs) + (hash)->dth_stroffs)), \
+               *((char **)((uintptr_t)(rhs) + (hash)->dth_stroffs))) == 0)
+
+static uint_t dtrace_hash_str(char *p)
+{
+       uint_t  g;
+       uint_t  hval = 0;
+
+       while (*p) {
+               hval = (hval << 4) + *p++;
+               if ((g = (hval & 0xf0000000)) != 0)
+                       hval ^= g >> 24;
+
+               hval &= ~g;
+       }
+
+       return hval;
+}
+
+dtrace_hash_t *dtrace_hash_create(uintptr_t stroffs, uintptr_t nextoffs,
+                                 uintptr_t prevoffs)
+{
+       dtrace_hash_t   *hash = kzalloc(sizeof (dtrace_hash_t), GFP_KERNEL);
+
+       hash->dth_stroffs = stroffs;
+       hash->dth_nextoffs = nextoffs;
+       hash->dth_prevoffs = prevoffs;
+
+       hash->dth_size = 1;
+       hash->dth_mask = hash->dth_size - 1;
+
+       hash->dth_tab = kzalloc(hash->dth_size *
+                               sizeof (dtrace_hashbucket_t *), GFP_KERNEL);
+
+       return hash;
+}
+
+static void dtrace_hash_resize(dtrace_hash_t *hash)
+{
+       int                     size = hash->dth_size, i, ndx;
+       int                     new_size = hash->dth_size << 1;
+       int                     new_mask = new_size - 1;
+       dtrace_hashbucket_t     **new_tab, *bucket, *next;
+
+       ASSERT((new_size & new_mask) == 0);
+
+       new_tab = kzalloc(new_size * sizeof (void *), GFP_KERNEL);
+
+       for (i = 0; i < size; i++) {
+               for (bucket = hash->dth_tab[i]; bucket != NULL;
+                    bucket = next) {
+                       dtrace_probe_t *probe = bucket->dthb_chain;
+
+                       ASSERT(probe != NULL);
+                       ndx = DTRACE_HASHSTR(hash, probe) & new_mask;
+
+                       next = bucket->dthb_next;
+                       bucket->dthb_next = new_tab[ndx];
+                       new_tab[ndx] = bucket;
+               }
+       }
+
+       kfree(hash->dth_tab);
+       hash->dth_tab = new_tab;
+       hash->dth_size = new_size;
+       hash->dth_mask = new_mask;
+}
+
+void dtrace_hash_add(dtrace_hash_t *hash, dtrace_probe_t *new)
+{
+       int                     hashval = DTRACE_HASHSTR(hash, new);
+       int                     ndx = hashval & hash->dth_mask;
+       dtrace_hashbucket_t     *bucket = hash->dth_tab[ndx];
+       dtrace_probe_t          **nextp, **prevp;
+
+       for (; bucket != NULL; bucket = bucket->dthb_next) {
+               if (DTRACE_HASHEQ(hash, bucket->dthb_chain, new))
+                       goto add;
+       }
+
+       if ((hash->dth_nbuckets >> 1) > hash->dth_size) {
+               dtrace_hash_resize(hash);
+               dtrace_hash_add(hash, new);
+               return;
+       }
+
+       bucket = kzalloc(sizeof (dtrace_hashbucket_t), GFP_KERNEL);
+       bucket->dthb_next = hash->dth_tab[ndx];
+       hash->dth_tab[ndx] = bucket;
+       hash->dth_nbuckets++;
+
+add:
+       nextp = DTRACE_HASHNEXT(hash, new);
+
+       ASSERT(*nextp == NULL && *(DTRACE_HASHPREV(hash, new)) == NULL);
+
+       *nextp = bucket->dthb_chain;
+
+       if (bucket->dthb_chain != NULL) {
+               prevp = DTRACE_HASHPREV(hash, bucket->dthb_chain);
+
+               ASSERT(*prevp == NULL);
+
+               *prevp = new;
+       }
+
+       bucket->dthb_chain = new;
+       bucket->dthb_len++;
+}
+
+dtrace_probe_t *dtrace_hash_lookup(dtrace_hash_t *hash,
+                                  dtrace_probe_t *template)
+{
+       int                     hashval = DTRACE_HASHSTR(hash, template);
+       int                     ndx = hashval & hash->dth_mask;
+       dtrace_hashbucket_t     *bucket = hash->dth_tab[ndx];
+
+       for (; bucket != NULL; bucket = bucket->dthb_next) {
+               if (DTRACE_HASHEQ(hash, bucket->dthb_chain, template))
+                       return bucket->dthb_chain;
+       }
+
+       return NULL;
+}
+
+int dtrace_hash_collisions(dtrace_hash_t *hash, dtrace_probe_t *template)
+{
+       int                     hashval = DTRACE_HASHSTR(hash, template);
+       int                     ndx = hashval & hash->dth_mask;
+       dtrace_hashbucket_t     *bucket = hash->dth_tab[ndx];
+
+       for (; bucket != NULL; bucket = bucket->dthb_next) {
+               if (DTRACE_HASHEQ(hash, bucket->dthb_chain, template))
+                       return bucket->dthb_len;
+       }
+
+       return 0;
+}
+
+void dtrace_hash_remove(dtrace_hash_t *hash, dtrace_probe_t *probe)
+{
+       int                     ndx = DTRACE_HASHSTR(hash, probe) &
+                                     hash->dth_mask;
+       dtrace_hashbucket_t     *bucket = hash->dth_tab[ndx];
+       dtrace_probe_t          **prevp = DTRACE_HASHPREV(hash, probe);
+       dtrace_probe_t          **nextp = DTRACE_HASHNEXT(hash, probe);
+
+       for (; bucket != NULL; bucket = bucket->dthb_next) {
+               if (DTRACE_HASHEQ(hash, bucket->dthb_chain, probe))
+                       break;
+       }
+
+       ASSERT(bucket != NULL);
+
+       if (*prevp == NULL) {
+               if (*nextp == NULL) {
+                       /*
+                        * This is the last probe in the bucket; we can remove
+                        * the bucket.
+                        */
+                       dtrace_hashbucket_t     *b = hash->dth_tab[ndx];
+
+                       ASSERT(bucket->dthb_chain == probe);
+                       ASSERT(b != NULL);
+
+                       if (b == bucket)
+                               hash->dth_tab[ndx] = bucket->dthb_next;
+                       else {
+                               while (b->dthb_next != bucket)
+                                       b = b->dthb_next;
+
+                               b->dthb_next = bucket->dthb_next;
+                       }
+
+                       ASSERT(hash->dth_nbuckets > 0);
+
+                       hash->dth_nbuckets--;
+                       kfree(bucket);
+
+                       return;
+               }
+
+               bucket->dthb_chain = *nextp;
+       } else
+               *(DTRACE_HASHNEXT(hash, *prevp)) = *nextp;
+
+       if (*nextp != NULL)
+               *(DTRACE_HASHPREV(hash, *nextp)) = *prevp;
+}
diff --git a/dtrace/dtrace_helper.c b/dtrace/dtrace_helper.c
new file mode 100644 (file)
index 0000000..75060f4
--- /dev/null
@@ -0,0 +1,175 @@
+/*
+ * FILE:       dtrace_helper.c
+ * DESCRIPTION:        Dynamic Tracing: helper functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include "dtrace.h"
+
+static uint32_t        dtrace_helptrace_next = 0;
+static uint32_t        dtrace_helptrace_nlocals;
+static char    *dtrace_helptrace_buffer;
+static int     dtrace_helptrace_bufsize = 512 * 1024;
+
+#ifdef CONFIG_DT_DEBUG
+static int     dtrace_helptrace_enabled = 1;
+#else
+static int     dtrace_helptrace_enabled = 0;
+#endif
+
+static void dtrace_helper_trace(dtrace_helper_action_t *helper,
+                               dtrace_mstate_t *mstate,
+                               dtrace_vstate_t *vstate, int where)
+{
+       uint32_t                size, next, nnext, i;
+       dtrace_helptrace_t      *ent;
+       uint16_t                flags = cpu_core[
+                                           smp_processor_id()
+                                       ].cpuc_dtrace_flags;
+
+       if (!dtrace_helptrace_enabled)
+               return;
+
+       ASSERT(vstate->dtvs_nlocals <= dtrace_helptrace_nlocals);
+
+       /*
+        * What would a tracing framework be without its own tracing
+        * framework?  (Well, a hell of a lot simpler, for starters...)
+        */
+       size = sizeof(dtrace_helptrace_t) + dtrace_helptrace_nlocals *
+              sizeof(uint64_t) - sizeof(uint64_t);
+
+       /*
+        * Iterate until we can allocate a slot in the trace buffer.
+        */
+       do {
+               next = dtrace_helptrace_next;
+
+               if (next + size < dtrace_helptrace_bufsize)
+                       nnext = next + size;
+               else
+                       nnext = size;
+       } while (cmpxchg(&dtrace_helptrace_next, next, nnext) != next);
+
+       /*
+        * We have our slot; fill it in.
+       */
+       if (nnext == size)
+               next = 0;
+
+       ent = (dtrace_helptrace_t *)&dtrace_helptrace_buffer[next];
+       ent->dtht_helper = helper;
+       ent->dtht_where = where;
+       ent->dtht_nlocals = vstate->dtvs_nlocals;
+
+       ent->dtht_fltoffs = (mstate->dtms_present & DTRACE_MSTATE_FLTOFFS)
+                               ?  mstate->dtms_fltoffs
+                               : -1;
+       ent->dtht_fault = DTRACE_FLAGS2FLT(flags);
+       ent->dtht_illval = cpu_core[smp_processor_id()].cpuc_dtrace_illval;
+
+       for (i = 0; i < vstate->dtvs_nlocals; i++) {
+               dtrace_statvar_t        *svar;
+
+               if ((svar = vstate->dtvs_locals[i]) == NULL)
+                       continue;
+
+               ASSERT(svar->dtsv_size >= NR_CPUS * sizeof(uint64_t));
+               ent->dtht_locals[i] =
+                       ((uint64_t *)(uintptr_t)svar->dtsv_data)[
+                                                       smp_processor_id()];
+       }
+}
+
+uint64_t dtrace_helper(int which, dtrace_mstate_t *mstate,
+                      dtrace_state_t *state, uint64_t arg0, uint64_t arg1)
+{
+       uint16_t                *flags = &cpu_core[
+                                               smp_processor_id()
+                                         ].cpuc_dtrace_flags;
+       uint64_t                sarg0 = mstate->dtms_arg[0];
+       uint64_t                sarg1 = mstate->dtms_arg[1];
+       uint64_t                rval = 0;
+       dtrace_helpers_t        *helpers = current->dtrace_helpers;
+       dtrace_helper_action_t  *helper;
+       dtrace_vstate_t         *vstate;
+       dtrace_difo_t           *pred;
+       int                     i, trace = dtrace_helptrace_enabled;
+
+       ASSERT(which >= 0 && which < DTRACE_NHELPER_ACTIONS);
+
+       if (helpers == NULL)
+               return 0;
+
+       if ((helper = helpers->dthps_actions[which]) == NULL)
+               return 0;
+
+       vstate = &helpers->dthps_vstate;
+       mstate->dtms_arg[0] = arg0;
+       mstate->dtms_arg[1] = arg1;
+
+       /*
+        * Now iterate over each helper.  If its predicate evaluates to 'true',
+        * we'll call the corresponding actions.  Note that the below calls
+        * to dtrace_dif_emulate() may set faults in machine state.  This is
+        * okay:  our caller (the outer dtrace_dif_emulate()) will simply plow
+        * the stored DIF offset with its own (which is the desired behavior).
+        * Also, note the calls to dtrace_dif_emulate() may allocate scratch
+        * from machine state; this is okay, too.
+        */
+       for (; helper != NULL; helper = helper->dtha_next) {
+               if ((pred = helper->dtha_predicate) != NULL) {
+                       if (trace)
+                               dtrace_helper_trace(helper, mstate, vstate, 0);
+
+                       if (!dtrace_dif_emulate(pred, mstate, vstate, state))
+                               goto next;
+
+                       if (*flags & CPU_DTRACE_FAULT)
+                               goto err;
+               }
+
+               for (i = 0; i < helper->dtha_nactions; i++) {
+                       if (trace)
+                               dtrace_helper_trace(helper, mstate, vstate,
+                                                   i + 1);
+
+                       rval = dtrace_dif_emulate(helper->dtha_actions[i],
+                                                 mstate, vstate, state);
+
+                       if (*flags & CPU_DTRACE_FAULT)
+                               goto err;
+               }
+
+next:
+               if (trace)
+                       dtrace_helper_trace(helper, mstate, vstate,
+                                           DTRACE_HELPTRACE_NEXT);
+       }
+
+       if (trace)
+               dtrace_helper_trace(helper, mstate, vstate,
+                                   DTRACE_HELPTRACE_DONE);
+
+       /*
+        * Restore the arg0 that we saved upon entry.
+        */
+       mstate->dtms_arg[0] = sarg0;
+       mstate->dtms_arg[1] = sarg1;
+
+       return rval;
+
+err:
+       if (trace)
+               dtrace_helper_trace(helper, mstate, vstate,
+                                   DTRACE_HELPTRACE_ERR);
+
+       /*
+        * Restore the arg0 that we saved upon entry.
+        */
+       mstate->dtms_arg[0] = sarg0;
+       mstate->dtms_arg[1] = sarg1;
+
+       return 0;
+}
diff --git a/dtrace/dtrace_isa.c b/dtrace/dtrace_isa.c
new file mode 100644 (file)
index 0000000..8fd14fa
--- /dev/null
@@ -0,0 +1,547 @@
+/*
+ * FILE:       dtrace_isa.c
+ * DESCRIPTION:        Dynamic Tracing: architecture specific support functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/hardirq.h>
+#include <linux/smp.h>
+#include <asm/stacktrace.h>
+
+#include "dtrace.h"
+
+/* FIXME */
+uintptr_t _userlimit = 0x00007fffffffffffLL;
+uintptr_t kernelbase = 0xffff880000000000LL;
+
+cpu_core_t     cpu_core[NR_CPUS];
+EXPORT_SYMBOL(cpu_core);
+EXPORT_SYMBOL(dtrace_getfp);
+
+DEFINE_MUTEX(cpu_lock);
+EXPORT_SYMBOL(cpu_lock);
+
+extern void    dtrace_copy(uintptr_t, uintptr_t, size_t);
+extern void    dtrace_copystr(uintptr_t, uintptr_t, size_t,
+                              volatile uint16_t *);
+
+static int dtrace_copycheck(uintptr_t uaddr, uintptr_t kaddr, size_t size)
+{
+#ifdef FIXME
+       ASSERT(kaddr >= kernelbase && kaddr + size >= kaddr);
+#else
+       if (kaddr < kernelbase || kaddr + size < kaddr) {
+               DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR);
+               cpu_core[smp_processor_id()].cpuc_dtrace_illval = kaddr;
+               return 0;
+       }
+#endif
+
+       if (uaddr + size >= kernelbase || uaddr + size < uaddr) {
+               DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR);
+               cpu_core[smp_processor_id()].cpuc_dtrace_illval = uaddr;
+               return 0;
+       }
+
+       return 1;
+}
+
+void dtrace_copyin(uintptr_t uaddr, uintptr_t kaddr, size_t size,
+                  volatile uint16_t *flags)
+{
+       if (dtrace_copycheck(uaddr, kaddr, size))
+               dtrace_copy(uaddr, kaddr, size);
+}
+
+void dtrace_copyout(uintptr_t uaddr, uintptr_t kaddr, size_t size,
+                   volatile uint16_t *flags)
+{
+       if (dtrace_copycheck(uaddr, kaddr, size))
+               dtrace_copy(kaddr, uaddr, size);
+}
+
+void dtrace_copyinstr(uintptr_t uaddr, uintptr_t kaddr, size_t size,
+                     volatile uint16_t *flags)
+{
+       if (dtrace_copycheck(uaddr, kaddr, size))
+               dtrace_copystr(uaddr, kaddr, size, flags);
+}
+
+void dtrace_copyoutstr(uintptr_t uaddr, uintptr_t kaddr, size_t size,
+                      volatile uint16_t *flags)
+{
+       if (dtrace_copycheck(uaddr, kaddr, size))
+               dtrace_copystr(kaddr, uaddr, size, flags);
+}
+
+#define DTRACE_FUWORD(bits) \
+       uint##bits##_t dtrace_fuword##bits(void *uaddr)                       \
+       {                                                                     \
+               extern uint##bits##_t   dtrace_fuword##bits##_nocheck(void *);\
+                                                                             \
+               if ((uintptr_t)uaddr > _userlimit) {                          \
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR);               \
+                       cpu_core[smp_processor_id()].cpuc_dtrace_illval =     \
+                                                       (uintptr_t)uaddr;     \
+                       return 0;                                             \
+               }                                                             \
+                                                                             \
+               return dtrace_fuword##bits##_nocheck(uaddr);                  \
+       }
+
+DTRACE_FUWORD(8)
+DTRACE_FUWORD(16)
+DTRACE_FUWORD(32)
+DTRACE_FUWORD(64)
+
+struct frame {
+       struct frame    *fr_savfp;
+       unsigned long   fr_savpc;
+} __attribute__((packed));
+
+static void dtrace_invop_callsite(void)
+{
+}
+
+uint64_t dtrace_getarg(int arg, int aframes)
+{
+       struct frame    *fp = (struct frame *)dtrace_getfp();
+       uintptr_t       *stack;
+       int             i;
+       uint64_t        val;
+#ifdef __i386__
+       int             regmap[] = {
+                                       REG_EAX,
+                                       REG_EDX,
+                                       REG_ECX
+                                  };
+#else
+       int             regmap[] = {
+                                       REG_RDI,
+                                       REG_RSI,
+                                       REG_RDX,
+                                       REG_RCX,
+                                       REG_R8,
+                                       REG_R9
+                                  };
+#endif
+       int             nreg = sizeof(regmap) / sizeof(regmap[0]) - 1;
+
+printk(KERN_INFO "getarg(%d, %d) -> nreg = %d\n", arg, aframes, nreg);
+       for (i = 1; i <= aframes; i++) {
+               fp = fp->fr_savfp;
+
+               if (fp->fr_savpc == (uintptr_t)dtrace_invop_callsite) {
+#ifdef __i386__
+                       /* FIXME */
+#else
+                       /* FIXME */
+#endif
+
+                       goto load;
+               }
+       }
+
+       /*
+        * We know that we did not get here through a trap to get into the
+        * dtrace_probe() function, so this was a straight call into it from
+        * a provider.  In that case, we need to shift the argument that we
+        * are looking for, because the probe ID will be the first argument to
+        * dtrace_probe().
+        */
+       arg++;
+
+#ifndef __i386__
+printk(KERN_INFO "getarg(%d, %d) [!i386]-> nreg = %d\n", arg, aframes, nreg);
+       if (arg <= nreg) {
+               /*
+                * This should not happen.  If the argument was passed in a
+                * register then it should have been, ...passed in a reguster.
+                */
+               DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
+               return 0;
+       }
+
+       arg -= nreg + 1;
+#endif
+
+       stack = (uintptr_t *)&fp[1];
+
+load:
+       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+       val = stack[arg];
+       DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
+
+       return val;
+}
+
+int dtrace_getipl(void)
+{
+       return in_interrupt();
+}
+
+ulong_t dtrace_getreg(struct pt_regs *rp, uint_t reg)
+{
+#ifdef __i386__
+       if (reg > REG_SS) {
+               DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
+               return 0;
+       }
+
+       switch (reg) {
+       case REG_GS:
+       case REG_FS:
+       case REG_ES:
+       case REG_DS:
+       case REG_CS:
+               return rp->cs;
+       case REG_EDI:
+               return rp->di;
+       case REG_ESI:
+               return rp->si;
+       case REG_EBP:
+               return rp->bp;
+       case REG_ESP:
+       case REG_UESP:
+               return rp->sp;
+       case REG_EBX:
+               return rp->bx;
+       case REG_EDX:
+               return rp->dx;
+       case REG_ECX:
+               return rp->cx;
+       case REG_EAX:
+               return rp->ax;
+       case REG_TRAPNO:
+               return rp->orig_ax;
+       case REG_ERR:
+               return rp->di;
+       case REG_EIP:
+               return rp->ip;
+       case REG_EFL:
+               return rp->flags;
+       case REG_SS:
+               return rp->ss;
+       default:
+               DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
+               return 0;
+       }
+#else
+       int     regmap[] = {
+                               REG_GS,         /*  0 -> GS */
+                               REG_FS,         /*  1 -> FS */
+                               REG_ES,         /*  2 -> ES */
+                               REG_DS,         /*  3 -> DS */
+                               REG_RDI,        /*  4 -> EDI */
+                               REG_RSI,        /*  5 -> ESI */
+                               REG_RBP,        /*  6 -> EBP */
+                               REG_RSP,        /*  7 -> ESP */
+                               REG_RBX,        /*  8 -> EBX */
+                               REG_RDX,        /*  9 -> EDX */
+                               REG_RCX,        /* 10 -> ECX */
+                               REG_RAX,        /* 11 -> EAX */
+                               REG_TRAPNO,     /* 12 -> TRAPNO */
+                               REG_ERR,        /* 13 -> ERR */
+                               REG_RIP,        /* 14 -> EIP */
+                               REG_CS,         /* 15 -> CS */
+                               REG_RFL,        /* 16 -> EFL */
+                               REG_RSP,        /* 17 -> UESP */
+                               REG_SS,         /* 18 -> SS */
+                          };
+
+       if (reg <= REG_SS) {
+               if (reg >= sizeof(regmap) / sizeof(int)) {
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
+                       return 0;
+               }
+
+               reg = regmap[reg];
+       } else
+               reg -= REG_SS + 1;
+
+       switch (reg) {
+       case REG_RDI:
+               return rp->di;
+       case REG_RSI:
+               return rp->si;
+       case REG_RDX:
+               return rp->dx;
+       case REG_RCX:
+               return rp->cx;
+       case REG_R8:
+               return rp->r8;
+       case REG_R9:
+               return rp->r9;
+       case REG_RAX:
+               return rp->ax;
+       case REG_RBX:
+               return rp->bx;
+       case REG_RBP:
+               return rp->bp;
+       case REG_R10:
+               return rp->r10;
+       case REG_R11:
+               return rp->r11;
+       case REG_R12:
+               return rp->r12;
+       case REG_R13:
+               return rp->r13;
+       case REG_R14:
+               return rp->r14;
+       case REG_R15:
+               return rp->r15;
+       case REG_CS:
+       case REG_DS:
+       case REG_ES:
+       case REG_FS:
+       case REG_GS:
+               return rp->cs;
+       case REG_TRAPNO:
+               return rp->orig_ax;
+       case REG_ERR:
+               return rp->di;
+       case REG_RIP:
+               return rp->ip;
+       case REG_SS:
+               return rp->ss;
+       case REG_RFL:
+               return rp->flags;
+       case REG_RSP:
+               return rp->sp;
+       default:
+               DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
+               return 0;
+       }
+#endif
+}
+
+static void dtrace_sync_func(void)
+{
+}
+
+void dtrace_sync(void)
+{
+       dtrace_xcall(DTRACE_CPUALL, (dtrace_xcall_t)dtrace_sync_func, NULL);
+}
+
+void dtrace_xcall(processorid_t cpu, dtrace_xcall_t func, void *arg)
+{
+       if (cpu == DTRACE_CPUALL) {
+               smp_call_function(func, arg, 1);
+       } else
+               smp_call_function_single(cpu, func, arg, 1);
+}
+
+void dtrace_toxic_ranges(void (*func)(uintptr_t, uintptr_t))
+{
+       /* FIXME */
+}
+
+ktime_t dtrace_gethrestime(void)
+{
+       return dtrace_gethrtime();
+}
+
+#define STACKTRACE_KERNEL      0x01
+#define STACKTRACE_USER                0x02
+#define STACKTRACE_SKIP                0x10
+
+struct stacktrace_state {
+       uint64_t        *pcs;
+       uint64_t        *fps;
+       int             limit;
+       int             depth;
+       int             flags;
+};
+
+static void dtrace_stacktrace_warning(void *data, char *msg)
+{
+}
+
+static void dtrace_stacktrace_warning_symbol(void *data, char *msg,
+                                            unsigned long symbol)
+{
+}
+
+static int dtrace_stacktrace_stack(void *data, char *name)
+{
+       struct stacktrace_state *st = (struct stacktrace_state *)data;
+
+       /*
+        * We do not skip anything for non-user stack analysis.
+        */
+       if (!(st->flags & STACKTRACE_USER))
+               return 0;
+
+       if (name != NULL && strlen(name) > 3) {
+               /*
+                * Sadly, the dump stack code calls us with both <EOE> and EOI.
+                * Consistency would be much nicer.
+                */
+               if ((name[0] == '<' && name[1] == 'E' && name[2] == 'O') ||
+                   (name[0] == 'E' && name[2] == 'O'))
+                       st->flags &= ~STACKTRACE_SKIP;
+       }
+
+       return 0;
+}
+
+static void dtrace_stacktrace_address(void *data, unsigned long addr,
+                                     int reliable)
+{
+       struct stacktrace_state *st = (struct stacktrace_state *)data;
+
+       if (st->flags & STACKTRACE_SKIP)
+               return;
+
+       if (reliable == 2) {
+               if (st->fps)
+                       st->fps[st->depth] = addr;
+       } else {
+               if (st->pcs != NULL) {
+                       if (st->depth < st->limit)
+                               st->pcs[st->depth++] = addr;
+               } else
+                       st->depth++;
+       }
+}
+
+static inline int valid_sp(struct thread_info *tinfo, void *p,
+                          unsigned int size, void *end)
+{
+       void    *t = tinfo;
+
+       if (end) {
+               if (p < end && p >= (end - THREAD_SIZE))
+                       return 1;
+               else
+                       return 0;
+       }
+
+       return p > t && p < t + THREAD_SIZE - size;
+}
+
+static unsigned long dtrace_stacktrace_walk_stack(
+                                       struct thread_info *tinfo,
+                                       unsigned long *stack,
+                                       unsigned long bp,
+                                       const struct stacktrace_ops *ops,
+                                       void *data, unsigned long *end,
+                                       int *graph)
+{
+       struct frame    *fr = (struct frame *)bp;
+       unsigned long   *pcp = &(fr->fr_savpc);
+
+       while (valid_sp(tinfo, pcp, sizeof(*pcp), end)) {
+               unsigned long   addr = *pcp;
+
+               fr = fr->fr_savfp;
+               ops->address(data, (unsigned long)fr, 2);
+               ops->address(data, addr, 1);
+               pcp = &(fr->fr_savpc);
+       }
+
+       return (unsigned long)fr;
+}
+
+static const struct stacktrace_ops     dtrace_tracetrace_ops = {
+       .warning        = dtrace_stacktrace_warning,
+       .warning_symbol = dtrace_stacktrace_warning_symbol,
+       .stack          = dtrace_stacktrace_stack,
+       .address        = dtrace_stacktrace_address,
+       .walk_stack     = print_context_stack
+};
+
+void dtrace_getpcstack(uint64_t *pcstack, int pcstack_limit, int aframes,
+                      uint32_t *intrpc)
+{
+       struct stacktrace_state st = {
+                                       pcstack,
+                                       NULL,
+                                       pcstack_limit,
+                                       0,
+                                       STACKTRACE_KERNEL
+                                    };
+
+       dump_trace(NULL, NULL, NULL, 0, &dtrace_tracetrace_ops, &st);
+
+       while (st.depth < st.limit)
+               pcstack[st.depth++] = 0;
+}
+
+void dtrace_getupcstack(uint64_t *pcstack, int pcstack_limit)
+{
+       struct stacktrace_state st = {
+                                       pcstack,
+                                       NULL,
+                                       pcstack_limit,
+                                       0,
+                                       STACKTRACE_USER
+                                    };
+
+       dump_trace(NULL, NULL, NULL, 0, &dtrace_tracetrace_ops, &st);
+
+       while (st.depth < st.limit)
+               pcstack[st.depth++] = 0;
+}
+
+static const struct stacktrace_ops     dtrace_tracetrace_ops_alt = {
+       .warning        = dtrace_stacktrace_warning,
+       .warning_symbol = dtrace_stacktrace_warning_symbol,
+       .stack          = dtrace_stacktrace_stack,
+       .address        = dtrace_stacktrace_address,
+       .walk_stack     = dtrace_stacktrace_walk_stack
+};
+
+void dtrace_getufpstack(uint64_t *pcstack, uint64_t *fpstack,
+                       int pcstack_limit)
+{
+       struct stacktrace_state st = {
+                                       pcstack,
+                                       fpstack,
+                                       pcstack_limit,
+                                       0,
+                                       STACKTRACE_USER
+                                    };
+
+       dump_trace(NULL, NULL, NULL, 0, &dtrace_tracetrace_ops_alt, &st);
+
+       while (st.depth < st.limit) {
+               fpstack[st.depth] = 0;
+               pcstack[st.depth++] = 0;
+       }
+}
+
+int dtrace_getstackdepth(int aframes)
+{
+       struct stacktrace_state st = {
+                                       NULL,
+                                       NULL,
+                                       0,
+                                       0,
+                                       STACKTRACE_KERNEL
+                                    };
+
+       dump_trace(NULL, NULL, NULL, 0, &dtrace_tracetrace_ops, &st);
+
+       if (st.depth <= aframes)
+               return 0;
+
+       return st.depth - aframes;
+}
+
+int dtrace_getustackdepth(void)
+{
+       struct stacktrace_state st = {
+                                       NULL,
+                                       NULL,
+                                       0,
+                                       0,
+                                       STACKTRACE_USER
+                                    };
+
+       dump_trace(NULL, NULL, NULL, 0, &dtrace_tracetrace_ops, &st);
+
+       return st.depth;
+}
diff --git a/dtrace/dtrace_match.c b/dtrace/dtrace_match.c
new file mode 100644 (file)
index 0000000..f70024f
--- /dev/null
@@ -0,0 +1,325 @@
+/*
+ * FILE:       dtrace_match.c
+ * DESCRIPTION:        Dynamic Tracing: matching functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include "dtrace.h"
+
+dtrace_hash_t  *dtrace_bymod;
+dtrace_hash_t  *dtrace_byfunc;
+dtrace_hash_t  *dtrace_byname;
+
+int dtrace_match_priv(const dtrace_probe_t *prp, uint32_t priv, uid_t uid)
+{
+       if (priv != DTRACE_PRIV_ALL) {
+               uint32_t        ppriv =
+                               prp->dtpr_provider->dtpv_priv.dtpp_flags;
+               uint32_t        match = priv & ppriv;
+
+               if ((priv & (DTRACE_PRIV_PROC | DTRACE_PRIV_USER |
+                   DTRACE_PRIV_KERNEL)) == 0)
+                       return 0;
+
+               if (match == 0 && ppriv != 0)
+                       return 0;
+
+               if (((ppriv & ~match) & DTRACE_PRIV_OWNER) != 0 &&
+                   uid != prp->dtpr_provider->dtpv_priv.dtpp_uid)
+                       return 0;
+       }
+
+       return 1;
+}
+
+int dtrace_match_probe(const dtrace_probe_t *prp, const dtrace_probekey_t *pkp,
+                      uint32_t priv, uid_t uid)
+{
+       dtrace_provider_t       *pvp = prp->dtpr_provider;
+       int                     rv;
+
+       if (pvp->dtpv_defunct)
+               return 0;
+
+       if ((rv = pkp->dtpk_pmatch(pvp->dtpv_name, pkp->dtpk_prov, 0)) <= 0)
+               return rv;
+
+       if ((rv = pkp->dtpk_mmatch(prp->dtpr_mod, pkp->dtpk_mod, 0)) <= 0)
+               return rv;
+
+       if ((rv = pkp->dtpk_fmatch(prp->dtpr_func, pkp->dtpk_func, 0)) <= 0)
+               return rv;
+
+       if ((rv = pkp->dtpk_nmatch(prp->dtpr_name, pkp->dtpk_name, 0)) <= 0)
+               return rv;
+
+       if (dtrace_match_priv(prp, priv, uid) == 0)
+               return 0;
+
+        return rv;
+}
+
+int dtrace_match_glob(const char *s, const char *p, int depth)
+{
+       const char      *olds;
+       char            s1, c;
+       int             gs;
+
+       if (depth > DTRACE_PROBEKEY_MAXDEPTH)
+               return -1;
+
+       if (s == NULL)
+               s = "";
+
+top:
+       olds = s;
+       s1 = *s++;
+
+       if (p == NULL)
+               return 0;
+
+       if ((c = *p++) == '\0')
+               return s1 == '\0';
+
+       switch (c) {
+       case '[':
+               {
+                       int     ok = 0, notflag = 0;
+                       char    lc = '\0';
+
+                       if (s1 == '\0')
+                               return 0;
+
+                       if (*p == '!') {
+                               notflag = 1;
+                               p++;
+                       }
+
+                       if ((c = *p++) == '\0')
+                               return 0;
+
+                       do {
+                               if (c == '-' && lc != '\0' && *p != ']') {
+                                       if ((c = *p++) == '\0')
+                                               return 0;
+                                       if (c == '\\' && (c = *p++) == '\0')
+                                               return 0;
+
+                                       if (notflag) {
+                                               if (s1 < lc || s1 > c)
+                                                       ok++;
+                                               else
+                                                       return 0;
+                                       } else if (lc <= s1 && s1 <= c)
+                                               ok++;
+                               } else if (c == '\\' && (c = *p++) == '\0')
+                                       return 0;
+
+                               lc = c;
+
+                               if (notflag) {
+                                       if (s1 != c)
+                                               ok++;
+                                       else
+                                               return 0;
+                               } else if (s1 == c)
+                                       ok++;
+
+                               if ((c = *p++) == '\0')
+                                       return 0;
+                       } while (c != ']');
+
+                       if (ok)
+                               goto top;
+
+                       return 0;
+               }
+
+       case '\\':
+               if ((c = *p++) == '\0')
+                       return 0;
+
+       default:
+               if (c != s1)
+                       return 0;
+
+       case '?':
+               if (s1 != '\0')
+                       goto top;
+
+               return 0;
+
+       case '*':
+               while (*p == '*')
+                       p++;
+
+               if (*p == '\0')
+                       return 1;
+
+               for (s = olds; *s != '\0'; s++) {
+                       if ((gs = dtrace_match_glob(s, p, depth + 1)) != 0)
+                               return gs;
+               }
+
+               return 0;
+       }
+}
+
+int dtrace_match_string(const char *s, const char *p, int depth)
+{
+       return s != NULL && strcmp(s, p) == 0;
+}
+
+int dtrace_match_nul(const char *s, const char *p, int depth)
+{
+       return 1;
+}
+
+int dtrace_match_nonzero(const char *s, const char *p, int depth)
+{
+       return s != NULL && s[0] != '\0';
+}
+
+struct probe_match {
+       const dtrace_probekey_t *pkp;
+       uint32_t                priv;
+       uid_t                   uid;
+       int                     (*matched)(dtrace_probe_t *, void *);
+       void                    *arg;
+       int                     nmatched;
+};
+
+static int dtrace_match_one(int id, void *p, void *data)
+{
+       struct probe_match      *pbm    = (struct probe_match *)data;
+       dtrace_probe_t          *probe  = (dtrace_probe_t *)p;
+       int                     rc;
+
+       if (dtrace_match_probe(probe, pbm->pkp, pbm->priv, pbm->uid) <= 0)
+               return 0;
+
+       pbm->nmatched++;
+
+       if ((rc = (pbm->matched)(probe, pbm->arg)) != DTRACE_MATCH_NEXT) {
+               if (rc == DTRACE_MATCH_FAIL)
+                       return DTRACE_MATCH_FAIL;
+       }
+
+       return 0;
+}
+
+int dtrace_match(const dtrace_probekey_t *pkp, uint32_t priv, uid_t uid,
+                int (*matched)(dtrace_probe_t *, void *), void *arg)
+{
+       dtrace_probe_t  template, *probe;
+       dtrace_hash_t   *hash = NULL;
+       int             len, rc, best = INT_MAX, nmatched = 0;
+
+       if (pkp->dtpk_id != DTRACE_IDNONE) {
+               if ((probe = dtrace_probe_lookup_id(pkp->dtpk_id)) != NULL &&
+                   dtrace_match_probe(probe, pkp, priv, uid) > 0) {
+                       if ((*matched)(probe, arg) == DTRACE_MATCH_FAIL)
+                               return DTRACE_MATCH_FAIL;
+
+                       nmatched++;
+               }
+
+               return nmatched;
+       }
+
+       template.dtpr_mod = (char *)pkp->dtpk_mod;
+       template.dtpr_func = (char *)pkp->dtpk_func;
+       template.dtpr_name = (char *)pkp->dtpk_name;
+
+       if (pkp->dtpk_mmatch == &dtrace_match_string &&
+           (len = dtrace_hash_collisions(dtrace_bymod, &template)) < best) {
+               best = len;
+               hash = dtrace_bymod;
+       }
+
+       if (pkp->dtpk_fmatch == &dtrace_match_string &&
+           (len = dtrace_hash_collisions(dtrace_byfunc, &template)) < best) {
+               best = len;
+               hash = dtrace_byfunc;
+       }
+
+       if (pkp->dtpk_nmatch == &dtrace_match_string &&
+           (len = dtrace_hash_collisions(dtrace_byname, &template)) < best) {
+               best = len;
+               hash = dtrace_byname;
+       }
+
+       if (hash == NULL) {
+               struct probe_match      pbm;
+
+               pbm.pkp = pkp;
+               pbm.priv = priv;
+               pbm.uid = uid;
+               pbm.matched = matched;
+               pbm.arg = arg;
+               pbm.nmatched = 0;
+
+               rc = dtrace_probe_for_each(dtrace_match_one, &pbm);
+               if (rc == DTRACE_MATCH_FAIL)
+                       return DTRACE_MATCH_FAIL;
+
+               return pbm.nmatched;
+       }
+
+       for (probe = dtrace_hash_lookup(hash, &template); probe != NULL;
+            probe = *(DTRACE_HASHNEXT(hash, probe))) {
+               if (dtrace_match_probe(probe, pkp, priv, uid) <= 0)
+                       continue;
+
+               nmatched++;
+
+               if ((rc = (*matched)(probe, arg)) != DTRACE_MATCH_NEXT) {
+                       if (rc == DTRACE_MATCH_FAIL)
+                               return DTRACE_MATCH_FAIL;
+
+                       break;
+               }
+       }
+
+       return nmatched;
+}
+
+static dtrace_probekey_f *dtrace_probekey_func(const char *p)
+{
+       char    c;
+
+       if (p == NULL || *p == '\0')
+               return &dtrace_match_nul;
+
+       while ((c = *p++) != '\0') {
+               if (c == '[' || c == '?' || c == '*' || c == '\\')
+                       return &dtrace_match_glob;
+       }
+
+       return &dtrace_match_string;
+}
+
+void dtrace_probekey(const dtrace_probedesc_t *pdp, dtrace_probekey_t *pkp)
+{
+       pkp->dtpk_prov = pdp->dtpd_provider;
+       pkp->dtpk_pmatch = dtrace_probekey_func(pdp->dtpd_provider);
+
+       pkp->dtpk_mod = pdp->dtpd_mod;
+       pkp->dtpk_mmatch = dtrace_probekey_func(pdp->dtpd_mod);
+
+       pkp->dtpk_func = pdp->dtpd_func;
+       pkp->dtpk_fmatch = dtrace_probekey_func(pdp->dtpd_func);
+
+       pkp->dtpk_name = pdp->dtpd_name;
+       pkp->dtpk_nmatch = dtrace_probekey_func(pdp->dtpd_name);
+
+       pkp->dtpk_id = pdp->dtpd_id;
+
+       if (pkp->dtpk_id == DTRACE_IDNONE &&
+           pkp->dtpk_pmatch == &dtrace_match_nul &&
+           pkp->dtpk_mmatch == &dtrace_match_nul &&
+           pkp->dtpk_fmatch == &dtrace_match_nul &&
+           pkp->dtpk_nmatch == &dtrace_match_nul)
+               pkp->dtpk_fmatch = &dtrace_match_nonzero;
+}
diff --git a/dtrace/dtrace_mod.c b/dtrace/dtrace_mod.c
new file mode 100644 (file)
index 0000000..9f36a0a
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * FILE:       dtrace_mod.c
+ * DESCRIPTION:        Dynamic Tracing: module handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/module.h>
+
+#include "dtrace_dev.h"
+
+MODULE_AUTHOR("Kris Van Hees (kris.van.hees@oracle.com)");
+MODULE_DESCRIPTION("Dynamic Tracing");
+MODULE_VERSION("v0.1");
+MODULE_LICENSE("Proprietary");
+
+/*
+ * Initialize the module.
+ */
+static int __init dtrace_init(void)
+{
+       return dtrace_dev_init();
+}
+
+/*
+ * Perform cleanup before the module is removed.
+ */
+static void __exit dtrace_exit(void)
+{
+       dtrace_dev_exit();
+}
+
+module_init(dtrace_init);
+module_exit(dtrace_exit);
diff --git a/dtrace/dtrace_predicate.c b/dtrace/dtrace_predicate.c
new file mode 100644 (file)
index 0000000..30c1512
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * FILE:       dtrace_predicate.c
+ * DESCRIPTION:        Dynamic Tracing: predicate functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/slab.h>
+
+#include "dtrace.h"
+
+static dtrace_cacheid_t        dtrace_predcache_id = DTRACE_CACHEIDNONE + 1;
+
+dtrace_predicate_t *dtrace_predicate_create(dtrace_difo_t *dp)
+{
+       dtrace_predicate_t      *pred;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(dp->dtdo_refcnt != 0);
+
+       pred = kzalloc(sizeof (dtrace_predicate_t), GFP_KERNEL);
+       pred->dtp_difo = dp;
+       pred->dtp_refcnt = 1;
+
+       if (!dtrace_difo_cacheable(dp))
+               return pred;
+
+       /*
+        * This is only theoretically possible -- we have had 2^32 cacheable
+        * predicates on this machine.  We cannot allow any more predicates to
+        * become cacheable:  as unlikely as it is, there may be a thread
+        * caching a (now stale) predicate cache ID. (N.B.: the temptation is
+        * being successfully resisted to have this cmn_err() "Holy shit -- we
+        * executed this code!")
+        */
+       if (dtrace_predcache_id == DTRACE_CACHEIDNONE)
+               return pred;
+
+       pred->dtp_cacheid = dtrace_predcache_id++;
+
+       return pred;
+}
+
+void dtrace_predicate_hold(dtrace_predicate_t *pred)
+{
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(pred->dtp_difo != NULL && pred->dtp_difo->dtdo_refcnt != 0);
+       ASSERT(pred->dtp_refcnt > 0);
+
+       pred->dtp_refcnt++;
+}
+
+void dtrace_predicate_release(dtrace_predicate_t *pred,
+                             dtrace_vstate_t *vstate)
+{
+       dtrace_difo_t *dp = pred->dtp_difo;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(dp != NULL && dp->dtdo_refcnt != 0);
+       ASSERT(pred->dtp_refcnt > 0);
+
+       if (--pred->dtp_refcnt == 0) {
+               dtrace_difo_release(dp, vstate);
+               kfree(pred);
+       }
+}
diff --git a/dtrace/dtrace_priv.c b/dtrace/dtrace_priv.c
new file mode 100644 (file)
index 0000000..57a0995
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * FILE:       dtrace_priv.c
+ * DESCRIPTION:        Dynamic Tracing: privilege check functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include "dtrace.h"
+
+/*
+ * This privilege check should be used by actions and subroutines to
+ * verify that the user credentials of the process that enabled the
+ * invoking ECB match the target credentials
+ */
+int dtrace_priv_proc_common_user(dtrace_state_t *state)
+{
+       const cred_t    *cr, *s_cr = state->dts_cred.dcr_cred;
+
+       /*
+        * We should always have a non-NULL state cred here, since if cred
+        * is null (anonymous tracing), we fast-path bypass this routine.
+        */
+       ASSERT(s_cr != NULL);
+
+       if ((cr = current_cred()) != NULL &&
+           s_cr->euid == cr->euid &&
+           s_cr->euid == cr->uid &&
+           s_cr->euid == cr->suid &&
+           s_cr->egid == cr->egid &&
+           s_cr->egid == cr->gid &&
+           s_cr->egid == cr->sgid)
+               return 1;
+
+       return 0;
+}
+
+/*
+ * This privilege check should be used by actions and subroutines to
+ * verify that the process has not setuid or changed credentials.
+ */
+int dtrace_priv_proc_common_nocd(void)
+{
+#ifdef FIXME
+       proc_t  *proc;
+
+       if ((proc = ttoproc(curthread)) != NULL && !(proc->p_flag & SNOCD))
+               return 1;
+#endif
+
+       return 0;
+}
+
+int dtrace_priv_proc_destructive(dtrace_state_t *state)
+{
+       int     action = state->dts_cred.dcr_action;
+
+       if (((action & DTRACE_CRA_PROC_DESTRUCTIVE_ALLUSER) == 0) &&
+           dtrace_priv_proc_common_user(state) == 0)
+               goto bad;
+
+       if (((action & DTRACE_CRA_PROC_DESTRUCTIVE_CREDCHG) == 0) &&
+           dtrace_priv_proc_common_nocd() == 0)
+               goto bad;
+
+       return 1;
+
+bad:
+       DTRACE_CPUFLAG_SET(CPU_DTRACE_UPRIV);
+   
+       return 0;
+}
+
+int dtrace_priv_proc_control(dtrace_state_t *state)
+{
+       if (state->dts_cred.dcr_action & DTRACE_CRA_PROC_CONTROL)
+               return 1;
+
+       if (dtrace_priv_proc_common_user(state) &&
+           dtrace_priv_proc_common_nocd())
+               return 1;
+
+       DTRACE_CPUFLAG_SET(CPU_DTRACE_UPRIV);
+
+       return 0;
+}
+
+int dtrace_priv_proc(dtrace_state_t *state)
+{
+       if (state->dts_cred.dcr_action & DTRACE_CRA_PROC)
+               return 1;
+
+       DTRACE_CPUFLAG_SET(CPU_DTRACE_UPRIV);
+
+       return 0;
+}
+
+int dtrace_priv_kernel(dtrace_state_t *state)
+{
+       if (state->dts_cred.dcr_action & DTRACE_CRA_KERNEL)
+               return 1;
+
+       DTRACE_CPUFLAG_SET(CPU_DTRACE_KPRIV);
+
+       return 0;
+}
diff --git a/dtrace/dtrace_probe.c b/dtrace/dtrace_probe.c
new file mode 100644 (file)
index 0000000..eb185d9
--- /dev/null
@@ -0,0 +1,1228 @@
+/*
+ * FILE:       dtrace_probe.c
+ * DESCRIPTION:        Dynamic Tracing: probe management functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/hardirq.h>
+#include <linux/idr.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <asm/cmpxchg.h>
+
+#include "dtrace.h"
+
+ktime_t                                dtrace_chill_interval =
+                                       KTIME_INIT(1, 0);
+ktime_t                                dtrace_chill_max =
+                                       KTIME_INIT(0,
+                                                  500 * (NANOSEC / MILLISEC));
+
+dtrace_genid_t                 dtrace_probegen;
+
+static struct idr              dtrace_probe_idr;
+static uint64_t                        dtrace_vtime_references;
+
+static struct task_struct      *dtrace_panicked;
+
+/*
+ * Create a new probe.
+ */
+dtrace_id_t dtrace_probe_create(dtrace_provider_id_t prov, const char *mod,
+                               const char *func, const char *name,
+                               int aframes, void *arg)
+{
+       dtrace_probe_t          *probe;
+       dtrace_provider_t       *provider = (dtrace_provider_t *)prov;
+       dtrace_id_t             id;
+       int                     err;
+
+       probe = kzalloc(sizeof(dtrace_probe_t), __GFP_NOFAIL);
+
+       /*
+        * The idr_pre_get() function should be called without holding locks.
+        * When the provider is the DTrace core itself, dtrace_lock will be
+        * held when we enter this function.
+        */
+       if (provider == dtrace_provider) {
+               ASSERT(mutex_is_locked(&dtrace_lock));
+               mutex_unlock(&dtrace_lock);
+       }
+
+again:
+       idr_pre_get(&dtrace_probe_idr, __GFP_NOFAIL);
+
+       mutex_lock(&dtrace_lock);
+       err = idr_get_new(&dtrace_probe_idr, probe, &id);
+       if (err == -EAGAIN) {
+               mutex_unlock(&dtrace_lock);
+               goto again;
+       }
+
+       probe->dtpr_id = id;
+       probe->dtpr_gen = dtrace_probegen++;
+       probe->dtpr_mod = dtrace_strdup(mod);
+       probe->dtpr_func = dtrace_strdup(func);
+       probe->dtpr_name = dtrace_strdup(name);
+       probe->dtpr_arg = arg;
+       probe->dtpr_aframes = aframes;
+       probe->dtpr_provider = provider;
+
+       dtrace_hash_add(dtrace_bymod, probe);
+       dtrace_hash_add(dtrace_byfunc, probe);
+       dtrace_hash_add(dtrace_byname, probe);
+
+       if (provider != dtrace_provider)
+               mutex_unlock(&dtrace_lock);
+
+printk(KERN_INFO "probe_create(%s, %s, %s, %s) -> %d\n", provider->dtpv_name, mod, func, name, id);
+       return id;
+}
+EXPORT_SYMBOL(dtrace_probe_create);
+
+int dtrace_probe_enable(const dtrace_probedesc_t *desc, dtrace_enabling_t *enab)
+{
+       dtrace_probekey_t       pkey;
+       uint32_t                priv;
+       uid_t                   uid;
+
+       dtrace_ecb_create_cache = NULL;
+
+       if (desc == NULL) {
+               (void) dtrace_ecb_create_enable(NULL, enab);
+
+               return 0;
+       }
+
+       dtrace_probekey(desc, &pkey);
+       dtrace_cred2priv(enab->dten_vstate->dtvs_state->dts_cred.dcr_cred,
+                        &priv, &uid);
+printk(KERN_INFO "probe_enable(%d, %s, %s, %s, %s)\n", pkey.dtpk_id, pkey.dtpk_prov, pkey.dtpk_mod, pkey.dtpk_func, pkey.dtpk_name);
+       return dtrace_match(&pkey, priv, uid, dtrace_ecb_create_enable, enab);
+}
+
+/*
+ * Return the probe argument associated with the specified probe.
+ */
+void *dtrace_probe_arg(dtrace_provider_id_t id, dtrace_id_t pid)
+{
+       dtrace_probe_t  *probe;
+       void            *rval = NULL;
+
+       mutex_lock(&dtrace_lock);
+
+       if ((probe = dtrace_probe_lookup_id(pid)) != NULL &&
+           probe->dtpr_provider == (dtrace_provider_t *)id)
+               rval = probe->dtpr_arg;
+
+       mutex_unlock(&dtrace_lock);
+
+       return rval;
+}
+EXPORT_SYMBOL(dtrace_probe_arg);
+
+/*
+ * Copy a probe into a probe description.
+ */
+void dtrace_probe_description(const dtrace_probe_t *prp,
+                             dtrace_probedesc_t *pdp)
+{
+       memset(pdp, 0, sizeof(dtrace_probedesc_t));
+       pdp->dtpd_id = prp->dtpr_id;
+
+       strncpy(pdp->dtpd_provider, prp->dtpr_provider->dtpv_name,
+               DTRACE_PROVNAMELEN - 1);
+
+       strncpy(pdp->dtpd_mod, prp->dtpr_mod, DTRACE_MODNAMELEN - 1);
+       strncpy(pdp->dtpd_func, prp->dtpr_func, DTRACE_FUNCNAMELEN - 1);
+       strncpy(pdp->dtpd_name, prp->dtpr_name, DTRACE_NAMELEN - 1);
+}
+
+void dtrace_probe_provide(dtrace_probedesc_t *desc, dtrace_provider_t *prv)
+{
+       struct module   *mod;
+       int             all = 0;
+
+       if (prv == NULL) {
+               all = 1;
+               prv = dtrace_provider;
+       }
+
+       do {
+               prv->dtpv_pops.dtps_provide(prv->dtpv_arg, desc);
+
+#ifdef FIXME
+/*
+ * This needs work because (so far) I have not found a way to get access to the
+ * list of modules in Linux.
+ */
+               mutex_lock(&module_mutex);
+
+               list_for_each_entry(mod, &modules, list) {
+                       if (mod->state != MODULE_STATE_LIVE)
+                               continue;
+
+                       prv->dtpv_pops.dtps_provide_module(prv->dtpv_arg, mod);
+               }
+
+               mutex_unlock(&module_mutex);
+#endif
+       } while (all && (prv = prv->dtpv_next) != NULL);
+}
+
+/*
+ * Atomically increment a specified error counter from probe context.
+ */
+static void dtrace_error(uint32_t *counter)
+{
+       /*
+        * Most counters stored to in probe context are per-CPU counters.
+        * However, there are some error conditions that are sufficiently
+        * arcane that they don't merit per-CPU storage.  If these counters
+        * are incremented concurrently on different CPUs, scalability will be
+        * adversely affected -- but we don't expect them to be white-hot in a
+        * correctly constructed enabling...
+        */
+       uint32_t        oval, nval;
+
+       do {
+               oval = *counter;
+
+               if ((nval = oval + 1) == 0) {
+                       /*
+                        * If the counter would wrap, set it to 1 -- assuring
+                        * that the counter is never zero when we have seen
+                        * errors.  (The counter must be 32-bits because we
+                        * aren't guaranteed a 64-bit compare&swap operation.)
+                        * To save this code both the infamy of being fingered
+                        * by a priggish news story and the indignity of being
+                        * the target of a neo-puritan witch trial, we're
+                        * carefully avoiding any colorful description of the
+                        * likelihood of this condition -- but suffice it to
+                        * say that it is only slightly more likely than the
+                        * overflow of predicate cache IDs, as discussed in
+                        * dtrace_predicate_create().
+                        */
+                       nval = 1;
+               }
+       } while (cmpxchg(counter, oval, nval) != oval);
+}
+
+static int dtrace_priv_kernel_destructive(dtrace_state_t *state)
+{
+       if (state->dts_cred.dcr_action & DTRACE_CRA_KERNEL_DESTRUCTIVE)
+               return 1;
+
+       DTRACE_CPUFLAG_SET(CPU_DTRACE_KPRIV);
+
+       return 0;
+}
+
+static void dtrace_action_breakpoint(dtrace_ecb_t *ecb)
+{
+       dtrace_probe_t          *probe = ecb->dte_probe;
+       dtrace_provider_t       *prov = probe->dtpr_provider;
+       char                    c[DTRACE_FULLNAMELEN + 80], *str;
+       char                    *msg = "dtrace: breakpoint action at probe ";
+       char                    *ecbmsg = " (ecb ";
+       uintptr_t               mask = (0xf << (sizeof(uintptr_t) * NBBY / 4));
+       uintptr_t               val = (uintptr_t)ecb;
+       int                     shift = (sizeof(uintptr_t) * NBBY) - 4, i = 0;
+
+       if (dtrace_destructive_disallow)
+               return;
+
+       /*
+        * It's impossible to be taking action on the NULL probe.
+        */
+       ASSERT(probe != NULL);
+
+       /*
+        * This is a poor man's (destitute man's?) sprintf():  we want to
+        * print the provider name, module name, function name and name of
+        * the probe, along with the hex address of the ECB with the breakpoint
+        * action -- all of which we must place in the character buffer by
+        * hand.
+        */
+       while (*msg != '\0')
+               c[i++] = *msg++;
+
+       for (str = prov->dtpv_name; *str != '\0'; str++)
+               c[i++] = *str;
+       c[i++] = ':';
+
+       for (str = probe->dtpr_mod; *str != '\0'; str++)
+               c[i++] = *str;
+       c[i++] = ':';
+
+       for (str = probe->dtpr_func; *str != '\0'; str++)
+               c[i++] = *str;
+       c[i++] = ':';
+
+       for (str = probe->dtpr_name; *str != '\0'; str++)
+               c[i++] = *str;
+
+       while (*ecbmsg != '\0')
+               c[i++] = *ecbmsg++;
+
+       while (shift >= 0) {
+               mask = (uintptr_t)0xf << shift;
+
+               if (val >= ((uintptr_t)1 << shift))
+                       c[i++] = "0123456789abcdef"[(val & mask) >> shift];
+
+               shift -= 4;
+       }
+
+       c[i++] = ')';
+       c[i] = '\0';
+
+//     debug_enter(c); /* FIXME */
+}
+
+static void dtrace_action_panic(dtrace_ecb_t *ecb)
+{
+       dtrace_probe_t  *probe = ecb->dte_probe;
+
+       /*
+        * It's impossible to be taking action on the NULL probe.
+        */
+       ASSERT(probe != NULL);
+
+       if (dtrace_destructive_disallow)
+               return;
+
+       if (dtrace_panicked != NULL)
+               return;
+
+       if (cmpxchg(&dtrace_panicked, NULL, current) != NULL)
+               return;
+
+       /*
+        * We won the right to panic.  (We want to be sure that only one
+        * thread calls panic() from dtrace_probe(), and that panic() is
+        * called exactly once.)
+        */
+       dtrace_panic(KERN_EMERG
+                    "dtrace: panic action at probe %s:%s:%s:%s (ecb %p)",
+                    probe->dtpr_provider->dtpv_name, probe->dtpr_mod,
+                    probe->dtpr_func, probe->dtpr_name, (void *)ecb);
+}
+
+static void dtrace_action_raise(uint64_t sig)
+{
+       if (dtrace_destructive_disallow)
+               return;
+
+       if (sig >= _NSIG) {
+               DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
+               return;
+       }
+
+       /*
+        * raise() has a queue depth of 1 -- we ignore all subsequent
+        * invocations of the raise() action.
+        */
+       if (current->dtrace_sig == 0)
+               current->dtrace_sig = (uint8_t)sig;
+
+//     current->sig_check = 1; /* FIXME */
+//     aston(current);         /* FIXME */
+}
+
+static void dtrace_action_stop(void)
+{
+       if (dtrace_destructive_disallow)
+               return;
+
+       if (!current->dtrace_stop) {
+               current->dtrace_stop = 1;
+//             current->sig_check = 1; /* FIXME */
+//             aston(current);         /* FIXME */
+       }
+}
+
+static void dtrace_action_chill(dtrace_mstate_t *mstate, ktime_t val)
+{
+       ktime_t                 now;
+       volatile uint16_t       *flags;
+       cpu_core_t              *cpu = &cpu_core[smp_processor_id()];
+
+       if (dtrace_destructive_disallow)
+               return;
+
+       flags = (volatile uint16_t *)&cpu->cpuc_dtrace_flags;
+
+       now = dtrace_gethrtime();
+
+       if (ktime_gt(ktime_sub(now, cpu->cpu_dtrace_chillmark),
+                    dtrace_chill_interval)) {
+               /*
+                * We need to advance the mark to the current time.
+                */
+               cpu->cpu_dtrace_chillmark = now;
+               cpu->cpu_dtrace_chilled = ktime_set(0, 0);
+       }
+
+       /*
+        * Now check to see if the requested chill time would take us over
+        * the maximum amount of time allowed in the chill interval.  (Or
+        * worse, if the calculation itself induces overflow.)
+        */
+       if (ktime_gt(ktime_add(cpu->cpu_dtrace_chilled, val),
+                    dtrace_chill_max) ||
+           ktime_lt(ktime_add(cpu->cpu_dtrace_chilled, val),
+                    cpu->cpu_dtrace_chilled)) {
+               *flags |= CPU_DTRACE_ILLOP;
+               return;
+       }
+
+       while (ktime_lt(ktime_sub(dtrace_gethrtime(), now), val))
+               continue;
+
+       /*
+        * Normally, we assure that the value of the variable "timestamp" does
+        * not change within an ECB.  The presence of chill() represents an
+        * exception to this rule, however.
+        */
+       mstate->dtms_present &= ~DTRACE_MSTATE_TIMESTAMP;
+       cpu->cpu_dtrace_chilled = ktime_add(cpu->cpu_dtrace_chilled, val);
+}
+
+static void dtrace_action_ustack(dtrace_mstate_t *mstate,
+                                dtrace_state_t *state, uint64_t *buf,
+                                uint64_t arg)
+{
+       int             nframes = DTRACE_USTACK_NFRAMES(arg);
+       int             strsize = DTRACE_USTACK_STRSIZE(arg);
+       uint64_t        *pcs = &buf[1], *fps;
+       char            *str = (char *)&pcs[nframes];
+       int             size, offs = 0, i, j;
+       uintptr_t       old = mstate->dtms_scratch_ptr, saved;
+       uint16_t        *flags = &cpu_core[
+                                       smp_processor_id()
+                                 ].cpuc_dtrace_flags;
+       char            *sym;
+
+       /*
+        * Should be taking a faster path if string space has not been
+        * allocated.
+        */
+       ASSERT(strsize != 0);
+
+       /*
+        * We will first allocate some temporary space for the frame pointers.
+        */
+       fps = (uint64_t *)P2ROUNDUP(mstate->dtms_scratch_ptr, 8);
+       size = (uintptr_t)fps - mstate->dtms_scratch_ptr +
+              (nframes * sizeof (uint64_t));
+
+       if (!DTRACE_INSCRATCH(mstate, size)) {
+               /*
+                * Not enough room for our frame pointers -- need to indicate
+                * that we ran out of scratch space.
+                */
+               DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+               return;
+       }
+
+       mstate->dtms_scratch_ptr += size;
+       saved = mstate->dtms_scratch_ptr;
+
+       /*
+        * Now get a stack with both program counters and frame pointers.
+        */
+       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+       dtrace_getufpstack(buf, fps, nframes + 1);
+       DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
+
+       /*
+        * If that faulted, we're cooked.
+        */
+       if (*flags & CPU_DTRACE_FAULT)
+               goto out;
+
+       /*
+        * Now we want to walk up the stack, calling the USTACK helper.  For
+        * each iteration, we restore the scratch pointer.
+        */
+       for (i = 0; i < nframes; i++) {
+               mstate->dtms_scratch_ptr = saved;
+
+               if (offs >= strsize)
+                       break;
+
+               sym = (char *)(uintptr_t)dtrace_helper(
+                                               DTRACE_HELPER_ACTION_USTACK,
+                                               mstate, state, pcs[i], fps[i]);
+
+               /*
+                * If we faulted while running the helper, we're going to
+                * clear the fault and null out the corresponding string.
+                */
+               if (*flags & CPU_DTRACE_FAULT) {
+                       *flags &= ~CPU_DTRACE_FAULT;
+                       str[offs++] = '\0';
+                       continue;
+               }
+
+               if (sym == NULL) {
+                       str[offs++] = '\0';
+                       continue;
+               }
+
+               DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+
+               /*
+                * Now copy in the string that the helper returned to us.
+                */
+               for (j = 0; offs + j < strsize; j++) {
+                       if ((str[offs + j] = sym[j]) == '\0')
+                       break;
+               }
+
+               DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
+
+               offs += j + 1;
+       }
+
+       /*
+        * If we didn't have room for all of the strings, we don't abort
+        * processing -- this needn't be a fatal error -- but we still want
+        * to increment a counter (dts_stkstroverflows) to allow this condition
+        * to be warned about.  (If this is from a jstack() action, it is
+        * easily tuned via jstackstrsize.)
+        */
+       if (offs >= strsize)
+               dtrace_error(&state->dts_stkstroverflows);
+
+       while (offs < strsize)
+               str[offs++] = '\0';
+
+out:
+       mstate->dtms_scratch_ptr = old;
+}
+
+void dtrace_probe(dtrace_id_t id, uintptr_t arg0, uintptr_t arg1,
+                 uintptr_t arg2, uintptr_t arg3, uintptr_t arg4)
+{
+       processorid_t           cpuid;
+       dtrace_icookie_t        cookie;
+       dtrace_probe_t          *probe;
+       dtrace_mstate_t         mstate;
+       dtrace_ecb_t            *ecb;
+       dtrace_action_t         *act;
+       intptr_t                offs;
+       size_t                  size;
+       int                     vtime, onintr;
+       volatile uint16_t       *flags;
+       ktime_t                 now;
+
+#ifdef FIXME
+       /*
+        * Kick out immediately if this CPU is still being born (in which case
+        * curthread will be set to -1) or the current thread can't allow
+        * probes in its current context.
+        */
+       if (((uintptr_t)curthread & 1) || (curthread->t_flag & T_DONTDTRACE))
+               return;
+#endif
+
+       local_irq_save(cookie);
+       probe = dtrace_probe_lookup_id(id);
+       cpuid = smp_processor_id();
+       onintr = in_interrupt();
+
+       if (!onintr && probe->dtpr_predcache != DTRACE_CACHEIDNONE &&
+           probe->dtpr_predcache == current->predcache) {
+               /*
+                * We have hit in the predicate cache; we know that
+                * this predicate would evaluate to be false.
+                */
+               local_irq_restore(cookie);
+               return;
+       }
+
+#ifdef FIXME
+       if (panic_quiesce) {
+               /*
+                * We don't trace anything if we're panicking.
+                */
+               local_irq_restore(cookie);
+               return;
+       }
+#endif
+
+       now = dtrace_gethrtime();
+       vtime = dtrace_vtime_references != 0;
+
+       if (vtime && ktime_nz(current->dtrace_start))
+               current->dtrace_vtime =
+                       ktime_add(current->dtrace_vtime,
+                                 ktime_sub(now,current->dtrace_start));
+
+       mstate.dtms_difo = NULL;
+       mstate.dtms_probe = probe;
+       mstate.dtms_strtok = (uintptr_t)NULL;
+       mstate.dtms_arg[0] = arg0;
+       mstate.dtms_arg[1] = arg1;
+       mstate.dtms_arg[2] = arg2;
+       mstate.dtms_arg[3] = arg3;
+       mstate.dtms_arg[4] = arg4;
+
+       flags = (volatile uint16_t *)&cpu_core[cpuid].cpuc_dtrace_flags;
+
+       for (ecb = probe->dtpr_ecb; ecb != NULL; ecb = ecb->dte_next) {
+               dtrace_predicate_t      *pred = ecb->dte_predicate;
+               dtrace_state_t          *state = ecb->dte_state;
+               dtrace_buffer_t         *buf = &state->dts_buffer[cpuid];
+               dtrace_buffer_t         *aggbuf = &state->dts_aggbuffer[cpuid];
+               dtrace_vstate_t         *vstate = &state->dts_vstate;
+               dtrace_provider_t       *prov = probe->dtpr_provider;
+               int                     committed = 0;
+               caddr_t                 tomax;
+
+               /*
+                * A little subtlety with the following (seemingly innocuous)
+                * declaration of the automatic 'val':  by looking at the
+                * code, you might think that it could be declared in the
+                * action processing loop, below.  (That is, it's only used in
+                * the action processing loop.)  However, it must be declared
+                * out of that scope because in the case of DIF expression
+                * arguments to aggregating actions, one iteration of the
+                * action loop will use the last iteration's value.
+                */
+               uint64_t val = 0;
+
+               mstate.dtms_present = DTRACE_MSTATE_ARGS | DTRACE_MSTATE_PROBE;
+               *flags &= ~CPU_DTRACE_ERROR;
+
+               if (prov == dtrace_provider) {
+                       /*
+                        * If dtrace itself is the provider of this probe,
+                        * we're only going to continue processing the ECB if
+                        * arg0 (the dtrace_state_t) is equal to the ECB's
+                        * creating state.  (This prevents disjoint consumers
+                        * from seeing one another's metaprobes.)
+                        */
+                       if (arg0 != (uint64_t)(uintptr_t)state)
+                               continue;
+               }
+
+               if (state->dts_activity != DTRACE_ACTIVITY_ACTIVE) {
+                       /*
+                        * We're not currently active.  If our provider isn't
+                        * the dtrace pseudo provider, we're not interested.
+                        */
+                       if (prov != dtrace_provider)
+                               continue;
+
+                       /*
+                        * Now we must further check if we are in the BEGIN
+                        * probe.  If we are, we will only continue orocessing
+                        * if we're still in WARMUP -- if one BEGIN enabling
+                        * has invoked the exit() action, we don't want to
+                        * evaluate subsequent BEGIN enablings.
+                        */
+                       if (probe->dtpr_id == dtrace_probeid_begin &&
+                           state->dts_activity != DTRACE_ACTIVITY_WARMUP) {
+                               ASSERT(state->dts_activity ==
+                                      DTRACE_ACTIVITY_DRAINING);
+                               continue;
+                       }
+               }
+
+               if (ecb->dte_cond) {
+                       /*
+                        * If the dte_cond bits indicate that this
+                        * consumer is only allowed to see user-mode firings
+                        * of this probe, call the provider's dtps_usermode()
+                        * entry point to check that the probe was fired
+                        * while in a user context. Skip this ECB if that's
+                        * not the case.
+                        */
+                       if ((ecb->dte_cond & DTRACE_COND_USERMODE) &&
+                           prov->dtpv_pops.dtps_usermode(
+                               prov->dtpv_arg, probe->dtpr_id, probe->dtpr_arg
+                           ) == 0)
+                               continue;
+
+                       /*
+                        * This is more subtle than it looks. We have to be
+                        * absolutely certain that current_cred() isn't going
+                        * to change out from under us so it's only legit to
+                        * examine that structure if we're in constrained
+                        * situations. Currently, the only times we'll use this
+                        * check is if a non-super-user has enabled the
+                        * profile or syscall providers -- providers that
+                        * allow visibility of all processes. For the
+                        * profile case, the check above will ensure that
+                        * we're examining a user context.
+                        */
+                       if (ecb->dte_cond & DTRACE_COND_OWNER) {
+                               const cred_t    *cr;
+                               const cred_t    *s_cr =
+                                       ecb->dte_state->dts_cred.dcr_cred;
+
+                               ASSERT(s_cr != NULL);
+
+                               if ((cr = current_cred()) == NULL ||
+                                   s_cr->euid != cr->euid ||
+                                   s_cr->euid != cr->uid ||
+                                   s_cr->euid != cr->suid ||
+                                   s_cr->egid != cr->egid ||
+                                   s_cr->egid != cr->gid ||
+                                   s_cr->egid != cr->sgid)
+                                       continue;
+                       }
+               }
+
+               if (ktime_gt(ktime_sub(now, state->dts_alive),
+                            dtrace_deadman_timeout)) {
+                       /*
+                        * We seem to be dead.  Unless we (a) have kernel
+                        * destructive permissions (b) have expicitly enabled
+                        * destructive actions and (c) destructive actions have
+                        * not been disabled, we're going to transition into
+                        * the KILLED state, from which no further processing
+                        * on this state will be performed.
+                        */
+                       if (!dtrace_priv_kernel_destructive(state) ||
+                           !state->dts_cred.dcr_destructive ||
+                           dtrace_destructive_disallow) {
+                               dtrace_activity_t       *activity =
+                                                       &state->dts_activity;
+                               dtrace_activity_t       curr;
+
+                               do {
+                                       curr = state->dts_activity;
+                               } while (cmpxchg(activity, curr,
+                                        DTRACE_ACTIVITY_KILLED) != curr);
+
+                               continue;
+                       }
+               }
+
+               if ((offs = dtrace_buffer_reserve(buf, ecb->dte_needed,
+                                                 ecb->dte_alignment, state,
+                                                 &mstate)) < 0)
+                       continue;
+
+               tomax = buf->dtb_tomax;
+               ASSERT(tomax != NULL);
+
+               if (ecb->dte_size != 0)
+                       DTRACE_STORE(uint32_t, tomax, offs, ecb->dte_epid);
+
+               mstate.dtms_epid = ecb->dte_epid;
+               mstate.dtms_present |= DTRACE_MSTATE_EPID;
+
+               if (state->dts_cred.dcr_visible & DTRACE_CRV_KERNEL)
+                       mstate.dtms_access = DTRACE_ACCESS_KERNEL;
+               else
+                       mstate.dtms_access = 0;
+
+               if (pred != NULL) {
+                       dtrace_difo_t   *dp = pred->dtp_difo;
+                       int             rval;
+
+                       rval = dtrace_dif_emulate(dp, &mstate, vstate, state);
+
+                       if (!(*flags & CPU_DTRACE_ERROR) && !rval) {
+                               dtrace_cacheid_t        cid =
+                                                       probe->dtpr_predcache;
+
+                               if (cid != DTRACE_CACHEIDNONE && !onintr) {
+                                       /*
+                                        * Update the predicate cache...
+                                        */
+                                       ASSERT(cid == pred->dtp_cacheid);
+                                       current->predcache = cid;
+                               }
+
+                               continue;
+                       }
+               }
+
+               for (act = ecb->dte_action;
+                    !(*flags & CPU_DTRACE_ERROR) && act != NULL;
+                    act = act->dta_next) {
+                       size_t                  valoffs;
+                       dtrace_difo_t           *dp;
+                       dtrace_recdesc_t        *rec = &act->dta_rec;
+
+                       size = rec->dtrd_size;
+                       valoffs = offs + rec->dtrd_offset;
+
+                       if (DTRACEACT_ISAGG(act->dta_kind)) {
+                               uint64_t                v = 0xbad;
+                               dtrace_aggregation_t    *agg;
+
+                               agg = (dtrace_aggregation_t *)act;
+
+                               if ((dp = act->dta_difo) != NULL)
+                                       v = dtrace_dif_emulate(dp, &mstate,
+                                                              vstate, state);
+
+                               if (*flags & CPU_DTRACE_ERROR)
+                                       continue;
+
+                               /*
+                                * Note that we always pass the expression
+                                * value from the previous iteration of the
+                                * action loop.  This value will only be used
+                                * if there is an expression argument to the
+                                * aggregating action, denoted by the
+                                * dtag_hasarg field.
+                                */
+                               dtrace_aggregate(agg, buf, offs, aggbuf, v,
+                                                val);
+                               continue;
+                       }
+
+                       switch (act->dta_kind) {
+                       case DTRACEACT_STOP:
+                               if (dtrace_priv_proc_destructive(state))
+                                       dtrace_action_stop();
+                               continue;
+
+                       case DTRACEACT_BREAKPOINT:
+                               if (dtrace_priv_kernel_destructive(state))
+                                       dtrace_action_breakpoint(ecb);
+                               continue;
+
+                       case DTRACEACT_PANIC:
+                               if (dtrace_priv_kernel_destructive(state))
+                                       dtrace_action_panic(ecb);
+                               continue;
+
+                       case DTRACEACT_STACK:
+                               if (!dtrace_priv_kernel(state))
+                                       continue;
+
+                               dtrace_getpcstack(
+                                       (uint64_t *)(tomax + valoffs),
+                                       size / sizeof(pc_t),
+                                       probe->dtpr_aframes,
+                                       DTRACE_ANCHORED(probe)
+                                               ? NULL
+                                               : (uint32_t *)arg0);
+
+                               continue;
+
+                       case DTRACEACT_JSTACK:
+                       case DTRACEACT_USTACK:
+                               if (!dtrace_priv_proc(state))
+                                       continue;
+
+                               /*
+                                * See comment in DIF_VAR_PID.
+                                */
+                               if (DTRACE_ANCHORED(mstate.dtms_probe) &&
+                                   in_interrupt()) {
+                                       int     depth = DTRACE_USTACK_NFRAMES(
+                                                           rec->dtrd_arg) + 1;
+
+                                       dtrace_bzero((void *)(tomax + valoffs),
+                                                    DTRACE_USTACK_STRSIZE(
+                                                       rec->dtrd_arg) +
+                                                    depth * sizeof(uint64_t));
+
+                                       continue;
+                               }
+
+                               if (DTRACE_USTACK_STRSIZE(rec->dtrd_arg) != 0 &&
+                                   current->dtrace_helpers != NULL) {
+                                       /*
+                                        * This is the slow path -- we have
+                                        * allocated string space, and we're
+                                        * getting the stack of a process that
+                                        * has helpers.  Call into a separate
+                                        * routine to perform this processing.
+                                        */
+                                       dtrace_action_ustack(
+                                               &mstate, state,
+                                               (uint64_t *)(tomax + valoffs),
+                                               rec->dtrd_arg);
+                                       continue;
+                               }
+
+                               DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+                               dtrace_getupcstack(
+                                       (uint64_t *)(tomax + valoffs),
+                                       DTRACE_USTACK_NFRAMES(rec->dtrd_arg) +
+                                       1);
+                               DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
+                               continue;
+
+                       default:
+                               break;
+                       }
+
+                       dp = act->dta_difo;
+                       ASSERT(dp != NULL);
+
+                       val = dtrace_dif_emulate(dp, &mstate, vstate, state);
+
+                       if (*flags & CPU_DTRACE_ERROR)
+                               continue;
+
+                       switch (act->dta_kind) {
+                       case DTRACEACT_SPECULATE:
+                               ASSERT(buf == &state->dts_buffer[cpuid]);
+                               buf = dtrace_speculation_buffer(state, cpuid,
+                                                               val);
+
+                               if (buf == NULL) {
+                                       *flags |= CPU_DTRACE_DROP;
+                                       continue;
+                               }
+
+                               offs = dtrace_buffer_reserve(buf,
+                                                            ecb->dte_needed,
+                                                            ecb->dte_alignment,
+                                                            state, NULL);
+
+                               if (offs < 0) {
+                                       *flags |= CPU_DTRACE_DROP;
+                                       continue;
+                               }
+
+                               tomax = buf->dtb_tomax;
+                               ASSERT(tomax != NULL);
+
+                               if (ecb->dte_size != 0)
+                                       DTRACE_STORE(uint32_t, tomax, offs,
+                                                    ecb->dte_epid);
+
+                               continue;
+
+                       case DTRACEACT_CHILL:
+                               if (dtrace_priv_kernel_destructive(state))
+                                       dtrace_action_chill(&mstate,
+                                                           ns_to_ktime(val));
+
+                               continue;
+
+                       case DTRACEACT_RAISE:
+                               if (dtrace_priv_proc_destructive(state))
+                                       dtrace_action_raise(val);
+
+                               continue;
+
+                       case DTRACEACT_COMMIT:
+                               ASSERT(!committed);
+
+                               /*
+                                * We need to commit our buffer state.
+                                */
+                               if (ecb->dte_size)
+                                       buf->dtb_offset = offs + ecb->dte_size;
+
+                               buf = &state->dts_buffer[cpuid];
+                               dtrace_speculation_commit(state, cpuid, val);
+                               committed = 1;
+                               continue;
+
+                       case DTRACEACT_DISCARD:
+                               dtrace_speculation_discard(state, cpuid, val);
+                               continue;
+
+                       case DTRACEACT_DIFEXPR:
+                       case DTRACEACT_LIBACT:
+                       case DTRACEACT_PRINTF:
+                       case DTRACEACT_PRINTA:
+                       case DTRACEACT_SYSTEM:
+                       case DTRACEACT_FREOPEN:
+                               break;
+
+                       case DTRACEACT_SYM:
+                       case DTRACEACT_MOD:
+                               if (!dtrace_priv_kernel(state))
+                                       continue;
+                               break;
+
+                       case DTRACEACT_USYM:
+                       case DTRACEACT_UMOD:
+                       case DTRACEACT_UADDR: {
+                               pid_t   pid = current->pid;
+
+                               if (!dtrace_priv_proc(state))
+                                       continue;
+
+                               DTRACE_STORE(uint64_t, tomax, valoffs,
+                                            (uint64_t)pid);
+                               DTRACE_STORE(uint64_t, tomax,
+                                            valoffs + sizeof(uint64_t), val);
+
+                               continue;
+                       }
+
+                       case DTRACEACT_EXIT: {
+                               /*
+                                * For the exit action, we are going to attempt
+                                * to atomically set our activity to be
+                                * draining.  If this fails (either because
+                                * another CPU has beat us to the exit action,
+                                * or because our current activity is something
+                                * other than ACTIVE or WARMUP), we will
+                                * continue.  This assures that the exit action
+                                * can be successfully recorded at most once
+                                * when we're in the ACTIVE state.  If we're
+                                * encountering the exit() action while in
+                                * COOLDOWN, however, we want to honor the new
+                                * status code.  (We know that we're the only
+                                * thread in COOLDOWN, so there is no race.)
+                                */
+                               dtrace_activity_t       *activity =
+                                                       &state->dts_activity;
+                               dtrace_activity_t       curr =
+                                                       state->dts_activity;
+
+                               if (curr == DTRACE_ACTIVITY_COOLDOWN)
+                                       break;
+
+                               if (curr != DTRACE_ACTIVITY_WARMUP)
+                                       curr = DTRACE_ACTIVITY_ACTIVE;
+
+                               if (cmpxchg(activity, curr,
+                                           DTRACE_ACTIVITY_DRAINING) != curr) {
+                                       *flags |= CPU_DTRACE_DROP;
+                                       continue;
+                               }
+
+                               break;
+                       }
+
+                       default:
+                               ASSERT(0);
+                       }
+
+                       if (dp->dtdo_rtype.dtdt_flags & DIF_TF_BYREF) {
+                               uintptr_t       end = valoffs + size;
+
+                               if (!dtrace_vcanload((void *)(uintptr_t)val,
+                                                     &dp->dtdo_rtype, &mstate,
+                                                     vstate))
+                                       continue;
+
+                               /*
+                                * If this is a string, we're going to only
+                                * load until we find the zero byte -- after
+                                * which we'll store zero bytes.
+                                */
+                               if (dp->dtdo_rtype.dtdt_kind ==
+                                   DIF_TYPE_STRING) {
+                                       char    c = '\0' + 1;
+                                       int     intuple = act->dta_intuple;
+                                       size_t  s;
+
+                                       for (s = 0; s < size; s++) {
+                                               if (c != '\0')
+                                                       c = dtrace_load8(val++);
+
+                                               DTRACE_STORE(uint8_t, tomax,
+                                                            valoffs++, c);
+
+                                               if (c == '\0' && intuple)
+                                                       break;
+                                       }
+
+                                       continue;
+                               }
+
+                               while (valoffs < end)
+                                       DTRACE_STORE(uint8_t, tomax, valoffs++,
+                                                    dtrace_load8(val++));
+
+                               continue;
+                       }
+
+                       switch (size) {
+                       case 0:
+                               break;
+                       case sizeof(uint8_t):
+                               DTRACE_STORE(uint8_t, tomax, valoffs, val);
+                               break;
+                       case sizeof(uint16_t):
+                               DTRACE_STORE(uint16_t, tomax, valoffs, val);
+                               break;
+                       case sizeof(uint32_t):
+                               DTRACE_STORE(uint32_t, tomax, valoffs, val);
+                               break;
+                       case sizeof(uint64_t):
+                               DTRACE_STORE(uint64_t, tomax, valoffs, val);
+                               break;
+                       default:
+                               /*
+                                * Any other size should have been returned by
+                                * reference, not by value.
+                                */
+                               ASSERT(0);
+                               break;
+                       }
+               }
+
+               if (*flags & CPU_DTRACE_DROP)
+                       continue;
+
+               if (*flags & CPU_DTRACE_FAULT) {
+                       int             ndx;
+                       dtrace_action_t *err;
+
+                       buf->dtb_errors++;
+
+                       if (probe->dtpr_id == dtrace_probeid_error) {
+                               /*
+                                * There's nothing we can do -- we had an
+                                * error on the error probe.  We bump an
+                                * error counter to at least indicate that
+                                * this condition happened.
+                                */
+                               dtrace_error(&state->dts_dblerrors);
+                               continue;
+                       }
+
+                       if (vtime)
+                               /*
+                                * Before recursing on dtrace_probe(), we
+                                * need to explicitly clear out our start
+                                * time to prevent it from being accumulated
+                                * into t_dtrace_vtime.
+                                */
+                               current->dtrace_start = ktime_set(0, 0);
+
+                       /*
+                        * Iterate over the actions to figure out which action
+                        * we were processing when we experienced the error.
+                        * Note that act points _past_ the faulting action; if
+                        * act is ecb->dte_action, the fault was in the
+                        * predicate, if it's ecb->dte_action->dta_next it's
+                        * in action #1, and so on.
+                        */
+                       for (err = ecb->dte_action, ndx = 0;
+                            err != act; err = err->dta_next, ndx++)
+                               continue;
+
+                       dtrace_probe_error(
+                               state, ecb->dte_epid, ndx,
+                               (mstate.dtms_present & DTRACE_MSTATE_FLTOFFS)
+                                       ?  mstate.dtms_fltoffs
+                                       : -1,
+                               DTRACE_FLAGS2FLT(*flags),
+                               cpu_core[cpuid].cpuc_dtrace_illval);
+
+                       continue;
+               }
+
+               if (!committed)
+                       buf->dtb_offset = offs + ecb->dte_size;
+       }
+
+       if (vtime)
+               current->dtrace_start = dtrace_gethrtime();
+
+       local_irq_restore(cookie);
+}
+EXPORT_SYMBOL(dtrace_probe);
+
+void dtrace_probe_init(void)
+{
+       dtrace_id_t     id;
+       int             err;
+
+       idr_init(&dtrace_probe_idr);
+
+       /*
+        * We create a ID 0 entry as a sentinel, so we can always depend on it
+        * being the very first entry.  This is used in functionality that runs
+        * through the list of probes.
+        *
+        * We need to drop our locks when calling idr_pre_get(), so we try to
+        * get them back right after.
+        */
+again:
+       mutex_unlock(&cpu_lock);
+       mutex_unlock(&dtrace_provider_lock);
+       mutex_unlock(&dtrace_lock);
+
+       idr_pre_get(&dtrace_probe_idr, __GFP_NOFAIL);
+
+       mutex_lock(&dtrace_lock);
+       mutex_lock(&dtrace_provider_lock);
+       mutex_lock(&cpu_lock);
+
+       err = idr_get_new(&dtrace_probe_idr, NULL, &id);
+       if (err == -EAGAIN)
+               goto again;
+
+       ASSERT(id == 0);
+}
+
+void dtrace_probe_exit(void)
+{
+       idr_remove_all(&dtrace_probe_idr);
+       idr_destroy(&dtrace_probe_idr);
+}
+
+void dtrace_probe_remove_id(dtrace_id_t id)
+{
+       return idr_remove(&dtrace_probe_idr, id);
+}
+
+dtrace_probe_t *dtrace_probe_lookup_id(dtrace_id_t id)
+{
+       return idr_find(&dtrace_probe_idr, id);
+}
+
+static int dtrace_probe_lookup_match(dtrace_probe_t *probe, void *arg)
+{
+       *((dtrace_id_t *)arg) = probe->dtpr_id;
+
+       return DTRACE_MATCH_DONE;
+}
+
+dtrace_id_t dtrace_probe_lookup(dtrace_provider_id_t prid, const char *mod,
+                               const char *func, const char *name)
+{
+       dtrace_probekey_t       pkey;
+       dtrace_id_t             id;
+       int                     match;
+
+       /* FIXME: Maybe?  We really should protect against this. */
+       if (mutex_is_locked(&dtrace_lock)) {
+               WARN(1, "dtrace_probe_lookup() called with dtrace_lock held!");
+               return 0;
+       }
+
+       pkey.dtpk_prov = ((dtrace_provider_t *)prid)->dtpv_name;
+       pkey.dtpk_pmatch = &dtrace_match_string;
+       pkey.dtpk_mod = mod;
+       pkey.dtpk_mmatch = mod ? &dtrace_match_string : &dtrace_match_nul;
+       pkey.dtpk_func = func;
+       pkey.dtpk_fmatch = func ? &dtrace_match_string : &dtrace_match_nul;
+       pkey.dtpk_name = name;
+       pkey.dtpk_nmatch = name ? &dtrace_match_string : &dtrace_match_nul;
+       pkey.dtpk_id = DTRACE_IDNONE;
+
+       mutex_lock(&dtrace_lock);
+       match = dtrace_match(&pkey, DTRACE_PRIV_ALL, 0,
+                            dtrace_probe_lookup_match, &id);
+       mutex_unlock(&dtrace_lock);
+
+       ASSERT(match == 1 || match == 0);
+
+       return match ? id : 0;
+}
+EXPORT_SYMBOL(dtrace_probe_lookup);
+
+dtrace_probe_t *dtrace_probe_get_next(dtrace_id_t id)
+{
+       return idr_get_next(&dtrace_probe_idr, &id);
+}
+
+int dtrace_probe_for_each(int (*fn)(int id, void *p, void *data), void *data)
+{
+       return idr_for_each(&dtrace_probe_idr, fn, data);
+}
diff --git a/dtrace/dtrace_probe_ctx.c b/dtrace/dtrace_probe_ctx.c
new file mode 100644 (file)
index 0000000..1fa96cd
--- /dev/null
@@ -0,0 +1,538 @@
+/*
+ * FILE:       dtrace_probe_ctx.c
+ * DESCRIPTION:        Dynamic Tracing: probe context functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include "dtrace.h"
+
+void dtrace_panic(const char *fmt, ...)
+{
+       va_list         alist;
+
+       va_start(alist, fmt);
+       vprintk(fmt, alist);
+       va_end(alist);
+
+       BUG();
+}
+
+int dtrace_assfail(const char *a, const char *f, int l)
+{
+       dtrace_panic(KERN_EMERG "assertion failed: %s, file: %s, line: %d",
+                    a, f, l);
+
+       /*
+        * FIXME: We can do better than this.  The OpenSolaris DTrace source
+        * states that this cannot be optimized away.
+        */
+       return a[(uintptr_t)f];
+}
+EXPORT_SYMBOL(dtrace_assfail);
+
+#define DT_MASK_LO     0x00000000FFFFFFFFULL
+
+static void dtrace_add_128(uint64_t *addend1, uint64_t *addend2, uint64_t *sum)
+{
+       uint64_t        result[2];
+
+       result[0] = addend1[0] + addend2[0];
+       result[1] = addend1[1] + addend2[1] +
+                   (result[0] < addend1[0] || result[0] < addend2[0] ? 1 : 0);
+
+       sum[0] = result[0];
+       sum[1] = result[1];
+}
+
+static void dtrace_shift_128(uint64_t *a, int b)
+{
+       uint64_t        mask;
+
+       if (b == 0)
+               return;
+
+       if (b < 0) {
+               b = -b;
+
+               if (b >= 64) {
+                       a[0] = a[1] >> (b - 64);
+                       a[1] = 0;
+               } else {
+                       a[0] >>= b;
+                       mask = 1LL << (64 - b);
+                       mask -= 1;
+                       a[0] |= ((a[1] & mask) << (64 - b));
+                       a[1] >>= b;
+               }
+       } else {
+               if (b >= 64) {
+                       a[1] = a[0] << (b - 64);
+                       a[0] = 0;
+               } else {
+                       a[1] <<= b;
+                       mask = a[0] >> (64 - b);
+                       a[1] |= mask;
+                       a[0] <<= b;
+               }
+       }
+}
+
+static void dtrace_multiply_128(uint64_t factor1, uint64_t factor2,
+                               uint64_t *product)
+{
+       uint64_t        hi1, hi2, lo1, lo2;
+       uint64_t        tmp[2];
+
+       hi1 = factor1 >> 32;
+       hi2 = factor2 >> 32;
+
+       lo1 = factor1 & DT_MASK_LO;
+       lo2 = factor2 & DT_MASK_LO;
+
+       product[0] = lo1 * lo2;
+       product[1] = hi1 * hi2;
+
+       tmp[0] = hi1 * lo2;
+       tmp[1] = 0;
+       dtrace_shift_128(tmp, 32);
+       dtrace_add_128(product, tmp, product);
+
+       tmp[0] = hi2 * lo1;
+       tmp[1] = 0;
+       dtrace_shift_128(tmp, 32);
+       dtrace_add_128(product, tmp, product);
+}
+
+void dtrace_aggregate_min(uint64_t *oval, uint64_t nval, uint64_t arg)
+{
+       if ((int64_t)nval < (int64_t)*oval)
+               *oval = nval;
+}
+
+void dtrace_aggregate_max(uint64_t *oval, uint64_t nval, uint64_t arg)
+{
+       if ((int64_t)nval > (int64_t)*oval)
+               *oval = nval;
+}
+
+void dtrace_aggregate_quantize(uint64_t *quanta, uint64_t nval, uint64_t incr)
+{
+       int     i, zero = DTRACE_QUANTIZE_ZEROBUCKET;
+       int64_t val = (int64_t)nval;
+
+       if (val < 0) {
+               for (i = 0; i < zero; i++) {
+                       if (val <= DTRACE_QUANTIZE_BUCKETVAL(i)) {
+                               quanta[i] += incr;
+
+                               return;
+                       }
+               }
+       } else {
+               for (i = zero + 1; i < DTRACE_QUANTIZE_NBUCKETS; i++) {
+                       if (val < DTRACE_QUANTIZE_BUCKETVAL(i)) {
+                               quanta[i - 1] += incr;
+
+                               return;
+                       }
+               }
+
+               quanta[DTRACE_QUANTIZE_NBUCKETS - 1] += incr;
+
+               return;
+       }
+
+       ASSERT(0);
+}
+
+void dtrace_aggregate_lquantize(uint64_t *lquanta, uint64_t nval,
+                               uint64_t incr)
+{
+       uint64_t        arg = *lquanta++;
+       int32_t         base = DTRACE_LQUANTIZE_BASE(arg);
+       uint16_t        step = DTRACE_LQUANTIZE_STEP(arg);
+       uint16_t        levels = DTRACE_LQUANTIZE_LEVELS(arg);
+       int32_t         val = (int32_t)nval, level;
+
+       ASSERT(step != 0);
+       ASSERT(levels != 0);
+
+       if (val < base) {
+               lquanta[0] += incr;
+
+               return;
+       }
+
+       level = (val - base) / step;
+
+       if (level < levels) {
+               lquanta[level + 1] += incr;
+
+               return;
+       }
+
+       lquanta[levels + 1] += incr;
+}
+
+void dtrace_aggregate_avg(uint64_t *data, uint64_t nval, uint64_t arg)
+{
+       data[0]++;
+       data[1] += nval;
+}
+
+void dtrace_aggregate_stddev(uint64_t *data, uint64_t nval, uint64_t arg)
+{
+       int64_t         snval = (int64_t)nval;
+       uint64_t        tmp[2];
+
+       data[0]++;
+       data[1] += nval;
+
+       if (snval < 0)
+               snval = -snval;
+
+       dtrace_multiply_128((uint64_t)snval, (uint64_t)snval, tmp);
+       dtrace_add_128(data + 2, tmp, data + 2);
+}
+
+void dtrace_aggregate_count(uint64_t *oval, uint64_t nval, uint64_t arg)
+{
+       *oval = *oval + 1;
+}
+
+void dtrace_aggregate_sum(uint64_t *oval, uint64_t nval, uint64_t arg)
+{
+       *oval += nval;
+}
+
+/*
+ * DTrace Aggregation Buffers
+ *
+ * Aggregation buffers use much of the same mechanism as described above
+ * ("DTrace Buffers").  However, because an aggregation is fundamentally a
+ * hash, there exists dynamic metadata associated with an aggregation buffer
+ * that is not associated with other kinds of buffers.  This aggregation
+ * metadata is _only_ relevant for the in-kernel implementation of
+ * aggregations; it is not actually relevant to user-level consumers.  To do
+ * this, we allocate dynamic aggregation data (hash keys and hash buckets)
+ * starting below the _limit_ of the buffer, and we allocate data from the
+ * _base_ of the buffer.  When the aggregation buffer is copied out, _only_ the
+ * data is copied out; the metadata is simply discarded.  Schematically,
+ * aggregation buffers look like:
+ *
+ *      base of data buffer --->  +-------+------+-----------+-------+
+ *                                | aggid | key  | value     | aggid |
+ *                                +-------+------+-----------+-------+
+ *                                | key                              |
+ *                                +-------+-------+-----+------------+
+ *                                | value | aggid | key | value      |
+ *                                +-------+------++-----+------+-----+
+ *                                | aggid | key  | value       |     |
+ *                                +-------+------+-------------+     |
+ *                                |                ||                |
+ *                                |                ||                |
+ *                                |                \/                |
+ *                                :                                  :
+ *                                .                                  .
+ *                                .                                  .
+ *                                .                                  .
+ *                                :                                  :
+ *                                |                /\                |
+ *                                |                ||   +------------+
+ *                                |                ||   |            |
+ *                                +---------------------+            |
+ *                                | hash keys                        |
+ *                                | (dtrace_aggkey structures)       |
+ *                                |                                  |
+ *                                +----------------------------------+
+ *                                | hash buckets                     |
+ *                                | (dtrace_aggbuffer structure)     |
+ *                                |                                  |
+ *     limit of data buffer --->  +----------------------------------+
+ *
+ * As implied above, just as we assure that ECBs always store a constant
+ * amount of data, we assure that a given aggregation -- identified by its
+ * aggregation ID -- always stores data of a constant quantity and type.
+ * As with EPIDs, this allows the aggregation ID to serve as the metadata for a
+ * given record.
+ *
+ * Note that the size of the dtrace_aggkey structure must be sizeof (uintptr_t)
+ * aligned.  (If this the structure changes such that this becomes false, an
+ * assertion will fail in dtrace_aggregate().)
+ */
+#define DTRACE_AGGHASHSIZE_SLEW                17
+
+typedef struct dtrace_aggkey {
+       uint32_t dtak_hashval;                  /* hash value */
+       uint32_t dtak_action:4;                 /* action -- 4 bits */
+       uint32_t dtak_size:28;                  /* size -- 28 bits */
+       caddr_t dtak_data;                      /* data pointer */
+       struct dtrace_aggkey *dtak_next;        /* next in hash chain */
+} dtrace_aggkey_t;
+
+typedef struct dtrace_aggbuffer {
+       uintptr_t dtagb_hashsize;               /* number of buckets */
+       uintptr_t dtagb_free;                   /* free list of keys */
+       dtrace_aggkey_t **dtagb_hash;           /* hash table */
+} dtrace_aggbuffer_t;
+
+#define DTRACEACT_ISSTRING(act)                                                      \
+       ((act)->dta_kind == DTRACEACT_DIFEXPR &&                              \
+        (act)->dta_difo->dtdo_rtype.dtdt_kind == DIF_TYPE_STRING)
+
+/*
+ * Aggregate given the tuple in the principal data buffer, and the aggregating
+ * action denoted by the specified dtrace_aggregation_t.  The aggregation
+ * buffer is specified as the buf parameter.  This routine does not return
+ * failure; if there is no space in the aggregation buffer, the data will be
+ * dropped, and a corresponding counter incremented.
+ */
+void dtrace_aggregate(dtrace_aggregation_t *agg, dtrace_buffer_t *dbuf,
+                     intptr_t offset, dtrace_buffer_t *buf, uint64_t expr,
+                     uint64_t arg)
+{
+       dtrace_recdesc_t        *rec = &agg->dtag_action.dta_rec;
+       uint32_t                i, ndx, size, fsize;
+       uint32_t                align = sizeof (uint64_t) - 1;
+       dtrace_aggbuffer_t      *agb;
+       dtrace_aggkey_t         *key;
+       uint32_t                hashval = 0, limit, isstr;
+       caddr_t                 tomax, data, kdata;
+       dtrace_actkind_t        action;
+       dtrace_action_t         *act;
+       uintptr_t               offs;
+
+       if (buf == NULL)
+               return;
+
+       if (!agg->dtag_hasarg)
+               /*
+                * Currently, only quantize() and lquantize() take additional
+                * arguments, and they have the same semantics:  an increment
+                * value that defaults to 1 when not present.  If additional
+                * aggregating actions take arguments, the setting of the
+                * default argument value will presumably have to become more
+                * sophisticated...
+                */
+               arg = 1;
+
+       action = agg->dtag_action.dta_kind - DTRACEACT_AGGREGATION;
+       size = rec->dtrd_offset - agg->dtag_base;
+       fsize = size + rec->dtrd_size;
+
+       ASSERT(dbuf->dtb_tomax != NULL);
+       data = dbuf->dtb_tomax + offset + agg->dtag_base;
+
+       if ((tomax = buf->dtb_tomax) == NULL) {
+               dtrace_buffer_drop(buf);
+               return;
+       }
+
+       /*
+        * The metastructure is always at the bottom of the buffer.
+        */
+       agb = (dtrace_aggbuffer_t *)(tomax + buf->dtb_size -
+                                            sizeof (dtrace_aggbuffer_t));
+
+       if (buf->dtb_offset == 0) {
+               /*
+                * We just kludge up approximately 1/8th of the size to be
+                * buckets.  If this guess ends up being routinely
+                * off-the-mark, we may need to dynamically readjust this
+                * based on past performance.
+                */
+               uintptr_t       hashsize = (buf->dtb_size >> 3) /
+                                          sizeof (uintptr_t);
+
+               if ((uintptr_t)agb - hashsize * sizeof (dtrace_aggkey_t *) <
+                   (uintptr_t)tomax || hashsize == 0) {
+                       /*
+                        * We've been given a ludicrously small buffer;
+                        * increment our drop count and leave.
+                        */
+                       dtrace_buffer_drop(buf);
+                       return;
+               }
+
+               /*
+                * And now, a pathetic attempt to try to get a an odd (or
+                * perchance, a prime) hash size for better hash distribution.
+                */
+               if (hashsize > (DTRACE_AGGHASHSIZE_SLEW << 3))
+                       hashsize -= DTRACE_AGGHASHSIZE_SLEW;
+
+               agb->dtagb_hashsize = hashsize;
+               agb->dtagb_hash = (dtrace_aggkey_t **)((uintptr_t)agb -
+               agb->dtagb_hashsize * sizeof (dtrace_aggkey_t *));
+               agb->dtagb_free = (uintptr_t)agb->dtagb_hash;
+
+               for (i = 0; i < agb->dtagb_hashsize; i++)
+                       agb->dtagb_hash[i] = NULL;
+       }
+
+       ASSERT(agg->dtag_first != NULL);
+       ASSERT(agg->dtag_first->dta_intuple);
+
+       /*
+        * Calculate the hash value based on the key.  Note that we _don't_
+        * include the aggid in the hashing (but we will store it as part of
+        * the key).  The hashing algorithm is Bob Jenkins' "One-at-a-time"
+        * algorithm: a simple, quick algorithm that has no known funnels, and
+        * gets good distribution in practice.  The efficacy of the hashing
+        * algorithm (and a comparison with other algorithms) may be found by
+        * running the ::dtrace_aggstat MDB dcmd.
+        */
+       for (act = agg->dtag_first; act->dta_intuple; act = act->dta_next) {
+               i = act->dta_rec.dtrd_offset - agg->dtag_base;
+               limit = i + act->dta_rec.dtrd_size;
+               ASSERT(limit <= size);
+               isstr = DTRACEACT_ISSTRING(act);
+
+               for (; i < limit; i++) {
+                       hashval += data[i];
+                       hashval += (hashval << 10);
+                       hashval ^= (hashval >> 6);
+
+                       if (isstr && data[i] == '\0')
+                               break;
+               }
+       }
+
+       hashval += (hashval << 3);
+       hashval ^= (hashval >> 11);
+       hashval += (hashval << 15);
+
+       /*
+        * Yes, the divide here is expensive -- but it's generally the least
+        * of the performance issues given the amount of data that we iterate
+        * over to compute hash values, compare data, etc.
+        */
+       ndx = hashval % agb->dtagb_hashsize;
+
+       for (key = agb->dtagb_hash[ndx]; key != NULL; key = key->dtak_next) {
+               ASSERT((caddr_t)key >= tomax);
+               ASSERT((caddr_t)key < tomax + buf->dtb_size);
+
+               if (hashval != key->dtak_hashval || key->dtak_size != size)
+                       continue;
+
+               kdata = key->dtak_data;
+               ASSERT(kdata >= tomax && kdata < tomax + buf->dtb_size);
+
+               for (act = agg->dtag_first; act->dta_intuple;
+                    act = act->dta_next) {
+                       i = act->dta_rec.dtrd_offset - agg->dtag_base;
+                       limit = i + act->dta_rec.dtrd_size;
+                       ASSERT(limit <= size);
+                       isstr = DTRACEACT_ISSTRING(act);
+
+                       for (; i < limit; i++) {
+                               if (kdata[i] != data[i])
+                                       goto next;
+
+                               if (isstr && data[i] == '\0')
+                                       break;
+                       }
+               }
+
+               if (action != key->dtak_action) {
+                       /*
+                        * We are aggregating on the same value in the same
+                        * aggregation with two different aggregating actions.
+                        * (This should have been picked up in the compiler,
+                        * so we may be dealing with errant or devious DIF.)
+                        * This is an error condition; we indicate as much,
+                        * and return.
+                        */
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
+                       return;
+               }
+
+               /*
+                * This is a hit:  we need to apply the aggregator to
+                * the value at this key.
+                */
+               agg->dtag_aggregate((uint64_t *)(kdata + size), expr, arg);
+               return;
+next:
+               continue;
+       }
+
+       /*
+        * We didn't find it.  We need to allocate some zero-filled space,
+        * link it into the hash table appropriately, and apply the aggregator
+        * to the (zero-filled) value.
+        */
+       offs = buf->dtb_offset;
+       while (offs & (align - 1))
+               offs += sizeof (uint32_t);
+
+       /*
+        * If we don't have enough room to both allocate a new key _and_
+        * its associated data, increment the drop count and return.
+        */
+       if ((uintptr_t)tomax + offs + fsize >
+           agb->dtagb_free - sizeof (dtrace_aggkey_t)) {
+               dtrace_buffer_drop(buf);
+               return;
+       }
+
+       ASSERT(!(sizeof (dtrace_aggkey_t) & (sizeof (uintptr_t) - 1)));
+       key = (dtrace_aggkey_t *)(agb->dtagb_free - sizeof (dtrace_aggkey_t));
+       agb->dtagb_free -= sizeof (dtrace_aggkey_t);
+
+       key->dtak_data = kdata = tomax + offs;
+       buf->dtb_offset = offs + fsize;
+
+       /*
+        * Now copy the data across.
+        */
+       *((dtrace_aggid_t *)kdata) = agg->dtag_id;
+
+       for (i = sizeof (dtrace_aggid_t); i < size; i++)
+               kdata[i] = data[i];
+
+       /*
+        * Because strings are not zeroed out by default, we need to iterate
+        * looking for actions that store strings, and we need to explicitly
+        * pad these strings out with zeroes.
+        */
+       for (act = agg->dtag_first; act->dta_intuple; act = act->dta_next) {
+               int     nul;
+
+               if (!DTRACEACT_ISSTRING(act))
+                       continue;
+
+               i = act->dta_rec.dtrd_offset - agg->dtag_base;
+               limit = i + act->dta_rec.dtrd_size;
+               ASSERT(limit <= size);
+
+               for (nul = 0; i < limit; i++) {
+                       if (nul) {
+                               kdata[i] = '\0';
+                               continue;
+                       }
+
+                       if (data[i] != '\0')
+                               continue;
+
+                       nul = 1;
+               }
+       }
+
+       for (i = size; i < fsize; i++)
+               kdata[i] = 0;
+
+       key->dtak_hashval = hashval;
+       key->dtak_size = size;
+       key->dtak_action = action;
+       key->dtak_next = agb->dtagb_hash[ndx];
+       agb->dtagb_hash[ndx] = key;
+
+       /*
+        * Finally, apply the aggregator.
+        */
+       *((uint64_t *)(key->dtak_data + size)) = agg->dtag_initial;
+       agg->dtag_aggregate((uint64_t *)(key->dtak_data + size), expr, arg);
+}
diff --git a/dtrace/dtrace_ptofapi.c b/dtrace/dtrace_ptofapi.c
new file mode 100644 (file)
index 0000000..9e42af9
--- /dev/null
@@ -0,0 +1,417 @@
+/*
+ * FILE:       dtrace_ptofapi.c
+ * DESCRIPTION:        Dynamic Tracing: provider-to-framework API
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/idr.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+
+#include "dtrace.h"
+
+dtrace_provider_t      *dtrace_provider;
+
+DEFINE_MUTEX(dtrace_lock);
+DEFINE_MUTEX(dtrace_provider_lock);
+DEFINE_MUTEX(dtrace_meta_lock);
+
+/*
+ * Register the calling provider with the DTrace core.  This should generally
+ * be called by providers during module initialization.
+ */
+int dtrace_register(const char *name, const dtrace_pattr_t *pap, uint32_t priv,
+                   cred_t *cr, const dtrace_pops_t *pops, void *arg,
+                   dtrace_provider_id_t *idp)
+{
+       dtrace_provider_t       *provider;
+
+       if (name == NULL || pap == NULL || pops == NULL || idp == NULL) {
+               pr_warning("Failed to register provider %s: invalid args\n",
+                          name ? name : "<NULL>");
+               return -EINVAL;
+       }
+
+       if (name[0] == '\0' || dtrace_badname(name)) {
+               pr_warning("Failed to register provider %s: invalid name\n",
+                          name);
+               return -EINVAL;
+       }
+
+       if ((pops->dtps_provide == NULL && pops->dtps_provide_module == NULL) ||
+           pops->dtps_enable == NULL || pops->dtps_disable == NULL ||
+           pops->dtps_destroy == NULL ||
+           ((pops->dtps_resume == NULL) != (pops->dtps_suspend == NULL))) {
+               pr_warning("Failed to register provider %s: invalid ops\n",
+                          name);
+               return -EINVAL;
+       }
+
+       if (dtrace_badattr(&pap->dtpa_provider) ||
+           dtrace_badattr(&pap->dtpa_mod) ||
+           dtrace_badattr(&pap->dtpa_func) ||
+           dtrace_badattr(&pap->dtpa_name) ||
+           dtrace_badattr(&pap->dtpa_args)) {
+               pr_warning("Failed to register provider %s: invalid "
+                          "attributes\n", name);
+               return -EINVAL;
+       }
+
+       if (priv & ~DTRACE_PRIV_ALL) {
+               pr_warning("Failed to register provider %s: invalid privilege "
+                          "attributes\n", name);
+               return -EINVAL;
+       }
+
+       if ((priv & DTRACE_PRIV_KERNEL) &&
+           (priv & (DTRACE_PRIV_USER | DTRACE_PRIV_OWNER)) &&
+           pops->dtps_usermode == NULL) {
+               pr_warning("Failed to register provider %s: need "
+                          "dtps_usermode() op for given privilege "
+                          "attributes\n", name);
+               return -EINVAL;
+       }
+
+       provider = kzalloc(sizeof (dtrace_provider_t), GFP_KERNEL);
+       provider->dtpv_name = dtrace_strdup(name);
+       provider->dtpv_attr = *pap;
+       provider->dtpv_priv.dtpp_flags = priv;
+
+       if (cr != NULL) {
+               provider->dtpv_priv.dtpp_uid = get_cred(cr)->uid;
+               put_cred(cr);
+       }
+
+       provider->dtpv_pops = *pops;
+
+       if (pops->dtps_provide == NULL) {
+               ASSERT(pops->dtps_provide_module != NULL);
+               provider->dtpv_pops.dtps_provide =
+                   (void (*)(void *, const dtrace_probedesc_t *))dtrace_nullop;
+       }
+
+       if (pops->dtps_provide_module == NULL) {
+               ASSERT(pops->dtps_provide != NULL);
+               provider->dtpv_pops.dtps_provide_module =
+                   (void (*)(void *, struct module *))dtrace_nullop;
+       }
+
+       if (pops->dtps_suspend == NULL) {
+               ASSERT(pops->dtps_resume == NULL);
+               provider->dtpv_pops.dtps_suspend =
+                   (void (*)(void *, dtrace_id_t, void *))dtrace_nullop;
+               provider->dtpv_pops.dtps_resume =
+                   (void (*)(void *, dtrace_id_t, void *))dtrace_nullop;
+       }
+
+       provider->dtpv_arg = arg;
+       *idp = (dtrace_provider_id_t)provider;
+
+       if (pops == &dtrace_provider_ops) {
+               ASSERT(mutex_is_locked(&dtrace_provider_lock));
+               ASSERT(mutex_is_locked(&dtrace_lock));
+               ASSERT(dtrace_anon.dta_enabling == NULL);
+
+               /*
+                * The DTrace provider must be at the head of the provider
+                * chain.
+                */
+               provider->dtpv_next = dtrace_provider;
+               dtrace_provider = provider;
+
+               return 0;
+       }
+
+       mutex_lock(&dtrace_provider_lock);
+       mutex_lock(&dtrace_lock);
+
+       /*
+        * If there is at least one provider registered, we'll add this new one
+        * after the first provider.
+        */
+       if (dtrace_provider != NULL) {
+               provider->dtpv_next = dtrace_provider->dtpv_next;
+               dtrace_provider->dtpv_next = provider;
+       } else
+               dtrace_provider = provider;
+
+       if (dtrace_retained != NULL) {
+               dtrace_enabling_provide(provider);
+
+               /*
+                * We must now call dtrace_enabling_matchall() which needs to
+                * acquire cpu_lock and dtrace_lock.  We therefore need to drop
+                * our locks before calling it.
+                */
+               mutex_unlock(&dtrace_lock);
+               mutex_unlock(&dtrace_provider_lock);
+               dtrace_enabling_matchall();
+
+               return 0;
+       }
+
+       mutex_unlock(&dtrace_lock);
+       mutex_unlock(&dtrace_provider_lock);
+
+       return 0;
+}
+EXPORT_SYMBOL(dtrace_register);
+
+struct unreg_state {
+       dtrace_provider_t       *prov;
+       dtrace_probe_t          *first;
+};
+
+/*
+ * Check whether the given probe is still enabled for the given provider.
+ */
+static int dtrace_unregister_check(int id, void *p, void *data)
+{
+       dtrace_probe_t          *probe = (dtrace_probe_t *)p;
+       struct unreg_state      *st = (struct unreg_state *)data;
+
+       if (probe->dtpr_provider != st->prov)
+               return 0;
+
+       if (probe->dtpr_ecb == NULL)
+               return 0;
+
+       return -EBUSY;
+}
+
+/*
+ * Remove the given probe from the hash tables and the probe IDR.  The probes
+ * are chained for further processing.
+ */
+static int dtrace_unregister_probe(int id, void *p, void *data)
+{
+       dtrace_probe_t          *probe = (dtrace_probe_t *)p;
+       struct unreg_state      *st = (struct unreg_state *)data;
+
+       if (probe->dtpr_provider != st->prov)
+               return 0;
+
+       dtrace_hash_remove(dtrace_bymod, probe);
+       dtrace_hash_remove(dtrace_byfunc, probe);
+       dtrace_hash_remove(dtrace_byname, probe);
+
+       if (st->first == NULL) {
+               st->first = probe;
+               probe->dtpr_nextmod = NULL;
+       } else {
+               probe->dtpr_nextmod = st->first;
+               st->first = probe;
+       }
+
+       return 0;
+}
+
+/*
+ * Unregister the specified provider from the DTrace core.  This should be
+ * called by provider during module cleanup.
+ */
+int dtrace_unregister(dtrace_provider_id_t id)
+{
+       dtrace_provider_t       *old = (dtrace_provider_t *)id;
+       dtrace_provider_t       *prev = NULL;
+       int                     err, self = 0;
+       dtrace_probe_t          *probe;
+       struct unreg_state      st = {
+                                       old,
+                                       NULL
+                                    };
+
+printk(KERN_INFO "unregister(%p)\n", old);
+       if (old->dtpv_pops.dtps_enable ==
+           (int (*)(void *, dtrace_id_t, void *))dtrace_enable_nullop) {
+               /*
+                * When the provider is the DTrace core itself, we're called
+                * with locks already held.
+                */
+               ASSERT(old == dtrace_provider);
+               ASSERT(mutex_is_locked(&dtrace_provider_lock));
+               ASSERT(mutex_is_locked(&dtrace_lock));
+
+               self = 1;
+
+               if (dtrace_provider->dtpv_next != NULL) {
+                       /*
+                        * We cannot and should not remove the DTrace provider
+                        * if there is any other provider left.
+                        */
+                       return -EBUSY;
+               }
+       } else {
+               mutex_lock(&dtrace_provider_lock);
+               /* FIXME: mutex_lock(&mod_lock); */
+               mutex_lock(&dtrace_lock);
+       }
+
+       /*
+        * If /dev/dtrace/dtrace is still held open by a process, or if there
+        * are anonymous probes that are still enabled, we refuse to deregister
+        * providers, unless the provider has been invalidated explicitly.
+        */
+printk(KERN_INFO "unregister(%p) %d opens\n", old, dtrace_opens);
+       if (!old->dtpv_defunct &&
+           (dtrace_opens || (dtrace_anon.dta_state != NULL &&
+            dtrace_anon.dta_state->dts_necbs > 0))) {
+               if (!self) {
+                       mutex_unlock(&dtrace_lock);
+                       /* FIXME: mutex_unlock(&mod_lock); */
+                       mutex_unlock(&dtrace_provider_lock);
+               }
+
+               return -EBUSY;
+       }
+
+       /*
+        * Check whether any of the probes associated with this provider are
+        * still enabled (having at least one ECB).  If any are found, we
+        * cannot remove this provider.
+        */
+       st.prov = old;
+       err = dtrace_probe_for_each(dtrace_unregister_check, &st);
+printk(KERN_INFO "unregister(%p) check -> %d\n", old, err);
+       if (err < 0) {
+               if (!self) {
+                       mutex_unlock(&dtrace_lock);
+                       /* FIXME: mutex_unlock(&mod_lock); */
+                       mutex_unlock(&dtrace_provider_lock);
+               }
+
+               return err;
+       }
+
+       /*
+        * All the probes associated with this provider are disabled.  We can
+        * safely remove these probes from the hashtables and the probe array.
+        * We chain all the probes together for further processing.
+        */
+       dtrace_probe_for_each(dtrace_unregister_probe, &st);
+printk(KERN_INFO "unregister(%p) unregister_probe done\n", old);
+
+       /*
+        * The probes associated with the provider have been removed.  Ensure
+        * synchronization on probe IDR processing.
+        */
+       dtrace_sync();
+
+       /*
+        * Now get rid of the actual probes.
+        */
+       for (probe = st.first; probe != NULL; probe = st.first) {
+               int     probe_id = probe->dtpr_id;
+
+               st.first = probe->dtpr_nextmod;
+
+printk(KERN_INFO "unregister(%p) Destroying probe %d\n", old, probe_id);
+               old->dtpv_pops.dtps_destroy(old->dtpv_arg, probe_id,
+                                           probe->dtpr_arg);
+
+               kfree(probe->dtpr_mod);
+               kfree(probe->dtpr_func);
+               kfree(probe->dtpr_name);
+               kfree(probe);
+
+               dtrace_probe_remove_id(probe_id);
+       }
+
+       if ((prev = dtrace_provider) == old) {
+               /*
+                * We are removing the provider at the head of the chain.
+                */
+               ASSERT(self);
+               ASSERT(old->dtpv_next == NULL);
+
+               dtrace_provider = old->dtpv_next;
+       } else {
+               while (prev != NULL && prev->dtpv_next != old)
+                       prev = prev->dtpv_next;
+
+               if (prev == NULL) {
+                       pr_err("Attempt to unregister non-existent DTrace "
+                              "provider %p\n", (void *)id);
+                       BUG();
+               }
+
+               prev->dtpv_next = old->dtpv_next;
+       }
+
+       if (!self) {
+               mutex_unlock(&dtrace_lock);
+               /* FIXME: mutex_unlock(&mod_lock); */
+               mutex_unlock(&dtrace_provider_lock);
+       }
+
+       kfree(old->dtpv_name);
+       kfree(old);
+
+       return 0;
+}
+EXPORT_SYMBOL(dtrace_unregister);
+
+/*
+ * Invalidate the specified provider.  All subsequent probe lookups for the
+ * specified provider will fail, but the probes will not be removed.
+ */
+void dtrace_invalidate(dtrace_provider_id_t id)
+{
+       dtrace_provider_t       *pvp = (dtrace_provider_t *)id;
+
+       ASSERT(pvp->dtpv_pops.dtps_enable !=
+              (int (*)(void *, dtrace_id_t, void *))dtrace_enable_nullop);
+
+       mutex_lock(&dtrace_provider_lock);
+       mutex_lock(&dtrace_lock);
+
+       pvp->dtpv_defunct = 1;
+
+       mutex_unlock(&dtrace_lock);
+       mutex_unlock(&dtrace_provider_lock);
+}
+EXPORT_SYMBOL(dtrace_invalidate);
+
+/*
+ * Indicate whether or not DTrace has attached.
+ */
+int dtrace_attached(void)
+{
+       /*
+        * dtrace_provider will be non-NULL iff the DTrace driver has
+        * attached.  (It's non-NULL because DTrace is always itself a
+        * provider.)
+        */
+       return dtrace_provider != NULL;
+}
+EXPORT_SYMBOL(dtrace_attached);
+
+/*
+ * Remove all the unenabled probes for the given provider.  This function is
+ * not unlike dtrace_unregister(), except that it doesn't remove the provider
+ * -- just as many of its associated probes as it can.
+ */
+int dtrace_condense(dtrace_provider_id_t id)
+{
+       dtrace_provider_t       *prov = (dtrace_provider_t *)id;
+       int                     i;
+       dtrace_probe_t          *probe;
+
+       /*
+        * Make sure this isn't the DTrace provider itself.
+        */
+       ASSERT(prov->dtpv_pops.dtps_enable !=
+              (int (*)(void *, dtrace_id_t, void *))dtrace_enable_nullop);
+
+       mutex_lock(&dtrace_provider_lock);
+       mutex_lock(&dtrace_lock);
+
+       /* FIXME - INCOMPLETE */
+
+       mutex_unlock(&dtrace_lock);
+       mutex_unlock(&dtrace_provider_lock);
+
+       return 0;
+}
+EXPORT_SYMBOL(dtrace_condense);
diff --git a/dtrace/dtrace_spec.c b/dtrace/dtrace_spec.c
new file mode 100644 (file)
index 0000000..4b30d2f
--- /dev/null
@@ -0,0 +1,426 @@
+/*
+ * FILE:       dtrace_spec.c
+ * DESCRIPTION:        Dynamic Tracing: speculation functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/smp.h>
+#include <asm/cmpxchg.h>
+
+#include "dtrace.h"
+
+/*
+ * Given consumer state, this routine finds a speculation in the INACTIVE
+ * state and transitions it into the ACTIVE state.  If there is no speculation
+ * in the INACTIVE state, 0 is returned.  In this case, no error counter is
+ * incremented -- it is up to the caller to take appropriate action.
+ */
+int dtrace_speculation(dtrace_state_t *state)
+{
+       int                             i = 0;
+       dtrace_speculation_state_t      curr;
+       uint32_t                        *stat =
+                                           &state->dts_speculations_unavail,
+                                       count;
+
+       while (i < state->dts_nspeculations) {
+               dtrace_speculation_t    *spec = &state->dts_speculations[i];
+
+               curr = spec->dtsp_state;
+
+               if (curr != DTRACESPEC_INACTIVE) {
+                       if (curr == DTRACESPEC_COMMITTINGMANY ||
+                           curr == DTRACESPEC_COMMITTING ||
+                           curr == DTRACESPEC_DISCARDING)
+                               stat = &state->dts_speculations_busy;
+
+                       i++;
+                       continue;
+               }
+
+               if (cmpxchg((uint32_t *)&spec->dtsp_state, curr,
+                           DTRACESPEC_ACTIVE) == curr)
+                       return i + 1;
+       }
+
+       /*
+        * We couldn't find a speculation.  If we found as much as a single
+        * busy speculation buffer, we'll attribute this failure as "busy"
+        * instead of "unavail".
+        */
+       do {
+               count = *stat;
+       } while (cmpxchg(stat, count, count + 1) != count);
+
+       return 0;
+}
+
+/*
+ * This routine commits an active speculation.  If the specified speculation
+ * is not in a valid state to perform a commit(), this routine will silently do
+ * nothing.  The state of the specified speculation is transitioned according
+ * to the state transition diagram outlined in <sys/dtrace_impl.h>
+ */
+void dtrace_speculation_commit(dtrace_state_t *state, processorid_t cpu,
+                              dtrace_specid_t which)
+{
+       dtrace_speculation_t            *spec;
+       dtrace_buffer_t                 *src, *dest;
+       uintptr_t                       daddr, saddr, dlimit;
+       dtrace_speculation_state_t      curr, new = 0;
+       intptr_t                        offs;
+
+       if (which == 0)
+               return;
+
+printk(KERN_INFO "spec-commit: CPU#%d, which %d\n", cpu, which);
+       if (which > state->dts_nspeculations) {
+               cpu_core[cpu].cpuc_dtrace_flags |= CPU_DTRACE_ILLOP;
+               return;
+       }
+
+       spec = &state->dts_speculations[which - 1];
+       src = &spec->dtsp_buffer[cpu];
+       dest = &state->dts_buffer[cpu];
+
+       do {
+printk(KERN_INFO "spec-commit: a) CPU#%d, which %d, spec-state %d\n", cpu, which, spec->dtsp_state);
+               curr = spec->dtsp_state;
+
+               if (curr == DTRACESPEC_COMMITTINGMANY)
+                       break;
+
+               switch (curr) {
+               case DTRACESPEC_INACTIVE:
+               case DTRACESPEC_DISCARDING:
+                       return;
+
+               case DTRACESPEC_COMMITTING:
+                       /*
+                        * This is only possible if we are (a) commit()'ing
+                        * without having done a prior speculate() on this CPU
+                        * and (b) racing with another commit() on a different
+                        * CPU.  There's nothing to do -- we just assert that
+                        * our offset is 0.
+                        */
+                       ASSERT(src->dtb_offset == 0);
+                       return;
+
+               case DTRACESPEC_ACTIVE:
+                       new = DTRACESPEC_COMMITTING;
+                       break;
+
+               case DTRACESPEC_ACTIVEONE:
+                       /*
+                        * This speculation is active on one CPU.  If our
+                        * buffer offset is non-zero, we know that the one CPU
+                        * must be us.  Otherwise, we are committing on a
+                        * different CPU from the speculate(), and we must
+                        * rely on being asynchronously cleaned.
+                        */
+                       if (src->dtb_offset != 0) {
+                               new = DTRACESPEC_COMMITTING;
+                               break;
+                       }
+                       /*FALLTHROUGH*/
+
+               case DTRACESPEC_ACTIVEMANY:
+                       new = DTRACESPEC_COMMITTINGMANY;
+                       break;
+
+               default:
+                       ASSERT(0);
+               }
+printk(KERN_INFO "spec-commit: a) CPU#%d, which %d, spec-state %d -> %d\n", cpu, which, curr, new);
+       } while (cmpxchg((uint32_t *)&spec->dtsp_state, curr, new) !=
+                curr);
+
+       /*
+        * We have set the state to indicate that we are committing this
+        * speculation.  Now reserve the necessary space in the destination
+        * buffer.
+        */
+       offs = dtrace_buffer_reserve(dest, src->dtb_offset, sizeof (uint64_t),
+                                    state, NULL);
+       if (offs < 0) {
+               dtrace_buffer_drop(dest);
+               goto out;
+       }
+
+       /*
+        * We have the space; copy the buffer across.  (Note that this is a
+        * highly subobtimal bcopy(); in the unlikely event that this becomes
+        * a serious performance issue, a high-performance DTrace-specific
+        * bcopy() should obviously be invented.)
+        */
+       daddr = (uintptr_t)dest->dtb_tomax + offs;
+       dlimit = daddr + src->dtb_offset;
+       saddr = (uintptr_t)src->dtb_tomax;
+
+       /*
+        * First, the aligned portion.
+        */
+       while (dlimit - daddr >= sizeof (uint64_t)) {
+               *((uint64_t *)daddr) = *((uint64_t *)saddr);
+               *((uint64_t *)daddr) = *((uint64_t *)saddr);
+
+               daddr += sizeof (uint64_t);
+               saddr += sizeof (uint64_t);
+       }
+
+       /*
+        * Now any left-over bit...
+        */
+       while (dlimit - daddr)
+               *((uint8_t *)daddr++) = *((uint8_t *)saddr++);
+
+       /*
+        * Finally, commit the reserved space in the destination buffer.
+        */
+       dest->dtb_offset = offs + src->dtb_offset;
+
+out:
+       /*
+        * If we're lucky enough to be the only active CPU on this speculation
+        * buffer, we can just set the state back to DTRACESPEC_INACTIVE.
+        */
+       if (curr == DTRACESPEC_ACTIVE ||
+           (curr == DTRACESPEC_ACTIVEONE && new == DTRACESPEC_COMMITTING)) {
+               /*
+                * Will cause unused warning if DEBUG is not defined.
+                */
+               uint32_t        rval =
+                               cmpxchg((uint32_t *)&spec->dtsp_state,
+                                       DTRACESPEC_COMMITTING,
+                                       DTRACESPEC_INACTIVE);
+
+               ASSERT(rval == DTRACESPEC_COMMITTING);
+               rval = 0; /* Avoid warning about unused variable if !DEBUG */
+       }
+
+       src->dtb_offset = 0;
+       src->dtb_xamot_drops += src->dtb_drops;
+       src->dtb_drops = 0;
+}
+
+/*
+ * This routine discards an active speculation.  If the specified speculation
+ * is not in a valid state to perform a discard(), this routine will silently
+ * do nothing.  The state of the specified speculation is transitioned
+ * according to the state transition diagram outlined in <sys/dtrace_impl.h>
+ */
+void dtrace_speculation_discard(dtrace_state_t *state, processorid_t cpu,
+                               dtrace_specid_t which)
+{
+       dtrace_speculation_t            *spec;
+       dtrace_speculation_state_t      curr, new = 0;
+       dtrace_buffer_t                 *buf;
+
+       if (which == 0)
+               return;
+
+       if (which > state->dts_nspeculations) {
+               cpu_core[cpu].cpuc_dtrace_flags |= CPU_DTRACE_ILLOP;
+               return;
+       }
+
+       spec = &state->dts_speculations[which - 1];
+       buf = &spec->dtsp_buffer[cpu];
+
+       do {
+               curr = spec->dtsp_state;
+
+               switch (curr) {
+               case DTRACESPEC_INACTIVE:
+               case DTRACESPEC_COMMITTINGMANY:
+               case DTRACESPEC_COMMITTING:
+               case DTRACESPEC_DISCARDING:
+                       return;
+
+               case DTRACESPEC_ACTIVE:
+               case DTRACESPEC_ACTIVEMANY:
+                       new = DTRACESPEC_DISCARDING;
+                       break;
+
+               case DTRACESPEC_ACTIVEONE:
+                       if (buf->dtb_offset != 0)
+                               new = DTRACESPEC_INACTIVE;
+                       else
+                               new = DTRACESPEC_DISCARDING;
+
+                       break;
+
+               default:
+                       ASSERT(0);
+               }
+       } while (cmpxchg((uint32_t *)&spec->dtsp_state, curr, new) != curr);
+
+       buf->dtb_offset = 0;
+       buf->dtb_drops = 0;
+}
+
+/*
+ * Note:  not called from probe context.  This function is called
+ * asynchronously from cross call context to clean any speculations that are
+ * in the COMMITTINGMANY or DISCARDING states.  These speculations may not be
+ * transitioned back to the INACTIVE state until all CPUs have cleaned the
+ * speculation.
+ */
+void dtrace_speculation_clean_here(dtrace_state_t *state)
+{
+       dtrace_icookie_t        cookie;
+       processorid_t           cpu = smp_processor_id();
+       dtrace_buffer_t         *dest = &state->dts_buffer[cpu];
+       dtrace_specid_t         i;
+
+       local_irq_save(cookie);
+
+       if (dest->dtb_tomax == NULL) {
+               local_irq_restore(cookie);
+               return;
+       }
+
+       for (i = 0; i < state->dts_nspeculations; i++) {
+               dtrace_speculation_t    *spec = &state->dts_speculations[i];
+               dtrace_buffer_t         *src = &spec->dtsp_buffer[cpu];
+
+               if (src->dtb_tomax == NULL)
+                       continue;
+
+               if (spec->dtsp_state == DTRACESPEC_DISCARDING) {
+                       src->dtb_offset = 0;
+                       continue;
+               }
+
+               if (spec->dtsp_state != DTRACESPEC_COMMITTINGMANY)
+                       continue;
+
+               if (src->dtb_offset == 0)
+                       continue;
+
+               dtrace_speculation_commit(state, cpu, i + 1);
+       }
+
+       local_irq_restore(cookie);
+}
+
+void dtrace_speculation_clean(dtrace_state_t *state)
+{
+       int             work = 0, rv;
+       dtrace_specid_t i;
+
+       for (i = 0; i < state->dts_nspeculations; i++) {
+               dtrace_speculation_t    *spec = &state->dts_speculations[i];
+
+               ASSERT(!spec->dtsp_cleaning);
+
+               if (spec->dtsp_state != DTRACESPEC_DISCARDING &&
+                   spec->dtsp_state != DTRACESPEC_COMMITTINGMANY)
+                       continue;
+
+               work++;
+               spec->dtsp_cleaning = 1;
+       }
+
+       if (!work)
+               return;
+
+       dtrace_xcall(DTRACE_CPUALL,
+                    (dtrace_xcall_t)dtrace_speculation_clean_here, state);
+
+       /*
+        * We now know that all CPUs have committed or discarded their
+        * speculation buffers, as appropriate.  We can now set the state
+        * to inactive.
+        */
+       for (i = 0; i < state->dts_nspeculations; i++) {
+               dtrace_speculation_t            *spec =
+                                               &state->dts_speculations[i];
+               dtrace_speculation_state_t      curr, new;
+
+               if (!spec->dtsp_cleaning)
+                       continue;
+
+               curr= spec->dtsp_state;
+               ASSERT(curr == DTRACESPEC_DISCARDING ||
+                      curr == DTRACESPEC_COMMITTINGMANY);
+
+               new = DTRACESPEC_INACTIVE;
+
+               rv = cmpxchg((uint32_t *)&spec->dtsp_state, curr, new);
+               ASSERT(rv == curr);
+               spec->dtsp_cleaning = 0;
+       }
+}
+
+/*
+ * Called as part of a speculate() to get the speculative buffer associated
+ * with a given speculation.  Returns NULL if the specified speculation is not
+ * in an ACTIVE state.  If the speculation is in the ACTIVEONE state -- and
+ * the active CPU is not the specified CPU -- the speculation will be
+ * atomically transitioned into the ACTIVEMANY state.
+ */
+dtrace_buffer_t *dtrace_speculation_buffer(dtrace_state_t *state,
+                                          processorid_t cpuid,
+                                          dtrace_specid_t which)
+{
+       dtrace_speculation_t            *spec;
+       dtrace_speculation_state_t      curr, new = 0;
+       dtrace_buffer_t                 *buf;
+
+       if (which == 0)
+               return NULL;
+
+       if (which > state->dts_nspeculations) {
+               cpu_core[cpuid].cpuc_dtrace_flags |= CPU_DTRACE_ILLOP;
+               return NULL;
+       }
+
+       spec = &state->dts_speculations[which - 1];
+       buf = &spec->dtsp_buffer[cpuid];
+
+       do {
+               curr = spec->dtsp_state;
+
+               switch (curr) {
+               case DTRACESPEC_INACTIVE:
+               case DTRACESPEC_COMMITTINGMANY:
+               case DTRACESPEC_DISCARDING:
+                       return NULL;
+
+               case DTRACESPEC_COMMITTING:
+                       ASSERT(buf->dtb_offset == 0);
+                       return NULL;
+
+               case DTRACESPEC_ACTIVEONE:
+                       /*
+                        * This speculation is currently active on one CPU.
+                        * Check the offset in the buffer; if it's non-zero,
+                        * that CPU must be us (and we leave the state alone).
+                        * If it's zero, assume that we're starting on a new
+                        * CPU -- and change the state to indicate that the
+                        * speculation is active on more than one CPU.
+                        */
+                       if (buf->dtb_offset != 0)
+                               return buf;
+
+                       new = DTRACESPEC_ACTIVEMANY;
+                       break;
+
+               case DTRACESPEC_ACTIVEMANY:
+                       return buf;
+
+               case DTRACESPEC_ACTIVE:
+                       new = DTRACESPEC_ACTIVEONE;
+                       break;
+
+               default:
+                       ASSERT(0);
+               }
+       } while (cmpxchg((uint32_t *)&spec->dtsp_state, curr, new) != curr);
+
+       ASSERT(new == DTRACESPEC_ACTIVEONE || new == DTRACESPEC_ACTIVEMANY);
+
+       return buf;
+}
diff --git a/dtrace/dtrace_state.c b/dtrace/dtrace_state.c
new file mode 100644 (file)
index 0000000..11d8819
--- /dev/null
@@ -0,0 +1,1057 @@
+/*
+ * FILE:       dtrace_state.c
+ * DESCRIPTION:        Dynamic Tracing: consumer state functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/fs.h>
+#include <linux/idr.h>
+#include <linux/slab.h>
+#include <linux/smp.h>
+#include <linux/vmalloc.h>
+#include <asm/cmpxchg.h>
+
+#include "cyclic.h"
+#include "dtrace.h"
+
+struct kmem_cache      *dtrace_state_cache;
+int                    dtrace_destructive_disallow = 0;
+dtrace_optval_t                dtrace_nspec_default = 1;
+dtrace_optval_t                dtrace_specsize_default = 32 * 1024;
+dtrace_optval_t                dtrace_dstate_defsize = 1 * 1024 * 1024;
+size_t                 dtrace_strsize_default = 256;
+dtrace_optval_t                dtrace_stackframes_default = 20;
+dtrace_optval_t                dtrace_ustackframes_default = 20;
+dtrace_optval_t                dtrace_cleanrate_default = 9900990;
+dtrace_optval_t                dtrace_cleanrate_min = 20000;
+dtrace_optval_t                dtrace_cleanrate_max = (uint64_t)60 * NANOSEC;
+dtrace_optval_t                dtrace_aggrate_default = NANOSEC;
+dtrace_optval_t                dtrace_switchrate_default = NANOSEC;
+dtrace_optval_t                dtrace_statusrate_default = NANOSEC;
+dtrace_optval_t                dtrace_statusrate_max = (uint64_t)10 * NANOSEC;
+dtrace_optval_t                dtrace_jstackframes_default = 50;
+dtrace_optval_t                dtrace_jstackstrsize_default = 512;
+ktime_t                        dtrace_deadman_interval = KTIME_INIT(1, 0);
+ktime_t                        dtrace_deadman_timeout = KTIME_INIT(10, 0);
+ktime_t                        dtrace_deadman_user = KTIME_INIT(30, 0);
+
+dtrace_id_t            dtrace_probeid_begin;
+dtrace_id_t            dtrace_probeid_end;
+dtrace_id_t            dtrace_probeid_error;
+
+dtrace_dynvar_t                dtrace_dynhash_sink;
+
+#define DTRACE_DYNHASH_FREE            0
+#define DTRACE_DYNHASH_SINK            1
+#define DTRACE_DYNHASH_VALID           2
+
+#define DTRACE_DYNVAR_CHUNKSIZE                256
+
+static void dtrace_dynvar_clean(dtrace_dstate_t *dstate)
+{
+       dtrace_dynvar_t         *dirty;
+       dtrace_dstate_percpu_t  *dcpu;
+       int                     i, work = 0;
+
+       for (i = 0; i < NR_CPUS; i++) {
+               dcpu = &dstate->dtds_percpu[i];
+
+               ASSERT(dcpu->dtdsc_rinsing == NULL);
+
+               /*
+                * If the dirty list is NULL, there is no dirty work to do.
+               */
+               if (dcpu->dtdsc_dirty == NULL)
+                       continue;
+
+               /*
+                * If the clean list is non-NULL, then we're not going to do
+                * any work for this CPU -- it means that there has not been
+                * a dtrace_dynvar() allocation on this CPU (or from this CPU)
+                * since the last time we cleaned house.
+                */
+               if (dcpu->dtdsc_clean != NULL)
+                       continue;
+
+               work = 1;
+
+               /*
+                * Atomically move the dirty list aside.
+                */
+               do {
+                       dirty = dcpu->dtdsc_dirty;
+
+                       /*
+                        * Before we zap the dirty list, set the rinsing list.
+                        * (This allows for a potential assertion in
+                        * dtrace_dynvar():  if a free dynamic variable appears
+                        * on a hash chain, either the dirty list or the
+                        * rinsing list for some CPU must be non-NULL.)
+                        */
+                       dcpu->dtdsc_rinsing = dirty;
+                       dtrace_membar_producer();
+               } while (cmpxchg(&dcpu->dtdsc_dirty, dirty, NULL) != dirty);
+       }
+
+       /*
+        * No work to do; return.
+        */
+       if (!work)
+               return;
+
+       dtrace_sync();
+
+       for (i = 0; i < NR_CPUS; i++) {
+               dcpu = &dstate->dtds_percpu[i];
+
+               if (dcpu->dtdsc_rinsing == NULL)
+                       continue;
+
+               /*
+                * We are now guaranteed that no hash chain contains a pointer
+                * into this dirty list; we can make it clean.
+                */
+               ASSERT(dcpu->dtdsc_clean == NULL);
+               dcpu->dtdsc_clean = dcpu->dtdsc_rinsing;
+               dcpu->dtdsc_rinsing = NULL;
+       }
+
+       /*
+        * Before we actually set the state to be DTRACE_DSTATE_CLEAN, make
+        * sure that all CPUs have seen all of the dtdsc_clean pointers.
+        * This prevents a race whereby a CPU incorrectly decides that
+        * the state should be something other than DTRACE_DSTATE_CLEAN
+        * after dtrace_dynvar_clean() has completed.
+        */
+       dtrace_sync();
+
+       dstate->dtds_state = DTRACE_DSTATE_CLEAN;
+}
+
+int dtrace_dstate_init(dtrace_dstate_t *dstate, size_t size)
+{
+       size_t          hashsize, maxper, min,
+                       chunksize = dstate->dtds_chunksize;
+       void            *base;
+       uintptr_t       limit;
+       dtrace_dynvar_t *dvar, *next, *start;
+       int             i;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(dstate->dtds_base == NULL && dstate->dtds_percpu == NULL);
+
+       memset(dstate, 0, sizeof (dtrace_dstate_t));
+
+       if ((dstate->dtds_chunksize = chunksize) == 0)
+               dstate->dtds_chunksize = DTRACE_DYNVAR_CHUNKSIZE;
+
+       if (size < (min = dstate->dtds_chunksize + sizeof (dtrace_dynhash_t)))
+               size = min;
+
+       if ((base = dtrace_vzalloc(size)) == NULL)
+               return -ENOMEM;
+
+       dstate->dtds_size = size;
+       dstate->dtds_base = base;
+       dstate->dtds_percpu = kmem_cache_alloc(dtrace_state_cache, GFP_KERNEL);
+       memset(dstate->dtds_percpu, 0,
+              NR_CPUS * sizeof (dtrace_dstate_percpu_t));
+
+       hashsize = size / (dstate->dtds_chunksize + sizeof (dtrace_dynhash_t));
+
+       if (hashsize != 1 && (hashsize & 1))
+               hashsize--;
+
+       dstate->dtds_hashsize = hashsize;
+       dstate->dtds_hash = dstate->dtds_base;
+
+       /*
+        * Set all of our hash buckets to point to the single sink, and (if
+        * it hasn't already been set), set the sink's hash value to be the
+        * sink sentinel value.  The sink is needed for dynamic variable
+        * lookups to know that they have iterated over an entire, valid hash
+        * chain.
+        */
+       for (i = 0; i < hashsize; i++)
+               dstate->dtds_hash[i].dtdh_chain = &dtrace_dynhash_sink;
+
+       if (dtrace_dynhash_sink.dtdv_hashval != DTRACE_DYNHASH_SINK)
+               dtrace_dynhash_sink.dtdv_hashval = DTRACE_DYNHASH_SINK;
+
+       /*
+        * Determine number of active CPUs.  Divide free list evenly among
+        * active CPUs.
+        */
+       start = (dtrace_dynvar_t *)((uintptr_t)base +
+                                   hashsize * sizeof (dtrace_dynhash_t));
+       limit = (uintptr_t)base + size;
+
+       maxper = (limit - (uintptr_t)start) / NR_CPUS;
+       maxper = (maxper / dstate->dtds_chunksize) * dstate->dtds_chunksize;
+
+       for (i = 0; i < NR_CPUS; i++) {
+               dstate->dtds_percpu[i].dtdsc_free = dvar = start;
+
+               /*
+                * If we don't even have enough chunks to make it once through
+                * NCPUs, we're just going to allocate everything to the first
+                * CPU.  And if we're on the last CPU, we're going to allocate
+                * whatever is left over.  In either case, we set the limit to
+                * be the limit of the dynamic variable space.
+                */
+               if (maxper == 0 || i == NR_CPUS - 1) {
+                       limit = (uintptr_t)base + size;
+                       start = NULL;
+               } else {
+                       limit = (uintptr_t)start + maxper;
+                       start = (dtrace_dynvar_t *)limit;
+               }
+
+               ASSERT(limit <= (uintptr_t)base + size);
+
+               for (;;) {
+                       next = (dtrace_dynvar_t *)((uintptr_t)dvar +
+                                                  dstate->dtds_chunksize);
+
+                       if ((uintptr_t)next + dstate->dtds_chunksize >= limit)
+                               break;
+
+                       dvar->dtdv_next = next;
+                       dvar = next;
+               }
+
+               if (maxper == 0)
+                       break;
+       }
+
+       return 0;
+}
+
+void dtrace_dstate_fini(dtrace_dstate_t *dstate)
+{
+       ASSERT(mutex_is_locked(&cpu_lock));
+
+       if (dstate->dtds_base == NULL)
+               return;
+
+       vfree(dstate->dtds_base);
+       kmem_cache_free(dtrace_state_cache, dstate->dtds_percpu);
+}
+
+void dtrace_vstate_fini(dtrace_vstate_t *vstate)
+{
+       /*
+        * If only there was a logical XOR operator...
+        */
+       ASSERT((vstate->dtvs_nglobals == 0) ^ (vstate->dtvs_globals != NULL));
+
+       if (vstate->dtvs_nglobals > 0)
+               kfree(vstate->dtvs_globals);
+
+       if (vstate->dtvs_ntlocals > 0)
+               kfree(vstate->dtvs_tlocals);
+
+       ASSERT((vstate->dtvs_nlocals == 0) ^ (vstate->dtvs_locals != NULL));
+
+       if (vstate->dtvs_nlocals > 0)
+               kfree(vstate->dtvs_locals);
+}
+
+static void dtrace_state_clean(dtrace_state_t *state)
+{
+       if (state->dts_activity == DTRACE_ACTIVITY_INACTIVE)
+               return;
+
+       dtrace_dynvar_clean(&state->dts_vstate.dtvs_dynvars);
+       dtrace_speculation_clean(state);
+}
+
+static void dtrace_state_deadman(dtrace_state_t *state)
+{
+       ktime_t now;
+
+#ifdef FIXME
+       /*
+        * This may not be needed for Linux - we'll see.
+        */
+       dtrace_sync();
+#endif
+
+       now = dtrace_gethrtime();
+
+       if (state != dtrace_anon.dta_state &&
+           ktime_ge(ktime_sub(now, state->dts_laststatus),
+                              dtrace_deadman_user))
+               return;
+
+       /*
+        * We must be sure that dts_alive never appears to be less than the
+        * value upon entry to dtrace_state_deadman(), and because we lack a
+        * dtrace_cas64(), we cannot store to it atomically.  We thus instead
+        * store KTIME_MAX to it, followed by a memory barrier, followed by
+        * the new value.  This assures that dts_alive never appears to be
+        * less than its true value, regardless of the order in which the
+        * stores to the underlying storage are issued.
+        */
+       state->dts_alive = ktime_set(KTIME_SEC_MAX, 0);
+       dtrace_membar_producer();
+       state->dts_alive = now;
+}
+
+dtrace_state_t *dtrace_state_create(struct file *file)
+{
+       dtrace_state_t  *state;
+       dtrace_optval_t *opt;
+       int             bufsize = NR_CPUS * sizeof (dtrace_buffer_t), i;
+       const cred_t    *cr = file->f_cred;
+       int             err;
+       dtrace_aggid_t  aggid;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(mutex_is_locked(&cpu_lock));
+
+       state = kzalloc(sizeof (dtrace_state_t), GFP_KERNEL);
+       state->dts_epid = DTRACE_EPIDNONE + 1;
+       /* state->dts_dev = NULL;  -- FIXME: Do we even need this? */
+       state->dts_buffer = kzalloc(NR_CPUS * sizeof (dtrace_buffer_t),
+                                   GFP_KERNEL);
+       state->dts_buffer = kzalloc(bufsize, GFP_KERNEL);
+       state->dts_aggbuffer = kzalloc(bufsize, GFP_KERNEL);
+       idr_init(&state->dts_agg_idr);
+       state->dts_cleaner = 0;
+       state->dts_deadman = 0;
+       state->dts_vstate.dtvs_state = state;
+
+       /*
+        * Create a first entry in the aggregation IDR, so that ID 0 is used as
+        * that gets used as meaning 'none'.
+        */
+again:
+       mutex_unlock(&cpu_lock);
+       mutex_unlock(&dtrace_lock);
+
+       idr_pre_get(&state->dts_agg_idr, __GFP_NOFAIL);
+
+       mutex_lock(&dtrace_lock);
+       mutex_lock(&cpu_lock);
+
+       err = idr_get_new(&state->dts_agg_idr, NULL, &aggid);
+       if (err == -EAGAIN)
+               goto again;
+
+       ASSERT(aggid == 0);
+
+       for (i = 0; i < DTRACEOPT_MAX; i++)
+               state->dts_options[i] = DTRACEOPT_UNSET;
+
+       /*
+        * Set the default options.
+        */
+       opt = state->dts_options;
+       opt[DTRACEOPT_BUFPOLICY] = DTRACEOPT_BUFPOLICY_SWITCH;
+       opt[DTRACEOPT_BUFRESIZE] = DTRACEOPT_BUFRESIZE_AUTO;
+       opt[DTRACEOPT_NSPEC] = dtrace_nspec_default;
+       opt[DTRACEOPT_SPECSIZE] = dtrace_specsize_default;
+       opt[DTRACEOPT_CPU] = (dtrace_optval_t)DTRACE_CPUALL;
+       opt[DTRACEOPT_STRSIZE] = dtrace_strsize_default;
+       opt[DTRACEOPT_STACKFRAMES] = dtrace_stackframes_default;
+       opt[DTRACEOPT_USTACKFRAMES] = dtrace_ustackframes_default;
+       opt[DTRACEOPT_CLEANRATE] = dtrace_cleanrate_default;
+       opt[DTRACEOPT_AGGRATE] = dtrace_aggrate_default;
+       opt[DTRACEOPT_SWITCHRATE] = dtrace_switchrate_default;
+       opt[DTRACEOPT_STATUSRATE] = dtrace_statusrate_default;
+       opt[DTRACEOPT_JSTACKFRAMES] = dtrace_jstackframes_default;
+       opt[DTRACEOPT_JSTACKSTRSIZE] = dtrace_jstackstrsize_default;
+
+       state->dts_activity = DTRACE_ACTIVITY_INACTIVE;
+
+#ifdef FIXME
+       /*
+        * Set probe visibility and destructiveness based on user credential
+        * information.  For actual anonymous tracing or if all privileges are
+        * set, checks are bypassed.
+        */
+       if (cr == NULL ||
+           PRIV_POLICY_ONLY(cr, PRIV_ALL, FALSE)) {
+               state->dts_cred.dcr_visible = DTRACE_CRV_ALL;
+               state->dts_cred.dcr_action = DTRACE_CRA_ALL;
+       } else {
+               state->dts_cred.dcr_cred = get_cred(cr);
+
+               /*
+                * CRA_PROC means "we have *some* privilege for dtrace" and
+                * it unlocks the use of variables like pid, etc.
+                */
+               if (PRIV_POLICY_ONLY(cr, PRIV_DTRACE_USER, FALSE) ||
+                   PRIV_POLICY_ONLY(cr, PRIV_DTRACE_PROC, FALSE))
+                       state->dts_cred.dcr_action |= DTRACE_CRA_PROC;
+
+               /*
+                * The DTRACE_USER privilege allows the use of syscall and
+                * profile providers.  If the user also has PROC_OWNER, we
+                * extend the scope to include additional visibility and
+                * destructive power.
+                */
+               if (PRIV_POLICY_ONLY(cr, PRIV_DTRACE_USER, FALSE)) {
+                       if (PRIV_POLICY_ONLY(cr, PRIV_PROC_OWNER, FALSE))
+                               state->dts_cred.dcr_visible |=
+                                       DTRACE_CRV_ALLPROC;
+
+                       state->dts_cred.dcr_action |=
+                                       DTRACE_CRA_PROC_DESTRUCTIVE_ALLUSER;
+               }
+
+               /*
+                * Holding the DTRACE_KERNEL privilege also implies that
+                * the user has the DTRACE_USER privilege from a visibility
+                * perspective.  But without further privileges, some
+                * destructive actions are not available.
+                */
+               if (PRIV_POLICY_ONLY(cr, PRIV_DTRACE_KERNEL, FALSE)) {
+                       /*
+                        * Make all probes in all zones visible.  However,
+                        * this doesn't mean that all actions become available
+                        * to all zones.
+                        */
+                       state->dts_cred.dcr_visible |= DTRACE_CRV_KERNEL |
+                                                      DTRACE_CRV_ALLPROC;
+                       state->dts_cred.dcr_action |= DTRACE_CRA_KERNEL |
+                                                     DTRACE_CRA_PROC;
+
+                       /*
+                        * Holding PROC_OWNER means that destructive actions
+                        * are allowed.
+                        */
+                       if (PRIV_POLICY_ONLY(cr, PRIV_PROC_OWNER, FALSE))
+                               state->dts_cred.dcr_action |=
+                                       DTRACE_CRA_PROC_DESTRUCTIVE_ALLUSER;
+               }
+
+               /*
+                * Holding the DTRACE_PROC privilege gives control over the
+                * fasttrap and pid providers.  We need to grant wider
+                * destructive privileges in the event that the user has
+                * PROC_OWNER .
+               */
+               if (PRIV_POLICY_ONLY(cr, PRIV_DTRACE_PROC, FALSE)) {
+                       if (PRIV_POLICY_ONLY(cr, PRIV_PROC_OWNER, FALSE))
+                               state->dts_cred.dcr_action |=
+                                       DTRACE_CRA_PROC_DESTRUCTIVE_ALLUSER;
+               }
+       }
+#else
+       state->dts_cred.dcr_visible = DTRACE_CRV_ALLPROC;
+       state->dts_cred.dcr_action = DTRACE_CRA_ALL;
+#endif
+
+       return state;
+}
+
+static int dtrace_state_buffer(dtrace_state_t *state, dtrace_buffer_t *buf,
+                              int which)
+{
+       dtrace_optval_t *opt = state->dts_options, size;
+       processorid_t   cpu = DTRACE_CPUALL;
+       int             flags = 0, rval;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(mutex_is_locked(&cpu_lock));
+       ASSERT(which < DTRACEOPT_MAX);
+       ASSERT(state->dts_activity == DTRACE_ACTIVITY_INACTIVE ||
+              (state == dtrace_anon.dta_state &&
+              state->dts_activity == DTRACE_ACTIVITY_ACTIVE));
+printk(KERN_INFO "state_buffer(%p, %p, %d) opt[%d] = %lld\n", state, buf, which, which, opt[which]);
+
+       if (opt[which] == DTRACEOPT_UNSET || opt[which] == 0)
+               return 0;
+
+       if (opt[DTRACEOPT_CPU] != DTRACEOPT_UNSET)
+               cpu = opt[DTRACEOPT_CPU];
+
+       if (which == DTRACEOPT_SPECSIZE)
+               flags |= DTRACEBUF_NOSWITCH;
+
+       if (which == DTRACEOPT_BUFSIZE) {
+printk(KERN_INFO "state_buffer(%p, %p, %d) opt[CPU] = %lld, opt[BUFPOLICY] = %lld, sta_state = %p\n", state, buf, which, opt[DTRACEOPT_CPU], opt[DTRACEOPT_BUFPOLICY], dtrace_anon.dta_state);
+               if (opt[DTRACEOPT_BUFPOLICY] == DTRACEOPT_BUFPOLICY_RING)
+                       flags |= DTRACEBUF_RING;
+
+               if (opt[DTRACEOPT_BUFPOLICY] == DTRACEOPT_BUFPOLICY_FILL)
+                       flags |= DTRACEBUF_FILL;
+
+               if (state != dtrace_anon.dta_state ||
+                   state->dts_activity != DTRACE_ACTIVITY_ACTIVE)
+                       flags |= DTRACEBUF_INACTIVE;
+printk(KERN_INFO "state_buffer(%p, %p, %d) flags = %08x\n", state, buf, which, flags);
+       }
+
+       for (size = opt[which]; size >= sizeof (uint64_t); size >>= 1) {
+               /*
+                * The size must be 8-byte aligned.  If the size is not 8-byte
+                * aligned, drop it down by the difference.
+                */
+               if (size & (sizeof (uint64_t) - 1))
+                       size -= size & (sizeof (uint64_t) - 1);
+
+               if (size < state->dts_reserve) {
+                       /*
+                        * Buffers always must be large enough to accommodate
+                        * their prereserved space.  We return -E2BIG instead
+                        * of ENOMEM in this case to allow for user-level
+                        * software to differentiate the cases.
+                        */
+                       return -E2BIG;
+               }
+
+               rval = dtrace_buffer_alloc(buf, size, flags, cpu);
+printk(KERN_INFO "state_buffer: Alloc %d buffer: tomax %p xamot %p\n", which, buf->dtb_tomax, buf->dtb_xamot);
+
+               if (rval != -ENOMEM) {
+                       opt[which] = size;
+                       return rval;
+               }
+
+               if (opt[DTRACEOPT_BUFRESIZE] == DTRACEOPT_BUFRESIZE_MANUAL)
+                       return rval;
+       }
+
+       return -ENOMEM;
+}
+
+static int dtrace_state_buffers(dtrace_state_t *state)
+{
+       dtrace_speculation_t    *spec = state->dts_speculations;
+       int                     rval, i;
+
+       if ((rval = dtrace_state_buffer(state, state->dts_buffer,
+                                       DTRACEOPT_BUFSIZE)) != 0)
+               return rval;
+
+       if ((rval = dtrace_state_buffer(state, state->dts_aggbuffer,
+                                       DTRACEOPT_AGGSIZE)) != 0)
+               return rval;
+
+       for (i = 0; i < state->dts_nspeculations; i++) {
+               if ((rval = dtrace_state_buffer(state, spec[i].dtsp_buffer,
+                                               DTRACEOPT_SPECSIZE)) != 0)
+                       return rval;
+       }
+
+       return 0;
+}
+
+static void dtrace_state_prereserve(dtrace_state_t *state)
+{
+       dtrace_ecb_t    *ecb;
+       dtrace_probe_t  *probe;
+
+       state->dts_reserve = 0;
+
+       if (state->dts_options[DTRACEOPT_BUFPOLICY] != DTRACEOPT_BUFPOLICY_FILL)
+               return;
+
+       /*
+        * If our buffer policy is a "fill" buffer policy, we need to set the
+        * prereserved space to be the space required by the END probes.
+        */
+       probe = dtrace_probe_lookup_id(dtrace_probeid_end);
+       ASSERT(probe != NULL);
+
+       for (ecb = probe->dtpr_ecb; ecb != NULL; ecb = ecb->dte_next) {
+               if (ecb->dte_state != state)
+                       continue;
+
+               state->dts_reserve += ecb->dte_needed + ecb->dte_alignment;
+       }
+}
+
+int dtrace_state_go(dtrace_state_t *state, processorid_t *cpu)
+{
+       dtrace_optval_t         *opt = state->dts_options, sz, nspec;
+       dtrace_speculation_t    *spec;
+       dtrace_buffer_t         *buf;
+       cyc_handler_t           hdlr;
+       cyc_time_t              when;
+       int                     rval = 0, i,
+                               bufsize = NR_CPUS * sizeof (dtrace_buffer_t);
+       dtrace_icookie_t        cookie;
+
+       mutex_lock(&cpu_lock);
+       mutex_lock(&dtrace_lock);
+
+printk(KERN_INFO "state_go(1): dts_activity = %d (vs warmup %d or draining %d)\n", state->dts_activity, DTRACE_ACTIVITY_WARMUP, DTRACE_ACTIVITY_DRAINING);
+       if (state->dts_activity != DTRACE_ACTIVITY_INACTIVE) {
+               rval = -EBUSY;
+               goto out;
+       }
+
+       /*
+        * Before we can perform any checks, we must prime all of the
+        * retained enablings that correspond to this state.
+        */
+       dtrace_enabling_prime(state);
+
+       if (state->dts_destructive && !state->dts_cred.dcr_destructive) {
+               rval = -EACCES;
+               goto out;
+       }
+
+       dtrace_state_prereserve(state);
+
+       /*
+        * Now we want to do is try to allocate our speculations.
+        * We do not automatically resize the number of speculations; if
+        * this fails, we will fail the operation.
+        */
+       nspec = opt[DTRACEOPT_NSPEC];
+       ASSERT(nspec != DTRACEOPT_UNSET);
+
+       if (nspec > INT_MAX) {
+               rval = -ENOMEM;
+               goto out;
+       }
+
+       spec = kzalloc(nspec * sizeof(dtrace_speculation_t), GFP_KERNEL);
+printk(KERN_INFO "state_go: nspec = %d, spec = %p (%lld bytes)\n", (int)nspec, spec, nspec * sizeof(dtrace_speculation_t));
+       if (spec == NULL) {
+               rval = -ENOMEM;
+               goto out;
+       }
+
+       state->dts_speculations = spec;
+       state->dts_nspeculations = (int)nspec;
+
+       for (i = 0; i < nspec; i++) {
+               if ((buf = kzalloc(bufsize, GFP_KERNEL)) == NULL) {
+                       rval = -ENOMEM;
+                       goto err;
+               }
+
+printk(KERN_INFO "state_go: spec[%d].buf = %p (%d bytes)\n", i, buf, bufsize);
+               spec[i].dtsp_buffer = buf;
+       }
+
+       if (opt[DTRACEOPT_GRABANON] != DTRACEOPT_UNSET) {
+               if (dtrace_anon.dta_state == NULL) {
+                       rval = -ENOENT;
+                       goto out;
+               }
+
+               if (state->dts_necbs != 0) {
+                       rval = -EALREADY;
+                       goto out;
+               }
+
+               state->dts_anon = dtrace_anon_grab();
+               ASSERT(state->dts_anon != NULL);
+               state = state->dts_anon;
+
+               /*
+                * We want "grabanon" to be set in the grabbed state, so we'll
+                * copy that option value from the grabbing state into the
+                * grabbed state.
+                */
+               state->dts_options[DTRACEOPT_GRABANON] =
+                                               opt[DTRACEOPT_GRABANON];
+
+               *cpu = dtrace_anon.dta_beganon;
+
+               /*
+                * If the anonymous state is active (as it almost certainly
+                * is if the anonymous enabling ultimately matched anything),
+                * we don't allow any further option processing -- but we
+                * don't return failure.
+                */
+               if (state->dts_activity != DTRACE_ACTIVITY_INACTIVE)
+                       goto out;
+       }
+
+       if (opt[DTRACEOPT_AGGSIZE] != DTRACEOPT_UNSET &&
+           opt[DTRACEOPT_AGGSIZE] != 0) {
+               if (idr_empty(&state->dts_agg_idr)) {
+                       /*
+                        * We're not going to create an aggregation buffer
+                        * because we don't have any ECBs that contain
+                        * aggregations -- set this option to 0.
+                        */
+                       opt[DTRACEOPT_AGGSIZE] = 0;
+               } else {
+                       /*
+                        * If we have an aggregation buffer, we must also have
+                        * a buffer to use as scratch.
+                        */
+                       if (opt[DTRACEOPT_BUFSIZE] == DTRACEOPT_UNSET ||
+                           opt[DTRACEOPT_BUFSIZE] < state->dts_needed)
+                               opt[DTRACEOPT_BUFSIZE] = state->dts_needed;
+               }
+       }
+
+       if (opt[DTRACEOPT_SPECSIZE] != DTRACEOPT_UNSET &&
+           opt[DTRACEOPT_SPECSIZE] != 0) {
+               /*
+                * We are not going to create speculation buffers if we do not
+                * have any ECBs that actually speculate.
+                */
+               if (!state->dts_speculates)
+                       opt[DTRACEOPT_SPECSIZE] = 0;
+       }
+
+       /*
+        * The bare minimum size for any buffer that we're actually going to
+        * do anything to is sizeof (uint64_t).
+        */
+       sz = sizeof (uint64_t);
+
+       if ((state->dts_needed != 0 && opt[DTRACEOPT_BUFSIZE] < sz) ||
+           (state->dts_speculates && opt[DTRACEOPT_SPECSIZE] < sz) ||
+           (!idr_empty(&state->dts_agg_idr) && opt[DTRACEOPT_AGGSIZE] < sz)) {
+               /*
+                * A buffer size has been explicitly set to 0 (or to a size
+                * that will be adjusted to 0) and we need the space -- we
+                * need to return failure.  We return -ENOSPC to differentiate
+                * it from failing to allocate a buffer due to failure to meet
+                * the reserve (for which we return -E2BIG).
+                */
+               rval = -ENOSPC;
+               goto out;
+       }
+
+       if ((rval = dtrace_state_buffers(state)) != 0)
+               goto err;
+
+       if ((sz = opt[DTRACEOPT_DYNVARSIZE]) == DTRACEOPT_UNSET)
+               sz = dtrace_dstate_defsize;
+
+       do {
+               rval = dtrace_dstate_init(&state->dts_vstate.dtvs_dynvars, sz);
+
+               if (rval == 0)
+                       break;
+
+               if (opt[DTRACEOPT_BUFRESIZE] == DTRACEOPT_BUFRESIZE_MANUAL)
+                       goto err;
+       } while (sz >>= 1);
+
+       opt[DTRACEOPT_DYNVARSIZE] = sz;
+
+       if (rval != 0)
+               goto err;
+
+       if (opt[DTRACEOPT_STATUSRATE] > dtrace_statusrate_max)
+               opt[DTRACEOPT_STATUSRATE] = dtrace_statusrate_max;
+
+       if (opt[DTRACEOPT_CLEANRATE] == 0)
+               opt[DTRACEOPT_CLEANRATE] = dtrace_cleanrate_max;
+
+       if (opt[DTRACEOPT_CLEANRATE] < dtrace_cleanrate_min)
+               opt[DTRACEOPT_CLEANRATE] = dtrace_cleanrate_min;
+
+       if (opt[DTRACEOPT_CLEANRATE] > dtrace_cleanrate_max)
+               opt[DTRACEOPT_CLEANRATE] = dtrace_cleanrate_max;
+
+       hdlr.cyh_func = (cyc_func_t)dtrace_state_clean;
+       hdlr.cyh_arg = state;
+       hdlr.cyh_level = CY_LOW_LEVEL;
+
+       when.cyt_when = ktime_set(0, 0);
+       when.cyt_interval = ns_to_ktime(opt[DTRACEOPT_CLEANRATE]);
+
+       state->dts_cleaner = cyclic_add(&hdlr, &when);
+
+       hdlr.cyh_func = (cyc_func_t)dtrace_state_deadman;
+       hdlr.cyh_arg = state;
+       hdlr.cyh_level = CY_LOW_LEVEL;
+
+       when.cyt_when = ktime_set(0, 0);
+       when.cyt_interval = dtrace_deadman_interval;
+
+       state->dts_alive = state->dts_laststatus = dtrace_gethrtime();
+       state->dts_deadman = cyclic_add(&hdlr, &when);
+
+       state->dts_activity = DTRACE_ACTIVITY_WARMUP;
+printk(KERN_INFO "state_go(2): dts_activity = %d (vs warmup %d or draining %d)\n", state->dts_activity, DTRACE_ACTIVITY_WARMUP, DTRACE_ACTIVITY_DRAINING);
+
+       /*
+        * Now it's time to actually fire the BEGIN probe.  We need to disable
+        * interrupts here both to record the CPU on which we fired the BEGIN
+        * probe (the data from this CPU will be processed first at user
+        * level) and to manually activate the buffer for this CPU.
+        */
+       local_irq_save(cookie);
+       *cpu = smp_processor_id();
+//     ASSERT(state->dts_buffer[*cpu].dtb_flags & DTRACEBUF_INACTIVE);
+       state->dts_buffer[*cpu].dtb_flags &= ~DTRACEBUF_INACTIVE;
+
+       dtrace_probe(dtrace_probeid_begin, (uint64_t)(uintptr_t)state, 0, 0, 0,
+                    0);
+       local_irq_restore(cookie);
+
+       /*
+        * We may have had an exit action from a BEGIN probe; only change our
+        * state to ACTIVE if we're still in WARMUP.
+        */
+printk(KERN_INFO "state_go(3): dts_activity = %d (vs warmup %d or draining %d)\n", state->dts_activity, DTRACE_ACTIVITY_WARMUP, DTRACE_ACTIVITY_DRAINING);
+       ASSERT(state->dts_activity == DTRACE_ACTIVITY_WARMUP ||
+              state->dts_activity == DTRACE_ACTIVITY_DRAINING);
+
+       if (state->dts_activity == DTRACE_ACTIVITY_WARMUP)
+               state->dts_activity = DTRACE_ACTIVITY_ACTIVE;
+
+       /*
+        * Regardless of whether or not now we're in ACTIVE or DRAINING, we
+        * want each CPU to transition its principal buffer out of the
+        * INACTIVE state.  Doing this assures that no CPU will suddenly begin
+        * processing an ECB halfway down a probe's ECB chain; all CPUs will
+        * atomically transition from processing none of a state's ECBs to
+        * processing all of them.
+        */
+       dtrace_xcall(DTRACE_CPUALL, (dtrace_xcall_t)dtrace_buffer_activate,
+                    state);
+       goto out;
+
+err:
+       dtrace_buffer_free(state->dts_buffer);
+       dtrace_buffer_free(state->dts_aggbuffer);
+
+       if ((nspec = state->dts_nspeculations) == 0) {
+               ASSERT(state->dts_speculations == NULL);
+               goto out;
+       }
+
+       spec = state->dts_speculations;
+       ASSERT(spec != NULL);
+
+       for (i = 0; i < state->dts_nspeculations; i++) {
+               if ((buf = spec[i].dtsp_buffer) == NULL)
+                       break;
+
+               dtrace_buffer_free(buf);
+               kfree(buf);
+       }
+
+       kfree(spec);
+       state->dts_nspeculations = 0;
+       state->dts_speculations = NULL;
+
+out:
+       mutex_unlock(&dtrace_lock);
+       mutex_unlock(&cpu_lock);
+
+       return rval;
+}
+
+int dtrace_state_stop(dtrace_state_t *state, processorid_t *cpu)
+{
+       dtrace_icookie_t        cookie;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+
+       if (state->dts_activity != DTRACE_ACTIVITY_ACTIVE &&
+           state->dts_activity != DTRACE_ACTIVITY_DRAINING)
+               return -EINVAL;
+
+       /*
+        * We'll set the activity to DTRACE_ACTIVITY_DRAINING, and issue a sync
+        * to be sure that every CPU has seen it.  See below for the details
+        * on why this is done.
+        */
+       state->dts_activity = DTRACE_ACTIVITY_DRAINING;
+       dtrace_sync();
+
+       /*
+        * By this point, it is impossible for any CPU to be still processing
+        * with DTRACE_ACTIVITY_ACTIVE.  We can thus set our activity to
+        * DTRACE_ACTIVITY_COOLDOWN and know that we're not racing with any
+        * other CPU in dtrace_buffer_reserve().  This allows dtrace_probe()
+        * and callees to know that the activity is DTRACE_ACTIVITY_COOLDOWN
+        * iff we're in the END probe.
+        */
+       state->dts_activity = DTRACE_ACTIVITY_COOLDOWN;
+       dtrace_sync();
+       ASSERT(state->dts_activity == DTRACE_ACTIVITY_COOLDOWN);
+
+       /*
+        * Finally, we can release the reserve and call the END probe.  We
+        * disable interrupts across calling the END probe to allow us to
+        * return the CPU on which we actually called the END probe.  This
+        * allows user-land to be sure that this CPU's principal buffer is
+        * processed last.
+        */
+       state->dts_reserve = 0;
+
+       local_irq_save(cookie);
+       *cpu = smp_processor_id();
+       dtrace_probe(dtrace_probeid_end, (uint64_t)(uintptr_t)state, 0, 0, 0,
+                    0);
+       local_irq_restore(cookie);
+
+       state->dts_activity = DTRACE_ACTIVITY_STOPPED;
+       dtrace_sync();
+
+       return 0;
+}
+
+int dtrace_state_option(dtrace_state_t *state, dtrace_optid_t option,
+                       dtrace_optval_t val)
+{
+       ASSERT(mutex_is_locked(&dtrace_lock));
+
+       if (state->dts_activity != DTRACE_ACTIVITY_INACTIVE)
+               return -EBUSY;
+
+       if (option >= DTRACEOPT_MAX)
+               return -EINVAL;
+
+       if (option != DTRACEOPT_CPU && val < 0)
+               return -EINVAL;
+
+       switch (option) {
+       case DTRACEOPT_DESTRUCTIVE:
+               if (dtrace_destructive_disallow)
+                       return -EACCES;
+
+               state->dts_cred.dcr_destructive = 1;
+               break;
+
+       case DTRACEOPT_BUFSIZE:
+       case DTRACEOPT_DYNVARSIZE:
+       case DTRACEOPT_AGGSIZE:
+       case DTRACEOPT_SPECSIZE:
+       case DTRACEOPT_STRSIZE:
+               if (val < 0)
+                       return -EINVAL;
+
+               /*
+                * If this is an otherwise negative value, set it to the
+                * highest multiple of 128m less than LONG_MAX.  Technically,
+                * we're adjusting the size without regard to the buffer
+                * resizing policy, but in fact, this has no effect -- if we
+                * set the buffer size to ~LONG_MAX and the buffer policy is
+                * ultimately set to be "manual", the buffer allocation is
+                * guaranteed to fail, if only because the allocation requires
+                * two buffers.  (We set the the size to the highest multiple
+                * of 128m because it ensures that the size will remain a
+                * multiple of a megabyte when repeatedly halved -- all the
+                * way down to 15m.)
+                */
+               if (val >= LONG_MAX)
+                       val = LONG_MAX - (1 << 27) + 1;
+       }
+
+       state->dts_options[option] = val;
+
+       return 0;
+}
+
+void dtrace_state_destroy(dtrace_state_t *state)
+{
+       dtrace_ecb_t            *ecb;
+       dtrace_vstate_t         *vstate = &state->dts_vstate;
+       int                     i;
+       dtrace_speculation_t    *spec = state->dts_speculations;
+       int                     nspec = state->dts_nspeculations;
+       uint32_t                match;
+
+       ASSERT(mutex_is_locked(&dtrace_lock));
+       ASSERT(mutex_is_locked(&cpu_lock));
+
+       /*
+        * First, retract any retained enablings for this state.
+        */
+       dtrace_enabling_retract(state);
+       ASSERT(state->dts_nretained == 0);
+
+       if (state->dts_activity == DTRACE_ACTIVITY_ACTIVE ||
+           state->dts_activity == DTRACE_ACTIVITY_DRAINING) {
+               /*
+                * We have managed to come into dtrace_state_destroy() on a
+                * hot enabling -- almost certainly because of a disorderly
+                * shutdown of a consumer.  (That is, a consumer that is
+                * exiting without having called dtrace_stop().) In this case,
+                * we're going to set our activity to be KILLED, and then
+                * issue a sync to be sure that everyone is out of probe
+                * context before we start blowing away ECBs.
+                */
+printk(KERN_INFO "state_destroy: Setting dts_activity from %d to %d (KILLED)\n", state->dts_activity, DTRACE_ACTIVITY_KILLED);
+               state->dts_activity = DTRACE_ACTIVITY_KILLED;
+               dtrace_sync();
+       }
+
+       /*
+        * Release the credential hold we took in dtrace_state_create().
+        */
+       if (state->dts_cred.dcr_cred != NULL)
+               put_cred(state->dts_cred.dcr_cred);
+
+       /*
+        * Now we can safely disable and destroy any enabled probes.  Because
+        * any DTRACE_PRIV_KERNEL probes may actually be slowing our progress
+        * (especially if they're all enabled), we take two passes through the
+        * ECBs: in the first, we disable just DTRACE_PRIV_KERNEL probes, and
+        * in the second we disable whatever is left over.
+       */
+       for (match = DTRACE_PRIV_KERNEL; ; match = 0) {
+               for (i = 0; i < state->dts_necbs; i++) {
+                       if ((ecb = state->dts_ecbs[i]) == NULL)
+                               continue;
+
+                       if (match && ecb->dte_probe != NULL) {
+                               dtrace_probe_t          *probe =
+                                                       ecb->dte_probe;
+                               dtrace_provider_t       *prov =
+                                                       probe->dtpr_provider;
+
+                               if (!(prov->dtpv_priv.dtpp_flags & match))
+                                       continue;
+                       }
+
+                       dtrace_ecb_disable(ecb);
+                       dtrace_ecb_destroy(ecb);
+               }
+
+               if (!match)
+                       break;
+       }
+
+       /*
+        * Before we free the buffers, perform one more sync to assure that
+        * every CPU is out of probe context.
+        */
+       dtrace_sync();
+
+       dtrace_buffer_free(state->dts_buffer);
+       dtrace_buffer_free(state->dts_aggbuffer);
+
+       for (i = 0; i < nspec; i++)
+               dtrace_buffer_free(spec[i].dtsp_buffer);
+
+       if (state->dts_cleaner != CYCLIC_NONE)
+               cyclic_remove(state->dts_cleaner);
+
+       if (state->dts_deadman != CYCLIC_NONE)
+               cyclic_remove(state->dts_deadman);
+
+       dtrace_dstate_fini(&vstate->dtvs_dynvars);
+       dtrace_vstate_fini(vstate);
+       kfree(state->dts_ecbs);
+
+       /*
+        * If there were aggregations allocated, they should have been cleaned
+        * up by now, so we can get rid of the idr.
+        */
+       if (!idr_empty(&state->dts_agg_idr)) {
+               idr_remove_all(&state->dts_agg_idr);
+               idr_destroy(&state->dts_agg_idr);
+       }
+
+       kfree(state->dts_buffer);
+       kfree(state->dts_aggbuffer);
+
+       for (i = 0; i < nspec; i++)
+               kfree(spec[i].dtsp_buffer);
+
+       kfree(spec);
+
+       dtrace_format_destroy(state);
+}
diff --git a/dtrace/dtrace_util.c b/dtrace/dtrace_util.c
new file mode 100644 (file)
index 0000000..6b87207
--- /dev/null
@@ -0,0 +1,215 @@
+/*
+ * FILE:       dtrace_util.c
+ * DESCRIPTION:        DTrace utility functions
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/vmalloc.h>
+
+#include "dtrace.h"
+
+dtrace_vtime_state_t           dtrace_vtime_active = 0;
+
+int dtrace_badattr(const dtrace_attribute_t *a)
+{
+       return a->dtat_name > DTRACE_STABILITY_MAX ||
+              a->dtat_data > DTRACE_STABILITY_MAX ||
+              a->dtat_class > DTRACE_CLASS_MAX;
+}
+
+/*
+ * Allocate a chunk of virtual memory in kernel space, and zero it out.  This
+ * allocation might fail (which will report a backtrace in the kernel log, yet
+ * it is harmless).
+ */
+void *dtrace_vzalloc_try(unsigned long size)
+{
+       return __vmalloc(size,
+                        __GFP_IO | __GFP_FS | __GFP_NORETRY | __GFP_ZERO,
+                        PAGE_KERNEL);
+}
+
+/*
+ * Allocate a chunk of virtual memory in kernel space, and zero it out.
+ */
+void *dtrace_vzalloc(unsigned long size)
+{
+       void    *ptr = vmalloc(size);
+
+       if (ptr == NULL)
+               return NULL;
+
+       return memset(ptr, 0, size);
+}
+
+/*
+ * Return a duplicate copy of a string.  If the specified string is NULL, this
+ * function returs a zero-length string.
+ */
+char *dtrace_strdup(const char *str)
+{
+       return kstrdup(str ? str : "", GFP_KERNEL);
+}
+
+/*
+ * Compare two strings using safe loads.
+ */
+int dtrace_strncmp(char *s1, char *s2, size_t limit)
+{
+       uint8_t                 c1, c2;
+       volatile uint16_t       *flags;
+
+       if (s1 == s2 || limit == 0)
+               return 0;
+
+       flags = (volatile uint16_t *)
+               &cpu_core[smp_processor_id()].cpuc_dtrace_flags;
+
+       do {
+               if (s1 == NULL)
+                       c1 = '\0';
+               else
+                       c1 = dtrace_load8((uintptr_t)s1++);
+
+               if (s2 == NULL)
+                       c2 = '\0';
+               else
+                       c2 = dtrace_load8((uintptr_t)s2++);
+
+               if (c1 != c2)
+                       return (c1 - c2);
+       } while (--limit && c1 != '\0' && !(*flags & CPU_DTRACE_FAULT));
+
+       return 0;
+}
+
+/*
+ * Compute strlen(s) for a string using safe memory accesses.  The additional
+ * len parameter is used to specify a maximum length to ensure completion.
+ */
+size_t dtrace_strlen(const char *s, size_t lim)
+{
+       uint_t  len;
+
+       for (len = 0; len != lim; len++) {
+               if (dtrace_load8((uintptr_t)s++) == '\0')
+                       break;
+       }
+
+       return len;
+}
+
+#define DTRACE_ISALPHA(c)      (((c) >= 'a' && (c) <= 'z') || \
+                                ((c) >= 'A' && (c) <= 'Z'))
+int dtrace_badname(const char *s)
+{
+       char    c;
+
+       if (s == NULL || (c = *s++) == '\0')
+               return 0;
+
+       if (!DTRACE_ISALPHA(c) && c != '-' && c!= '_' && c != '.')
+               return 1;
+
+       while ((c = *s++) != '\0') {
+               if (!DTRACE_ISALPHA(c) && (c < '0' || c > '9') &&
+                   c != '-' && c!= '_' && c != '.' && c != '`')
+                       return 1;
+       }
+
+       return 0;
+}
+
+void dtrace_cred2priv(const cred_t *cr, uint32_t *privp, uid_t *uidp)
+{
+#ifdef FIXME
+/*
+ * This should probably be rewritten based on capabilities in the cred_t struct.
+ */
+       uint32_t        priv;
+
+       if (cr == NULL)
+               priv = DTRACE_PRIV_ALL;
+       else {
+               const cred_t    *lcr = get_cred(cr);
+
+               if (PRIV_POLICY_ONLY(lcr, PRIV_ALL, FALSE))
+                       priv = DTRACE_PRIV_ALL;
+               else {
+                       *uidp = lcr->uid;
+                       priv = 0;
+
+                       if (PRIV_POLICY_ONLY(lcr, PRIV_DTRACE_KERNEL, FALSE))
+                               priv |= DTRACE_PRIV_KERNEL | DTRACE_PRIV_USER;
+                       else if (PRIV_POLICY_ONLY(lcr, PRIV_DTRACE_USER,
+                                                 FALSE))
+                               priv |= DTRACE_PRIV_USER;
+
+                       if (PRIV_POLICY_ONLY(lcr, PRIV_DTRACE_PROC, FALSE))
+                               priv |= DTRACE_PRIV_PROC;
+                       if (PRIV_POLICY_ONLY(lcr, PRIV_PROC_OWNER, FALSE))
+                               priv |= DTRACE_PRIV_OWNER;
+               }
+
+               put_cred(cr);
+       }
+
+       *privp = priv;
+#else
+       *privp = DTRACE_PRIV_ALL;
+
+       if (cr != NULL) {
+               const cred_t    *lcr = get_cred(cr);
+
+               *uidp = lcr->uid;
+               put_cred(cr);
+       }
+#endif
+}
+
+void dtrace_vtime_enable(void)
+{
+       dtrace_vtime_state_t    state, nstate = 0;
+
+       do {
+               state = dtrace_vtime_active;
+
+               switch (state) {
+               case DTRACE_VTIME_INACTIVE:
+                       nstate = DTRACE_VTIME_ACTIVE;
+                       break;
+               case DTRACE_VTIME_INACTIVE_TNF:
+                       nstate = DTRACE_VTIME_ACTIVE_TNF;
+                       break;
+               case DTRACE_VTIME_ACTIVE:
+               case DTRACE_VTIME_ACTIVE_TNF:
+                       panic("DTrace virtual time already enabled");
+                       /*NOTREACHED*/
+               }
+       } while (cmpxchg((uint32_t *)&dtrace_vtime_active, state, nstate) !=
+                state);
+}
+
+void dtrace_vtime_disable(void)
+{
+       dtrace_vtime_state_t    state, nstate = 0;
+
+       do {
+               state = dtrace_vtime_active;
+
+               switch (state) {
+               case DTRACE_VTIME_ACTIVE:
+                       nstate = DTRACE_VTIME_INACTIVE;
+                       break;
+               case DTRACE_VTIME_ACTIVE_TNF:
+                       nstate = DTRACE_VTIME_INACTIVE_TNF;
+                       break;
+               case DTRACE_VTIME_INACTIVE:
+               case DTRACE_VTIME_INACTIVE_TNF:
+                       panic("DTrace virtual time already disabled");
+                       /*NOTREACHED*/
+               }
+       } while (cmpxchg((uint32_t *)&dtrace_vtime_active, state, nstate) !=
+                state);
+}
diff --git a/dtrace/fasttrap.h b/dtrace/fasttrap.h
new file mode 100644 (file)
index 0000000..665a26c
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef _FASTTRAP_H_
+#define _FASTTRAP_H_
+
+extern int fasttrap_dev_init(void);
+extern void fasttrap_dev_exit(void);
+
+#endif /* _FASTTRAP_H_ */
diff --git a/dtrace/fasttrap_dev.c b/dtrace/fasttrap_dev.c
new file mode 100644 (file)
index 0000000..2ad91b9
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * FILE:       fasttrap_dev.c
+ * DESCRIPTION:        Fasttrap Tracing: device file handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+
+#include "dtrace_dev.h"
+
+static long fasttrap_ioctl(struct file *file,
+                        unsigned int cmd, unsigned long arg)
+{
+       return -EAGAIN;
+}
+
+static int fasttrap_open(struct inode *inode, struct file *file)
+{
+       return -EAGAIN;
+}
+
+static int fasttrap_close(struct inode *inode, struct file *file)
+{
+       return 0;
+}
+
+static const struct file_operations fasttrap_fops = {
+       .owner  = THIS_MODULE,
+        .unlocked_ioctl = fasttrap_ioctl,
+        .open   = fasttrap_open,
+        .release = fasttrap_close,
+};
+
+static struct miscdevice fasttrap_dev = {
+       .minor = DT_DEV_FASTTRAP_MINOR,
+       .name = "fasttrap",
+       .nodename = "dtrace/provider/fasttrap",
+       .fops = &fasttrap_fops,
+};
+
+int fasttrap_dev_init(void)
+{
+       int ret = 0;
+
+       ret = misc_register(&fasttrap_dev);
+       if (ret)
+               pr_err("%s: Can't register misc device %d\n",
+                      fasttrap_dev.name, fasttrap_dev.minor);
+
+       return ret;
+}
+
+void fasttrap_dev_exit(void)
+{
+       misc_deregister(&fasttrap_dev);
+}
diff --git a/dtrace/fasttrap_mod.c b/dtrace/fasttrap_mod.c
new file mode 100644 (file)
index 0000000..44e7340
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * FILE:       fasttrap_mod.c
+ * DESCRIPTION:        Fasttrap Tracing: module handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/module.h>
+
+#include "dtrace.h"
+#include "dtrace_dev.h"
+#include "fasttrap.h"
+
+MODULE_AUTHOR("Kris Van Hees (kris.van.hees@oracle.com)");
+MODULE_DESCRIPTION("Fasttrap Tracing");
+MODULE_VERSION("v0.1");
+MODULE_LICENSE("Proprietary");
+
+static const dtrace_pattr_t fasttrap_attr = {
+};
+
+static dtrace_pops_t fasttrap_pops = {
+};
+
+DT_PROVIDER_MODULE(fasttrap, DTRACE_PRIV_PROC | DTRACE_PRIV_OWNER)
diff --git a/dtrace/fbt.h b/dtrace/fbt.h
new file mode 100644 (file)
index 0000000..6b61349
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef _FBT_H_
+#define _FBT_H_
+
+extern int fbt_dev_init(void);
+extern void fbt_dev_exit(void);
+
+#endif /* _FBT_H_ */
diff --git a/dtrace/fbt_dev.c b/dtrace/fbt_dev.c
new file mode 100644 (file)
index 0000000..17f3b88
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * FILE:       fbt_dev.c
+ * DESCRIPTION:        Function Boundary Tracing: device file handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+
+#include "dtrace_dev.h"
+
+static long fbt_ioctl(struct file *file,
+                        unsigned int cmd, unsigned long arg)
+{
+       return -EAGAIN;
+}
+
+static int fbt_open(struct inode *inode, struct file *file)
+{
+       return -EAGAIN;
+}
+
+static int fbt_close(struct inode *inode, struct file *file)
+{
+       return 0;
+}
+
+static const struct file_operations fbt_fops = {
+       .owner  = THIS_MODULE,
+        .unlocked_ioctl = fbt_ioctl,
+        .open   = fbt_open,
+        .release = fbt_close,
+};
+
+static struct miscdevice fbt_dev = {
+       .minor = DT_DEV_FBT_MINOR,
+       .name = "fbt",
+       .nodename = "dtrace/provider/fbt",
+       .fops = &fbt_fops,
+};
+
+int fbt_dev_init(void)
+{
+       int ret = 0;
+
+       ret = misc_register(&fbt_dev);
+       if (ret)
+               pr_err("%s: Can't register misc device %d\n",
+                      fbt_dev.name, fbt_dev.minor);
+
+       return ret;
+}
+
+void fbt_dev_exit(void)
+{
+       misc_deregister(&fbt_dev);
+}
diff --git a/dtrace/fbt_mod.c b/dtrace/fbt_mod.c
new file mode 100644 (file)
index 0000000..b41d2b1
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * FILE:       fbt_dmod.c
+ * DESCRIPTION:        Function Boundary Tracing: module handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/module.h>
+
+#include "dtrace.h"
+#include "dtrace_dev.h"
+#include "fbt.h"
+
+MODULE_AUTHOR("Kris Van Hees (kris.van.hees@oracle.com)");
+MODULE_DESCRIPTION("Function Boundary Tracing");
+MODULE_VERSION("v0.1");
+MODULE_LICENSE("Proprietary");
+
+static const dtrace_pattr_t fbt_attr = {
+};
+
+static dtrace_pops_t fbt_pops = {
+};
+
+DT_PROVIDER_MODULE(fbt, DTRACE_PRIV_KERNEL);
diff --git a/dtrace/lockstat.h b/dtrace/lockstat.h
new file mode 100644 (file)
index 0000000..156ce73
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef _LOCKSTAT_H_
+#define _LOCKSTAT_H_
+
+extern int lockstat_dev_init(void);
+extern void lockstat_dev_exit(void);
+
+#endif /* _LOCKSTAT_H_ */
diff --git a/dtrace/lockstat_dev.c b/dtrace/lockstat_dev.c
new file mode 100644 (file)
index 0000000..a4525bf
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * FILE:       lockstat_dev.c
+ * DESCRIPTION:        Lock Statistics: device file handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+
+#include "dtrace_dev.h"
+
+static long lockstat_ioctl(struct file *file,
+                        unsigned int cmd, unsigned long arg)
+{
+       return -EAGAIN;
+}
+
+static int lockstat_open(struct inode *inode, struct file *file)
+{
+       return -EAGAIN;
+}
+
+static int lockstat_close(struct inode *inode, struct file *file)
+{
+       return 0;
+}
+
+static const struct file_operations lockstat_fops = {
+       .owner  = THIS_MODULE,
+        .unlocked_ioctl = lockstat_ioctl,
+        .open   = lockstat_open,
+        .release = lockstat_close,
+};
+
+static struct miscdevice lockstat_dev = {
+       .minor = DT_DEV_LOCKSTAT_MINOR,
+       .name = "dtrace",
+       .nodename = "dtrace/provider/lockstat",
+       .fops = &lockstat_fops,
+};
+
+int lockstat_dev_init(void)
+{
+       int ret = 0;
+
+       ret = misc_register(&lockstat_dev);
+       if (ret)
+               pr_err("%s: Can't register misc device %d\n",
+                      lockstat_dev.name, lockstat_dev.minor);
+
+       return ret;
+}
+
+void lockstat_dev_exit(void)
+{
+       misc_deregister(&lockstat_dev);
+}
diff --git a/dtrace/lockstat_mod.c b/dtrace/lockstat_mod.c
new file mode 100644 (file)
index 0000000..0b16ea9
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * FILE:       lockstat_mod.c
+ * DESCRIPTION:        Lock Statistics: module handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/module.h>
+
+#include "dtrace.h"
+#include "dtrace_dev.h"
+#include "lockstat.h"
+
+MODULE_AUTHOR("Kris Van Hees (kris.van.hees@oracle.com)");
+MODULE_DESCRIPTION("Lock Statistics");
+MODULE_VERSION("v0.1");
+MODULE_LICENSE("Proprietary");
+
+static const dtrace_pattr_t lockstat_attr = {
+};
+
+static dtrace_pops_t lockstat_pops = {
+};
+
+DT_PROVIDER_MODULE(lockstat, DTRACE_PRIV_KERNEL)
diff --git a/dtrace/profile.h b/dtrace/profile.h
new file mode 100644 (file)
index 0000000..8f96a8a
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef _PROFILE_H_
+#define _PROFILE_H_
+
+extern void profile_provide(void *, const dtrace_probedesc_t *);
+extern int profile_enable(void *, dtrace_id_t, void *);
+extern void profile_disable(void *, dtrace_id_t, void *);
+extern int profile_usermode(void *, dtrace_id_t, void *);
+extern void profile_destroy(void *, dtrace_id_t, void *);
+
+extern dtrace_provider_id_t    profile_id;
+
+extern int profile_dev_init(void);
+extern void profile_dev_exit(void);
+
+#endif /* _PROFILE_H_ */
diff --git a/dtrace/profile_dev.c b/dtrace/profile_dev.c
new file mode 100644 (file)
index 0000000..4f98957
--- /dev/null
@@ -0,0 +1,348 @@
+/*
+ * FILE:       profile_dev.c
+ * DESCRIPTION:        Profile Interrupt Tracing: device file handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+
+#include "dtrace.h"
+#include "dtrace_dev.h"
+#include "profile.h"
+
+#define PROF_NAMELEN           15
+#define PROF_PROFILE           0
+#define PROF_TICK              1
+#define PROF_PREFIX_PROFILE    "profile-"
+#define PROF_PREFIX_TICK       "tick-"
+
+typedef struct profile_probe {
+       char            prof_name[PROF_NAMELEN];
+       dtrace_id_t     prof_id;
+       int             prof_kind;
+       ktime_t         prof_interval;
+       cyclic_id_t     prof_cyclic;
+} profile_probe_t;
+
+typedef struct profile_probe_percpu {
+       ktime_t         profc_expected;
+       ktime_t         profc_interval;
+       profile_probe_t *profc_probe;
+} profile_probe_percpu_t;
+
+static ktime_t profile_interval_min = KTIME_INIT(0, NANOSEC / 5000);
+static int     profile_aframes = 0;
+
+static int     profile_rates[] = {
+                                   97, 199, 499, 997, 1999,
+                                   4001, 4999, 0, 0, 0,
+                                   0, 0, 0, 0, 0,
+                                   0, 0, 0, 0, 0,
+                                 };
+static int     profile_ticks[] = {
+                                   1, 10, 100, 500, 1000,
+                                   5000, 0, 0, 0, 0,
+                                   0, 0, 0, 0, 0,
+                                 };
+
+/*
+ * profile_max defines the upper bound on the number of profile probes that
+ * can exist (this is to prevent malicious or clumsy users from exhausing
+ * system resources by creating a slew of profile probes). At mod load time,
+ * this gets its value from PROFILE_MAX_DEFAULT or profile-max-probes if it's
+ * present as module parameter.
+ * FIXME: module parameter yet to be implemented.
+ */
+#define PROFILE_MAX_DEFAULT    1000    /* default max. number of probes */
+
+static int     profile_max;            /* maximum number of profile probes */
+static atomic_t        profile_total;          /* current number of profile probes */
+
+static void profile_tick(void *arg)
+{
+       profile_probe_t *prof = arg;
+
+       dtrace_probe(prof->prof_id, 0, 0, 0, 0, 0); /* FIXME */
+}
+
+static void profile_create(ktime_t interval, const char *name, int kind)
+{
+       profile_probe_t *prof;
+       int             nr_frames = 0; /* FIXME */
+
+       if (profile_aframes)
+               nr_frames = profile_aframes;
+
+       if (ktime_lt(interval, profile_interval_min))
+               return;
+
+       if (dtrace_probe_lookup(profile_id, NULL, NULL, name) != 0)
+               return;
+
+       atomic_inc(&profile_total);
+       if (atomic_read(&profile_total) > profile_max) {
+               atomic_dec(&profile_total);
+               return;
+       }
+
+       prof = kzalloc(sizeof(profile_probe_t), GFP_KERNEL);
+       strcpy(prof->prof_name, name);
+       prof->prof_interval = interval;
+       prof->prof_cyclic = CYCLIC_NONE;
+       prof->prof_kind = kind;
+       prof->prof_id = dtrace_probe_create(profile_id, NULL, NULL, name,
+                                           nr_frames, prof);
+}
+
+void profile_provide(void *arg, const dtrace_probedesc_t *desc)
+{
+       int             i, j, rate, kind;
+       long            val = 0, mult = 1, mult_s = 0, mult_ns = 0, len;
+       ktime_t         interval;
+       const char      *name, *suffix = NULL;
+       const struct {
+                       char    *prefix;
+                       int     kind;
+       } types[] = {
+                       { PROF_PREFIX_PROFILE, PROF_PROFILE },
+                       { PROF_PREFIX_TICK, PROF_TICK },
+                       { NULL, 0 },
+                   };
+
+       const struct {
+                       char    *name;
+                       long    mult_s;
+                       long    mult_ns;
+       } suffixes[] = {
+                       { "ns",         0, 1 },
+                       { "nsec",       0, 1 },
+                       { "us",         0, NANOSEC / MICROSEC },
+                       { "usec",       0, NANOSEC / MICROSEC },
+                       { "ms",         0, NANOSEC / MILLISEC },
+                       { "msec",       0, NANOSEC / MILLISEC },
+                       { "s",          1, 0 },
+                       { "sec",        1, 0 },
+                       { "m",          60, 0 },
+                       { "min",        60, 0 },
+                       { "h",          60 * 60, 0 },
+                       { "hour",       60 * 60, 0 },
+                       { "d",          24 * 60 * 60, 0 },
+                       { "day",        24 * 60 * 60, 0 },
+                       { "hz",         0, 0 },
+                       { NULL, },
+                      };
+
+       if (desc == NULL) {
+               char    n[PROF_NAMELEN];
+
+               /*
+                * If no description was provided, provide all of our probes.
+                */
+               for (i = 0; i < sizeof(profile_rates) / sizeof(int); i++) {
+                       if ((rate = profile_rates[i]) == 0)
+                               continue;
+
+                       snprintf(n, PROF_NAMELEN, "%s%d",
+                                PROF_PREFIX_PROFILE, rate);
+                       profile_create(ktime_set(0, NANOSEC / rate),
+                                      n, PROF_PROFILE);
+               }
+
+               for (i = 0; i < sizeof(profile_ticks) / sizeof(int); i++) {
+                       if ((rate = profile_ticks[i]) == 0)
+                               continue;
+
+                       snprintf(n, PROF_NAMELEN, "%s%d",
+                                PROF_PREFIX_TICK, rate);
+                       profile_create(ktime_set(0, NANOSEC / rate),
+                                      n, PROF_TICK);
+               }
+
+               return;
+       }
+
+       name = desc->dtpd_name;
+
+       for (i = 0; types[i].prefix != NULL; i++) {
+               len = strlen(types[i].prefix);
+
+               if (strncmp(name, types[i].prefix, len) != 0)
+                       continue;
+
+               break;
+       }
+
+       if (types[i].prefix == NULL)
+               return;
+
+       kind = types[i].kind;
+
+       /*
+        * We need to start before any time suffix.
+        */
+       for (j = strlen(name); j >= len; j--) {
+               if (name[j] >= '0' && name[j] <= '9')
+                       break;
+
+               suffix = &name[j];
+       }
+
+       ASSERT(suffix != NULL);
+
+       /*
+        * Now determine the numerical value present in the probe name.
+        */
+       for (; j >= len; j--) {
+               if (name[j] < '0' || name[j] > '9')
+                       return;
+
+               val += (name[j] - '0') * mult;
+               mult *= 10;
+       }
+
+       if (val == 0)
+               return;
+
+       /*
+        * Look up the suffix to determine the multiplier.
+        */
+       for (i = 0; suffixes[i].name != NULL; i++) {
+               if (strcasecmp(suffixes[i].name, suffix) == 0) {
+                       mult_s = suffixes[i].mult_s;
+                       mult_ns = suffixes[i].mult_ns;
+                       break;
+               }
+       }
+
+       if (suffixes[i].name == NULL && *suffix != '\0')
+               return;
+
+       if (mult_s == 0 && mult_ns == 0) {
+               /*
+                * The default is frequency-per-second.
+                */
+               interval = ns_to_ktime((int64_t)NANOSEC / val);
+       } else {
+               long    sec;
+               long    nsec = val * mult_ns;
+
+               sec = nsec / NANOSEC;
+               nsec %= NANOSEC;
+
+               interval = ktime_set(val * mult_s + sec, nsec);
+       }
+
+
+       profile_create(interval, name, kind);
+}
+
+int profile_enable(void *arg, dtrace_id_t id, void *parg)
+{
+       profile_probe_t         *prof = parg;
+#ifdef FIXME
+       cyc_omni_handler_t      omni;
+#endif
+       cyc_handler_t           hdlr;
+       cyc_time_t              when;
+
+       ASSERT(ktime_nz(prof->prof_interval));
+       ASSERT(mutex_is_locked(&cpu_lock));
+
+       if (prof->prof_kind == PROF_TICK) {
+               hdlr.cyh_func = profile_tick;
+               hdlr.cyh_arg = prof;
+               hdlr.cyh_level = CY_HIGH_LEVEL;
+
+               when.cyt_interval = prof->prof_interval;
+               when.cyt_when = ktime_set(0, 0);
+
+               prof->prof_cyclic = cyclic_add(&hdlr, &when);
+       } else {
+               ASSERT(prof->prof_kind == PROF_PROFILE);        
+
+#ifdef FIXME
+               omni.cyo_online = profile_online;
+               omni.cyo_offline = profile_offline;
+               omni.cyo_arg = prof;
+
+               prof->prof_cyclic = cyclic_add_omni(&omni);
+#else
+               prof->prof_cyclic = CYCLIC_NONE;
+               return -ENOTSUPP;
+#endif
+       }
+
+       return 0;
+}
+
+void profile_disable(void *arg, dtrace_id_t id, void *parg)
+{
+       profile_probe_t *prof = parg;
+
+if (prof->prof_cyclic == CYCLIC_NONE) return;
+       ASSERT(prof->prof_cyclic != CYCLIC_NONE);
+       ASSERT(mutex_is_locked(&cpu_lock));
+
+       cyclic_remove(prof->prof_cyclic);
+       prof->prof_cyclic = CYCLIC_NONE;
+}
+
+int profile_usermode(void *arg, dtrace_id_t id, void *parg)
+{
+       return 1; /* FIXME */
+}
+
+void profile_destroy(void *arg, dtrace_id_t id, void *parg)
+{
+       profile_probe_t *prof = parg;
+
+       ASSERT(prof->prof_cyclic == CYCLIC_NONE);
+       kfree(prof);
+
+       ASSERT(atomic_read(&profile_total) >= 1);
+       atomic_dec(&profile_total);
+}
+
+static int profile_open(struct inode *inode, struct file *file)
+{
+       return 0;
+}
+
+static int profile_close(struct inode *inode, struct file *file)
+{
+       return 0;
+}
+
+static const struct file_operations profile_fops = {
+       .owner  = THIS_MODULE,
+        .open   = profile_open,
+        .release = profile_close,
+};
+
+static struct miscdevice profile_dev = {
+       .minor = DT_DEV_PROFILE_MINOR,
+       .name = "profile",
+       .nodename = "dtrace/provider/profile",
+       .fops = &profile_fops,
+};
+
+int profile_dev_init(void)
+{
+       int ret = 0;
+
+       ret = misc_register(&profile_dev);
+       if (ret)
+               pr_err("%s: Can't register misc device %d\n",
+                      profile_dev.name, profile_dev.minor);
+
+       profile_max = PROFILE_MAX_DEFAULT;
+
+       return ret;
+}
+
+void profile_dev_exit(void)
+{
+       misc_deregister(&profile_dev);
+}
diff --git a/dtrace/profile_mod.c b/dtrace/profile_mod.c
new file mode 100644 (file)
index 0000000..0f0be15
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * FILE:       profile_mod.c
+ * DESCRIPTION:        Profile Interrupt Tracing: module handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/module.h>
+
+#include "dtrace.h"
+#include "dtrace_dev.h"
+#include "profile.h"
+
+MODULE_AUTHOR("Kris Van Hees (kris.van.hees@oracle.com)");
+MODULE_DESCRIPTION("Profile Interrupt Tracing");
+MODULE_VERSION("v0.1");
+MODULE_LICENSE("Proprietary");
+
+static const dtrace_pattr_t profile_attr = {
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
+{ DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
+};
+
+static dtrace_pops_t profile_pops = {
+       profile_provide,
+       NULL,
+       profile_enable,
+       profile_disable,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       profile_usermode,
+       profile_destroy,
+};
+
+DT_PROVIDER_MODULE(profile, DTRACE_PRIV_KERNEL | DTRACE_PRIV_USER)
diff --git a/dtrace/sdt.h b/dtrace/sdt.h
new file mode 100644 (file)
index 0000000..6ad3c80
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef _SDT_H_
+#define _SDT_H_
+
+extern int sdt_dev_init(void);
+extern void sdt_dev_exit(void);
+
+#endif /* _SDT_H_ */
diff --git a/dtrace/sdt_dev.c b/dtrace/sdt_dev.c
new file mode 100644 (file)
index 0000000..6c3cbb8
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * FILE:       sdt_dev.c
+ * DESCRIPTION:        Statically Defined Tracing: device file handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+
+#include "dtrace_dev.h"
+
+static long sdt_ioctl(struct file *file,
+                        unsigned int cmd, unsigned long arg)
+{
+       return -EAGAIN;
+}
+
+static int sdt_open(struct inode *inode, struct file *file)
+{
+       return -EAGAIN;
+}
+
+static int sdt_close(struct inode *inode, struct file *file)
+{
+       return 0;
+}
+
+static const struct file_operations sdt_fops = {
+       .owner  = THIS_MODULE,
+        .unlocked_ioctl = sdt_ioctl,
+        .open   = sdt_open,
+        .release = sdt_close,
+};
+
+static struct miscdevice sdt_dev = {
+       .minor = DT_DEV_SDT_MINOR,
+       .name = "sdt",
+       .nodename = "dtrace/provider/sdt",
+       .fops = &sdt_fops,
+};
+
+int sdt_dev_init(void)
+{
+       int ret = 0;
+
+       ret = misc_register(&sdt_dev);
+       if (ret)
+               pr_err("%s: Can't register misc device %d\n",
+                      sdt_dev.name, sdt_dev.minor);
+
+       return ret;
+}
+
+void sdt_dev_exit(void)
+{
+       misc_deregister(&sdt_dev);
+}
diff --git a/dtrace/sdt_impl.h b/dtrace/sdt_impl.h
new file mode 100644 (file)
index 0000000..e10a096
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2004 Oracle America, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _SYS_SDT_IMPL_H
+#define        _SYS_SDT_IMPL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "dtrace.h"
+
+#if defined(__i386__) || defined(__x86_64__)
+typedef uint8_t sdt_instr_t;
+#else
+typedef uint32_t sdt_instr_t;
+#endif
+
+typedef struct sdt_provider {
+       char                    *sdtp_name;     /* name of provider */
+       char                    *sdtp_prefix;   /* prefix for probe names */
+       dtrace_pattr_t          *sdtp_attr;     /* stability attributes */
+       dtrace_provider_id_t    sdtp_id;        /* provider ID */
+} sdt_provider_t;
+
+extern sdt_provider_t sdt_providers[];         /* array of providers */
+
+typedef struct sdt_probe {
+       sdt_provider_t  *sdp_provider;          /* provider */
+       char            *sdp_name;              /* name of probe */
+       int             sdp_namelen;            /* length of allocated name */
+       dtrace_id_t     sdp_id;                 /* probe ID */
+       struct module   *sdp_ctl;               /* module ptr */
+       int             sdp_loadcnt;            /* load count for module */
+       int             sdp_primary;            /* non-zero if primary mod */
+       sdt_instr_t     *sdp_patchpoint;        /* patch point */
+       sdt_instr_t     sdp_patchval;           /* instruction to patch */
+       sdt_instr_t     sdp_savedval;           /* saved instruction value */
+       struct sdt_probe *sdp_next;             /* next probe */
+       struct sdt_probe *sdp_hashnext;         /* next on hash */
+} sdt_probe_t;
+
+typedef struct sdt_argdesc {
+       const char *sda_provider;               /* provider for arg */
+       const char *sda_name;                   /* name of probe */
+       const int sda_ndx;                      /* argument index */
+       const int sda_mapping;                  /* mapping of argument */
+       const char *sda_native;                 /* native type of argument */
+       const char *sda_xlate;                  /* translated type of arg */
+} sdt_argdesc_t;
+
+extern void sdt_getargdesc(void *, dtrace_id_t, void *, dtrace_argdesc_t *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SYS_SDT_IMPL_H */
diff --git a/dtrace/sdt_mod.c b/dtrace/sdt_mod.c
new file mode 100644 (file)
index 0000000..5989f0d
--- /dev/null
@@ -0,0 +1,618 @@
+/*
+ * FILE:       sdt_mod.c
+ * DESCRIPTION:        Statically Defined Tracing: module handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/gfp.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/ptrace.h>
+#include <linux/sdt.h>
+#include <linux/slab.h>
+
+#include "dtrace.h"
+#include "dtrace_dev.h"
+#include "sdt.h"
+#include "sdt_impl.h"
+
+#define        SDT_PATCHVAL    0xf0
+#define        SDT_ADDR2NDX(addr)      ((((uintptr_t)(addr)) >> 4) & sdt_probetab_mask)
+#define        SDT_PROBETAB_SIZE       0x1000          /* 4k entries -- 16K total */
+
+///static dev_info_t           *sdt_devi;
+static int                     sdt_verbose = 0;
+static sdt_probe_t             **sdt_probetab;
+static int                     sdt_probetab_size;
+static int                     sdt_probetab_mask;
+
+struct frame { /* TBD: move to header file, used in dtrace_isa.c also */
+       struct frame    *fr_savfp;
+       unsigned long   fr_savpc;
+} __attribute__((packed));
+
+static inline bool mod_loaded(struct module *mod)
+{
+       return mod->state == MODULE_STATE_LIVE;
+}
+
+static unsigned int mod_loadcnt(struct module *mod)
+{
+#ifdef CONFIG_MODULE_UNLOAD
+       return module_refcount(mod);
+#else
+       return 1;
+#endif
+}
+
+#if ELF_CLASS == ELFCLASS32
+typedef Elf32_Sym Sym;
+#else
+typedef Elf64_Sym Sym;
+#endif
+
+char *
+kernel_searchsym(struct module *mp, uintptr_t value, ulong_t *offset)
+{
+       Sym *symtabptr;
+       char *strtabptr;
+       int symnum;
+       Sym *sym;
+       Sym *cursym;
+       uintptr_t curval;
+
+       *offset = (ulong_t)-1l;         /* assume not found */
+       cursym  = NULL;
+
+       if (!within_module_core((unsigned long)value, mp) &&
+           !within_module_init((unsigned long)value, mp))
+               return NULL;            /* not in this module */
+
+       strtabptr  = NULL; ///FIXME: mp->strings;
+       symtabptr  = (Sym *)mp->symtab;
+
+       /*
+        * Scan the module's symbol table for a symbol <= value
+        */
+       for (symnum = 1, sym = symtabptr + 1;
+           symnum < mp->num_symtab; symnum++, sym = (Sym *)
+           ((uintptr_t)sym /* FIXME: + mp->symhdr->sh_entsize*/)) {
+               if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL) {
+                       if (ELF_ST_BIND(sym->st_info) != STB_LOCAL)
+                               continue;
+                       if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT &&
+                           ELF_ST_TYPE(sym->st_info) != STT_FUNC)
+                               continue;
+               }
+
+               curval = (uintptr_t)sym->st_value;
+
+               if (curval > value)
+                       continue;
+
+               /*
+                * If one or both are functions...
+                */
+               if (ELF_ST_TYPE(sym->st_info) == STT_FUNC || (cursym != NULL &&
+                   ELF_ST_TYPE(cursym->st_info) == STT_FUNC)) {
+                       /* Ignore if the address is out of the bounds */
+                       if (value - sym->st_value >= sym->st_size)
+                               continue;
+
+                       if (cursym != NULL &&
+                           ELF_ST_TYPE(cursym->st_info) == STT_FUNC) {
+                               /* Prefer the function to the non-function */
+                               if (ELF_ST_TYPE(sym->st_info) != STT_FUNC)
+                                       continue;
+
+                               /* Prefer the larger of the two functions */
+                               if (sym->st_size <= cursym->st_size)
+                                       continue;
+                       }
+               } else if (value - curval >= *offset) {
+                       continue;
+               }
+
+               *offset = (ulong_t)(value - curval);
+               cursym = sym;
+       }
+       if (cursym == NULL)
+               return (NULL);
+
+       return (strtabptr + cursym->st_name);
+}
+
+static void dtrace_invop_callsite(void)        /* TBD: copied from dtrace_isa.c */
+{
+}
+
+/*ARGSUSED*/
+static int
+sdt_invop(uintptr_t addr, uintptr_t *stack, uintptr_t eax)
+{
+       uintptr_t stack0, stack1, stack2, stack3, stack4;
+       int i = 0;
+       sdt_probe_t *sdt = sdt_probetab[SDT_ADDR2NDX(addr)];
+
+#ifdef __x86_64__
+       /*
+        * On amd64, stack[0] contains the dereferenced stack pointer,
+        * stack[1] contains savfp, stack[2] contains savpc.  We want
+        * to step over these entries.
+        */
+       i += 3;
+#endif
+
+       for (; sdt != NULL; sdt = sdt->sdp_hashnext) {
+               if ((uintptr_t)sdt->sdp_patchpoint == addr) {
+                       /*
+                        * When accessing the arguments on the stack, we must
+                        * protect against accessing beyond the stack.  We can
+                        * safely set NOFAULT here -- we know that interrupts
+                        * are already disabled.
+                        */
+                       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+                       stack0 = stack[i++];
+                       stack1 = stack[i++];
+                       stack2 = stack[i++];
+                       stack3 = stack[i++];
+                       stack4 = stack[i++];
+                       DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT |
+                           CPU_DTRACE_BADADDR);
+
+                       dtrace_probe(sdt->sdp_id, stack0, stack1,
+                           stack2, stack3, stack4);
+
+                       return (DTRACE_INVOP_NOP);
+               }
+       }
+
+       return (0);
+}
+
+/*ARGSUSED*/
+static void
+sdt_provide_module(void *arg, struct module *module)
+{
+       char *modname = module->name;
+       sdt_probedesc_t *sdpd;
+       sdt_probe_t *sdp, *old;
+       sdt_provider_t *prov;
+       int len;
+
+       /*
+        * One for all, and all for one:  if we haven't yet registered all of
+        * our providers, we'll refuse to provide anything.
+        */
+       for (prov = sdt_providers; prov->sdtp_name != NULL; prov++) {
+               if (prov->sdtp_id == DTRACE_PROVNONE)
+                       return;
+       }
+
+       if (module->sdt_nprobes != 0 || (sdpd = module->sdt_probes) == NULL)
+               return;
+
+       for (sdpd = module->sdt_probes; sdpd != NULL; sdpd = sdpd->sdpd_next) {
+               char *name = sdpd->sdpd_name, *func, *nname;
+               int i, j;
+               sdt_provider_t *prov;
+               ulong_t offs;
+               dtrace_id_t id;
+
+               for (prov = sdt_providers; prov->sdtp_prefix != NULL; prov++) {
+                       char *prefix = prov->sdtp_prefix;
+
+                       if (strncmp(name, prefix, strlen(prefix)) == 0) {
+                               name += strlen(prefix);
+                               break;
+                       }
+               }
+
+               nname = kmalloc(len = strlen(name) + 1, GFP_KERNEL);
+               if (!nname) {
+                       pr_warning("sdt cannot allocate memory for module: %s",
+                               module->name);
+                       return;
+               }
+
+               for (i = 0, j = 0; name[j] != '\0'; i++) {
+                       if (name[j] == '_' && name[j + 1] == '_') {
+                               nname[i] = '-';
+                               j += 2;
+                       } else {
+                               nname[i] = name[j++];
+                       }
+               }
+
+               nname[i] = '\0';
+
+               sdp = kzalloc(sizeof(sdt_probe_t), GFP_KERNEL);
+               if (!sdp) {
+                       pr_warning("sdt cannot allocate probe for module: %s",
+                               module->name);
+                       kfree(nname);
+                       return;
+               }
+#ifdef CONFIG_MODULE_UNLOAD
+               sdp->sdp_loadcnt = module_refcount(module); // TBD: not loadcnt
+#else
+               sdp->sdp_loadcnt = 1;
+#endif
+               sdp->sdp_ctl = module;
+               sdp->sdp_name = nname;
+               sdp->sdp_namelen = len;
+               sdp->sdp_provider = prov;
+
+               func = kernel_searchsym(module, sdpd->sdpd_offset, &offs);
+
+               if (func == NULL)
+                       func = "<unknown>";
+
+               /*
+                * We have our provider.  Now create the probe.
+                */
+               if ((id = dtrace_probe_lookup(prov->sdtp_id, modname,
+                   func, nname)) != DTRACE_IDNONE) {
+                       old = dtrace_probe_arg(prov->sdtp_id, id);
+                       ASSERT(old != NULL);
+
+                       sdp->sdp_next = old->sdp_next;
+                       sdp->sdp_id = id;
+                       old->sdp_next = sdp;
+               } else {
+                       sdp->sdp_id = dtrace_probe_create(prov->sdtp_id,
+                           modname, func, nname, 3, sdp);
+
+                       module->sdt_nprobes++;
+               }
+
+               sdp->sdp_hashnext =
+                   sdt_probetab[SDT_ADDR2NDX(sdpd->sdpd_offset)];
+               sdt_probetab[SDT_ADDR2NDX(sdpd->sdpd_offset)] = sdp;
+
+               sdp->sdp_patchval = SDT_PATCHVAL;
+               sdp->sdp_patchpoint = (uint8_t *)sdpd->sdpd_offset;
+               sdp->sdp_savedval = *sdp->sdp_patchpoint;
+       }
+}
+
+/*ARGSUSED*/
+static void
+sdt_destroy(void *arg, dtrace_id_t id, void *parg)
+{
+       sdt_probe_t *sdp = parg, *old, *last, *hash;
+       struct module *module = sdp->sdp_ctl;
+       int ndx;
+
+       if (module != NULL && mod_loadcnt(module) == sdp->sdp_loadcnt) {
+               if ((mod_loadcnt(module) == sdp->sdp_loadcnt &&
+                   mod_loaded(module))) {
+                       module->sdt_nprobes--;
+               }
+       }
+
+       while (sdp != NULL) {
+               old = sdp;
+
+               /*
+                * Now we need to remove this probe from the sdt_probetab.
+                */
+               ndx = SDT_ADDR2NDX(sdp->sdp_patchpoint);
+               last = NULL;
+               hash = sdt_probetab[ndx];
+
+               while (hash != sdp) {
+                       ASSERT(hash != NULL);
+                       last = hash;
+                       hash = hash->sdp_hashnext;
+               }
+
+               if (last != NULL) {
+                       last->sdp_hashnext = sdp->sdp_hashnext;
+               } else {
+                       sdt_probetab[ndx] = sdp->sdp_hashnext;
+               }
+
+               kfree(sdp->sdp_name);
+               sdp = sdp->sdp_next;
+               kfree(old);
+       }
+}
+
+/*ARGSUSED*/
+static int
+sdt_enable(void *arg, dtrace_id_t id, void *parg)
+{
+       sdt_probe_t *sdp = parg;
+       struct module *module = sdp->sdp_ctl;
+
+       module->mod_nenabled++;
+
+       /*
+        * If this module has disappeared since we discovered its probes,
+        * refuse to enable it.
+        */
+       if (!mod_loaded(module)) {
+               if (sdt_verbose) {
+                       pr_warning( "sdt is failing for probe %s "
+                           "(module %s unloaded)",
+                           sdp->sdp_name, module->name);
+               }
+               goto err;
+       }
+
+       /*
+        * Now check that our module has the expected load count.  If it
+        * doesn't, this module must have been unloaded and reloaded -- and
+        * we're not going to touch it.
+        */
+       if (mod_loadcnt(module) != sdp->sdp_loadcnt) {
+               if (sdt_verbose) {
+                       pr_warning("sdt is failing for probe %s "
+                           "(module %s reloaded)",
+                           sdp->sdp_name, module->name);
+               }
+               goto err;
+       }
+
+       while (sdp != NULL) {
+               *sdp->sdp_patchpoint = sdp->sdp_patchval;
+               sdp = sdp->sdp_next;
+       }
+err:
+       return (0);
+}
+
+/*ARGSUSED*/
+static void
+sdt_disable(void *arg, dtrace_id_t id, void *parg)
+{
+       sdt_probe_t *sdp = parg;
+       struct module *module = sdp->sdp_ctl;
+
+       module->mod_nenabled--;
+
+       if (!mod_loaded(module) || mod_loadcnt(module) != sdp->sdp_loadcnt)
+               goto err;
+
+       while (sdp != NULL) {
+               *sdp->sdp_patchpoint = sdp->sdp_savedval;
+               sdp = sdp->sdp_next;
+       }
+
+err:
+       ;
+}
+
+/*ARGSUSED*/
+uint64_t
+sdt_getarg(void *arg, dtrace_id_t id, void *parg, int argno, int aframes)
+{
+       uintptr_t val;
+       struct frame *fp = (struct frame *)dtrace_getfp();
+       uintptr_t *stack;
+       int i;
+#if defined(__x86_64__)
+       /*
+        * A total of 6 arguments are passed via registers; any argument with
+        * index of 5 or lower is therefore in a register.
+        */
+       int inreg = 5;
+#endif
+
+       for (i = 1; i <= aframes; i++) {
+               fp = (struct frame *)(fp->fr_savfp);
+
+               if (fp->fr_savpc == (pc_t)dtrace_invop_callsite) {
+#if !defined(__x86_64__)
+                       /*
+                        * If we pass through the invalid op handler, we will
+                        * use the pointer that it passed to the stack as the
+                        * second argument to dtrace_invop() as the pointer to
+                        * the stack.
+                        */
+                       stack = ((uintptr_t **)&fp[1])[1];
+#else
+                       /*
+                        * In the case of amd64, we will use the pointer to the
+                        * regs structure that was pushed when we took the
+                        * trap.  To get this structure, we must increment
+                        * beyond the frame structure.  If the argument that
+                        * we're seeking is passed on the stack, we'll pull
+                        * the true stack pointer out of the saved registers
+                        * and decrement our argument by the number of
+                        * arguments passed in registers; if the argument
+                        * we're seeking is passed in regsiters, we can just
+                        * load it directly.
+                        */
+                       struct pt_regs *rp = (struct pt_regs *)((uintptr_t)&fp[1]
+                           + sizeof(uintptr_t));       /* TBD: CHECK */
+
+                       if (argno <= inreg) {
+                               stack = (uintptr_t *)&rp->di;
+                       } else {
+                               stack = (uintptr_t *)(rp->sp);
+                               argno -= (inreg + 1);
+                       }
+#endif
+                       goto load;
+               }
+       }
+
+       /*
+        * We know that we did not come through a trap to get into
+        * dtrace_probe() -- the provider simply called dtrace_probe()
+        * directly.  As this is the case, we need to shift the argument
+        * that we're looking for:  the probe ID is the first argument to
+        * dtrace_probe(), so the argument n will actually be found where
+        * one would expect to find argument (n + 1).
+        */
+       argno++;
+
+#if defined(__x86_64__)
+       if (argno <= inreg) {
+               /*
+                * This shouldn't happen.  If the argument is passed in a
+                * register then it should have been, well, passed in a
+                * register...
+                */
+               DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
+               return (0);
+       }
+
+       argno -= (inreg + 1);
+#endif
+       stack = (uintptr_t *)&fp[1];
+
+load:
+       DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+       val = stack[argno];
+       DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
+
+       return (val);
+}
+
+static dtrace_pops_t sdt_pops = {
+       NULL,
+       sdt_provide_module,
+       sdt_enable,
+       sdt_disable,
+       NULL,
+       NULL,
+       sdt_getargdesc,
+       sdt_getarg,
+       NULL,
+       sdt_destroy
+};
+
+#if 0
+/*ARGSUSED*/
+static int
+sdt_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
+{
+       sdt_provider_t *prov;
+
+       if (ddi_create_minor_node(devi, "sdt", S_IFCHR,
+           0, DDI_PSEUDO, NULL) == DDI_FAILURE) {
+               pr_warning("/dev/sdt couldn't create minor node");
+               ddi_remove_minor_node(devi, NULL);
+               return (DDI_FAILURE);
+       }
+
+       ddi_report_dev(devi);
+       ///sdt_devi = devi;
+
+       if (sdt_probetab_size == 0)
+               sdt_probetab_size = SDT_PROBETAB_SIZE;
+
+       sdt_probetab_mask = sdt_probetab_size - 1;
+       sdt_probetab =
+           kzalloc(sdt_probetab_size * sizeof(sdt_probe_t *), GFP_KERNEL);
+       if (!sdt_probetab) {
+               pr_warning("sdt cannot allocate/register provider: %s",
+                       prov->sdtp_name);
+               ddi_remove_minor_node(devi, NULL);
+               return (DDI_FAILURE);
+       }
+
+       dtrace_invop_add(sdt_invop);
+
+       for (prov = sdt_providers; prov->sdtp_name != NULL; prov++) {
+               if (dtrace_register(prov->sdtp_name, prov->sdtp_attr,
+                   DTRACE_PRIV_KERNEL, NULL,
+                   &sdt_pops, prov, &prov->sdtp_id) != 0) {
+                       pr_warning("failed to register sdt provider %s",
+                           prov->sdtp_name);
+               }
+       }
+
+       return (DDI_SUCCESS);
+}
+
+/*ARGSUSED*/
+static int
+sdt_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
+{
+       sdt_provider_t *prov;
+
+       switch (cmd) {
+       case DDI_DETACH:
+               break;
+
+       case DDI_SUSPEND:
+               return (DDI_SUCCESS);
+
+       default:
+               return (DDI_FAILURE);
+       }
+
+       for (prov = sdt_providers; prov->sdtp_name != NULL; prov++) {
+               if (prov->sdtp_id != DTRACE_PROVNONE) {
+                       if (dtrace_unregister(prov->sdtp_id) != 0)
+                               return (DDI_FAILURE);
+
+                       prov->sdtp_id = DTRACE_PROVNONE;
+               }
+       }
+
+       dtrace_invop_remove(sdt_invop);
+       kmem_free(sdt_probetab, sdt_probetab_size * sizeof(sdt_probe_t *));
+
+       return (DDI_SUCCESS);
+}
+
+/*ARGSUSED*/
+static int
+sdt_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
+{
+       int error;
+
+       switch (infocmd) {
+       case DDI_INFO_DEVT2DEVINFO:
+               *result = (void *)sdt_devi;
+               error = DDI_SUCCESS;
+               break;
+       case DDI_INFO_DEVT2INSTANCE:
+               *result = (void *)0;
+               error = DDI_SUCCESS;
+               break;
+       default:
+               error = DDI_FAILURE;
+       }
+       return (error);
+}
+#endif
+
+/*ARGSUSED*/
+static int
+sdt_open(dev_t *devp, int flag, int otyp, cred_t *cred_p)
+{
+       return (0);
+}
+
+#if 0
+int
+sdt_init(void)
+{
+       return 0;
+}
+
+void
+sdt_exit(void)
+{
+}
+#endif
+
+static const dtrace_pattr_t sdt_attr = {
+};
+
+extern int sdt_dev_init(void);
+extern void sdt_dev_exit(void);
+
+DT_PROVIDER_MODULE(sdt, DTRACE_PRIV_KERNEL)
+
+MODULE_AUTHOR("Kris Van Hees (kris.van.hees@oracle.com)");
+MODULE_DESCRIPTION("Statically Defined Tracing");
+MODULE_VERSION("v0.1");
+MODULE_LICENSE("Proprietary");
diff --git a/dtrace/sdt_subr.c b/dtrace/sdt_subr.c
new file mode 100644 (file)
index 0000000..dd7ea5b
--- /dev/null
@@ -0,0 +1,1171 @@
+/*
+ * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
+ */
+
+#include "sdt_impl.h"
+
+static dtrace_pattr_t vtrace_attr = {
+{ DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_ISA },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_UNSTABLE, DTRACE_STABILITY_UNSTABLE, DTRACE_CLASS_ISA },
+};
+
+static dtrace_pattr_t info_attr = {
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
+};
+
+static dtrace_pattr_t fc_attr = {
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
+};
+
+static dtrace_pattr_t fpu_attr = {
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_CPU },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
+};
+
+static dtrace_pattr_t fsinfo_attr = {
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
+};
+
+static dtrace_pattr_t stab_attr = {
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
+};
+
+static dtrace_pattr_t sdt_attr = {
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
+};
+
+static dtrace_pattr_t xpv_attr = {
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_PLATFORM },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_PLATFORM },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_PLATFORM },
+};
+
+static dtrace_pattr_t iscsi_attr = {
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
+};
+
+sdt_provider_t sdt_providers[] = {
+       { "vtrace", "__vtrace_", &vtrace_attr, 0 },
+       { "sysinfo", "__cpu_sysinfo_", &info_attr, 0 },
+       { "vminfo", "__cpu_vminfo_", &info_attr, 0 },
+       { "fpuinfo", "__fpuinfo_", &fpu_attr, 0 },
+       { "sched", "__sched_", &stab_attr, 0 },
+       { "proc", "__proc_", &stab_attr, 0 },
+       { "io", "__io_", &stab_attr, 0 },
+       { "ip", "__ip_", &stab_attr, 0 },
+       { "tcp", "__tcp_", &stab_attr, 0 },
+       { "udp", "__udp_", &stab_attr, 0 },
+       { "mib", "__mib_", &stab_attr, 0 },
+       { "fsinfo", "__fsinfo_", &fsinfo_attr, 0 },
+       { "iscsi", "__iscsi_", &iscsi_attr, 0 },
+       { "nfsv3", "__nfsv3_", &stab_attr, 0 },
+       { "nfsv4", "__nfsv4_", &stab_attr, 0 },
+       { "xpv", "__xpv_", &xpv_attr, 0 },
+       { "fc", "__fc_", &fc_attr, 0 },
+       { "srp", "__srp_", &fc_attr, 0 },
+       { "sysevent", "__sysevent_", &stab_attr, 0 },
+       { "sdt", NULL, &sdt_attr, 0 },
+       { NULL }
+};
+
+sdt_argdesc_t sdt_args[] = {
+       { "sched", "wakeup", 0, 0, "kthread_t *", "lwpsinfo_t *" },
+       { "sched", "wakeup", 1, 0, "kthread_t *", "psinfo_t *" },
+       { "sched", "dequeue", 0, 0, "kthread_t *", "lwpsinfo_t *" },
+       { "sched", "dequeue", 1, 0, "kthread_t *", "psinfo_t *" },
+       { "sched", "dequeue", 2, 1, "disp_t *", "cpuinfo_t *" },
+       { "sched", "enqueue", 0, 0, "kthread_t *", "lwpsinfo_t *" },
+       { "sched", "enqueue", 1, 0, "kthread_t *", "psinfo_t *" },
+       { "sched", "enqueue", 2, 1, "disp_t *", "cpuinfo_t *" },
+       { "sched", "enqueue", 3, 2, "int" },
+       { "sched", "off-cpu", 0, 0, "kthread_t *", "lwpsinfo_t *" },
+       { "sched", "off-cpu", 1, 0, "kthread_t *", "psinfo_t *" },
+       { "sched", "tick", 0, 0, "kthread_t *", "lwpsinfo_t *" },
+       { "sched", "tick", 1, 0, "kthread_t *", "psinfo_t *" },
+       { "sched", "change-pri", 0, 0, "kthread_t *", "lwpsinfo_t *" },
+       { "sched", "change-pri", 1, 0, "kthread_t *", "psinfo_t *" },
+       { "sched", "change-pri", 2, 1, "pri_t" },
+       { "sched", "schedctl-nopreempt", 0, 0, "kthread_t *", "lwpsinfo_t *" },
+       { "sched", "schedctl-nopreempt", 1, 0, "kthread_t *", "psinfo_t *" },
+       { "sched", "schedctl-nopreempt", 2, 1, "int" },
+       { "sched", "schedctl-preempt", 0, 0, "kthread_t *", "lwpsinfo_t *" },
+       { "sched", "schedctl-preempt", 1, 0, "kthread_t *", "psinfo_t *" },
+       { "sched", "schedctl-yield", 0, 0, "int" },
+       { "sched", "surrender", 0, 0, "kthread_t *", "lwpsinfo_t *" },
+       { "sched", "surrender", 1, 0, "kthread_t *", "psinfo_t *" },
+       { "sched", "cpucaps-sleep", 0, 0, "kthread_t *", "lwpsinfo_t *" },
+       { "sched", "cpucaps-sleep", 1, 0, "kthread_t *", "psinfo_t *" },
+       { "sched", "cpucaps-wakeup", 0, 0, "kthread_t *", "lwpsinfo_t *" },
+       { "sched", "cpucaps-wakeup", 1, 0, "kthread_t *", "psinfo_t *" },
+
+       { "proc", "create", 0, 0, "proc_t *", "psinfo_t *" },
+       { "proc", "exec", 0, 0, "string" },
+       { "proc", "exec-failure", 0, 0, "int" },
+       { "proc", "exit", 0, 0, "int" },
+       { "proc", "fault", 0, 0, "int" },
+       { "proc", "fault", 1, 1, "siginfo_t *" },
+       { "proc", "lwp-create", 0, 0, "kthread_t *", "lwpsinfo_t *" },
+       { "proc", "lwp-create", 1, 0, "kthread_t *", "psinfo_t *" },
+       { "proc", "signal-clear", 0, 0, "int" },
+       { "proc", "signal-clear", 1, 1, "siginfo_t *" },
+       { "proc", "signal-discard", 0, 0, "kthread_t *", "lwpsinfo_t *" },
+       { "proc", "signal-discard", 1, 1, "proc_t *", "psinfo_t *" },
+       { "proc", "signal-discard", 2, 2, "int" },
+       { "proc", "signal-handle", 0, 0, "int" },
+       { "proc", "signal-handle", 1, 1, "siginfo_t *" },
+       { "proc", "signal-handle", 2, 2, "void (*)(void)" },
+       { "proc", "signal-send", 0, 0, "kthread_t *", "lwpsinfo_t *" },
+       { "proc", "signal-send", 1, 0, "kthread_t *", "psinfo_t *" },
+       { "proc", "signal-send", 2, 1, "int" },
+
+       { "io", "start", 0, 0, "buf_t *", "bufinfo_t *" },
+       { "io", "start", 1, 0, "buf_t *", "devinfo_t *" },
+       { "io", "start", 2, 0, "buf_t *", "fileinfo_t *" },
+       { "io", "done", 0, 0, "buf_t *", "bufinfo_t *" },
+       { "io", "done", 1, 0, "buf_t *", "devinfo_t *" },
+       { "io", "done", 2, 0, "buf_t *", "fileinfo_t *" },
+       { "io", "wait-start", 0, 0, "buf_t *", "bufinfo_t *" },
+       { "io", "wait-start", 1, 0, "buf_t *", "devinfo_t *" },
+       { "io", "wait-start", 2, 0, "buf_t *", "fileinfo_t *" },
+       { "io", "wait-done", 0, 0, "buf_t *", "bufinfo_t *" },
+       { "io", "wait-done", 1, 0, "buf_t *", "devinfo_t *" },
+       { "io", "wait-done", 2, 0, "buf_t *", "fileinfo_t *" },
+
+       { "mib", NULL, 0, 0, "int" },
+
+       { "fsinfo", NULL, 0, 0, "vnode_t *", "fileinfo_t *" },
+       { "fsinfo", NULL, 1, 1, "int", "int" },
+
+       { "iscsi", "async-send", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "async-send", 1, 1, "iscsi_async_evt_hdr_t *",
+           "iscsiinfo_t *" },
+       { "iscsi", "login-command", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "login-command", 1, 1, "iscsi_login_hdr_t *",
+           "iscsiinfo_t *" },
+       { "iscsi", "login-response", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "login-response", 1, 1, "iscsi_login_rsp_hdr_t *",
+           "iscsiinfo_t *" },
+       { "iscsi", "logout-command", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "logout-command", 1, 1, "iscsi_logout_hdr_t *",
+           "iscsiinfo_t *" },
+       { "iscsi", "logout-response", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "logout-response", 1, 1, "iscsi_logout_rsp_hdr_t *",
+           "iscsiinfo_t *" },
+       { "iscsi", "data-request", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "data-request", 1, 1, "iscsi_rtt_hdr_t *",
+           "iscsiinfo_t *" },
+       { "iscsi", "data-send", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "data-send", 1, 1, "iscsi_data_rsp_hdr_t *",
+           "iscsiinfo_t *" },
+       { "iscsi", "data-receive", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "data-receive", 1, 1, "iscsi_data_hdr_t *",
+           "iscsiinfo_t *" },
+       { "iscsi", "nop-send", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "nop-send", 1, 1, "iscsi_nop_in_hdr_t *", "iscsiinfo_t *" },
+       { "iscsi", "nop-receive", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "nop-receive", 1, 1, "iscsi_nop_out_hdr_t *",
+           "iscsiinfo_t *" },
+       { "iscsi", "scsi-command", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "scsi-command", 1, 1, "iscsi_scsi_cmd_hdr_t *",
+           "iscsiinfo_t *" },
+       { "iscsi", "scsi-command", 2, 2, "scsi_task_t *", "scsicmd_t *" },
+       { "iscsi", "scsi-response", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "scsi-response", 1, 1, "iscsi_scsi_rsp_hdr_t *",
+           "iscsiinfo_t *" },
+       { "iscsi", "task-command", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "task-command", 1, 1, "iscsi_scsi_task_mgt_hdr_t *",
+           "iscsiinfo_t *" },
+       { "iscsi", "task-response", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "task-response", 1, 1, "iscsi_scsi_task_mgt_rsp_hdr_t *",
+           "iscsiinfo_t *" },
+       { "iscsi", "text-command", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "text-command", 1, 1, "iscsi_text_hdr_t *",
+           "iscsiinfo_t *" },
+       { "iscsi", "text-response", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "text-response", 1, 1, "iscsi_text_rsp_hdr_t *",
+           "iscsiinfo_t *" },
+       { "iscsi", "xfer-start", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "xfer-start", 1, 0, "idm_conn_t *", "iscsiinfo_t *" },
+       { "iscsi", "xfer-start", 2, 1, "uintptr_t", "xferinfo_t *" },
+       { "iscsi", "xfer-start", 3, 2, "uint32_t"},
+       { "iscsi", "xfer-start", 4, 3, "uintptr_t"},
+       { "iscsi", "xfer-start", 5, 4, "uint32_t"},
+       { "iscsi", "xfer-start", 6, 5, "uint32_t"},
+       { "iscsi", "xfer-start", 7, 6, "uint32_t"},
+       { "iscsi", "xfer-start", 8, 7, "int"},
+       { "iscsi", "xfer-done", 0, 0, "idm_conn_t *", "conninfo_t *" },
+       { "iscsi", "xfer-done", 1, 0, "idm_conn_t *", "iscsiinfo_t *" },
+       { "iscsi", "xfer-done", 2, 1, "uintptr_t", "xferinfo_t *" },
+       { "iscsi", "xfer-done", 3, 2, "uint32_t"},
+       { "iscsi", "xfer-done", 4, 3, "uintptr_t"},
+       { "iscsi", "xfer-done", 5, 4, "uint32_t"},
+       { "iscsi", "xfer-done", 6, 5, "uint32_t"},
+       { "iscsi", "xfer-done", 7, 6, "uint32_t"},
+       { "iscsi", "xfer-done", 8, 7, "int"},
+
+       { "nfsv3", "op-getattr-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-getattr-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-getattr-start", 2, 3, "GETATTR3args *" },
+       { "nfsv3", "op-getattr-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-getattr-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-getattr-done", 2, 3, "GETATTR3res *" },
+       { "nfsv3", "op-setattr-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-setattr-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-setattr-start", 2, 3, "SETATTR3args *" },
+       { "nfsv3", "op-setattr-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-setattr-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-setattr-done", 2, 3, "SETATTR3res *" },
+       { "nfsv3", "op-lookup-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-lookup-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-lookup-start", 2, 3, "LOOKUP3args *" },
+       { "nfsv3", "op-lookup-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-lookup-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-lookup-done", 2, 3, "LOOKUP3res *" },
+       { "nfsv3", "op-access-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-access-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-access-start", 2, 3, "ACCESS3args *" },
+       { "nfsv3", "op-access-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-access-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-access-done", 2, 3, "ACCESS3res *" },
+       { "nfsv3", "op-commit-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-commit-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-commit-start", 2, 3, "COMMIT3args *" },
+       { "nfsv3", "op-commit-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-commit-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-commit-done", 2, 3, "COMMIT3res *" },
+       { "nfsv3", "op-create-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-create-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-create-start", 2, 3, "CREATE3args *" },
+       { "nfsv3", "op-create-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-create-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-create-done", 2, 3, "CREATE3res *" },
+       { "nfsv3", "op-fsinfo-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-fsinfo-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-fsinfo-start", 2, 3, "FSINFO3args *" },
+       { "nfsv3", "op-fsinfo-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-fsinfo-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-fsinfo-done", 2, 3, "FSINFO3res *" },
+       { "nfsv3", "op-fsstat-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-fsstat-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-fsstat-start", 2, 3, "FSSTAT3args *" },
+       { "nfsv3", "op-fsstat-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-fsstat-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-fsstat-done", 2, 3, "FSSTAT3res *" },
+       { "nfsv3", "op-link-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-link-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-link-start", 2, 3, "LINK3args *" },
+       { "nfsv3", "op-link-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-link-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-link-done", 2, 3, "LINK3res *" },
+       { "nfsv3", "op-mkdir-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-mkdir-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-mkdir-start", 2, 3, "MKDIR3args *" },
+       { "nfsv3", "op-mkdir-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-mkdir-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-mkdir-done", 2, 3, "MKDIR3res *" },
+       { "nfsv3", "op-mknod-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-mknod-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-mknod-start", 2, 3, "MKNOD3args *" },
+       { "nfsv3", "op-mknod-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-mknod-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-mknod-done", 2, 3, "MKNOD3res *" },
+       { "nfsv3", "op-null-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-null-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-null-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-null-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-pathconf-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-pathconf-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-pathconf-start", 2, 3, "PATHCONF3args *" },
+       { "nfsv3", "op-pathconf-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-pathconf-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-pathconf-done", 2, 3, "PATHCONF3res *" },
+       { "nfsv3", "op-read-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-read-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-read-start", 2, 3, "READ3args *" },
+       { "nfsv3", "op-read-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-read-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-read-done", 2, 3, "READ3res *" },
+       { "nfsv3", "op-readdir-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-readdir-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-readdir-start", 2, 3, "READDIR3args *" },
+       { "nfsv3", "op-readdir-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-readdir-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-readdir-done", 2, 3, "READDIR3res *" },
+       { "nfsv3", "op-readdirplus-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-readdirplus-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-readdirplus-start", 2, 3, "READDIRPLUS3args *" },
+       { "nfsv3", "op-readdirplus-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-readdirplus-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-readdirplus-done", 2, 3, "READDIRPLUS3res *" },
+       { "nfsv3", "op-readlink-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-readlink-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-readlink-start", 2, 3, "READLINK3args *" },
+       { "nfsv3", "op-readlink-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-readlink-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-readlink-done", 2, 3, "READLINK3res *" },
+       { "nfsv3", "op-remove-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-remove-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-remove-start", 2, 3, "REMOVE3args *" },
+       { "nfsv3", "op-remove-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-remove-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-remove-done", 2, 3, "REMOVE3res *" },
+       { "nfsv3", "op-rename-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-rename-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-rename-start", 2, 3, "RENAME3args *" },
+       { "nfsv3", "op-rename-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-rename-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-rename-done", 2, 3, "RENAME3res *" },
+       { "nfsv3", "op-rmdir-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-rmdir-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-rmdir-start", 2, 3, "RMDIR3args *" },
+       { "nfsv3", "op-rmdir-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-rmdir-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-rmdir-done", 2, 3, "RMDIR3res *" },
+       { "nfsv3", "op-setattr-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-setattr-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-setattr-start", 2, 3, "SETATTR3args *" },
+       { "nfsv3", "op-setattr-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-setattr-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-setattr-done", 2, 3, "SETATTR3res *" },
+       { "nfsv3", "op-symlink-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-symlink-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-symlink-start", 2, 3, "SYMLINK3args *" },
+       { "nfsv3", "op-symlink-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-symlink-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-symlink-done", 2, 3, "SYMLINK3res *" },
+       { "nfsv3", "op-write-start", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-write-start", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-write-start", 2, 3, "WRITE3args *" },
+       { "nfsv3", "op-write-done", 0, 0, "struct svc_req *",
+           "conninfo_t *" },
+       { "nfsv3", "op-write-done", 1, 1, "nfsv3oparg_t *",
+           "nfsv3opinfo_t *" },
+       { "nfsv3", "op-write-done", 2, 3, "WRITE3res *" },
+
+       { "nfsv4", "null-start", 0, 0, "struct svc_req *", "conninfo_t *" },
+       { "nfsv4", "null-done", 0, 0, "struct svc_req *", "conninfo_t *" },
+       { "nfsv4", "compound-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "compound-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "compound-start", 2, 1, "COMPOUND4args *" },
+       { "nfsv4", "compound-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "compound-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "compound-done", 2, 1, "COMPOUND4res *" },
+       { "nfsv4", "op-access-start", 0, 0, "struct compound_state *",
+           "conninfo_t *"},
+       { "nfsv4", "op-access-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-access-start", 2, 1, "ACCESS4args *" },
+       { "nfsv4", "op-access-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-access-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-access-done", 2, 1, "ACCESS4res *" },
+       { "nfsv4", "op-close-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-close-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-close-start", 2, 1, "CLOSE4args *" },
+       { "nfsv4", "op-close-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-close-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-close-done", 2, 1, "CLOSE4res *" },
+       { "nfsv4", "op-commit-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-commit-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-commit-start", 2, 1, "COMMIT4args *" },
+       { "nfsv4", "op-commit-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-commit-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-commit-done", 2, 1, "COMMIT4res *" },
+       { "nfsv4", "op-create-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-create-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-create-start", 2, 1, "CREATE4args *" },
+       { "nfsv4", "op-create-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-create-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-create-done", 2, 1, "CREATE4res *" },
+       { "nfsv4", "op-delegpurge-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-delegpurge-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-delegpurge-start", 2, 1, "DELEGPURGE4args *" },
+       { "nfsv4", "op-delegpurge-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-delegpurge-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-delegpurge-done", 2, 1, "DELEGPURGE4res *" },
+       { "nfsv4", "op-delegreturn-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-delegreturn-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-delegreturn-start", 2, 1, "DELEGRETURN4args *" },
+       { "nfsv4", "op-delegreturn-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-delegreturn-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-delegreturn-done", 2, 1, "DELEGRETURN4res *" },
+       { "nfsv4", "op-getattr-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-getattr-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-getattr-start", 2, 1, "GETATTR4args *" },
+       { "nfsv4", "op-getattr-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-getattr-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-getattr-done", 2, 1, "GETATTR4res *" },
+       { "nfsv4", "op-getfh-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-getfh-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-getfh-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-getfh-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-getfh-done", 2, 1, "GETFH4res *" },
+       { "nfsv4", "op-link-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-link-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-link-start", 2, 1, "LINK4args *" },
+       { "nfsv4", "op-link-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-link-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-link-done", 2, 1, "LINK4res *" },
+       { "nfsv4", "op-lock-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-lock-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-lock-start", 2, 1, "LOCK4args *" },
+       { "nfsv4", "op-lock-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-lock-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-lock-done", 2, 1, "LOCK4res *" },
+       { "nfsv4", "op-lockt-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-lockt-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-lockt-start", 2, 1, "LOCKT4args *" },
+       { "nfsv4", "op-lockt-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-lockt-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-lockt-done", 2, 1, "LOCKT4res *" },
+       { "nfsv4", "op-locku-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-locku-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-locku-start", 2, 1, "LOCKU4args *" },
+       { "nfsv4", "op-locku-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-locku-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-locku-done", 2, 1, "LOCKU4res *" },
+       { "nfsv4", "op-lookup-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-lookup-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-lookup-start", 2, 1, "LOOKUP4args *" },
+       { "nfsv4", "op-lookup-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-lookup-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-lookup-done", 2, 1, "LOOKUP4res *" },
+       { "nfsv4", "op-lookupp-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-lookupp-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-lookupp-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-lookupp-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-lookupp-done", 2, 1, "LOOKUPP4res *" },
+       { "nfsv4", "op-nverify-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-nverify-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-nverify-start", 2, 1, "NVERIFY4args *" },
+       { "nfsv4", "op-nverify-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-nverify-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-nverify-done", 2, 1, "NVERIFY4res *" },
+       { "nfsv4", "op-open-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-open-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-open-start", 2, 1, "OPEN4args *" },
+       { "nfsv4", "op-open-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-open-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-open-done", 2, 1, "OPEN4res *" },
+       { "nfsv4", "op-open-confirm-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-open-confirm-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-open-confirm-start", 2, 1, "OPEN_CONFIRM4args *" },
+       { "nfsv4", "op-open-confirm-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-open-confirm-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-open-confirm-done", 2, 1, "OPEN_CONFIRM4res *" },
+       { "nfsv4", "op-open-downgrade-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-open-downgrade-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-open-downgrade-start", 2, 1, "OPEN_DOWNGRADE4args *" },
+       { "nfsv4", "op-open-downgrade-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-open-downgrade-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-open-downgrade-done", 2, 1, "OPEN_DOWNGRADE4res *" },
+       { "nfsv4", "op-openattr-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-openattr-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-openattr-start", 2, 1, "OPENATTR4args *" },
+       { "nfsv4", "op-openattr-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-openattr-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-openattr-done", 2, 1, "OPENATTR4res *" },
+       { "nfsv4", "op-putfh-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-putfh-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-putfh-start", 2, 1, "PUTFH4args *" },
+       { "nfsv4", "op-putfh-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-putfh-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-putfh-done", 2, 1, "PUTFH4res *" },
+       { "nfsv4", "op-putpubfh-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-putpubfh-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-putpubfh-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-putpubfh-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-putpubfh-done", 2, 1, "PUTPUBFH4res *" },
+       { "nfsv4", "op-putrootfh-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-putrootfh-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-putrootfh-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-putrootfh-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-putrootfh-done", 2, 1, "PUTROOTFH4res *" },
+       { "nfsv4", "op-read-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-read-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-read-start", 2, 1, "READ4args *" },
+       { "nfsv4", "op-read-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-read-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-read-done", 2, 1, "READ4res *" },
+       { "nfsv4", "op-readdir-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-readdir-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-readdir-start", 2, 1, "READDIR4args *" },
+       { "nfsv4", "op-readdir-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-readdir-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-readdir-done", 2, 1, "READDIR4res *" },
+       { "nfsv4", "op-readlink-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-readlink-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-readlink-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-readlink-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-readlink-done", 2, 1, "READLINK4res *" },
+       { "nfsv4", "op-release-lockowner-start", 0, 0,
+           "struct compound_state *", "conninfo_t *" },
+       { "nfsv4", "op-release-lockowner-start", 1, 0,
+           "struct compound_state *", "nfsv4opinfo_t *" },
+       { "nfsv4", "op-release-lockowner-start", 2, 1,
+           "RELEASE_LOCKOWNER4args *" },
+       { "nfsv4", "op-release-lockowner-done", 0, 0,
+           "struct compound_state *", "conninfo_t *" },
+       { "nfsv4", "op-release-lockowner-done", 1, 0,
+           "struct compound_state *", "nfsv4opinfo_t *" },
+       { "nfsv4", "op-release-lockowner-done", 2, 1,
+           "RELEASE_LOCKOWNER4res *" },
+       { "nfsv4", "op-remove-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-remove-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-remove-start", 2, 1, "REMOVE4args *" },
+       { "nfsv4", "op-remove-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-remove-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-remove-done", 2, 1, "REMOVE4res *" },
+       { "nfsv4", "op-rename-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-rename-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-rename-start", 2, 1, "RENAME4args *" },
+       { "nfsv4", "op-rename-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-rename-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-rename-done", 2, 1, "RENAME4res *" },
+       { "nfsv4", "op-renew-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-renew-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-renew-start", 2, 1, "RENEW4args *" },
+       { "nfsv4", "op-renew-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-renew-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-renew-done", 2, 1, "RENEW4res *" },
+       { "nfsv4", "op-restorefh-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-restorefh-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-restorefh-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-restorefh-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-restorefh-done", 2, 1, "RESTOREFH4res *" },
+       { "nfsv4", "op-savefh-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-savefh-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-savefh-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-savefh-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-savefh-done", 2, 1, "SAVEFH4res *" },
+       { "nfsv4", "op-secinfo-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-secinfo-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-secinfo-start", 2, 1, "SECINFO4args *" },
+       { "nfsv4", "op-secinfo-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-secinfo-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-secinfo-done", 2, 1, "SECINFO4res *" },
+       { "nfsv4", "op-setattr-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-setattr-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-setattr-start", 2, 1, "SETATTR4args *" },
+       { "nfsv4", "op-setattr-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-setattr-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-setattr-done", 2, 1, "SETATTR4res *" },
+       { "nfsv4", "op-setclientid-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-setclientid-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-setclientid-start", 2, 1, "SETCLIENTID4args *" },
+       { "nfsv4", "op-setclientid-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-setclientid-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-setclientid-done", 2, 1, "SETCLIENTID4res *" },
+       { "nfsv4", "op-setclientid-confirm-start", 0, 0,
+           "struct compound_state *", "conninfo_t *" },
+       { "nfsv4", "op-setclientid-confirm-start", 1, 0,
+           "struct compound_state *", "nfsv4opinfo_t *" },
+       { "nfsv4", "op-setclientid-confirm-start", 2, 1,
+           "SETCLIENTID_CONFIRM4args *" },
+       { "nfsv4", "op-setclientid-confirm-done", 0, 0,
+           "struct compound_state *", "conninfo_t *" },
+       { "nfsv4", "op-setclientid-confirm-done", 1, 0,
+           "struct compound_state *", "nfsv4opinfo_t *" },
+       { "nfsv4", "op-setclientid-confirm-done", 2, 1,
+           "SETCLIENTID_CONFIRM4res *" },
+       { "nfsv4", "op-verify-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-verify-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-verify-start", 2, 1, "VERIFY4args *" },
+       { "nfsv4", "op-verify-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-verify-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-verify-done", 2, 1, "VERIFY4res *" },
+       { "nfsv4", "op-write-start", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-write-start", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-write-start", 2, 1, "WRITE4args *" },
+       { "nfsv4", "op-write-done", 0, 0, "struct compound_state *",
+           "conninfo_t *" },
+       { "nfsv4", "op-write-done", 1, 0, "struct compound_state *",
+           "nfsv4opinfo_t *" },
+       { "nfsv4", "op-write-done", 2, 1, "WRITE4res *" },
+       { "nfsv4", "cb-recall-start", 0, 0, "rfs4_client_t *",
+           "conninfo_t *" },
+       { "nfsv4", "cb-recall-start", 1, 1, "rfs4_deleg_state_t *",
+           "nfsv4cbinfo_t *" },
+       { "nfsv4", "cb-recall-start", 2, 2, "CB_RECALL4args *" },
+       { "nfsv4", "cb-recall-done", 0, 0, "rfs4_client_t *",
+           "conninfo_t *" },
+       { "nfsv4", "cb-recall-done", 1, 1, "rfs4_deleg_state_t *",
+           "nfsv4cbinfo_t *" },
+       { "nfsv4", "cb-recall-done", 2, 2, "CB_RECALL4res *" },
+
+       { "ip", "send", 0, 0, "mblk_t *", "pktinfo_t *" },
+       { "ip", "send", 1, 1, "conn_t *", "csinfo_t *" },
+       { "ip", "send", 2, 2, "void_ip_t *", "ipinfo_t *" },
+       { "ip", "send", 3, 3, "__dtrace_ipsr_ill_t *", "ifinfo_t *" },
+       { "ip", "send", 4, 4, "ipha_t *", "ipv4info_t *" },
+       { "ip", "send", 5, 5, "ip6_t *", "ipv6info_t *" },
+       { "ip", "send", 6, 6, "int" }, /* used by __dtrace_ipsr_ill_t */
+       { "ip", "receive", 0, 0, "mblk_t *", "pktinfo_t *" },
+       { "ip", "receive", 1, 1, "conn_t *", "csinfo_t *" },
+       { "ip", "receive", 2, 2, "void_ip_t *", "ipinfo_t *" },
+       { "ip", "receive", 3, 3, "__dtrace_ipsr_ill_t *", "ifinfo_t *" },
+       { "ip", "receive", 4, 4, "ipha_t *", "ipv4info_t *" },
+       { "ip", "receive", 5, 5, "ip6_t *", "ipv6info_t *" },
+       { "ip", "receive", 6, 6, "int" }, /* used by __dtrace_ipsr_ill_t */
+
+       { "tcp", "connect-established", 0, 0, "mblk_t *", "pktinfo_t *" },
+       { "tcp", "connect-established", 1, 1, "ip_xmit_attr_t *",
+           "csinfo_t *" },
+       { "tcp", "connect-established", 2, 2, "void_ip_t *", "ipinfo_t *" },
+       { "tcp", "connect-established", 3, 3, "tcp_t *", "tcpsinfo_t *" },
+       { "tcp", "connect-established", 4, 4, "tcph_t *", "tcpinfo_t *" },
+       { "tcp", "connect-refused", 0, 0, "mblk_t *", "pktinfo_t *" },
+       { "tcp", "connect-refused", 1, 1, "ip_xmit_attr_t *", "csinfo_t *" },
+       { "tcp", "connect-refused", 2, 2, "void_ip_t *", "ipinfo_t *" },
+       { "tcp", "connect-refused", 3, 3, "tcp_t *", "tcpsinfo_t *" },
+       { "tcp", "connect-refused", 4, 4, "tcph_t *", "tcpinfo_t *" },
+       { "tcp", "connect-request", 0, 0, "mblk_t *", "pktinfo_t *" },
+       { "tcp", "connect-request", 1, 1, "ip_xmit_attr_t *", "csinfo_t *" },
+       { "tcp", "connect-request", 2, 2, "void_ip_t *", "ipinfo_t *" },
+       { "tcp", "connect-request", 3, 3, "tcp_t *", "tcpsinfo_t *" },
+       { "tcp", "connect-request", 4, 4, "tcph_t *", "tcpinfo_t *" },
+       { "tcp", "accept-established", 0, 0, "mblk_t *", "pktinfo_t *" },
+       { "tcp", "accept-established", 1, 1, "ip_xmit_attr_t *", "csinfo_t *" },
+       { "tcp", "accept-established", 2, 2, "void_ip_t *", "ipinfo_t *" },
+       { "tcp", "accept-established", 3, 3, "tcp_t *", "tcpsinfo_t *" },
+       { "tcp", "accept-established", 4, 4, "tcph_t *", "tcpinfo_t *" },
+       { "tcp", "accept-refused", 0, 0, "mblk_t *", "pktinfo_t *" },
+       { "tcp", "accept-refused", 1, 1, "ip_xmit_attr_t *", "csinfo_t *" },
+       { "tcp", "accept-refused", 2, 2, "void_ip_t *", "ipinfo_t *" },
+       { "tcp", "accept-refused", 3, 3, "tcp_t *", "tcpsinfo_t *" },
+       { "tcp", "accept-refused", 4, 4, "tcph_t *", "tcpinfo_t *" },
+       { "tcp", "state-change", 0, 0, "void", "void" },
+       { "tcp", "state-change", 1, 1, "ip_xmit_attr_t *", "csinfo_t *" },
+       { "tcp", "state-change", 2, 2, "void", "void" },
+       { "tcp", "state-change", 3, 3, "tcp_t *", "tcpsinfo_t *" },
+       { "tcp", "state-change", 4, 4, "void", "void" },
+       { "tcp", "state-change", 5, 5, "int32_t", "tcplsinfo_t *" },
+       { "tcp", "send", 0, 0, "mblk_t *", "pktinfo_t *" },
+       { "tcp", "send", 1, 1, "ip_xmit_attr_t *", "csinfo_t *" },
+       { "tcp", "send", 2, 2, "__dtrace_tcp_void_ip_t *", "ipinfo_t *" },
+       { "tcp", "send", 3, 3, "tcp_t *", "tcpsinfo_t *" },
+       { "tcp", "send", 4, 4, "__dtrace_tcp_tcph_t *", "tcpinfo_t *" },
+       { "tcp", "receive", 0, 0, "mblk_t *", "pktinfo_t *" },
+       { "tcp", "receive", 1, 1, "ip_xmit_attr_t *", "csinfo_t *" },
+       { "tcp", "receive", 2, 2, "__dtrace_tcp_void_ip_t *", "ipinfo_t *" },
+       { "tcp", "receive", 3, 3, "tcp_t *", "tcpsinfo_t *" },
+       { "tcp", "receive", 4, 4, "__dtrace_tcp_tcph_t *", "tcpinfo_t *" },
+
+       { "udp", "send", 0, 0, "mblk_t *", "pktinfo_t *" },
+       { "udp", "send", 1, 1, "ip_xmit_attr_t *", "csinfo_t *" },
+       { "udp", "send", 2, 2, "void_ip_t *", "ipinfo_t *" },
+       { "udp", "send", 3, 3, "udp_t *", "udpsinfo_t *" },
+       { "udp", "send", 4, 4, "udpha_t *", "udpinfo_t *" },
+       { "udp", "receive", 0, 0, "mblk_t *", "pktinfo_t *" },
+       { "udp", "receive", 1, 1, "ip_xmit_attr_t *", "csinfo_t *" },
+       { "udp", "receive", 2, 2, "void_ip_t *", "ipinfo_t *" },
+       { "udp", "receive", 3, 3, "udp_t *", "udpsinfo_t *" },
+       { "udp", "receive", 4, 4, "udpha_t *", "udpinfo_t *" },
+
+       { "sysevent", "post", 0, 0, "evch_bind_t *", "syseventchaninfo_t *" },
+       { "sysevent", "post", 1, 1, "sysevent_impl_t *", "syseventinfo_t *" },
+
+       { "xpv", "add-to-physmap-end", 0, 0, "int" },
+       { "xpv", "add-to-physmap-start", 0, 0, "domid_t" },
+       { "xpv", "add-to-physmap-start", 1, 1, "uint_t" },
+       { "xpv", "add-to-physmap-start", 2, 2, "ulong_t" },
+       { "xpv", "add-to-physmap-start", 3, 3, "ulong_t" },
+       { "xpv", "decrease-reservation-end", 0, 0, "int" },
+       { "xpv", "decrease-reservation-start", 0, 0, "domid_t" },
+       { "xpv", "decrease-reservation-start", 1, 1, "ulong_t" },
+       { "xpv", "decrease-reservation-start", 2, 2, "uint_t" },
+       { "xpv", "decrease-reservation-start", 3, 3, "ulong_t *" },
+       { "xpv", "dom-create-start", 0, 0, "xen_domctl_t *" },
+       { "xpv", "dom-destroy-start", 0, 0, "domid_t" },
+       { "xpv", "dom-pause-start", 0, 0, "domid_t" },
+       { "xpv", "dom-unpause-start", 0, 0, "domid_t" },
+       { "xpv", "dom-create-end", 0, 0, "int" },
+       { "xpv", "dom-destroy-end", 0, 0, "int" },
+       { "xpv", "dom-pause-end", 0, 0, "int" },
+       { "xpv", "dom-unpause-end", 0, 0, "int" },
+       { "xpv", "evtchn-op-end", 0, 0, "int" },
+       { "xpv", "evtchn-op-start", 0, 0, "int" },
+       { "xpv", "evtchn-op-start", 1, 1, "void *" },
+       { "xpv", "increase-reservation-end", 0, 0, "int" },
+       { "xpv", "increase-reservation-start", 0, 0, "domid_t" },
+       { "xpv", "increase-reservation-start", 1, 1, "ulong_t" },
+       { "xpv", "increase-reservation-start", 2, 2, "uint_t" },
+       { "xpv", "increase-reservation-start", 3, 3, "ulong_t *" },
+       { "xpv", "mmap-end", 0, 0, "int" },
+       { "xpv", "mmap-entry", 0, 0, "ulong_t" },
+       { "xpv", "mmap-entry", 1, 1, "ulong_t" },
+       { "xpv", "mmap-entry", 2, 2, "ulong_t" },
+       { "xpv", "mmap-start", 0, 0, "domid_t" },
+       { "xpv", "mmap-start", 1, 1, "int" },
+       { "xpv", "mmap-start", 2, 2, "privcmd_mmap_entry_t *" },
+       { "xpv", "mmapbatch-end", 0, 0, "int" },
+       { "xpv", "mmapbatch-end", 1, 1, "struct seg *" },
+       { "xpv", "mmapbatch-end", 2, 2, "caddr_t" },
+       { "xpv", "mmapbatch-start", 0, 0, "domid_t" },
+       { "xpv", "mmapbatch-start", 1, 1, "int" },
+       { "xpv", "mmapbatch-start", 2, 2, "caddr_t" },
+       { "xpv", "mmu-ext-op-end", 0, 0, "int" },
+       { "xpv", "mmu-ext-op-start", 0, 0, "int" },
+       { "xpv", "mmu-ext-op-start", 1, 1, "struct mmuext_op *" },
+       { "xpv", "mmu-update-start", 0, 0, "int" },
+       { "xpv", "mmu-update-start", 1, 1, "int" },
+       { "xpv", "mmu-update-start", 2, 2, "mmu_update_t *" },
+       { "xpv", "mmu-update-end", 0, 0, "int" },
+       { "xpv", "populate-physmap-end", 0, 0, "int" },
+       { "xpv", "populate-physmap-start", 0, 0, "domid_t" },
+       { "xpv", "populate-physmap-start", 1, 1, "ulong_t" },
+       { "xpv", "populate-physmap-start", 2, 2, "ulong_t *" },
+       { "xpv", "set-memory-map-end", 0, 0, "int" },
+       { "xpv", "set-memory-map-start", 0, 0, "domid_t" },
+       { "xpv", "set-memory-map-start", 1, 1, "int" },
+       { "xpv", "set-memory-map-start", 2, 2, "struct xen_memory_map *" },
+       { "xpv", "setvcpucontext-end", 0, 0, "int" },
+       { "xpv", "setvcpucontext-start", 0, 0, "domid_t" },
+       { "xpv", "setvcpucontext-start", 1, 1, "vcpu_guest_context_t *" },
+
+       { "srp", "service-up", 0, 0, "srpt_session_t *", "conninfo_t *" },
+       { "srp", "service-up", 1, 0, "srpt_session_t *", "srp_portinfo_t *" },
+       { "srp", "service-down", 0, 0, "srpt_session_t *", "conninfo_t *" },
+       { "srp", "service-down", 1, 0, "srpt_session_t *",
+           "srp_portinfo_t *" },
+       { "srp", "login-command", 0, 0, "srpt_session_t *", "conninfo_t *" },
+       { "srp", "login-command", 1, 0, "srpt_session_t *",
+           "srp_portinfo_t *" },
+       { "srp", "login-command", 2, 1, "srp_login_req_t *",
+           "srp_logininfo_t *" },
+       { "srp", "login-response", 0, 0, "srpt_session_t *", "conninfo_t *" },
+       { "srp", "login-response", 1, 0, "srpt_session_t *",
+           "srp_portinfo_t *" },
+       { "srp", "login-response", 2, 1, "srp_login_rsp_t *",
+           "srp_logininfo_t *" },
+       { "srp", "login-response", 3, 2, "srp_login_rej_t *" },
+       { "srp", "logout-command", 0, 0, "srpt_channel_t *", "conninfo_t *" },
+       { "srp", "logout-command", 1, 0, "srpt_channel_t *",
+           "srp_portinfo_t *" },
+       { "srp", "task-command", 0, 0, "srpt_channel_t *", "conninfo_t *" },
+       { "srp", "task-command", 1, 0, "srpt_channel_t *",
+           "srp_portinfo_t *" },
+       { "srp", "task-command", 2, 1, "srp_cmd_req_t *", "srp_taskinfo_t *" },
+       { "srp", "task-response", 0, 0, "srpt_channel_t *", "conninfo_t *" },
+       { "srp", "task-response", 1, 0, "srpt_channel_t *",
+           "srp_portinfo_t *" },
+       { "srp", "task-response", 2, 1, "srp_rsp_t *", "srp_taskinfo_t *" },
+       { "srp", "task-response", 3, 2, "scsi_task_t *" },
+       { "srp", "task-response", 4, 3, "int8_t" },
+       { "srp", "scsi-command", 0, 0, "srpt_channel_t *", "conninfo_t *" },
+       { "srp", "scsi-command", 1, 0, "srpt_channel_t *",
+           "srp_portinfo_t *" },
+       { "srp", "scsi-command", 2, 1, "scsi_task_t *", "scsicmd_t *" },
+       { "srp", "scsi-command", 3, 2, "srp_cmd_req_t *", "srp_taskinfo_t *" },
+       { "srp", "scsi-response", 0, 0, "srpt_channel_t *", "conninfo_t *" },
+       { "srp", "scsi-response", 1, 0, "srpt_channel_t *",
+           "srp_portinfo_t *" },
+       { "srp", "scsi-response", 2, 1, "srp_rsp_t *", "srp_taskinfo_t *" },
+       { "srp", "scsi-response", 3, 2, "scsi_task_t *" },
+       { "srp", "scsi-response", 4, 3, "int8_t" },
+       { "srp", "xfer-start", 0, 0, "srpt_channel_t *", "conninfo_t *" },
+       { "srp", "xfer-start", 1, 0, "srpt_channel_t *",
+           "srp_portinfo_t *" },
+       { "srp", "xfer-start", 2, 1, "ibt_wr_ds_t *", "xferinfo_t *" },
+       { "srp", "xfer-start", 3, 2, "srpt_iu_t *", "srp_taskinfo_t *" },
+       { "srp", "xfer-start", 4, 3, "ibt_send_wr_t *"},
+       { "srp", "xfer-start", 5, 4, "uint32_t" },
+       { "srp", "xfer-start", 6, 5, "uint32_t" },
+       { "srp", "xfer-start", 7, 6, "uint32_t" },
+       { "srp", "xfer-start", 8, 7, "uint32_t" },
+       { "srp", "xfer-done", 0, 0, "srpt_channel_t *", "conninfo_t *" },
+       { "srp", "xfer-done", 1, 0, "srpt_channel_t *",
+           "srp_portinfo_t *" },
+       { "srp", "xfer-done", 2, 1, "ibt_wr_ds_t *", "xferinfo_t *" },
+       { "srp", "xfer-done", 3, 2, "srpt_iu_t *", "srp_taskinfo_t *" },
+       { "srp", "xfer-done", 4, 3, "ibt_send_wr_t *"},
+       { "srp", "xfer-done", 5, 4, "uint32_t" },
+       { "srp", "xfer-done", 6, 5, "uint32_t" },
+       { "srp", "xfer-done", 7, 6, "uint32_t" },
+       { "srp", "xfer-done", 8, 7, "uint32_t" },
+
+       { "fc", "link-up",   0, 0, "fct_i_local_port_t *", "conninfo_t *" },
+       { "fc", "link-down", 0, 0, "fct_i_local_port_t *", "conninfo_t *" },
+       { "fc", "fabric-login-start", 0, 0, "fct_i_local_port_t *",
+           "conninfo_t *" },
+       { "fc", "fabric-login-start", 1, 0, "fct_i_local_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "fabric-login-end", 0, 0, "fct_i_local_port_t *",
+           "conninfo_t *" },
+       { "fc", "fabric-login-end", 1, 0, "fct_i_local_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "rport-login-start", 0, 0, "fct_cmd_t *",
+           "conninfo_t *" },
+       { "fc", "rport-login-start", 1, 1, "fct_local_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "rport-login-start", 2, 2, "fct_i_remote_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "rport-login-start", 3, 3, "int", "int" },
+       { "fc", "rport-login-end", 0, 0, "fct_cmd_t *",
+           "conninfo_t *" },
+       { "fc", "rport-login-end", 1, 1, "fct_local_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "rport-login-end", 2, 2, "fct_i_remote_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "rport-login-end", 3, 3, "int", "int" },
+       { "fc", "rport-login-end", 4, 4, "int", "int" },
+       { "fc", "rport-logout-start", 0, 0, "fct_cmd_t *",
+           "conninfo_t *" },
+       { "fc", "rport-logout-start", 1, 1, "fct_local_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "rport-logout-start", 2, 2, "fct_i_remote_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "rport-logout-start", 3, 3, "int", "int" },
+       { "fc", "rport-logout-end", 0, 0, "fct_cmd_t *",
+           "conninfo_t *" },
+       { "fc", "rport-logout-end", 1, 1, "fct_local_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "rport-logout-end", 2, 2, "fct_i_remote_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "rport-logout-end", 3, 3, "int", "int" },
+       { "fc", "scsi-command", 0, 0, "fct_cmd_t *",
+           "conninfo_t *" },
+       { "fc", "scsi-command", 1, 1, "fct_i_local_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "scsi-command", 2, 2, "scsi_task_t *",
+           "scsicmd_t *" },
+       { "fc", "scsi-command", 3, 3, "fct_i_remote_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "scsi-response", 0, 0, "fct_cmd_t *",
+           "conninfo_t *" },
+       { "fc", "scsi-response", 1, 1, "fct_i_local_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "scsi-response", 2, 2, "scsi_task_t *",
+           "scsicmd_t *" },
+       { "fc", "scsi-response", 3, 3, "fct_i_remote_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "xfer-start", 0, 0, "fct_cmd_t *",
+           "conninfo_t *" },
+       { "fc", "xfer-start", 1, 1, "fct_i_local_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "xfer-start", 2, 2, "scsi_task_t *",
+           "scsicmd_t *" },
+       { "fc", "xfer-start", 3, 3, "fct_i_remote_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "xfer-start", 4, 4, "stmf_data_buf_t *",
+           "fc_xferinfo_t *" },
+       { "fc", "xfer-done", 0, 0, "fct_cmd_t *",
+           "conninfo_t *" },
+       { "fc", "xfer-done", 1, 1, "fct_i_local_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "xfer-done", 2, 2, "scsi_task_t *",
+           "scsicmd_t *" },
+       { "fc", "xfer-done", 3, 3, "fct_i_remote_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "xfer-done", 4, 4, "stmf_data_buf_t *",
+           "fc_xferinfo_t *" },
+       { "fc", "rscn-receive", 0, 0, "fct_i_local_port_t *",
+           "conninfo_t *" },
+       { "fc", "rscn-receive", 1, 1, "int", "int"},
+       { "fc", "abts-receive", 0, 0, "fct_cmd_t *",
+           "conninfo_t *" },
+       { "fc", "abts-receive", 1, 1, "fct_i_local_port_t *",
+           "fc_port_info_t *" },
+       { "fc", "abts-receive", 2, 2, "fct_i_remote_port_t *",
+           "fc_port_info_t *" },
+
+
+       { NULL }
+};
+
+/*ARGSUSED*/
+void
+sdt_getargdesc(void *arg, dtrace_id_t id, void *parg, dtrace_argdesc_t *desc)
+{
+       sdt_probe_t *sdp = parg;
+       int i;
+
+       desc->dtargd_native[0] = '\0';
+       desc->dtargd_xlate[0] = '\0';
+
+       for (i = 0; sdt_args[i].sda_provider != NULL; i++) {
+               sdt_argdesc_t *a = &sdt_args[i];
+
+               if (strcmp(sdp->sdp_provider->sdtp_name, a->sda_provider) != 0)
+                       continue;
+
+               if (a->sda_name != NULL &&
+                   strcmp(sdp->sdp_name, a->sda_name) != 0)
+                       continue;
+
+               if (desc->dtargd_ndx != a->sda_ndx)
+                       continue;
+
+               if (a->sda_native != NULL)
+                       (void) strcpy(desc->dtargd_native, a->sda_native);
+
+               if (a->sda_xlate != NULL)
+                       (void) strcpy(desc->dtargd_xlate, a->sda_xlate);
+
+               desc->dtargd_mapping = a->sda_mapping;
+               return;
+       }
+
+       desc->dtargd_ndx = DTRACE_ARGNONE;
+}
diff --git a/dtrace/systrace_dev.c b/dtrace/systrace_dev.c
new file mode 100644 (file)
index 0000000..964cb02
--- /dev/null
@@ -0,0 +1,211 @@
+/*
+ * FILE:       systrace_dev.c
+ * DESCRIPTION:        System Call Tracing: device file handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+#if 0
+#include <trace/syscall.h>
+#endif
+#include <asm/unistd.h>
+
+#include "dtrace.h"
+#include "dtrace_dev.h"
+#include "systrace.h"
+
+#define SYSTRACE_ARTIFICIAL_FRAMES     1
+
+#define SYSTRACE_SHIFT                 16
+#define SYSTRACE_ENTRY(id)             ((1 << SYSTRACE_SHIFT) | (id))
+#define SYSTRACE_RETURN(id)            (id)
+#define SYSTRACE_SYSNUM(x)             ((int)(x) & ((1 << SYSTRACE_SHIFT) - 1))
+#define SYSTRACE_ISENTRY(x)            ((int)(x) >> SYSTRACE_SHIFT)
+
+#if ((1 << SYSTRACE_SHIFT) <= NR_syscalls)
+# error 1 << SYSTRACE_SHIFT must exceed number of system calls
+#endif
+
+static systrace_info_t *systrace_info = NULL;
+
+void systrace_provide(void *arg, const dtrace_probedesc_t *desc)
+{
+       int     i;
+
+       ASSERT(systrace_info != NULL);
+
+       if (desc != NULL)
+               return;
+
+       for (i = 0; i < NR_syscalls; i++) {
+#if 0
+               struct syscall_metadata *sm = syscall_nr_to_meta(i);
+               const char              *nm;
+
+               if (sm == NULL)
+                       continue;
+#else
+               const char              *nm = systrace_info->sysent[i].name;
+               int                     sz;
+#endif
+printk(KERN_INFO "systrace_provide: [%d] = %s\n", i, nm);
+               if (nm == NULL)
+                       continue;
+
+               if (systrace_info->sysent[i].stsy_underlying == NULL)
+                       continue;
+
+#if 0
+               nm = sm->name;
+#endif
+               sz = strlen(nm);
+               if (sz > 4 && memcmp(nm, "sys_", 4) == 0)
+                       nm += 4;
+               else if (sz > 5 && memcmp(nm, "stub_", 5) == 0)
+                       nm += 5;
+
+               if (dtrace_probe_lookup(syscall_id, NULL, nm, "entry") != 0)
+                       continue;
+
+               dtrace_probe_create(syscall_id, NULL, nm, "entry",
+                                   SYSTRACE_ARTIFICIAL_FRAMES,
+                                   (void *)((uintptr_t)SYSTRACE_ENTRY(i)));
+               dtrace_probe_create(syscall_id, NULL, nm, "return",
+                                   SYSTRACE_ARTIFICIAL_FRAMES,
+                                   (void *)((uintptr_t)SYSTRACE_RETURN(i)));
+
+               systrace_info->sysent[i].stsy_entry = DTRACE_IDNONE;
+               systrace_info->sysent[i].stsy_return = DTRACE_IDNONE;
+       }
+}
+
+int systrace_enable(void *arg, dtrace_id_t id, void *parg)
+{
+       int     sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
+       int     enabled =
+               systrace_info->sysent[sysnum].stsy_entry != DTRACE_IDNONE ||
+               systrace_info->sysent[sysnum].stsy_return != DTRACE_IDNONE;
+
+#if 0
+       if (SYSTRACE_ISENTRY((uintptr_t)parg))
+               systrace_info->sysent[sysnum].stsy_entry = id;
+       else
+               systrace_info->sysent[sysnum].stsy_return = id;
+
+       if (enabled) {
+               ASSERT((void *)*(systrace_info->sysent[sysnum].stsy_tblent) ==
+                      (void *)systrace_info->syscall);
+
+               return 0;
+       }
+
+       (void)cmpxchg(systrace_info->sysent[sysnum].stsy_tblent,
+                     systrace_info->sysent[sysnum].stsy_underlying,
+                     systrace_info->syscall);
+#else
+       if (!enabled) {
+               if (cmpxchg(systrace_info->sysent[sysnum].stsy_tblent,
+                           systrace_info->sysent[sysnum].stsy_underlying,
+                           systrace_info->syscall) !=
+                   systrace_info->sysent[sysnum].stsy_underlying)
+                       return 0;
+       } else
+               ASSERT((void *)*(systrace_info->sysent[sysnum].stsy_tblent) ==
+                      (void *)systrace_info->syscall);
+
+       if (SYSTRACE_ISENTRY((uintptr_t)parg))
+               systrace_info->sysent[sysnum].stsy_entry = id;
+       else
+               systrace_info->sysent[sysnum].stsy_return = id;
+#endif
+
+       return 0;
+}
+
+void systrace_disable(void *arg, dtrace_id_t id, void *parg)
+{
+       int     sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
+       int     enabled =
+               systrace_info->sysent[sysnum].stsy_entry != DTRACE_IDNONE ||
+               systrace_info->sysent[sysnum].stsy_return != DTRACE_IDNONE;
+
+       if (enabled)
+               (void)cmpxchg(systrace_info->sysent[sysnum].stsy_tblent,
+                             systrace_info->syscall,
+                             systrace_info->sysent[sysnum].stsy_underlying);
+
+       if (SYSTRACE_ISENTRY((uintptr_t)parg))
+               systrace_info->sysent[sysnum].stsy_entry = DTRACE_IDNONE;
+       else
+               systrace_info->sysent[sysnum].stsy_return = DTRACE_IDNONE;
+}
+
+void systrace_destroy(void *arg, dtrace_id_t id, void *parg)
+{
+       int     sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
+
+       /*
+        * Nothing to be done here - just ensure our probe has been disabled.
+        */
+       if (SYSTRACE_ISENTRY((uintptr_t)parg))
+               ASSERT(systrace_info->sysent[sysnum].stsy_entry ==
+                      DTRACE_IDNONE);
+       else
+               ASSERT(systrace_info->sysent[sysnum].stsy_return ==
+                      DTRACE_IDNONE);
+}
+
+static long systrace_ioctl(struct file *file,
+                        unsigned int cmd, unsigned long arg)
+{
+       return -EAGAIN;
+}
+
+static int systrace_open(struct inode *inode, struct file *file)
+{
+       return -EAGAIN;
+}
+
+static int systrace_close(struct inode *inode, struct file *file)
+{
+       return 0;
+}
+
+static const struct file_operations systrace_fops = {
+       .owner  = THIS_MODULE,
+        .unlocked_ioctl = systrace_ioctl,
+        .open   = systrace_open,
+        .release = systrace_close,
+};
+
+static struct miscdevice systrace_dev = {
+       .minor = DT_DEV_SYSTRACE_MINOR,
+       .name = "systrace",
+       .nodename = "dtrace/provider/systrace",
+       .fops = &systrace_fops,
+};
+
+int syscall_dev_init(void)
+{
+       int     ret = 0;
+
+       systrace_info = dtrace_syscalls_init();
+
+       ret = misc_register(&systrace_dev);
+       if (ret)
+               pr_err("%s: Can't register misc device %d\n",
+                      systrace_dev.name, systrace_dev.minor);
+
+       *(systrace_info->probep) = (dtrace_systrace_probe_t)dtrace_probe;
+
+       return ret;
+}
+
+void syscall_dev_exit(void)
+{
+       *(systrace_info->probep) = systrace_info->stub;
+
+       misc_deregister(&systrace_dev);
+}
diff --git a/dtrace/systrace_mod.c b/dtrace/systrace_mod.c
new file mode 100644 (file)
index 0000000..6f75b18
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * FILE:       systrace_mod.c
+ * DESCRIPTION:        System Call Tracing: module handling
+ *
+ * Copyright (C) 2010 Oracle Corporation
+ */
+
+#include <linux/module.h>
+
+#include "dtrace.h"
+#include "dtrace_dev.h"
+#include "systrace.h"
+
+MODULE_AUTHOR("Kris Van Hees (kris.van.hees@oracle.com)");
+MODULE_DESCRIPTION("System Call Tracing");
+MODULE_VERSION("v0.1");
+MODULE_LICENSE("Proprietary");
+
+static const dtrace_pattr_t syscall_attr = {
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
+{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
+{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
+};
+
+static dtrace_pops_t syscall_pops = {
+       systrace_provide,
+       NULL,
+       systrace_enable,
+       systrace_disable,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       systrace_destroy
+};
+
+DT_PROVIDER_MODULE(syscall, DTRACE_PRIV_USER);