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
);
115 static int execargs_alloc(vm_offset_t
*addrp
);
116 static int execargs_free(vm_offset_t addr
);
119 execv(p
, args
, retval
)
124 ((struct execve_args
*)args
)->envp
= NULL
;
125 return (execve(p
, args
, retval
));
130 execve(p
, uap
, retval
)
131 register struct proc
*p
;
132 register struct execve_args
*uap
;
135 register struct ucred
*cred
= p
->p_ucred
;
136 register struct filedesc
*fdp
= p
->p_fd
;
139 int na
, ne
, ucp
, ap
, cc
;
146 struct vattr origvattr
;
147 vm_offset_t execargs
;
149 struct ps_strings ps
;
154 struct mach_header
*mach_header
;
155 struct fat_header
*fat_header
;
156 struct fat_arch fat_arch
;
158 load_result_t load_result
;
159 struct uthread
*uthread
;
164 /* #! and name of interpreter */
165 char ex_shell
[SHSIZE
];
166 /* Mach-O executable */
167 struct mach_header mach_header
;
169 struct fat_header fat_header
;
174 int savedpathlen
= 0;
175 vm_offset_t
*execargsp
;
179 thread_act_t thr_act
;
182 unsigned long arch_offset
=0;
183 unsigned long arch_size
= 0;
185 task
= current_task();
186 thr_act
= current_act();
187 uthread
= get_bsdthread_info(thr_act
);
189 if (uthread
->uu_flag
& P_VFORK
) {
190 vfexec
= 1; /* Mark in exec */
192 if (task
!= kernel_task
) {
193 numthreads
= get_task_numacts(task
);
194 if (numthreads
<= 0 )
196 if (numthreads
> 1) {
202 error
= execargs_alloc(&execargs
);
206 savedpath
= execargs
;
209 * To support new app package launching for Mac OS X, the dyld
210 * needs the first argument to execve() stored on the user stack.
211 * Copyin the "path" at the begining of the "execargs" buffer
214 * We have to do this before namei() because in case of
215 * symbolic links, namei() would overwrite the original "path".
216 * In case the last symbolic link resolved was a relative pathname
217 * we would loose the original "path", which could be an
218 * absolute pathname. This might be unacceptable for dyld.
220 /* XXX We could optimize to avoid copyinstr in the namei() */
222 error
= copyinstr(uap
->fname
, savedpath
, MAXPATHLEN
, &savedpathlen
);
226 * copyinstr will put in savedpathlen, the count of
227 * characters (including NULL) in the path.
230 /* Save the name aside for future use */
231 execargsp
= (vm_offset_t
*)((char *)(execargs
) + savedpathlen
);
233 NDINIT(&nd
, LOOKUP
, FOLLOW
| LOCKLEAF
| SAVENAME
,
234 UIO_USERSPACE
, uap
->fname
, p
);
235 if ((error
= namei(&nd
)))
238 VOP_LEASE(vp
, p
, p
->p_ucred
, LEASE_READ
);
240 if ((error
= VOP_GETATTR(vp
, &origvattr
, p
->p_ucred
, p
)))
243 /* Check mount point */
244 if (vp
->v_mount
->mnt_flag
& MNT_NOEXEC
) {
250 if ((vp
->v_mount
->mnt_flag
& MNT_NOSUID
) || (p
->p_flag
& P_TRACED
))
251 origvattr
.va_mode
&= ~(VSUID
| VSGID
);
253 *(&vattr
) = *(&origvattr
);
256 error
= check_exec_access(p
, vp
, &vattr
);
261 * Read in first few bytes of file for segment sizes, magic number:
262 * 407 = plain executable
264 * 413 = demand paged RO text
265 * Also an ASCII line beginning with #! is
266 * the file name of a ``shell'' and arguments may be prepended
267 * to the argument list if given here.
269 * SHELL NAMES ARE LIMITED IN LENGTH.
271 * ONLY ONE ARGUMENT MAY BE PASSED TO THE SHELL FROM
275 exdata
.ex_shell
[0] = '\0'; /* for zero length files */
277 error
= vn_rdwr(UIO_READ
, vp
, (caddr_t
)&exdata
, sizeof (exdata
), 0,
278 UIO_SYSSPACE
, IO_NODELOCKED
, p
->p_ucred
, &resid
, p
);
284 if (resid
> sizeof(exdata
) - min(sizeof(exdata
.mach_header
),
285 sizeof(exdata
.fat_header
))
286 && exdata
.ex_shell
[0] != '#') {
291 mach_header
= &exdata
.mach_header
;
292 fat_header
= &exdata
.fat_header
;
293 if (mach_header
->magic
== MH_MAGIC
)
295 else if (fat_header
->magic
== FAT_MAGIC
||
296 fat_header
->magic
== FAT_CIGAM
)
298 else if (mach_header
->magic
== MH_CIGAM
) {
302 if (exdata
.ex_shell
[0] != '#' ||
303 exdata
.ex_shell
[1] != '!' ||
308 cp
= &exdata
.ex_shell
[2]; /* skip "#!" */
309 while (cp
< &exdata
.ex_shell
[SHSIZE
]) {
312 else if (*cp
== '\n') {
322 cp
= &exdata
.ex_shell
[2];
326 while (*cp
&& *cp
!= ' ')
335 bcopy((caddr_t
)cp
, (caddr_t
)cfarg
, SHSIZE
);
339 * Support for new app package launching for Mac OS X.
340 * We are about to retry the execve() by changing the path to the
341 * interpreter name. Need to re-initialize the savedpath and
342 * savedpathlen. +1 for NULL.
344 savedpathlen
= (cpnospace
- execnamep
+ 1);
345 error
= copystr(execnamep
, savedpath
, savedpathlen
, &savedpathlen
);
349 /* Save the name aside for future use */
350 execargsp
= (vm_offset_t
*)((char *)(execargs
) + savedpathlen
);
354 nd
.ni_cnd
.cn_nameiop
= LOOKUP
;
355 nd
.ni_cnd
.cn_flags
= (nd
.ni_cnd
.cn_flags
& HASBUF
) |
356 (FOLLOW
| LOCKLEAF
| SAVENAME
);
357 nd
.ni_segflg
= UIO_SYSSPACE
;
358 nd
.ni_dirp
= execnamep
;
359 if ((error
= namei(&nd
)))
362 VOP_LEASE(vp
, p
, cred
, LEASE_READ
);
363 if ((error
= VOP_GETATTR(vp
, &vattr
, p
->p_ucred
, p
)))
369 * Collect arguments on "file" in swap space.
376 * Support for new app package launching for Mac OS X allocates
377 * the "path" at the begining.
378 * execargs get allocated after that
380 cp
= (char *) execargsp
; /* running pointer for copy */
382 * size of execargs less sizeof "path",
383 * a pointer to "path" and a NULL poiter
385 cc
= NCARGS
- savedpathlen
- 2*NBPW
;
387 * Copy arguments into file in argdev area.
389 if (uap
->argp
) for (;;) {
392 if (indir
&& na
== 0) {
393 sharg
= nd
.ni_cnd
.cn_nameptr
;
395 uap
->argp
++; /* ignore argv[0] */
396 } else if (indir
&& (na
== 1 && cfarg
[0])) {
399 } else if (indir
&& (na
== 1 || (na
== 2 && cfarg
[0])))
400 ap
= (int)uap
->fname
;
401 else if (uap
->argp
) {
402 ap
= fuword((caddr_t
)uap
->argp
);
405 if (ap
== NULL
&& uap
->envp
) {
407 if ((ap
= fuword((caddr_t
)uap
->envp
)) != NULL
)
418 if (nc
>= (NCARGS
- savedpathlen
- 2*NBPW
-1)) {
423 error
= copystr(sharg
, cp
, (unsigned)cc
, &len
);
426 error
= copyinstr((caddr_t
)ap
, cp
, (unsigned)cc
,
433 } while (error
== ENAMETOOLONG
);
438 nc
= (nc
+ NBPW
-1) & ~(NBPW
-1);
441 * If we have a fat file, find "our" executable.
445 * Look up our architecture in the fat file.
447 lret
= fatfile_getarch(vp
, (vm_offset_t
)fat_header
, &fat_arch
);
448 if (lret
!= LOAD_SUCCESS
) {
449 error
= load_return_to_errno(lret
);
452 /* Read the Mach-O header out of it */
453 error
= vn_rdwr(UIO_READ
, vp
, (caddr_t
)&exdata
.mach_header
,
454 sizeof (exdata
.mach_header
),
456 UIO_SYSSPACE
, (IO_UNIT
|IO_NODELOCKED
), cred
, &resid
, p
);
462 /* Did we read a complete header? */
468 /* Is what we found a Mach-O executable */
469 if (mach_header
->magic
!= MH_MAGIC
) {
474 arch_offset
= fat_arch
.offset
;
475 arch_size
= fat_arch
.size
;
478 * Load the Mach-O file.
481 arch_size
= (u_long
)vattr
.va_size
;
485 kern_return_t result
;
487 result
= task_create_local(task
, FALSE
, FALSE
, &new_task
);
488 if (result
!= KERN_SUCCESS
)
489 printf("execve: task_create failed. Code: 0x%x\n", result
);
491 set_bsdtask_info(new_task
, p
);
493 map
= get_task_map(new_task
);
494 result
= thread_create(new_task
, &thr_act
);
495 if (result
!= KERN_SUCCESS
)
496 printf("execve: thread_create failed. Code: 0x%x\n", result
);
497 uthread
= get_bsdthread_info(thr_act
);
504 * Load the Mach-O file.
506 VOP_UNLOCK(vp
, 0, p
);
507 lret
= load_machfile(vp
, mach_header
, arch_offset
,
508 arch_size
, &load_result
, thr_act
, map
);
510 if (lret
!= LOAD_SUCCESS
) {
511 error
= load_return_to_errno(lret
);
515 /* load_machfile() maps the vnode */
519 * deal with set[ug]id.
521 p
->p_flag
&= ~P_SUGID
;
522 if (((origvattr
.va_mode
& VSUID
) != 0 &&
523 p
->p_ucred
->cr_uid
!= origvattr
.va_uid
)
524 || (origvattr
.va_mode
& VSGID
) != 0 &&
525 p
->p_ucred
->cr_gid
!= origvattr
.va_gid
) {
526 p
->p_ucred
= crcopy(cred
);
529 * If process is being ktraced, turn off - unless
532 if (p
->p_tracep
&& !(p
->p_traceflag
& KTRFAC_ROOT
)) {
538 if (origvattr
.va_mode
& VSUID
)
539 p
->p_ucred
->cr_uid
= origvattr
.va_uid
;
540 if (origvattr
.va_mode
& VSGID
)
541 p
->p_ucred
->cr_gid
= origvattr
.va_gid
;
543 set_security_token(p
);
544 p
->p_flag
|= P_SUGID
;
546 /* Radar 2261856; setuid security hole fix */
547 /* Patch from OpenBSD: A. Ramesh */
549 * XXX For setuid processes, attempt to ensure that
550 * stdin, stdout, and stderr are already allocated.
551 * We do not want userland to accidentally allocate
552 * descriptors in this range which has implied meaning
555 for (i
= 0; i
< 3; i
++) {
556 extern struct fileops vnops
;
557 struct nameidata nd1
;
561 if (p
->p_fd
->fd_ofiles
[i
] == NULL
) {
562 if ((error
= falloc(p
, &fp
, &indx
)) != 0)
564 NDINIT(&nd1
, LOOKUP
, FOLLOW
, UIO_SYSSPACE
,
566 if ((error
= vn_open(&nd1
, FREAD
, 0)) != 0) {
568 p
->p_fd
->fd_ofiles
[indx
] = NULL
;
572 fp
->f_type
= DTYPE_VNODE
;
574 fp
->f_data
= (caddr_t
)nd1
.ni_vp
;
575 VOP_UNLOCK(nd1
.ni_vp
, 0, p
);
579 p
->p_cred
->p_svuid
= p
->p_ucred
->cr_uid
;
580 p
->p_cred
->p_svgid
= p
->p_ucred
->cr_gid
;
582 if (!vfexec
&& (p
->p_flag
& P_TRACED
)) {
590 VOP_LOCK(vp
, LK_EXCLUSIVE
| LK_RETRY
, p
);
594 if (load_result
.unixproc
&&
595 create_unix_stack(get_task_map(task
),
596 load_result
.user_stack
, load_result
.customstack
, p
)) {
597 error
= load_return_to_errno(LOAD_NOSPACE
);
602 uthread
->uu_ar0
= (void *)get_user_regs(thr_act
);
606 * Copy back arglist if necessary.
612 old_map
= vm_map_switch(get_task_map(task
));
614 if (load_result
.unixproc
) {
617 ucp
= ucp
- nc
- NBPW
; /* begining of the STRING AREA */
620 * Support for new app package launching for Mac OS X allocates
621 * the "path" at the begining of the execargs buffer.
622 * copy it just before the string area.
624 savedpathlen
= (savedpathlen
+ NBPW
-1) & ~(NBPW
-1);
626 pathptr
= ucp
- savedpathlen
;
627 error
= copyoutstr(savedpath
, (caddr_t
)pathptr
,
628 (unsigned)savedpathlen
, &len
);
631 vm_map_switch(old_map
);
635 /* Save a NULL pointer below it */
636 (void) suword((caddr_t
)(pathptr
- NBPW
), 0);
638 /* Save the pointer to "path" just below it */
639 (void) suword((caddr_t
)(pathptr
- 2*NBPW
), pathptr
);
642 * na includes arg[] and env[].
643 * NBPW for 2 NULL one each ofter arg[argc -1] and env[n]
645 * skip over saved path, NBPW for pointer to path,
646 * and NBPW for the NULL after pointer to path.
648 ap
= ucp
- na
*NBPW
- 3*NBPW
- savedpathlen
- 2*NBPW
;
649 uthread
->uu_ar0
[SP
] = ap
;
650 (void) suword((caddr_t
)ap
, na
-ne
); /* argc */
654 cp
= (char *) execargsp
;
655 cc
= NCARGS
- savedpathlen
- 2*NBPW
;
656 ps
.ps_argvstr
= (char *)ucp
; /* first argv string */
657 ps
.ps_nargvstr
= na
- ne
; /* argc */
661 (void) suword((caddr_t
)ap
, 0);
663 ps
.ps_envstr
= (char *)ucp
;
668 (void) suword((caddr_t
)ap
, ucp
);
670 error
= copyoutstr(cp
, (caddr_t
)ucp
,
676 } while (error
== ENAMETOOLONG
);
678 break; /* bad stack - user's problem */
680 (void) suword((caddr_t
)ap
, 0);
683 if (load_result
.dynlinker
) {
684 ap
= uthread
->uu_ar0
[SP
] -= 4;
685 (void) suword((caddr_t
)ap
, load_result
.mach_header
);
689 vm_map_switch(old_map
);
691 #if defined(i386) || defined(ppc)
692 uthread
->uu_ar0
[PC
] = load_result
.entry_point
;
694 #error architecture not implemented!
701 * Reset signal state.
706 * Close file descriptors
707 * which specify close-on-exec.
710 /* FIXME: Till vmspace inherit is fixed: */
715 * Remember file name for accounting.
717 p
->p_acflag
&= ~AFORK
;
718 if (nd
.ni_cnd
.cn_namelen
> MAXCOMLEN
)
719 nd
.ni_cnd
.cn_namelen
= MAXCOMLEN
;
720 bcopy((caddr_t
)nd
.ni_cnd
.cn_nameptr
, (caddr_t
)p
->p_comm
,
721 (unsigned)nd
.ni_cnd
.cn_namelen
);
722 p
->p_comm
[nd
.ni_cnd
.cn_namelen
] = '\0';
725 /* This is for kdebug */
726 long dbg_arg1
, dbg_arg2
, dbg_arg3
, dbg_arg4
;
728 /* Collect the pathname for tracing */
729 kdbg_trace_string(p
, &dbg_arg1
, &dbg_arg2
, &dbg_arg3
, &dbg_arg4
);
732 KERNEL_DEBUG_CONSTANT1((TRACEDBG_CODE(DBG_TRACE_STRING
, 2)) | DBG_FUNC_NONE
,
733 dbg_arg1
, dbg_arg2
, dbg_arg3
, dbg_arg4
, getshuttle_thread(thr_act
));
735 KERNEL_DEBUG_CONSTANT((TRACEDBG_CODE(DBG_TRACE_STRING
, 2)) | DBG_FUNC_NONE
,
736 dbg_arg1
, dbg_arg2
, dbg_arg3
, dbg_arg4
, 0);
740 * mark as execed, wakeup the process that vforked (if any) and tell
741 * it that it now has it's own resources back
744 if (p
->p_pptr
&& (p
->p_flag
& P_PPWAIT
)) {
745 p
->p_flag
&= ~P_PPWAIT
;
746 wakeup((caddr_t
)p
->p_pptr
);
749 if (vfexec
&& (p
->p_flag
& P_TRACED
)) {
750 psignal_vfork(p
, new_task
, thr_act
, SIGTRAP
);
755 (void) thread_resume(thr_act
);
756 task_deallocate(new_task
);
757 act_deallocate(thr_act
);
762 FREE_ZONE(nd
.ni_cnd
.cn_pnbuf
, nd
.ni_cnd
.cn_pnlen
, M_NAMEI
);
767 execargs_free(execargs
);
768 if (!error
&& vfexec
) {
769 vfork_return(current_act(), p
->p_pptr
, p
, retval
);
776 #define unix_stack_size(p) (p->p_rlimit[RLIMIT_STACK].rlim_cur)
779 create_unix_stack(map
, user_stack
, customstack
, p
)
781 vm_offset_t user_stack
;
788 p
->user_stack
= user_stack
;
790 size
= round_page(unix_stack_size(p
));
791 addr
= trunc_page(user_stack
- size
);
792 return (vm_allocate(map
,&addr
, size
, FALSE
));
794 return(KERN_SUCCESS
);
797 #include <sys/reboot.h>
799 char init_program_name
[128] = "/sbin/mach_init\0";
801 char init_args
[128] = "";
803 struct execve_args init_exec_args
;
804 int init_attempts
= 0;
811 vm_offset_t init_addr
;
815 register_t retval
[2];
822 /* init_args are copied in string form directly from bootstrap */
825 if (boothowto
& RB_INITNAME
) {
826 printf("init program? ");
828 gets(init_program_name
, init_program_name
);
832 if (error
&& ((boothowto
& RB_INITNAME
) == 0) &&
833 (init_attempts
== 1)) {
834 static char other_init
[] = "/etc/mach_init";
835 printf("Load of %s, errno %d, trying %s\n",
836 init_program_name
, error
, other_init
);
838 bcopy(other_init
, init_program_name
,
845 printf("Load of %s failed, errno %d\n",
846 init_program_name
, error
);
848 boothowto
|= RB_INITNAME
;
853 * Copy out program name.
856 init_addr
= VM_MIN_ADDRESS
;
857 (void) vm_allocate(current_map(), &init_addr
,
861 (void) copyout((caddr_t
) init_program_name
,
862 (caddr_t
) (init_addr
),
863 (unsigned) sizeof(init_program_name
)+1);
865 argv
[0] = (char *) init_addr
;
866 init_addr
+= sizeof(init_program_name
);
867 init_addr
= (vm_offset_t
)ROUND_PTR(char, init_addr
);
870 * Put out first (and only) argument, similarly.
871 * Assumes everything fits in a page as allocated
875 (void) copyout((caddr_t
) init_args
,
876 (caddr_t
) (init_addr
),
877 (unsigned) sizeof(init_args
));
879 argv
[1] = (char *) init_addr
;
880 init_addr
+= sizeof(init_args
);
881 init_addr
= (vm_offset_t
)ROUND_PTR(char, init_addr
);
884 * Null-end the argument list
887 argv
[2] = (char *) 0;
890 * Copy out the argument list.
893 (void) copyout((caddr_t
) argv
,
894 (caddr_t
) (init_addr
),
895 (unsigned) sizeof(argv
));
898 * Set up argument block for fake call to execve.
901 init_exec_args
.fname
= argv
[0];
902 init_exec_args
.argp
= (char **) init_addr
;
903 init_exec_args
.envp
= 0;
905 /* So that mach_init task
906 * is set with uid,gid 0 token
908 set_security_token(p
);
910 error
= execve(p
,&init_exec_args
,retval
);
917 * Convert a load_return_t to an errno.
920 load_return_to_errno(load_return_t lrtn
)
943 * exec_check_access()
946 check_exec_access(p
, vp
, vap
)
954 if (error
= VOP_ACCESS(vp
, VEXEC
, p
->p_ucred
, p
))
957 if (flag
& P_TRACED
) {
958 if (error
= VOP_ACCESS(vp
, VREAD
, p
->p_ucred
, p
))
961 if (vp
->v_type
!= VREG
||
962 (vap
->va_mode
& (S_IXUSR
| S_IXGRP
| S_IXOTH
)) == 0)
967 #include <mach/mach_types.h>
968 #include <mach/vm_prot.h>
969 #include <mach/semaphore.h>
970 #include <mach/sync_policy.h>
971 #include <kern/clock.h>
972 #include <mach/kern_return.h>
974 extern semaphore_t execve_semaphore
;
977 execargs_alloc(addrp
)
982 kret
= semaphore_wait(execve_semaphore
);
983 if (kret
!= KERN_SUCCESS
)
987 case KERN_INVALID_ADDRESS
:
988 case KERN_PROTECTION_FAILURE
:
991 case KERN_OPERATION_TIMED_OUT
:
995 kret
= kmem_alloc_pageable(bsd_pageable_map
, addrp
, NCARGS
);
996 if (kret
!= KERN_SUCCESS
)
1008 kmem_free(bsd_pageable_map
, addr
, NCARGS
);
1010 kret
= semaphore_signal(execve_semaphore
);
1012 case KERN_INVALID_ADDRESS
:
1013 case KERN_PROTECTION_FAILURE
:
1016 case KERN_OPERATION_TIMED_OUT
: