/*
- * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
*
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License"). You may not use this file except in compliance with the
- * License. Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
*
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
*
- * @APPLE_LICENSE_HEADER_END@
+ * @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 <kern/task.h>
#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 <bsm/audit_kernel.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
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;
* 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;
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;
}
}
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;
/*
*/
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");
#endif
+#if CONFIG_DTRACE
+ uthread->t_dtrace_errno = error;
+#endif /* CONFIG_DTRACE */
+
regs = find_user_regs(thread_act);
if (error == ERESTART) {
/* 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
* 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)) {
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();
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 */
/*
* Get index into sysent table
}
/* 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
* 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)