]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/dev/dtrace/systrace.c
xnu-4903.270.47.tar.gz
[apple/xnu.git] / bsd / dev / dtrace / systrace.c
index 10ba834332579255c66486cdb947416cee8538d7..27d199eebc7b98d375769ae0d3a2ee683b6edea3 100644 (file)
@@ -64,7 +64,7 @@
 #include <machine/pal_routines.h>
 
 #if defined (__x86_64__)
-#define        SYSTRACE_ARTIFICIAL_FRAMES      2
+#define SYSTRACE_ARTIFICIAL_FRAMES      2
 #define MACHTRACE_ARTIFICIAL_FRAMES 3
 #elif defined(__arm__) || defined(__arm64__)
 #define SYSTRACE_ARTIFICIAL_FRAMES  2
@@ -90,7 +90,7 @@ extern const char *syscallnames[];
 
 extern lck_attr_t* dtrace_lck_attr;
 extern lck_grp_t* dtrace_lck_grp;
-static lck_mtx_t       dtrace_systrace_lock;           /* probe state lock */
+static lck_mtx_t        dtrace_systrace_lock;           /* probe state lock */
 
 systrace_sysent_t *systrace_sysent = NULL;
 void (*systrace_probe)(dtrace_id_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
@@ -108,7 +108,7 @@ systrace_stub(dtrace_id_t id, uint64_t arg0, uint64_t arg1,
 int32_t
 dtrace_systrace_syscall(struct proc *pp, void *uap, int *rv)
 {
-       unsigned short      code;       /* The system call number */
+       unsigned short      code;       /* The system call number */
 
        systrace_sysent_t *sy;
        dtrace_id_t id;
@@ -135,7 +135,7 @@ dtrace_systrace_syscall(struct proc *pp, void *uap, int *rv)
                        code = saved_state32(tagged_regs)->eax & I386_SYSCALL_NUMBER_MASK;
 
                        if (code == 0) {
-                               vm_offset_t params = (vm_offset_t) (saved_state32(tagged_regs)->uesp + sizeof (int));
+                               vm_offset_t params = (vm_offset_t) (saved_state32(tagged_regs)->uesp + sizeof(int));
                                code = fuword(params);
                        }
                }
@@ -151,10 +151,11 @@ dtrace_systrace_syscall(struct proc *pp, void *uap, int *rv)
                arm_saved_state_t *arm_regs = (arm_saved_state_t *) find_user_regs(current_thread());
 
                /* Check for indirect system call */
-               if (arm_regs->r[12] != 0)
+               if (arm_regs->r[12] != 0) {
                        code = arm_regs->r[12];
-               else
+               } else {
                        code = arm_regs->r[0];
+               }
        }
 #elif defined(__arm64__)
        {
@@ -164,23 +165,21 @@ dtrace_systrace_syscall(struct proc *pp, void *uap, int *rv)
                 * ... and for u64 can be in either x0 or x16
                 */
 
-               /* see bsd/dev/arm/systemcalls.c:arm_get_syscall_number */              
+               /* see bsd/dev/arm/systemcalls.c:arm_get_syscall_number */
                arm_saved_state_t *arm_regs = (arm_saved_state_t *) find_user_regs(current_thread());
 
                if (is_saved_state32(arm_regs)) {
-                       /* Check for indirect system call */                    
+                       /* Check for indirect system call */
                        if (saved_state32(arm_regs)->r[12] != 0) {
                                code = saved_state32(arm_regs)->r[12];
-                       }
-                       else {
+                       } else {
                                code = saved_state32(arm_regs)->r[0];
                        }
                } else {
                        /* Check for indirect system call */
-                       if (saved_state64(arm_regs)->x[ARM64_SYSCALL_CODE_REG_NUM] != 0 ) {
+                       if (saved_state64(arm_regs)->x[ARM64_SYSCALL_CODE_REG_NUM] != 0) {
                                code = saved_state64(arm_regs)->x[ARM64_SYSCALL_CODE_REG_NUM];
-                       }
-                       else {
+                       } else {
                                code = saved_state64(arm_regs)->x[0];
                        }
                }
@@ -195,15 +194,17 @@ dtrace_systrace_syscall(struct proc *pp, void *uap, int *rv)
        systrace_args(code, ip, uargs);
 
        if ((id = sy->stsy_entry) != DTRACE_IDNONE) {
-               uthread_t uthread = (uthread_t)get_bsdthread_info(current_thread());            
-               if (uthread)
+               uthread_t uthread = (uthread_t)get_bsdthread_info(current_thread());
+               if (uthread) {
                        uthread->t_dtrace_syscall_args = uargs;
-               
+               }
+
                static_assert(SYSTRACE_NARGS >= 5, "not enough system call arguments");
                (*systrace_probe)(id, uargs[0], uargs[1], uargs[2], uargs[3], uargs[4]);
-               
-               if (uthread)
+
+               if (uthread) {
                        uthread->t_dtrace_syscall_args = NULL;
+               }
        }
 
 
@@ -227,14 +228,14 @@ dtrace_systrace_syscall(struct proc *pp, void *uap, int *rv)
 
        if ((id = sy->stsy_return) != DTRACE_IDNONE) {
                uint64_t munged_rv0, munged_rv1;
-       uthread_t uthread = (uthread_t)get_bsdthread_info(current_thread());
+               uthread_t uthread = (uthread_t)get_bsdthread_info(current_thread());
 
-               if (uthread)
+               if (uthread) {
                        uthread->t_dtrace_errno = rval; /* Establish t_dtrace_errno now in case this enabling refers to it. */
-
+               }
                /*
-                * "Decode" rv for use in the call to dtrace_probe()
-                */
+                * "Decode" rv for use in the call to dtrace_probe()
+                */
                if (rval == ERESTART) {
                        munged_rv0 = -1LL; /* System call will be reissued in user mode. Make DTrace report a -1 return. */
                        munged_rv1 = -1LL;
@@ -284,20 +285,20 @@ dtrace_systrace_syscall(struct proc *pp, void *uap, int *rv)
                 * "This is a bit of an historical artifact. At first, the syscall provider just
                 * had its return value in arg0, and the fbt and pid providers had their return
                 * values in arg1 (so that we could use arg0 for the offset of the return site).
-                * 
+                *
                 * We inevitably started writing scripts where we wanted to see the return
                 * values from probes in all three providers, and we made this script easier
                 * to write by replicating the syscall return values in arg1 to match fbt and
                 * pid. We debated briefly about removing the return value from arg0, but
                 * decided that it would be less confusing to have the same data in two places
                 * than to have some non-helpful, non-intuitive value in arg0.
-                * 
+                *
                 * This change was made 4/23/2003 according to the DTrace project's putback log."
-                */ 
+                */
                (*systrace_probe)(id, munged_rv0, munged_rv0, munged_rv1, (uint64_t)rval, 0);
        }
 
-       return (rval);
+       return rval;
 }
 
 void
@@ -311,14 +312,14 @@ dtrace_systrace_syscall_return(unsigned short code, int rval, int *rv)
 
        if ((id = sy->stsy_return) != DTRACE_IDNONE) {
                uint64_t munged_rv0, munged_rv1;
-       uthread_t uthread = (uthread_t)get_bsdthread_info(current_thread());
+               uthread_t uthread = (uthread_t)get_bsdthread_info(current_thread());
 
-               if (uthread)
+               if (uthread) {
                        uthread->t_dtrace_errno = rval; /* Establish t_dtrace_errno now in case this enabling refers to it. */
-
+               }
                /*
-                * "Decode" rv for use in the call to dtrace_probe()
-                */
+                * "Decode" rv for use in the call to dtrace_probe()
+                */
                if (rval == ERESTART) {
                        munged_rv0 = -1LL; /* System call will be reissued in user mode. Make DTrace report a -1 return. */
                        munged_rv1 = -1LL;
@@ -366,11 +367,11 @@ dtrace_systrace_syscall_return(unsigned short code, int rval, int *rv)
        }
 }
 
-#define        SYSTRACE_SHIFT                  16
-#define        SYSTRACE_ISENTRY(x)             ((int)(x) >> SYSTRACE_SHIFT)
-#define        SYSTRACE_SYSNUM(x)              ((int)(x) & ((1 << SYSTRACE_SHIFT) - 1))
-#define        SYSTRACE_ENTRY(id)              ((1 << SYSTRACE_SHIFT) | (id))
-#define        SYSTRACE_RETURN(id)             (id)
+#define SYSTRACE_SHIFT                  16
+#define SYSTRACE_ISENTRY(x)             ((int)(x) >> SYSTRACE_SHIFT)
+#define SYSTRACE_SYSNUM(x)              ((int)(x) & ((1 << SYSTRACE_SHIFT) - 1))
+#define SYSTRACE_ENTRY(id)              ((1 << SYSTRACE_SHIFT) | (id))
+#define SYSTRACE_RETURN(id)             (id)
 
 #if ((1 << SYSTRACE_SHIFT) <= NSYSCALL)
 #error 1 << SYSTRACE_SHIFT must exceed number of system calls
@@ -387,13 +388,12 @@ static dtrace_provider_id_t systrace_id;
 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 */
+                                                   *       from bsd/sys/sysent.h */
        unsigned int i;
 
        if (ssysent == NULL) {
-               *interposed = ssysent = kmem_zalloc(sizeof (systrace_sysent_t) *
+               *interposed = ssysent = kmem_zalloc(sizeof(systrace_sysent_t) *
                    NSYSCALL, KM_SLEEP);
        }
 
@@ -401,11 +401,13 @@ systrace_init(struct sysent *actual, systrace_sysent_t **interposed)
                struct sysent *a = &actual[i];
                systrace_sysent_t *s = &ssysent[i];
 
-               if (LOADABLE_SYSCALL(a) && !LOADED_SYSCALL(a))
+               if (LOADABLE_SYSCALL(a) && !LOADED_SYSCALL(a)) {
                        continue;
+               }
 
-               if (a->sy_callc == dtrace_systrace_syscall)
+               if (a->sy_callc == dtrace_systrace_syscall) {
                        continue;
+               }
 
                s->stsy_underlying = a->sy_callc;
                s->stsy_return_type = a->sy_return_type;
@@ -421,18 +423,21 @@ systrace_provide(void *arg, const dtrace_probedesc_t *desc)
 #pragma unused(arg) /* __APPLE__ */
        unsigned int i;
 
-       if (desc != NULL)
+       if (desc != NULL) {
                return;
+       }
 
        systrace_init(sysent, &systrace_sysent);
 
        for (i = 0; i < NSYSCALL; i++) {
-               if (systrace_sysent[i].stsy_underlying == NULL)
+               if (systrace_sysent[i].stsy_underlying == NULL) {
                        continue;
+               }
 
                if (dtrace_probe_lookup(systrace_id, NULL,
-                   syscallnames[i], "entry") != 0)
+                   syscallnames[i], "entry") != 0) {
                        continue;
+               }
 
                (void) dtrace_probe_create(systrace_id, NULL, syscallnames[i],
                    "entry", SYSTRACE_ARTIFICIAL_FRAMES,
@@ -472,7 +477,7 @@ static int
 systrace_enable(void *arg, dtrace_id_t id, void *parg)
 {
 #pragma unused(arg) /* __APPLE__ */
-    
+
        int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
        int enabled = (systrace_sysent[sysnum].stsy_entry != DTRACE_IDNONE ||
            systrace_sysent[sysnum].stsy_return != DTRACE_IDNONE);
@@ -485,7 +490,7 @@ systrace_enable(void *arg, dtrace_id_t id, void *parg)
 
        if (enabled) {
                ASSERT(sysent[sysnum].sy_callc == dtrace_systrace_syscall);
-               return(0);
+               return 0;
        }
 
        lck_mtx_lock(&dtrace_systrace_lock);
@@ -494,7 +499,7 @@ systrace_enable(void *arg, dtrace_id_t id, void *parg)
                ml_nofault_copy((vm_offset_t)&dss, (vm_offset_t)&sysent[sysnum].sy_callc, sizeof(vm_offset_t));
        }
        lck_mtx_unlock(&dtrace_systrace_lock);
-       return (0);
+       return 0;
 }
 
 /*ARGSUSED*/
@@ -502,17 +507,17 @@ static void
 systrace_disable(void *arg, dtrace_id_t id, void *parg)
 {
 #pragma unused(arg,id) /* __APPLE__ */
-    
+
        int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
        int disable = (systrace_sysent[sysnum].stsy_entry == DTRACE_IDNONE ||
            systrace_sysent[sysnum].stsy_return == DTRACE_IDNONE);
 
        if (disable) {
                lck_mtx_lock(&dtrace_systrace_lock);
-               if (sysent[sysnum].sy_callc == dtrace_systrace_syscall)
+               if (sysent[sysnum].sy_callc == dtrace_systrace_syscall) {
                        ml_nofault_copy((vm_offset_t)&systrace_sysent[sysnum].stsy_underlying, (vm_offset_t)&sysent[sysnum].sy_callc, sizeof(systrace_sysent[sysnum].stsy_underlying));
+               }
                lck_mtx_unlock(&dtrace_systrace_lock);
-
        }
 
        if (SYSTRACE_ISENTRY((uintptr_t)parg)) {
@@ -523,24 +528,24 @@ systrace_disable(void *arg, dtrace_id_t id, void *parg)
 }
 
 static dtrace_pattr_t systrace_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 },
+       { 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 systrace_pops = {
-       .dtps_provide =         systrace_provide,
-       .dtps_provide_module =  NULL,
-       .dtps_enable =          systrace_enable,
-       .dtps_disable =         systrace_disable,
-       .dtps_suspend =         NULL,
-       .dtps_resume =          NULL,
-       .dtps_getargdesc =      systrace_getargdesc,
-       .dtps_getargval =       systrace_getargval,
-       .dtps_usermode =        NULL,
-       .dtps_destroy =         systrace_destroy
+       .dtps_provide =         systrace_provide,
+       .dtps_provide_module =  NULL,
+       .dtps_enable =          systrace_enable,
+       .dtps_disable =         systrace_disable,
+       .dtps_suspend =         NULL,
+       .dtps_resume =          NULL,
+       .dtps_getargdesc =      systrace_getargdesc,
+       .dtps_getargval =       systrace_getargval,
+       .dtps_usermode =        NULL,
+       .dtps_destroy =         systrace_destroy
 };
 
 static int
@@ -555,10 +560,10 @@ systrace_attach(dev_info_t *devi)
            &systrace_pops, NULL, &systrace_id) != 0) {
                systrace_probe = systrace_stub;
                ddi_remove_minor_node(devi, NULL);
-               return (DDI_FAILURE);
+               return DDI_FAILURE;
        }
 
-       return (DDI_SUCCESS);
+       return DDI_SUCCESS;
 }
 
 
@@ -573,17 +578,18 @@ systrace_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
        case DDI_DETACH:
                break;
        case DDI_SUSPEND:
-               return (DDI_SUCCESS);
+               return DDI_SUCCESS;
        default:
-               return (DDI_FAILURE);
+               return DDI_FAILURE;
        }
 
-       if (dtrace_unregister(systrace_id) != 0)
-               return (DDI_FAILURE);
+       if (dtrace_unregister(systrace_id) != 0) {
+               return DDI_FAILURE;
+       }
 
        ddi_remove_minor_node(devi, NULL);
        systrace_probe = systrace_stub;
-       return (DDI_SUCCESS);
+       return DDI_SUCCESS;
 }
 #endif /* __APPLE__ */
 
@@ -594,14 +600,14 @@ typedef kern_return_t (*mach_call_t)(void *);
 typedef void    mach_munge_t(void *);
 
 typedef struct {
-       int                     mach_trap_arg_count;
-       kern_return_t           (*mach_trap_function)(void *);
+       int                     mach_trap_arg_count;
+       kern_return_t           (*mach_trap_function)(void *);
 #if defined(__arm64__) || defined(__x86_64__)
-       mach_munge_t            *mach_trap_arg_munge32; /* system call arguments for 32-bit */
+       mach_munge_t            *mach_trap_arg_munge32; /* system call arguments for 32-bit */
 #endif
-       int                     mach_trap_u32_words;
-#if    MACH_ASSERT
-       const char*             mach_trap_name;
+       int                     mach_trap_u32_words;
+#if     MACH_ASSERT
+       const char*             mach_trap_name;
 #endif /* MACH_ASSERT */
 } mach_trap_t;
 
@@ -612,15 +618,15 @@ extern const char *mach_syscall_name_table[];
 
 /* XXX From osfmk/i386/bsd_i386.c */
 struct mach_call_args {
-        syscall_arg_t arg1;
-        syscall_arg_t arg2;
-        syscall_arg_t arg3;
-        syscall_arg_t arg4;
-        syscall_arg_t arg5;
-        syscall_arg_t arg6;
-        syscall_arg_t arg7;
-        syscall_arg_t arg8;
-        syscall_arg_t arg9;
+       syscall_arg_t arg1;
+       syscall_arg_t arg2;
+       syscall_arg_t arg3;
+       syscall_arg_t arg4;
+       syscall_arg_t arg5;
+       syscall_arg_t arg6;
+       syscall_arg_t arg7;
+       syscall_arg_t arg8;
+       syscall_arg_t arg9;
 };
 
 #undef NSYSCALL
@@ -631,10 +637,10 @@ struct mach_call_args {
 #endif
 
 typedef struct machtrace_sysent {
-       dtrace_id_t     stsy_entry;
-       dtrace_id_t     stsy_return;
-       kern_return_t   (*stsy_underlying)(void *);
-       int32_t         stsy_return_type;
+       dtrace_id_t     stsy_entry;
+       dtrace_id_t     stsy_return;
+       kern_return_t   (*stsy_underlying)(void *);
+       int32_t         stsy_return_type;
 } machtrace_sysent_t;
 
 static machtrace_sysent_t *machtrace_sysent = NULL;
@@ -642,14 +648,14 @@ static machtrace_sysent_t *machtrace_sysent = NULL;
 void (*machtrace_probe)(dtrace_id_t, uint64_t, uint64_t,
     uint64_t, uint64_t, uint64_t);
 
-static uint64_t machtrace_getarg(void *, dtrace_id_t, void *, int, int);       
+static uint64_t machtrace_getarg(void *, dtrace_id_t, void *, int, int);
 
 static dtrace_provider_id_t machtrace_id;
 
 static kern_return_t
 dtrace_machtrace_syscall(struct mach_call_args *args)
 {
-       int code;       /* The mach call number */
+       int code;       /* The mach call number */
 
        machtrace_sysent_t *sy;
        dtrace_id_t id;
@@ -689,9 +695,9 @@ dtrace_machtrace_syscall(struct mach_call_args *args)
                        code = (int)saved_state64(arm_regs)->x[ARM64_SYSCALL_CODE_REG_NUM];
                }
 
-                /* From bsd/arm64.c:mach_syscall */
+               /* From bsd/arm64.c:mach_syscall */
                ASSERT(code < 0);    /* Otherwise it would be a Unix syscall */
-               code = -code;           
+               code = -code;
        }
 #else
 #error Unknown Architecture
@@ -700,15 +706,17 @@ dtrace_machtrace_syscall(struct mach_call_args *args)
        sy = &machtrace_sysent[code];
 
        if ((id = sy->stsy_entry) != DTRACE_IDNONE) {
-               uthread_t uthread = (uthread_t)get_bsdthread_info(current_thread());    
+               uthread_t uthread = (uthread_t)get_bsdthread_info(current_thread());
 
-               if (uthread)
+               if (uthread) {
                        uthread->t_dtrace_syscall_args = (void *)ip;
-               
-               (*machtrace_probe)(id, *ip, *(ip+1), *(ip+2), *(ip+3), *(ip+4));
-               
-               if (uthread)
-                       uthread->t_dtrace_syscall_args = (void *)0;             
+               }
+
+               (*machtrace_probe)(id, *ip, *(ip + 1), *(ip + 2), *(ip + 3), *(ip + 4));
+
+               if (uthread) {
+                       uthread->t_dtrace_syscall_args = (void *)0;
+               }
        }
 
 #if 0 /* XXX */
@@ -729,10 +737,11 @@ dtrace_machtrace_syscall(struct mach_call_args *args)
        mach_call = (mach_call_t)(*sy->stsy_underlying);
        rval = mach_call(args);
 
-       if ((id = sy->stsy_return) != DTRACE_IDNONE)
+       if ((id = sy->stsy_return) != DTRACE_IDNONE) {
                (*machtrace_probe)(id, (uint64_t)rval, 0, 0, 0, 0);
+       }
 
-       return (rval);
+       return rval;
 }
 
 static void
@@ -742,19 +751,21 @@ machtrace_init(const mach_trap_t *actual, machtrace_sysent_t **interposed)
        int i;
 
        if (msysent == NULL) {
-               *interposed = msysent = kmem_zalloc(sizeof (machtrace_sysent_t) *
-                               NSYSCALL, KM_SLEEP);
+               *interposed = msysent = kmem_zalloc(sizeof(machtrace_sysent_t) *
+                   NSYSCALL, KM_SLEEP);
        }
 
        for (i = 0; i < NSYSCALL; i++) {
                const mach_trap_t *a = &actual[i];
                machtrace_sysent_t *s = &msysent[i];
 
-               if (LOADABLE_SYSCALL(a) && !LOADED_SYSCALL(a))
+               if (LOADABLE_SYSCALL(a) && !LOADED_SYSCALL(a)) {
                        continue;
+               }
 
-               if (a->mach_trap_function == (mach_call_t)(dtrace_machtrace_syscall))
+               if (a->mach_trap_function == (mach_call_t)(dtrace_machtrace_syscall)) {
                        continue;
+               }
 
                s->stsy_underlying = a->mach_trap_function;
        }
@@ -765,29 +776,31 @@ static void
 machtrace_provide(void *arg, const dtrace_probedesc_t *desc)
 {
 #pragma unused(arg) /* __APPLE__ */
-    
+
        int i;
 
-       if (desc != NULL)
+       if (desc != NULL) {
                return;
+       }
 
        machtrace_init(mach_trap_table, &machtrace_sysent);
 
        for (i = 0; i < NSYSCALL; i++) {
-               
-               if (machtrace_sysent[i].stsy_underlying == NULL)
+               if (machtrace_sysent[i].stsy_underlying == NULL) {
                        continue;
+               }
 
                if (dtrace_probe_lookup(machtrace_id, NULL,
-                                       mach_syscall_name_table[i], "entry") != 0)
+                   mach_syscall_name_table[i], "entry") != 0) {
                        continue;
+               }
 
                (void) dtrace_probe_create(machtrace_id, NULL, mach_syscall_name_table[i],
-                                          "entry", MACHTRACE_ARTIFICIAL_FRAMES,
-                                          (void *)((uintptr_t)SYSTRACE_ENTRY(i)));
+                   "entry", MACHTRACE_ARTIFICIAL_FRAMES,
+                   (void *)((uintptr_t)SYSTRACE_ENTRY(i)));
                (void) dtrace_probe_create(machtrace_id, NULL, mach_syscall_name_table[i],
-                                          "return", MACHTRACE_ARTIFICIAL_FRAMES,
-                                          (void *)((uintptr_t)SYSTRACE_RETURN(i)));
+                   "return", MACHTRACE_ARTIFICIAL_FRAMES,
+                   (void *)((uintptr_t)SYSTRACE_RETURN(i)));
 
                machtrace_sysent[i].stsy_entry = DTRACE_IDNONE;
                machtrace_sysent[i].stsy_return = DTRACE_IDNONE;
@@ -800,7 +813,7 @@ machtrace_destroy(void *arg, dtrace_id_t id, void *parg)
 {
 #pragma unused(arg,id) /* __APPLE__ */
        int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
-       
+
 #pragma unused(sysnum) /* __APPLE__ */
 
        /*
@@ -819,10 +832,10 @@ static int
 machtrace_enable(void *arg, dtrace_id_t id, void *parg)
 {
 #pragma unused(arg) /* __APPLE__ */
-    
+
        int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
        int enabled = (machtrace_sysent[sysnum].stsy_entry != DTRACE_IDNONE ||
-                       machtrace_sysent[sysnum].stsy_return != DTRACE_IDNONE);
+           machtrace_sysent[sysnum].stsy_return != DTRACE_IDNONE);
 
        if (SYSTRACE_ISENTRY((uintptr_t)parg)) {
                machtrace_sysent[sysnum].stsy_entry = id;
@@ -831,8 +844,8 @@ machtrace_enable(void *arg, dtrace_id_t id, void *parg)
        }
 
        if (enabled) {
-           ASSERT(mach_trap_table[sysnum].mach_trap_function == (void *)dtrace_machtrace_syscall);
-           return(0);
+               ASSERT(mach_trap_table[sysnum].mach_trap_function == (void *)dtrace_machtrace_syscall);
+               return 0;
        }
 
        lck_mtx_lock(&dtrace_systrace_lock);
@@ -844,7 +857,7 @@ machtrace_enable(void *arg, dtrace_id_t id, void *parg)
 
        lck_mtx_unlock(&dtrace_systrace_lock);
 
-       return(0);
+       return 0;
 }
 
 /*ARGSUSED*/
@@ -852,13 +865,12 @@ static void
 machtrace_disable(void *arg, dtrace_id_t id, void *parg)
 {
 #pragma unused(arg,id) /* __APPLE__ */
-      
+
        int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
        int disable = (machtrace_sysent[sysnum].stsy_entry == DTRACE_IDNONE ||
-                       machtrace_sysent[sysnum].stsy_return == DTRACE_IDNONE);
+           machtrace_sysent[sysnum].stsy_return == DTRACE_IDNONE);
 
        if (disable) {
-
                lck_mtx_lock(&dtrace_systrace_lock);
 
                if (mach_trap_table[sysnum].mach_trap_function == (mach_call_t)dtrace_machtrace_syscall) {
@@ -875,24 +887,24 @@ machtrace_disable(void *arg, dtrace_id_t id, void *parg)
 }
 
 static dtrace_pattr_t machtrace_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 },
+       { 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 machtrace_pops = {
-       .dtps_provide =         machtrace_provide,
-       .dtps_provide_module =  NULL,
-       .dtps_enable =          machtrace_enable,
-       .dtps_disable =         machtrace_disable,
-       .dtps_suspend =         NULL,
-       .dtps_resume =          NULL,
-       .dtps_getargdesc =      NULL,
-       .dtps_getargval =       machtrace_getarg,
-       .dtps_usermode =        NULL,
-       .dtps_destroy =         machtrace_destroy
+       .dtps_provide =         machtrace_provide,
+       .dtps_provide_module =  NULL,
+       .dtps_enable =          machtrace_enable,
+       .dtps_disable =         machtrace_disable,
+       .dtps_suspend =         NULL,
+       .dtps_resume =          NULL,
+       .dtps_getargdesc =      NULL,
+       .dtps_getargval =       machtrace_getarg,
+       .dtps_usermode =        NULL,
+       .dtps_destroy =         machtrace_destroy
 };
 
 static int
@@ -900,22 +912,23 @@ machtrace_attach(dev_info_t *devi)
 {
        machtrace_probe = dtrace_probe;
        membar_enter();
-       
+
        if (ddi_create_minor_node(devi, "machtrace", S_IFCHR, 0,
-                               DDI_PSEUDO, 0) == DDI_FAILURE ||
-                       dtrace_register("mach_trap", &machtrace_attr, DTRACE_PRIV_USER, NULL,
-                               &machtrace_pops, NULL, &machtrace_id) != 0) {
-                machtrace_probe = (void*)&systrace_stub;
+           DDI_PSEUDO, 0) == DDI_FAILURE ||
+           dtrace_register("mach_trap", &machtrace_attr, DTRACE_PRIV_USER, NULL,
+           &machtrace_pops, NULL, &machtrace_id) != 0) {
+               machtrace_probe = (void*)&systrace_stub;
                ddi_remove_minor_node(devi, NULL);
-               return (DDI_FAILURE);
+               return DDI_FAILURE;
        }
 
-       return (DDI_SUCCESS);
+       return DDI_SUCCESS;
 }
 
 d_open_t _systrace_open;
 
-int _systrace_open(dev_t dev, int flags, int devtype, struct proc *p)
+int
+_systrace_open(dev_t dev, int flags, int devtype, struct proc *p)
 {
 #pragma unused(dev,flags,devtype,p)
        return 0;
@@ -929,25 +942,26 @@ int _systrace_open(dev_t dev, int flags, int devtype, struct proc *p)
  */
 static struct cdevsw systrace_cdevsw =
 {
-       _systrace_open,         /* open */
-       eno_opcl,               /* close */
-       eno_rdwrt,                      /* read */
-       eno_rdwrt,                      /* write */
-       eno_ioctl,              /* ioctl */
+       _systrace_open,         /* open */
+       eno_opcl,               /* close */
+       eno_rdwrt,                      /* read */
+       eno_rdwrt,                      /* write */
+       eno_ioctl,              /* ioctl */
        (stop_fcn_t *)nulldev, /* stop */
        (reset_fcn_t *)nulldev, /* reset */
-       NULL,                           /* tty's */
-       eno_select,                     /* select */
-       eno_mmap,                       /* mmap */
-       eno_strat,                      /* strategy */
-       eno_getc,                       /* getc */
-       eno_putc,                       /* putc */
-       0                                       /* type */
+       NULL,                           /* tty's */
+       eno_select,                     /* select */
+       eno_mmap,                       /* mmap */
+       eno_strat,                      /* strategy */
+       eno_getc,                       /* getc */
+       eno_putc,                       /* putc */
+       0                                       /* type */
 };
 
 void systrace_init( void );
 
-void systrace_init( void )
+void
+systrace_init( void )
 {
        if (dtrace_sdt_probes_restricted()) {
                return;
@@ -972,24 +986,27 @@ systrace_getargval(void *arg, dtrace_id_t id, void *parg, int argno, int aframes
        uint64_t val = 0;
        uint64_t *uargs = NULL;
 
-       uthread_t uthread = (uthread_t)get_bsdthread_info(current_thread());    
+       uthread_t uthread = (uthread_t)get_bsdthread_info(current_thread());
 
-       if (uthread)
+       if (uthread) {
                uargs = uthread->t_dtrace_syscall_args;
-       if (!uargs)
-               return(0);
-       if (argno < 0 || argno >= SYSTRACE_NARGS)
-               return(0);
+       }
+       if (!uargs) {
+               return 0;
+       }
+       if (argno < 0 || argno >= SYSTRACE_NARGS) {
+               return 0;
+       }
 
        DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
        val = uargs[argno];
        DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
-       return (val);
+       return val;
 }
 
 static void
 systrace_getargdesc(void *arg, dtrace_id_t id, void *parg,
-       dtrace_argdesc_t *desc)
+    dtrace_argdesc_t *desc)
 {
 #pragma unused(arg, id)
        int sysnum = SYSTRACE_SYSNUM(parg);
@@ -1005,15 +1022,15 @@ systrace_getargdesc(void *arg, dtrace_id_t id, void *parg,
 
        if (SYSTRACE_ISENTRY((uintptr_t)parg)) {
                systrace_entry_setargdesc(sysnum, desc->dtargd_ndx,
-                       desc->dtargd_native, sizeof(desc->dtargd_native));
-       }
-       else {
+                   desc->dtargd_native, sizeof(desc->dtargd_native));
+       } else {
                systrace_return_setargdesc(sysnum, desc->dtargd_ndx,
-                       desc->dtargd_native, sizeof(desc->dtargd_native));
+                   desc->dtargd_native, sizeof(desc->dtargd_native));
        }
 
-       if (desc->dtargd_native[0] == '\0')
+       if (desc->dtargd_native[0] == '\0') {
                desc->dtargd_ndx = DTRACE_ARGNONE;
+       }
 }
 
 static uint64_t
@@ -1024,17 +1041,18 @@ machtrace_getarg(void *arg, dtrace_id_t id, void *parg, int argno, int aframes)
        syscall_arg_t *stack = (syscall_arg_t *)NULL;
 
        uthread_t uthread = (uthread_t)get_bsdthread_info(current_thread());
-       
-       if (uthread)
+
+       if (uthread) {
                stack = (syscall_arg_t *)uthread->t_dtrace_syscall_args;
-       
-       if (!stack)
-               return(0);
+       }
+
+       if (!stack) {
+               return 0;
+       }
 
        DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
        /* dtrace_probe arguments arg0 .. arg4 are 64bits wide */
-       val = (uint64_t)*(stack+argno); 
+       val = (uint64_t)*(stack + argno);
        DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
-       return (val);
+       return val;
 }
-