X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/0c530ab8987f0ae6a1a3d9284f40182b88852816..593a1d5fd87cdf5b46dd5fcb84467b432cea0f91:/bsd/dev/ppc/systemcalls.c diff --git a/bsd/dev/ppc/systemcalls.c b/bsd/dev/ppc/systemcalls.c index 4d0a3d397..8cc3ca4b8 100644 --- a/bsd/dev/ppc/systemcalls.c +++ b/bsd/dev/ppc/systemcalls.c @@ -1,23 +1,35 @@ /* - * 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 @@ -27,6 +39,7 @@ #include #include #include +#include #include #include @@ -36,7 +49,6 @@ #include #include #include -#include #include #include #include @@ -44,17 +56,19 @@ #include +#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 @@ -71,10 +85,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; @@ -113,15 +125,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; @@ -129,7 +135,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; } @@ -153,27 +159,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; /* @@ -191,21 +179,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"); #endif +#if CONFIG_DTRACE + uthread->t_dtrace_errno = error; +#endif /* CONFIG_DTRACE */ + regs = find_user_regs(thread_act); if (error == ERESTART) { @@ -262,29 +255,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 @@ -292,8 +268,7 @@ 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)) { @@ -316,9 +291,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(); @@ -331,7 +305,12 @@ 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 */ /* * Get index into sysent table @@ -387,31 +366,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 @@ -419,8 +380,7 @@ 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)