2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 * Mach Operating System
25 * Copyright (c) 1987 Carnegie-Mellon University
26 * All rights reserved. The CMU software License Agreement specifies
27 * the terms and conditions for use and redistribution.
33 * Copyright (c) 1982, 1986, 1991, 1993
34 * The Regents of the University of California. All rights reserved.
35 * (c) UNIX System Laboratories, Inc.
36 * All or some portions of this file are derived from material licensed
37 * to the University of California by American Telephone and Telegraph
38 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
39 * the permission of UNIX System Laboratories, Inc.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. All advertising materials mentioning features or use of this software
50 * must display the following acknowledgement:
51 * This product includes software developed by the University of
52 * California, Berkeley and its contributors.
53 * 4. Neither the name of the University nor the names of its contributors
54 * may be used to endorse or promote products derived from this software
55 * without specific prior written permission.
57 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
58 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
60 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
61 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
62 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
63 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
65 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * from: @(#)kern_exec.c 8.1 (Berkeley) 6/10/93
71 #include <machine/reg.h>
73 #include <sys/param.h>
74 #include <sys/systm.h>
75 #include <sys/filedesc.h>
76 #include <sys/kernel.h>
80 #include <sys/socketvar.h>
81 #include <sys/malloc.h>
82 #include <sys/namei.h>
83 #include <sys/mount.h>
84 #include <sys/vnode.h>
90 #include <sys/kdebug.h>
91 #include <sys/signal.h>
93 #include <mach/vm_param.h>
95 #include <vm/vm_map.h>
96 #include <vm/vm_kern.h>
98 #include <kern/thread.h>
99 #include <kern/task.h>
101 #include <kern/ast.h>
102 #include <kern/mach_loader.h>
103 #include <mach-o/fat.h>
104 #include <mach-o/loader.h>
105 #include <machine/vmparam.h>
107 extern vm_map_t bsd_pageable_map
;
109 #define ROUND_PTR(type, addr) \
110 (type *)( ( (unsigned)(addr) + 16 - 1) \
113 static int load_return_to_errno(load_return_t lrtn
);
114 int execve(struct proc
*p
, struct execve_args
*uap
, register_t
*retval
);
117 execv(p
, args
, retval
)
122 ((struct execve_args
*)args
)->envp
= NULL
;
123 return (execve(p
, args
, retval
));
128 execve(p
, uap
, retval
)
129 register struct proc
*p
;
130 register struct execve_args
*uap
;
133 register struct ucred
*cred
= p
->p_ucred
;
134 register struct filedesc
*fdp
= p
->p_fd
;
137 int na
, ne
, ucp
, ap
, cc
;
144 struct vattr origvattr
;
145 vm_offset_t execargs
;
147 struct ps_strings ps
;
152 struct mach_header
*mach_header
;
153 struct fat_header
*fat_header
;
154 struct fat_arch fat_arch
;
156 load_result_t load_result
;
157 struct uthread
*uthread
;
162 /* #! and name of interpreter */
163 char ex_shell
[SHSIZE
];
164 /* Mach-O executable */
165 struct mach_header mach_header
;
167 struct fat_header fat_header
;
172 int savedpathlen
= 0;
173 vm_offset_t
*execargsp
;
177 thread_act_t thr_act
;
180 unsigned long arch_offset
=0;
181 unsigned long arch_size
= 0;
183 task
= current_task();
184 thr_act
= current_act();
185 uthread
= get_bsdthread_info(thr_act
);
187 if (uthread
->uu_flag
& P_VFORK
) {
188 vfexec
= 1; /* Mark in exec */
190 if (task
!= kernel_task
) {
191 numthreads
= get_task_numacts(task
);
192 if (numthreads
<= 0 )
194 if (numthreads
> 1) {
200 ret
= kmem_alloc_pageable(bsd_pageable_map
, &execargs
, NCARGS
);
201 if (ret
!= KERN_SUCCESS
)
204 savedpath
= execargs
;
207 * To support new app package launching for Mac OS X, the dyld
208 * needs the first argument to execve() stored on the user stack.
209 * Copyin the "path" at the begining of the "execargs" buffer
212 * We have to do this before namei() because in case of
213 * symbolic links, namei() would overwrite the original "path".
214 * In case the last symbolic link resolved was a relative pathname
215 * we would loose the original "path", which could be an
216 * absolute pathname. This might be unacceptable for dyld.
218 /* XXX We could optimize to avoid copyinstr in the namei() */
220 error
= copyinstr(uap
->fname
, savedpath
, MAXPATHLEN
, &savedpathlen
);
224 * copyinstr will put in savedpathlen, the count of
225 * characters (including NULL) in the path.
228 /* Save the name aside for future use */
229 execargsp
= (vm_offset_t
*)((char *)(execargs
) + savedpathlen
);
231 NDINIT(&nd
, LOOKUP
, FOLLOW
| LOCKLEAF
| SAVENAME
,
232 UIO_USERSPACE
, uap
->fname
, p
);
233 if ((error
= namei(&nd
)))
236 VOP_LEASE(vp
, p
, p
->p_ucred
, LEASE_READ
);
238 if ((error
= VOP_GETATTR(vp
, &origvattr
, p
->p_ucred
, p
)))
241 /* Check mount point */
242 if (vp
->v_mount
->mnt_flag
& MNT_NOEXEC
) {
248 if ((vp
->v_mount
->mnt_flag
& MNT_NOSUID
) || (p
->p_flag
& P_TRACED
))
249 origvattr
.va_mode
&= ~(VSUID
| VSGID
);
251 *(&vattr
) = *(&origvattr
);
254 error
= check_exec_access(p
, vp
, &vattr
);
259 * Read in first few bytes of file for segment sizes, magic number:
260 * 407 = plain executable
262 * 413 = demand paged RO text
263 * Also an ASCII line beginning with #! is
264 * the file name of a ``shell'' and arguments may be prepended
265 * to the argument list if given here.
267 * SHELL NAMES ARE LIMITED IN LENGTH.
269 * ONLY ONE ARGUMENT MAY BE PASSED TO THE SHELL FROM
273 exdata
.ex_shell
[0] = '\0'; /* for zero length files */
275 error
= vn_rdwr(UIO_READ
, vp
, (caddr_t
)&exdata
, sizeof (exdata
), 0,
276 UIO_SYSSPACE
, IO_NODELOCKED
, p
->p_ucred
, &resid
, p
);
282 if (resid
> sizeof(exdata
) - min(sizeof(exdata
.mach_header
),
283 sizeof(exdata
.fat_header
))
284 && exdata
.ex_shell
[0] != '#') {
289 mach_header
= &exdata
.mach_header
;
290 fat_header
= &exdata
.fat_header
;
291 if (mach_header
->magic
== MH_MAGIC
)
293 else if (fat_header
->magic
== FAT_MAGIC
||
294 fat_header
->magic
== FAT_CIGAM
)
296 else if (mach_header
->magic
== MH_CIGAM
) {
300 if (exdata
.ex_shell
[0] != '#' ||
301 exdata
.ex_shell
[1] != '!' ||
306 cp
= &exdata
.ex_shell
[2]; /* skip "#!" */
307 while (cp
< &exdata
.ex_shell
[SHSIZE
]) {
310 else if (*cp
== '\n') {
320 cp
= &exdata
.ex_shell
[2];
324 while (*cp
&& *cp
!= ' ')
333 bcopy((caddr_t
)cp
, (caddr_t
)cfarg
, SHSIZE
);
337 * Support for new app package launching for Mac OS X.
338 * We are about to retry the execve() by changing the path to the
339 * interpreter name. Need to re-initialize the savedpath and
340 * savedpathlen. +1 for NULL.
342 savedpathlen
= (cpnospace
- execnamep
+ 1);
343 error
= copystr(execnamep
, savedpath
, savedpathlen
, &savedpathlen
);
347 /* Save the name aside for future use */
348 execargsp
= (vm_offset_t
*)((char *)(execargs
) + savedpathlen
);
352 nd
.ni_cnd
.cn_nameiop
= LOOKUP
;
353 nd
.ni_cnd
.cn_flags
= (nd
.ni_cnd
.cn_flags
& HASBUF
) |
354 (FOLLOW
| LOCKLEAF
| SAVENAME
);
355 nd
.ni_segflg
= UIO_SYSSPACE
;
356 nd
.ni_dirp
= execnamep
;
357 if ((error
= namei(&nd
)))
360 VOP_LEASE(vp
, p
, cred
, LEASE_READ
);
361 if ((error
= VOP_GETATTR(vp
, &vattr
, p
->p_ucred
, p
)))
367 * Collect arguments on "file" in swap space.
374 * Support for new app package launching for Mac OS X allocates
375 * the "path" at the begining.
376 * execargs get allocated after that
378 cp
= (char *) execargsp
; /* running pointer for copy */
380 * size of execargs less sizeof "path",
381 * a pointer to "path" and a NULL poiter
383 cc
= NCARGS
- savedpathlen
- 2*NBPW
;
385 * Copy arguments into file in argdev area.
387 if (uap
->argp
) for (;;) {
390 if (indir
&& na
== 0) {
391 sharg
= nd
.ni_cnd
.cn_nameptr
;
393 uap
->argp
++; /* ignore argv[0] */
394 } else if (indir
&& (na
== 1 && cfarg
[0])) {
397 } else if (indir
&& (na
== 1 || (na
== 2 && cfarg
[0])))
398 ap
= (int)uap
->fname
;
399 else if (uap
->argp
) {
400 ap
= fuword((caddr_t
)uap
->argp
);
403 if (ap
== NULL
&& uap
->envp
) {
405 if ((ap
= fuword((caddr_t
)uap
->envp
)) != NULL
)
416 if (nc
>= (NCARGS
- savedpathlen
- 2*NBPW
-1)) {
421 error
= copystr(sharg
, cp
, (unsigned)cc
, &len
);
424 error
= copyinstr((caddr_t
)ap
, cp
, (unsigned)cc
,
431 } while (error
== ENAMETOOLONG
);
436 nc
= (nc
+ NBPW
-1) & ~(NBPW
-1);
439 * If we have a fat file, find "our" executable.
443 * Look up our architecture in the fat file.
445 lret
= fatfile_getarch(vp
, (vm_offset_t
)fat_header
, &fat_arch
);
446 if (lret
!= LOAD_SUCCESS
) {
447 error
= load_return_to_errno(lret
);
450 /* Read the Mach-O header out of it */
451 error
= vn_rdwr(UIO_READ
, vp
, (caddr_t
)&exdata
.mach_header
,
452 sizeof (exdata
.mach_header
),
454 UIO_SYSSPACE
, (IO_UNIT
|IO_NODELOCKED
), cred
, &resid
, p
);
460 /* Did we read a complete header? */
466 /* Is what we found a Mach-O executable */
467 if (mach_header
->magic
!= MH_MAGIC
) {
472 arch_offset
= fat_arch
.offset
;
473 arch_size
= fat_arch
.size
;
476 * Load the Mach-O file.
479 arch_size
= (u_long
)vattr
.va_size
;
483 kern_return_t result
;
485 result
= task_create_local(task
, FALSE
, FALSE
, &new_task
);
486 if (result
!= KERN_SUCCESS
)
487 printf("execve: task_create failed. Code: 0x%x\n", result
);
489 set_bsdtask_info(new_task
, p
);
491 map
= get_task_map(new_task
);
492 result
= thread_create(new_task
, &thr_act
);
493 if (result
!= KERN_SUCCESS
)
494 printf("execve: thread_create failed. Code: 0x%x\n", result
);
495 uthread
= get_bsdthread_info(thr_act
);
502 * Load the Mach-O file.
504 VOP_UNLOCK(vp
, 0, p
);
505 lret
= load_machfile(vp
, mach_header
, arch_offset
,
506 arch_size
, &load_result
, thr_act
, map
);
508 if (lret
!= LOAD_SUCCESS
) {
509 error
= load_return_to_errno(lret
);
513 /* load_machfile() maps the vnode */
517 * deal with set[ug]id.
519 p
->p_flag
&= ~P_SUGID
;
520 if (((origvattr
.va_mode
& VSUID
) != 0 &&
521 p
->p_ucred
->cr_uid
!= origvattr
.va_uid
)
522 || (origvattr
.va_mode
& VSGID
) != 0 &&
523 p
->p_ucred
->cr_gid
!= origvattr
.va_gid
) {
524 p
->p_ucred
= crcopy(cred
);
527 * If process is being ktraced, turn off - unless
530 if (p
->p_tracep
&& !(p
->p_traceflag
& KTRFAC_ROOT
)) {
536 if (origvattr
.va_mode
& VSUID
)
537 p
->p_ucred
->cr_uid
= origvattr
.va_uid
;
538 if (origvattr
.va_mode
& VSGID
)
539 p
->p_ucred
->cr_gid
= origvattr
.va_gid
;
541 set_security_token(p
);
542 p
->p_flag
|= P_SUGID
;
544 /* Radar 2261856; setuid security hole fix */
545 /* Patch from OpenBSD: A. Ramesh */
547 * XXX For setuid processes, attempt to ensure that
548 * stdin, stdout, and stderr are already allocated.
549 * We do not want userland to accidentally allocate
550 * descriptors in this range which has implied meaning
553 for (i
= 0; i
< 3; i
++) {
554 extern struct fileops vnops
;
555 struct nameidata nd1
;
559 if (p
->p_fd
->fd_ofiles
[i
] == NULL
) {
560 if ((error
= falloc(p
, &fp
, &indx
)) != 0)
562 NDINIT(&nd1
, LOOKUP
, FOLLOW
, UIO_SYSSPACE
,
564 if ((error
= vn_open(&nd1
, FREAD
, 0)) != 0) {
566 p
->p_fd
->fd_ofiles
[indx
] = NULL
;
570 fp
->f_type
= DTYPE_VNODE
;
572 fp
->f_data
= (caddr_t
)nd1
.ni_vp
;
573 VOP_UNLOCK(nd1
.ni_vp
, 0, p
);
577 p
->p_cred
->p_svuid
= p
->p_ucred
->cr_uid
;
578 p
->p_cred
->p_svgid
= p
->p_ucred
->cr_gid
;
580 if (!vfexec
&& (p
->p_flag
& P_TRACED
)) {
588 VOP_LOCK(vp
, LK_EXCLUSIVE
| LK_RETRY
, p
);
592 if (load_result
.unixproc
&&
593 create_unix_stack(get_task_map(task
),
594 load_result
.user_stack
, load_result
.customstack
, p
)) {
595 error
= load_return_to_errno(LOAD_NOSPACE
);
600 uthread
->uu_ar0
= (void *)get_user_regs(thr_act
);
604 * Copy back arglist if necessary.
610 old_map
= vm_map_switch(get_task_map(task
));
612 if (load_result
.unixproc
) {
615 ucp
= ucp
- nc
- NBPW
; /* begining of the STRING AREA */
618 * Support for new app package launching for Mac OS X allocates
619 * the "path" at the begining of the execargs buffer.
620 * copy it just before the string area.
622 savedpathlen
= (savedpathlen
+ NBPW
-1) & ~(NBPW
-1);
624 pathptr
= ucp
- savedpathlen
;
625 error
= copyoutstr(savedpath
, (caddr_t
)pathptr
,
626 (unsigned)savedpathlen
, &len
);
629 vm_map_switch(old_map
);
633 /* Save a NULL pointer below it */
634 (void) suword((caddr_t
)(pathptr
- NBPW
), 0);
636 /* Save the pointer to "path" just below it */
637 (void) suword((caddr_t
)(pathptr
- 2*NBPW
), pathptr
);
640 * na includes arg[] and env[].
641 * NBPW for 2 NULL one each ofter arg[argc -1] and env[n]
643 * skip over saved path, NBPW for pointer to path,
644 * and NBPW for the NULL after pointer to path.
646 ap
= ucp
- na
*NBPW
- 3*NBPW
- savedpathlen
- 2*NBPW
;
647 uthread
->uu_ar0
[SP
] = ap
;
648 (void) suword((caddr_t
)ap
, na
-ne
); /* argc */
652 cp
= (char *) execargsp
;
653 cc
= NCARGS
- savedpathlen
- 2*NBPW
;
654 ps
.ps_argvstr
= (char *)ucp
; /* first argv string */
655 ps
.ps_nargvstr
= na
- ne
; /* argc */
659 (void) suword((caddr_t
)ap
, 0);
661 ps
.ps_envstr
= (char *)ucp
;
666 (void) suword((caddr_t
)ap
, ucp
);
668 error
= copyoutstr(cp
, (caddr_t
)ucp
,
674 } while (error
== ENAMETOOLONG
);
676 break; /* bad stack - user's problem */
678 (void) suword((caddr_t
)ap
, 0);
681 if (load_result
.dynlinker
) {
682 ap
= uthread
->uu_ar0
[SP
] -= 4;
683 (void) suword((caddr_t
)ap
, load_result
.mach_header
);
687 vm_map_switch(old_map
);
689 #if defined(i386) || defined(ppc)
690 uthread
->uu_ar0
[PC
] = load_result
.entry_point
;
692 #error architecture not implemented!
699 * Reset signal state.
704 * Close file descriptors
705 * which specify close-on-exec.
708 /* FIXME: Till vmspace inherit is fixed: */
713 * Remember file name for accounting.
715 p
->p_acflag
&= ~AFORK
;
716 if (nd
.ni_cnd
.cn_namelen
> MAXCOMLEN
)
717 nd
.ni_cnd
.cn_namelen
= MAXCOMLEN
;
718 bcopy((caddr_t
)nd
.ni_cnd
.cn_nameptr
, (caddr_t
)p
->p_comm
,
719 (unsigned)nd
.ni_cnd
.cn_namelen
);
720 p
->p_comm
[nd
.ni_cnd
.cn_namelen
] = '\0';
723 /* This is for kdebug */
724 long dbg_arg1
, dbg_arg2
, dbg_arg3
, dbg_arg4
;
726 /* Collect the pathname for tracing */
727 kdbg_trace_string(p
, &dbg_arg1
, &dbg_arg2
, &dbg_arg3
, &dbg_arg4
);
730 KERNEL_DEBUG_CONSTANT1((TRACEDBG_CODE(DBG_TRACE_STRING
, 2)) | DBG_FUNC_NONE
,
731 dbg_arg1
, dbg_arg2
, dbg_arg3
, dbg_arg4
, getshuttle_thread(thr_act
));
733 KERNEL_DEBUG_CONSTANT((TRACEDBG_CODE(DBG_TRACE_STRING
, 2)) | DBG_FUNC_NONE
,
734 dbg_arg1
, dbg_arg2
, dbg_arg3
, dbg_arg4
, 0);
738 * mark as execed, wakeup the process that vforked (if any) and tell
739 * it that it now has it's own resources back
742 if (p
->p_pptr
&& (p
->p_flag
& P_PPWAIT
)) {
743 p
->p_flag
&= ~P_PPWAIT
;
744 wakeup((caddr_t
)p
->p_pptr
);
747 if (vfexec
&& (p
->p_flag
& P_TRACED
)) {
748 psignal_vfork(p
, new_task
, thr_act
, SIGTRAP
);
753 (void) thread_resume(thr_act
);
754 task_deallocate(new_task
);
755 act_deallocate(thr_act
);
760 FREE_ZONE(nd
.ni_cnd
.cn_pnbuf
, nd
.ni_cnd
.cn_pnlen
, M_NAMEI
);
765 kmem_free(bsd_pageable_map
, execargs
, NCARGS
);
766 if (!error
&& vfexec
) {
767 vfork_return(current_act(), p
->p_pptr
, p
, retval
);
774 #define unix_stack_size(p) (p->p_rlimit[RLIMIT_STACK].rlim_cur)
777 create_unix_stack(map
, user_stack
, customstack
, p
)
779 vm_offset_t user_stack
;
786 p
->user_stack
= user_stack
;
788 size
= round_page(unix_stack_size(p
));
789 addr
= trunc_page(user_stack
- size
);
790 return (vm_allocate(map
,&addr
, size
, FALSE
));
792 return(KERN_SUCCESS
);
795 #include <sys/reboot.h>
797 char init_program_name
[128] = "/sbin/mach_init\0";
799 char init_args
[128] = "";
801 struct execve_args init_exec_args
;
802 int init_attempts
= 0;
809 vm_offset_t init_addr
;
813 register_t retval
[2];
820 /* init_args are copied in string form directly from bootstrap */
823 if (boothowto
& RB_INITNAME
) {
824 printf("init program? ");
826 gets(init_program_name
, init_program_name
);
830 if (error
&& ((boothowto
& RB_INITNAME
) == 0) &&
831 (init_attempts
== 1)) {
832 static char other_init
[] = "/etc/mach_init";
833 printf("Load of %s, errno %d, trying %s\n",
834 init_program_name
, error
, other_init
);
836 bcopy(other_init
, init_program_name
,
843 printf("Load of %s failed, errno %d\n",
844 init_program_name
, error
);
846 boothowto
|= RB_INITNAME
;
851 * Copy out program name.
854 init_addr
= VM_MIN_ADDRESS
;
855 (void) vm_allocate(current_map(), &init_addr
,
859 (void) copyout((caddr_t
) init_program_name
,
860 (caddr_t
) (init_addr
),
861 (unsigned) sizeof(init_program_name
)+1);
863 argv
[0] = (char *) init_addr
;
864 init_addr
+= sizeof(init_program_name
);
865 init_addr
= (vm_offset_t
)ROUND_PTR(char, init_addr
);
868 * Put out first (and only) argument, similarly.
869 * Assumes everything fits in a page as allocated
873 (void) copyout((caddr_t
) init_args
,
874 (caddr_t
) (init_addr
),
875 (unsigned) sizeof(init_args
));
877 argv
[1] = (char *) init_addr
;
878 init_addr
+= sizeof(init_args
);
879 init_addr
= (vm_offset_t
)ROUND_PTR(char, init_addr
);
882 * Null-end the argument list
885 argv
[2] = (char *) 0;
888 * Copy out the argument list.
891 (void) copyout((caddr_t
) argv
,
892 (caddr_t
) (init_addr
),
893 (unsigned) sizeof(argv
));
896 * Set up argument block for fake call to execve.
899 init_exec_args
.fname
= argv
[0];
900 init_exec_args
.argp
= (char **) init_addr
;
901 init_exec_args
.envp
= 0;
903 /* So that mach_init task
904 * is set with uid,gid 0 token
906 set_security_token(p
);
908 error
= execve(p
,&init_exec_args
,retval
);
915 * Convert a load_return_t to an errno.
918 load_return_to_errno(load_return_t lrtn
)
941 * exec_check_access()
944 check_exec_access(p
, vp
, vap
)
952 if (error
= VOP_ACCESS(vp
, VEXEC
, p
->p_ucred
, p
))
955 if (flag
& P_TRACED
) {
956 if (error
= VOP_ACCESS(vp
, VREAD
, p
->p_ucred
, p
))
959 if (vp
->v_type
!= VREG
||
960 (vap
->va_mode
& (S_IXUSR
| S_IXGRP
| S_IXOTH
)) == 0)