]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/dev/ppc/systemcalls.c
xnu-1504.3.12.tar.gz
[apple/xnu.git] / bsd / dev / ppc / systemcalls.c
index 39ae16682e889ad1b63fc547a63202bfcc6b797a..973d35899420d9aaed1a1fc6fa358d33916b4daf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  * 
  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
+/*
+ * NOTICE: This file was modified by McAfee Research in 2004 to introduce
+ * support for mandatory and extensible security protections.  This notice
+ * is included in support of clause 2.2 (b) of the Apple Public License,
+ * Version 2.0.
+ */
+
+#include <mach/mach_traps.h>
 
 #include <kern/task.h>
 #include <kern/thread.h>
@@ -33,6 +41,7 @@
 #include <kern/locks.h>
 #include <kern/sched_prim.h>
 #include <mach/machine/thread_status.h>
+#include <mach/thread_act.h>
 #include <ppc/savearea.h>
 
 #include <sys/kernel.h>
 #include <sys/systm.h>
 #include <sys/user.h>
 #include <sys/errno.h>
-#include <sys/ktrace.h>
 #include <sys/kdebug.h>
 #include <sys/sysent.h>
 #include <sys/sysproto.h>
 #include <sys/kauth.h>
 
-#include <bsm/audit_kernel.h>
+#include <security/audit/audit.h>
+
+#if CONFIG_DTRACE
+extern int32_t dtrace_systrace_syscall(struct proc *, void *, int *);
+extern void dtrace_systrace_syscall_return(unsigned short, int, int *);
+#endif
 
 extern void
 unix_syscall(struct savearea *regs);
-void
-unix_syscall_return(int error);
 
 extern struct savearea * 
 find_user_regs(
        thread_t act);
 
-extern void enter_funnel_section(funnel_t *funnel_lock);
-extern void exit_funnel_section(void);
+extern lck_spin_t * tz_slock;
 
 /*
  * Function:   unix_syscall
@@ -77,10 +87,8 @@ unix_syscall(struct savearea *regs)
        struct proc                     *proc;
        struct sysent           *callp;
        int                                     error;
-       unsigned short          code;
+       unsigned int            code;
        boolean_t                       flavor;
-       int funnel_type;
-       unsigned int cancel_enable;
 
        flavor = (((unsigned int)regs->save_r0) == 0)? 1: 0;
 
@@ -119,15 +127,9 @@ unix_syscall(struct savearea       *regs)
         * Delayed binding of thread credential to process credential, if we
         * are not running with an explicitly set thread credential.
         */
-       if (uthread->uu_ucred != proc->p_ucred &&
-           (uthread->uu_flag & UT_SETUID) == 0) {
-               kauth_cred_t old = uthread->uu_ucred;
-               uthread->uu_ucred = kauth_cred_proc_ref(proc);
-               if (IS_VALID_CRED(old))
-                       kauth_cred_unref(&old);
-       }
+       kauth_cred_uthread_update(uthread, proc);
 
-       callp = (code >= nsysent) ? &sysent[63] : &sysent[code];
+       callp = (code >= NUM_SYSENT) ? &sysent[63] : &sysent[code];
 
        if (callp->sy_narg != 0) {
                void            *regsp;
@@ -135,7 +137,7 @@ unix_syscall(struct savearea        *regs)
                
                if (IS_64BIT_PROCESS(proc)) {
                        /* XXX Turn 64 bit unsafe calls into nosys() */
-                       if (callp->sy_funnel & UNSAFE_64BIT) {
+                       if (callp->sy_flags & UNSAFE_64BIT) {
                                callp = &sysent[63];
                                goto unsafe;
                        }
@@ -159,27 +161,9 @@ unix_syscall(struct savearea       *regs)
        }
 
 unsafe:
-       cancel_enable = callp->sy_cancel;
        
-       if (cancel_enable == _SYSCALL_CANCEL_NONE) {
-                       uthread->uu_flag |= UT_NOTCANCELPT;
-       } else {
-               if((uthread->uu_flag & (UT_CANCELDISABLE | UT_CANCEL | UT_CANCELED)) == UT_CANCEL) {
-                       if (cancel_enable == _SYSCALL_CANCEL_PRE) {
-                                       /* system call cancelled; return to handle cancellation */
-                                       regs->save_r3 = (long long)EINTR;
-                                       thread_exception_return();
-                                       /* NOTREACHED */
-                       } else {
-                        thread_abort_safely(thread_act);
-                       }
-               }
-       }
+       uthread->uu_flag |= UT_NOTCANCELPT;
 
-       funnel_type = (int)(callp->sy_funnel & FUNNEL_MASK);
-       if (funnel_type == KERNEL_FUNNEL) 
-                enter_funnel_section(kernel_flock);
-       
        uthread->uu_rval[0] = 0;
 
        /*
@@ -197,21 +181,26 @@ unsafe:
         */
        regs->save_srr0 += 4;
 
-       if (KTRPOINT(proc, KTR_SYSCALL))
-               ktrsyscall(proc, code, callp->sy_narg, uthread->uu_arg);
-
 #ifdef JOE_DEBUG
        uthread->uu_iocount = 0;
        uthread->uu_vpindex = 0;
 #endif
        AUDIT_SYSCALL_ENTER(code, proc, uthread);
        error = (*(callp->sy_call))(proc, (void *)uthread->uu_arg, &(uthread->uu_rval[0]));
-       AUDIT_SYSCALL_EXIT(error, proc, uthread);
+       AUDIT_SYSCALL_EXIT(code, proc, uthread, error);
+#if CONFIG_MACF
+       mac_thread_userret(code, error, thread_act);
+#endif
+
 
 #ifdef JOE_DEBUG
        if (uthread->uu_iocount)
-               joe_debug("system call returned with uu_iocount != 0");
+               printf("system call returned with uu_iocount != 0\n");
 #endif
+#if CONFIG_DTRACE
+       uthread->t_dtrace_errno = error;
+#endif /* CONFIG_DTRACE */
+
        regs = find_user_regs(thread_act);
 
        if (error == ERESTART) {
@@ -268,29 +257,12 @@ unsafe:
        /* else  (error == EJUSTRETURN) { nothing } */
 
 
-       if (KTRPOINT(proc, KTR_SYSRET)) {
-               switch(callp->sy_return_type) {
-               case _SYSCALL_RET_ADDR_T:
-               case _SYSCALL_RET_SIZE_T:
-               case _SYSCALL_RET_SSIZE_T:
-                       /*
-                        * Trace the value of the least significant bits,
-                        * until we can revise the ktrace API safely.
-                        */
-                       ktrsysret(proc, code, error, uthread->uu_rval[1]);
-                       break;
-               default:
-                       ktrsysret(proc, code, error, uthread->uu_rval[0]);
-                       break;
-               }
-       }
+       uthread->uu_flag &= ~UT_NOTCANCELPT;
 
-       if (cancel_enable == _SYSCALL_CANCEL_NONE)
-                uthread->uu_flag &= ~UT_NOTCANCELPT;
+       /* panic if funnel is held */
+       syscall_exit_funnelcheck();
 
-       exit_funnel_section();
-
-       if (uthread->uu_lowpri_delay) {
+       if (uthread->uu_lowpri_window) {
                /*
                 * task is marked as a low priority I/O type
                 * and the I/O we issued while in this system call
@@ -298,17 +270,16 @@ unsafe:
                 * delay in order to mitigate the impact of this
                 * task on the normal operation of the system
                 */
-               IOSleep(uthread->uu_lowpri_delay);
-               uthread->uu_lowpri_delay = 0;
+               throttle_lowpri_io(TRUE);
        }
        if (kdebug_enable && (code != 180)) {
 
                if (callp->sy_return_type == _SYSCALL_RET_SSIZE_T)
                        KERNEL_DEBUG_CONSTANT(BSDDBG_CODE(DBG_BSD_EXCP_SC, code) | DBG_FUNC_END,
-                                             error, uthread->uu_rval[1], 0, 0, 0);
+                                             error, uthread->uu_rval[1], 0, proc->p_pid, 0);
                else
                        KERNEL_DEBUG_CONSTANT(BSDDBG_CODE(DBG_BSD_EXCP_SC, code) | DBG_FUNC_END,
-                                             error, uthread->uu_rval[0], uthread->uu_rval[1], 0, 0);
+                                             error, uthread->uu_rval[0], uthread->uu_rval[1], proc->p_pid, 0);
        }
 
        thread_exception_return();
@@ -322,9 +293,8 @@ unix_syscall_return(int error)
        struct uthread                          *uthread;
        struct proc                                     *proc;
        struct savearea                         *regs;
-       unsigned short                          code;
+       unsigned int                            code;
        struct sysent                           *callp;
-       unsigned int cancel_enable;
 
        thread_act = current_thread();
        proc = current_proc();
@@ -337,7 +307,13 @@ unix_syscall_return(int error)
        else
                code = regs->save_r3;
 
-       callp = (code >= nsysent) ? &sysent[63] : &sysent[code];
+       callp = (code >= NUM_SYSENT) ? &sysent[63] : &sysent[code];
+
+#if CONFIG_DTRACE
+        if (callp->sy_call == dtrace_systrace_syscall)
+                dtrace_systrace_syscall_return( code, error, uthread->uu_rval );
+#endif /* CONFIG_DTRACE */
+       AUDIT_SYSCALL_EXIT(code, proc, uthread, error);
 
        /*
         * Get index into sysent table
@@ -393,31 +369,13 @@ unix_syscall_return(int error)
        }
        /* else  (error == EJUSTRETURN) { nothing } */
 
-       if (KTRPOINT(proc, KTR_SYSRET)) {
-               switch(callp->sy_return_type) {
-               case _SYSCALL_RET_ADDR_T:
-               case _SYSCALL_RET_SIZE_T:
-               case _SYSCALL_RET_SSIZE_T:
-                       /*
-                        * Trace the value of the least significant bits,
-                        * until we can revise the ktrace API safely.
-                        */
-                       ktrsysret(proc, code, error, uthread->uu_rval[1]);
-                       break;
-               default:
-                       ktrsysret(proc, code, error, uthread->uu_rval[0]);
-                       break;
-               }
-       }
-
-       cancel_enable = callp->sy_cancel;
 
-       if (cancel_enable == _SYSCALL_CANCEL_NONE)
-                uthread->uu_flag &= ~UT_NOTCANCELPT;
+       uthread->uu_flag &= ~UT_NOTCANCELPT;
 
-       exit_funnel_section();
+       /* panic if funnel is held */
+       syscall_exit_funnelcheck();
 
-       if (uthread->uu_lowpri_delay) {
+       if (uthread->uu_lowpri_window) {
                /*
                 * task is marked as a low priority I/O type
                 * and the I/O we issued while in this system call
@@ -425,25 +383,51 @@ unix_syscall_return(int error)
                 * delay in order to mitigate the impact of this
                 * task on the normal operation of the system
                 */
-               IOSleep(uthread->uu_lowpri_delay);
-               uthread->uu_lowpri_delay = 0;
+               throttle_lowpri_io(TRUE);
        }
        if (kdebug_enable && (code != 180)) {
                if (callp->sy_return_type == _SYSCALL_RET_SSIZE_T)
                        KERNEL_DEBUG_CONSTANT(BSDDBG_CODE(DBG_BSD_EXCP_SC, code) | DBG_FUNC_END,
-                                             error, uthread->uu_rval[1], 0, 0, 0);
+                                             error, uthread->uu_rval[1], 0, proc->p_pid, 0);
                else
                        KERNEL_DEBUG_CONSTANT(BSDDBG_CODE(DBG_BSD_EXCP_SC, code) | DBG_FUNC_END,
-                                             error, uthread->uu_rval[0], uthread->uu_rval[1], 0, 0);
+                                             error, uthread->uu_rval[0], uthread->uu_rval[1], proc->p_pid, 0);
        }
 
        thread_exception_return();
        /* NOTREACHED */
 }
 
-#ifdef JOE_DEBUG
-joe_debug(char *p) {
+void
+munge_lwww(
+       const void      *in32,
+       void            *out64)
+{
+       const uint32_t  *arg32;
+       uint64_t        *arg64;
 
-        printf("%s\n", p);
+       arg32 = (const uint32_t *) in32;
+       arg64 = (uint64_t *) out64;
+
+       arg64[3] = arg32[9];    /* lwwW */
+       arg64[2] = arg32[7];    /* lwWw */
+       arg64[1] = arg32[5];    /* lWww */
+       arg64[0] = ((uint64_t) arg32[1]) << 32; /* Lwww (hi) */
+       arg64[0] |= (uint64_t) arg32[3];        /* Lwww (lo) */
+}
+
+void
+munge_lw(
+       const void      *in32,
+       void            *out64)
+{
+       const uint32_t  *arg32;
+       uint64_t        *arg64;
+
+       arg32 = (const uint32_t *) in32;
+       arg64 = (uint64_t *) out64;
+
+       arg64[1] = arg32[5];    /* lW */
+       arg64[0] = ((uint64_t) arg32[1]) << 32; /* Lw (hi) */
+       arg64[0] |= (uint64_t) arg32[3];        /* Lw (lo) */
 }
-#endif