Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | /* * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved. * * @APPLE_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 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. * * @APPLE_LICENSE_HEADER_END@ */ #include <kern/task.h> #include <kern/thread.h> #include <kern/thread_act.h> #include <kern/assert.h> #include <kern/clock.h> #include <mach/machine/thread_status.h> #include <ppc/savearea.h> #include <sys/kernel.h> #include <sys/vm.h> #include <sys/proc.h> #include <sys/syscall.h> #include <sys/systm.h> #include <sys/user.h> #include <sys/errno.h> #include <sys/ktrace.h> #include <sys/kdebug.h> #include <bsm/audit_kernel.h> extern void unix_syscall( struct savearea *regs ); extern struct savearea * find_user_regs( thread_act_t act); extern void enter_funnel_section(funnel_t *funnel_lock); extern void exit_funnel_section(void); /* * Function: unix_syscall * * Inputs: regs - pointer to Process Control Block * * Outputs: none */ void unix_syscall( struct savearea *regs ) { thread_act_t thread_act; struct uthread *uthread; struct proc *proc; struct sysent *callp; int error; unsigned short code; boolean_t flavor; int funnel_type; flavor = (((unsigned int)regs->save_r0) == NULL)? 1: 0; if (flavor) code = regs->save_r3; else code = regs->save_r0; if (kdebug_enable && (code != 180)) { if (flavor) KERNEL_DEBUG_CONSTANT(BSDDBG_CODE(DBG_BSD_EXCP_SC, code) | DBG_FUNC_START, regs->save_r4, regs->save_r5, regs->save_r6, regs->save_r7, 0); else KERNEL_DEBUG_CONSTANT(BSDDBG_CODE(DBG_BSD_EXCP_SC, code) | DBG_FUNC_START, regs->save_r3, regs->save_r4, regs->save_r5, regs->save_r6, 0); } thread_act = current_act(); uthread = get_bsdthread_info(thread_act); if (!(uthread->uu_flag & P_VFORK)) proc = (struct proc *)get_bsdtask_info(current_task()); else proc = current_proc(); uthread->uu_ar0 = (int *)regs; callp = (code >= nsysent) ? &sysent[63] : &sysent[code]; #ifdef DEBUG if (callp->sy_narg > 8) panic("unix_syscall: max arg count exceeded"); #endif if (callp->sy_narg != 0) { if ( !flavor) { uthread->uu_arg[0] = regs->save_r3; uthread->uu_arg[1] = regs->save_r4; uthread->uu_arg[2] = regs->save_r5; uthread->uu_arg[3] = regs->save_r6; uthread->uu_arg[4] = regs->save_r7; uthread->uu_arg[5] = regs->save_r8; uthread->uu_arg[6] = regs->save_r9; uthread->uu_arg[7] = regs->save_r10; } else { uthread->uu_arg[0] = regs->save_r4; uthread->uu_arg[1] = regs->save_r5; uthread->uu_arg[2] = regs->save_r6; uthread->uu_arg[3] = regs->save_r7; uthread->uu_arg[4] = regs->save_r8; uthread->uu_arg[5] = regs->save_r9; uthread->uu_arg[7] = regs->save_r10; } } funnel_type = (int)callp->sy_funnel; if (funnel_type == KERNEL_FUNNEL) enter_funnel_section(kernel_flock); else if (funnel_type == NETWORK_FUNNEL) enter_funnel_section(network_flock); uthread->uu_rval[0] = 0; /* * r4 is volatile, if we set it to regs->save_r4 here the child * will have parents r4 after execve */ uthread->uu_rval[1] = 0; error = 0; /* * PPC runtime calls cerror after every unix system call, so * assume no error and adjust the "pc" to skip this call. * It will be set back to the cerror call if an error is detected. */ regs->save_srr0 += 4; if (KTRPOINT(proc, KTR_SYSCALL)) ktrsyscall(proc, code, callp->sy_narg, uthread->uu_arg, funnel_type); 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); regs = find_user_regs(thread_act); if (error == ERESTART) { regs->save_srr0 -= 8; } else if (error != EJUSTRETURN) { if (error) { regs->save_r3 = (long long)error; /* set the "pc" to execute cerror routine */ regs->save_srr0 -= 4; } else { /* (not error) */ regs->save_r3 = uthread->uu_rval[0]; regs->save_r4 = uthread->uu_rval[1]; } } /* else (error == EJUSTRETURN) { nothing } */ if (KTRPOINT(proc, KTR_SYSRET)) ktrsysret(proc, code, error, uthread->uu_rval[0], funnel_type); exit_funnel_section(); if (kdebug_enable && (code != 180)) { KERNEL_DEBUG_CONSTANT(BSDDBG_CODE(DBG_BSD_EXCP_SC, code) | DBG_FUNC_END, error, uthread->uu_rval[0], uthread->uu_rval[1], 0, 0); } thread_exception_return(); /* NOTREACHED */ } unix_syscall_return(error) { thread_act_t thread_act; struct uthread *uthread; struct proc *proc; struct savearea *regs; unsigned short code; struct sysent *callp; int funnel_type; thread_act = current_act(); proc = current_proc(); uthread = get_bsdthread_info(thread_act); regs = find_user_regs(thread_act); /* * Get index into sysent table */ if (error == ERESTART) { regs->save_srr0 -= 8; } else if (error != EJUSTRETURN) { if (error) { regs->save_r3 = (long long)error; /* set the "pc" to execute cerror routine */ regs->save_srr0 -= 4; } else { /* (not error) */ regs->save_r3 = uthread->uu_rval[0]; regs->save_r4 = uthread->uu_rval[1]; } } /* else (error == EJUSTRETURN) { nothing } */ if (regs->save_r0 != NULL) code = regs->save_r0; else code = regs->save_r3; callp = (code >= nsysent) ? &sysent[63] : &sysent[code]; funnel_type = (int)callp->sy_funnel; if (KTRPOINT(proc, KTR_SYSRET)) ktrsysret(proc, code, error, uthread->uu_rval[0], funnel_type); exit_funnel_section(); if (kdebug_enable && (code != 180)) { KERNEL_DEBUG_CONSTANT(BSDDBG_CODE(DBG_BSD_EXCP_SC, code) | DBG_FUNC_END, error, uthread->uu_rval[0], uthread->uu_rval[1], 0, 0); } thread_exception_return(); /* NOTREACHED */ } /* * Time of day and interval timer support. * * These routines provide the kernel entry points to get and set * the time-of-day and per-process interval timers. Subroutines * here provide support for adding and subtracting timeval structures * and decrementing interval timers, optionally reloading the interval * timers when they expire. */ struct gettimeofday_args{ struct timeval *tp; struct timezone *tzp; }; /* NOTE THIS implementation is for ppc architectures only. * It is infrequently called, since the commpage intercepts * most calls in user mode. */ int ppc_gettimeofday(p, uap, retval) struct proc *p; register struct gettimeofday_args *uap; register_t *retval; { int error = 0; if (uap->tp) clock_gettimeofday(&retval[0], &retval[1]); if (uap->tzp) { struct timezone ltz; extern simple_lock_data_t tz_slock; usimple_lock(&tz_slock); ltz = tz; usimple_unlock(&tz_slock); error = copyout((caddr_t)<z, (caddr_t)uap->tzp, sizeof (tz)); } return (error); } |