]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/dev/dtrace/systrace.c
xnu-3789.31.2.tar.gz
[apple/xnu.git] / bsd / dev / dtrace / systrace.c
index cdd5a304063d69d4a0b1863f38e78e96f8dd3d8f..00ee62d29bfe25acf41bf52d6279b13db7bc55d3 100644 (file)
 
 /* #pragma ident       "@(#)systrace.c 1.6     06/09/19 SMI" */
 
-#if !defined(__APPLE__)
-#include <sys/dtrace.h>
-#include <sys/systrace.h>
-#include <sys/stat.h>
-#include <sys/systm.h>
-#include <sys/conf.h>
-#include <sys/ddi.h>
-#include <sys/sunddi.h>
-#include <sys/atomic.h>
-#define        SYSTRACE_ARTIFICIAL_FRAMES      1
-#else
-
 #ifdef KERNEL
 #ifndef _KERNEL
 #define _KERNEL /* Solaris vs. Darwin */
@@ -61,6 +49,7 @@
 #include <sys/ioctl.h>
 #include <sys/conf.h>
 #include <sys/fcntl.h>
+#include <sys/syscall.h>
 #include <miscfs/devfs/devfs.h>
 
 #include <sys/dtrace.h>
@@ -151,7 +140,7 @@ dtrace_systrace_syscall(struct proc *pp, void *uap, int *rv)
 #endif
 
        // Bounds "check" the value of code a la unix_syscall
-       sy = (code >= NUM_SYSENT) ? &systrace_sysent[63] : &systrace_sysent[code];
+       sy = (code >= nsysent) ? &systrace_sysent[SYS_invalid] : &systrace_sysent[code];
 
        if ((id = sy->stsy_entry) != DTRACE_IDNONE) {
                uthread_t uthread = (uthread_t)get_bsdthread_info(current_thread());            
@@ -169,6 +158,7 @@ dtrace_systrace_syscall(struct proc *pp, void *uap, int *rv)
 
 #if 0 /* XXX */
        /*
+        * APPLE NOTE: Not implemented.
         * We want to explicitly allow DTrace consumers to stop a process
         * before it actually executes the meat of the syscall.
         */
@@ -265,7 +255,7 @@ dtrace_systrace_syscall_return(unsigned short code, int rval, int *rv)
        dtrace_id_t id;
 
        // Bounds "check" the value of code a la unix_syscall_return
-       sy = (code >= NUM_SYSENT) ? &systrace_sysent[63] : &systrace_sysent[code];
+       sy = (code >= nsysent) ? &systrace_sysent[SYS_invalid] : &systrace_sysent[code];
 
        if ((id = sy->stsy_return) != DTRACE_IDNONE) {
                uint64_t munged_rv0, munged_rv1;
@@ -323,7 +313,6 @@ dtrace_systrace_syscall_return(unsigned short code, int rval, int *rv)
                (*systrace_probe)(id, munged_rv0, munged_rv0, munged_rv1, (uint64_t)rval, 0);
        }
 }
-#endif /* __APPLE__ */
 
 #define        SYSTRACE_SHIFT                  16
 #define        SYSTRACE_ISENTRY(x)             ((int)(x) >> SYSTRACE_SHIFT)
@@ -338,45 +327,19 @@ dtrace_systrace_syscall_return(unsigned short code, int rval, int *rv)
 static dev_info_t *systrace_devi;
 static dtrace_provider_id_t systrace_id;
 
-#if !defined (__APPLE__)
-static void
-systrace_init(struct sysent *actual, systrace_sysent_t **interposed)
-{
-       systrace_sysent_t *sysent = *interposed;
-       int i;
-
-       if (sysent == NULL) {
-               *interposed = sysent = kmem_zalloc(sizeof (systrace_sysent_t) *
-                   NSYSCALL, KM_SLEEP);
-       }
-
-       for (i = 0; i < NSYSCALL; i++) {
-               struct sysent *a = &actual[i];
-               systrace_sysent_t *s = &sysent[i];
-
-               if (LOADABLE_SYSCALL(a) && !LOADED_SYSCALL(a))
-                       continue;
-
-               if (a->sy_callc == dtrace_systrace_syscall)
-                       continue;
-
-#ifdef _SYSCALL32_IMPL
-               if (a->sy_callc == dtrace_systrace_syscall32)
-                       continue;
-#endif
+/*
+ * APPLE NOTE: Avoid name clash with Darwin automagic conf symbol.
+ * See balanced undef below.
+ */
+#define systrace_init _systrace_init
 
-               s->stsy_underlying = a->sy_callc;
-       }
-}
-#else
-#define systrace_init _systrace_init /* Avoid name clash with Darwin automagic conf symbol */
 static void
 systrace_init(struct sysent *actual, systrace_sysent_t **interposed)
 {
 
        systrace_sysent_t *ssysent = *interposed;  /* Avoid sysent shadow warning
                                                           from bsd/sys/sysent.h */
-       int i;
+       unsigned int i;
 
        if (ssysent == NULL) {
                *interposed = ssysent = kmem_zalloc(sizeof (systrace_sysent_t) *
@@ -404,14 +367,13 @@ systrace_init(struct sysent *actual, systrace_sysent_t **interposed)
        lck_mtx_init(&dtrace_systrace_lock, dtrace_lck_grp, dtrace_lck_attr);
 }
 
-#endif /* __APPLE__ */
 
 /*ARGSUSED*/
 static void
 systrace_provide(void *arg, const dtrace_probedesc_t *desc)
 {
 #pragma unused(arg) /* __APPLE__ */
-       int i;
+       unsigned int i;
 
        if (desc != NULL)
                return;
@@ -444,9 +406,7 @@ systrace_provide(void *arg, const dtrace_probedesc_t *desc)
 #endif
        }
 }
-#if defined(__APPLE__)
 #undef systrace_init
-#endif
 
 /*ARGSUSED*/
 static void
@@ -584,19 +544,6 @@ systrace_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
                return (DDI_FAILURE);
        }
 
-#if !defined(__APPLE__)        
-       systrace_probe = (void (*)())dtrace_probe;
-       membar_enter();
-
-       if (ddi_create_minor_node(devi, "systrace", S_IFCHR, 0,
-           DDI_PSEUDO, NULL) == DDI_FAILURE ||
-           dtrace_register("syscall", &systrace_attr, DTRACE_PRIV_USER, NULL,
-           &systrace_pops, NULL, &systrace_id) != 0) {
-               systrace_probe = systrace_stub;
-               ddi_remove_minor_node(devi, NULL);
-               return (DDI_FAILURE);
-       }
-#else
        systrace_probe = (void(*))&dtrace_probe;
        membar_enter();
 
@@ -608,7 +555,6 @@ systrace_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
                ddi_remove_minor_node(devi, NULL);
                return (DDI_FAILURE);
        }
-#endif /* __APPLE__ */
 
        ddi_report_dev(devi);
        systrace_devi = devi;
@@ -616,6 +562,10 @@ systrace_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
        return (DDI_SUCCESS);
 }
 
+
+/*
+ * APPLE NOTE:  systrace_detach not implemented
+ */
 #if !defined(__APPLE__)
 static int
 systrace_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
@@ -636,109 +586,18 @@ systrace_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
        systrace_probe = systrace_stub;
        return (DDI_SUCCESS);
 }
+#endif /* __APPLE__ */
 
-/*ARGSUSED*/
-static int
-systrace_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
-{
-       int error;
-
-       switch (infocmd) {
-       case DDI_INFO_DEVT2DEVINFO:
-               *result = (void *)systrace_devi;
-               error = DDI_SUCCESS;
-               break;
-       case DDI_INFO_DEVT2INSTANCE:
-               *result = (void *)0;
-               error = DDI_SUCCESS;
-               break;
-       default:
-               error = DDI_FAILURE;
-       }
-       return (error);
-}
-
-/*ARGSUSED*/
-static int
-systrace_open(dev_t *devp, int flag, int otyp, cred_t *cred_p)
-{
-       return (0);
-}
-
-static struct cb_ops systrace_cb_ops = {
-       systrace_open,          /* open */
-       nodev,                  /* close */
-       nulldev,                /* strategy */
-       nulldev,                /* print */
-       nodev,                  /* dump */
-       nodev,                  /* read */
-       nodev,                  /* write */
-       nodev,                  /* ioctl */
-       nodev,                  /* devmap */
-       nodev,                  /* mmap */
-       nodev,                  /* segmap */
-       nochpoll,               /* poll */
-       ddi_prop_op,            /* cb_prop_op */
-       0,                      /* streamtab  */
-       D_NEW | D_MP            /* Driver compatibility flag */
-};
-
-static struct dev_ops systrace_ops = {
-       DEVO_REV,               /* devo_rev, */
-       0,                      /* refcnt  */
-       systrace_info,          /* get_dev_info */
-       nulldev,                /* identify */
-       nulldev,                /* probe */
-       systrace_attach,        /* attach */
-       systrace_detach,        /* detach */
-       nodev,                  /* reset */
-       &systrace_cb_ops,       /* driver operations */
-       NULL,                   /* bus operations */
-       nodev                   /* dev power */
-};
-
-/*
- * Module linkage information for the kernel.
- */
-static struct modldrv modldrv = {
-       &mod_driverops,         /* module type (this is a pseudo driver) */
-       "System Call Tracing",  /* name of module */
-       &systrace_ops,          /* driver ops */
-};
-
-static struct modlinkage modlinkage = {
-       MODREV_1,
-       (void *)&modldrv,
-       NULL
-};
-
-int
-_init(void)
-{
-       return (mod_install(&modlinkage));
-}
-
-int
-_info(struct modinfo *modinfop)
-{
-       return (mod_info(&modlinkage, modinfop));
-}
 
-int
-_fini(void)
-{
-       return (mod_remove(&modlinkage));
-}
-#else
 typedef kern_return_t (*mach_call_t)(void *);
 
-/* XXX From #include <kern/syscall_sw.h> which may be changed for 64 bit! */
-typedef void    mach_munge_t(const void *, void *);
+/* APPLE NOTE: From #include <kern/syscall_sw.h> which may be changed for 64 bit! */
+typedef void    mach_munge_t(void *);
 
 typedef struct {
        int                     mach_trap_arg_count;
        kern_return_t           (*mach_trap_function)(void *);
-#if defined(__x86_64__)
+#if defined(__arm64__) || defined(__x86_64__)
        mach_munge_t            *mach_trap_arg_munge32; /* system call arguments for 32-bit */
 #endif
        int                     mach_trap_u32_words;
@@ -834,6 +693,7 @@ dtrace_machtrace_syscall(struct mach_call_args *args)
 
 #if 0 /* XXX */
        /*
+        * APPLE NOTE:  Not implemented.
         * We want to explicitly allow DTrace consumers to stop a process
         * before it actually executes the meat of the syscall.
         */
@@ -1027,16 +887,6 @@ machtrace_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
                        return (DDI_FAILURE);
        }
 
-#if !defined(__APPLE__)
-       machtrace_probe = (void (*)())dtrace_probe;
-       membar_enter();
-
-       if (ddi_create_minor_node(devi, "machtrace", S_IFCHR, 0,
-                               DDI_PSEUDO, NULL) == DDI_FAILURE ||
-                       dtrace_register("mach_trap", &machtrace_attr, DTRACE_PRIV_USER, NULL,
-                               &machtrace_pops, NULL, &machtrace_id) != 0) {
-               machtrace_probe = systrace_stub;
-#else
        machtrace_probe = dtrace_probe;
        membar_enter();
        
@@ -1045,7 +895,6 @@ machtrace_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
                        dtrace_register("mach_trap", &machtrace_attr, DTRACE_PRIV_USER, NULL,
                                &machtrace_pops, NULL, &machtrace_id) != 0) {
                 machtrace_probe = (void (*))&systrace_stub;
-#endif /* __APPLE__ */         
                ddi_remove_minor_node(devi, NULL);
                return (DDI_FAILURE);
        }
@@ -1095,6 +944,10 @@ void systrace_init( void );
 void systrace_init( void )
 {
        if (0 == gSysTraceInited) {
+               if (dtrace_sdt_probes_restricted()) {
+                       return;
+               }
+
                int majdevno = cdevsw_add(SYSTRACE_MAJOR, &systrace_cdevsw);
 
                if (majdevno < 0) {
@@ -1111,7 +964,6 @@ void systrace_init( void )
                panic("systrace_init: called twice!\n");
 }
 #undef SYSTRACE_MAJOR
-#endif /* __APPLE__ */
 
 static uint64_t
 systrace_getarg(void *arg, dtrace_id_t id, void *parg, int argno, int aframes)