kern_exec.c (1e1e0b44635dd1f8946929ef8a136ca65afb170a) kern_exec.c (68940ac1a05aed6f6ec47c8540a640f3eab17f79)
1/*
2 * Copyright (c) 1993, David Greenman
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 14 unchanged lines hidden (view full) ---

23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
1/*
2 * Copyright (c) 1993, David Greenman
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 14 unchanged lines hidden (view full) ---

23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * $Id: kern_exec.c,v 1.11 1995/01/09 16:04:49 davidg Exp $
31 * $Id: kern_exec.c,v 1.12 1995/02/14 19:22:28 sos Exp $
32 */
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/signalvar.h>
37#include <sys/resourcevar.h>
38#include <sys/kernel.h>
39#include <sys/mount.h>

--- 53 unchanged lines hidden (view full) ---

93 iparams->proc = p;
94 iparams->uap = uap;
95 iparams->attr = &attr;
96
97 /*
98 * Allocate temporary demand zeroed space for argument and
99 * environment strings
100 */
32 */
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/signalvar.h>
37#include <sys/resourcevar.h>
38#include <sys/kernel.h>
39#include <sys/mount.h>

--- 53 unchanged lines hidden (view full) ---

93 iparams->proc = p;
94 iparams->uap = uap;
95 iparams->attr = &attr;
96
97 /*
98 * Allocate temporary demand zeroed space for argument and
99 * environment strings
100 */
101 error = vm_allocate(exec_map, (vm_offset_t *)&iparams->stringbase,
102 ARG_MAX, TRUE);
101 iparams->stringbase = (char *)vm_map_min(exec_map);
102 error = vm_map_find(exec_map, NULL, 0, (vm_offset_t *)&iparams->stringbase,
103 ARG_MAX, TRUE);
103 if (error) {
104 log(LOG_WARNING, "execve: failed to allocate string space\n");
105 return (error);
106 }
107
108 if (!iparams->stringbase) {
109 error = ENOMEM;
110 goto exec_fail;

--- 12 unchanged lines hidden (view full) ---

123 ndp->ni_cnd.cn_cred = curproc->p_cred->pc_ucred;
124 ndp->ni_segflg = UIO_USERSPACE;
125 ndp->ni_dirp = uap->fname;
126
127interpret:
128
129 error = namei(ndp);
130 if (error) {
104 if (error) {
105 log(LOG_WARNING, "execve: failed to allocate string space\n");
106 return (error);
107 }
108
109 if (!iparams->stringbase) {
110 error = ENOMEM;
111 goto exec_fail;

--- 12 unchanged lines hidden (view full) ---

124 ndp->ni_cnd.cn_cred = curproc->p_cred->pc_ucred;
125 ndp->ni_segflg = UIO_USERSPACE;
126 ndp->ni_dirp = uap->fname;
127
128interpret:
129
130 error = namei(ndp);
131 if (error) {
131 vm_deallocate(exec_map, (vm_offset_t)iparams->stringbase,
132 ARG_MAX);
132 vm_map_remove(exec_map, (vm_offset_t)iparams->stringbase,
133 (vm_offset_t)iparams->stringbase + ARG_MAX);
133 goto exec_fail;
134 }
135
136 iparams->vnodep = vnodep = ndp->ni_vp;
137
138 if (vnodep == NULL) {
139 error = ENOEXEC;
140 goto exec_fail_dealloc;

--- 41 unchanged lines hidden (view full) ---

182 if (error == -1)
183 continue;
184 if (error)
185 goto exec_fail_dealloc;
186 if (iparams->interpreted) {
187 /* free old vnode and name buffer */
188 vput(ndp->ni_vp);
189 FREE(ndp->ni_cnd.cn_pnbuf, M_NAMEI);
134 goto exec_fail;
135 }
136
137 iparams->vnodep = vnodep = ndp->ni_vp;
138
139 if (vnodep == NULL) {
140 error = ENOEXEC;
141 goto exec_fail_dealloc;

--- 41 unchanged lines hidden (view full) ---

183 if (error == -1)
184 continue;
185 if (error)
186 goto exec_fail_dealloc;
187 if (iparams->interpreted) {
188 /* free old vnode and name buffer */
189 vput(ndp->ni_vp);
190 FREE(ndp->ni_cnd.cn_pnbuf, M_NAMEI);
190 if (vm_deallocate(kernel_map,
191 (vm_offset_t)image_header, PAGE_SIZE))
191 if (vm_map_remove(kernel_map, (vm_offset_t)image_header,
192 (vm_offset_t)image_header + PAGE_SIZE))
192 panic("execve: header dealloc failed (1)");
193
194 /* set new name to that of the interpreter */
195 ndp->ni_segflg = UIO_SYSSPACE;
196 ndp->ni_dirp = iparams->interpreter_name;
197 ndp->ni_cnd.cn_nameiop = LOOKUP;
198 ndp->ni_cnd.cn_flags = LOCKLEAF | FOLLOW | SAVENAME;
199 ndp->ni_cnd.cn_proc = curproc;

--- 97 unchanged lines hidden (view full) ---

297 p->p_acflag &= ~AFORK;
298
299 /* Set entry address */
300 setregs(p, iparams->entry_addr, (u_long)stack_base);
301
302 /*
303 * free various allocated resources
304 */
193 panic("execve: header dealloc failed (1)");
194
195 /* set new name to that of the interpreter */
196 ndp->ni_segflg = UIO_SYSSPACE;
197 ndp->ni_dirp = iparams->interpreter_name;
198 ndp->ni_cnd.cn_nameiop = LOOKUP;
199 ndp->ni_cnd.cn_flags = LOCKLEAF | FOLLOW | SAVENAME;
200 ndp->ni_cnd.cn_proc = curproc;

--- 97 unchanged lines hidden (view full) ---

298 p->p_acflag &= ~AFORK;
299
300 /* Set entry address */
301 setregs(p, iparams->entry_addr, (u_long)stack_base);
302
303 /*
304 * free various allocated resources
305 */
305 if (vm_deallocate(exec_map, (vm_offset_t)iparams->stringbase, ARG_MAX))
306 if (vm_map_remove(exec_map, (vm_offset_t)iparams->stringbase,
307 (vm_offset_t)iparams->stringbase + ARG_MAX))
306 panic("execve: string buffer dealloc failed (1)");
308 panic("execve: string buffer dealloc failed (1)");
307 if (vm_deallocate(kernel_map, (vm_offset_t)image_header, PAGE_SIZE))
309 if (vm_map_remove(kernel_map, (vm_offset_t)image_header,
310 (vm_offset_t)image_header + PAGE_SIZE))
308 panic("execve: header dealloc failed (2)");
309 vput(ndp->ni_vp);
310 FREE(ndp->ni_cnd.cn_pnbuf, M_NAMEI);
311
312 return (0);
313
314exec_fail_dealloc:
315 if (iparams->stringbase && iparams->stringbase != (char *)-1)
311 panic("execve: header dealloc failed (2)");
312 vput(ndp->ni_vp);
313 FREE(ndp->ni_cnd.cn_pnbuf, M_NAMEI);
314
315 return (0);
316
317exec_fail_dealloc:
318 if (iparams->stringbase && iparams->stringbase != (char *)-1)
316 if (vm_deallocate(exec_map, (vm_offset_t)iparams->stringbase,
317 ARG_MAX))
319 if (vm_map_remove(exec_map, (vm_offset_t)iparams->stringbase,
320 (vm_offset_t)iparams->stringbase + ARG_MAX))
318 panic("execve: string buffer dealloc failed (2)");
319 if (iparams->image_header && iparams->image_header != (char *)-1)
321 panic("execve: string buffer dealloc failed (2)");
322 if (iparams->image_header && iparams->image_header != (char *)-1)
320 if (vm_deallocate(kernel_map,
321 (vm_offset_t)iparams->image_header, PAGE_SIZE))
323 if (vm_map_remove(kernel_map, (vm_offset_t)image_header,
324 (vm_offset_t)image_header + PAGE_SIZE))
322 panic("execve: header dealloc failed (3)");
323 vput(ndp->ni_vp);
324 FREE(ndp->ni_cnd.cn_pnbuf, M_NAMEI);
325
326exec_fail:
327 if (iparams->vmspace_destroyed) {
328 /* sorry, no more process anymore. exit gracefully */
325 panic("execve: header dealloc failed (3)");
326 vput(ndp->ni_vp);
327 FREE(ndp->ni_cnd.cn_pnbuf, M_NAMEI);
328
329exec_fail:
330 if (iparams->vmspace_destroyed) {
331 /* sorry, no more process anymore. exit gracefully */
329#if 0 /* XXX */
330 vm_deallocate(&vs->vm_map, USRSTACK - MAXSSIZ, MAXSSIZ);
331#endif
332 exit1(p, W_EXITCODE(0, SIGABRT));
333 /* NOT REACHED */
334 return(0);
335 } else {
336 return(error);
337 }
338}
339

--- 12 unchanged lines hidden (view full) ---

352
353 iparams->vmspace_destroyed = 1;
354
355 /* Blow away entire process VM */
356#ifdef SYSVSHM
357 if (vmspace->vm_shm)
358 shmexit(iparams->proc);
359#endif
332 exit1(p, W_EXITCODE(0, SIGABRT));
333 /* NOT REACHED */
334 return(0);
335 } else {
336 return(error);
337 }
338}
339

--- 12 unchanged lines hidden (view full) ---

352
353 iparams->vmspace_destroyed = 1;
354
355 /* Blow away entire process VM */
356#ifdef SYSVSHM
357 if (vmspace->vm_shm)
358 shmexit(iparams->proc);
359#endif
360 vm_deallocate(&vmspace->vm_map, 0, USRSTACK);
360 vm_map_remove(&vmspace->vm_map, 0, USRSTACK);
361
362 /* Allocate a new stack */
361
362 /* Allocate a new stack */
363 error = vm_allocate(&vmspace->vm_map, (vm_offset_t *)&stack_addr,
364 SGROWSIZ, FALSE);
363 error = vm_map_find(&vmspace->vm_map, NULL, 0, (vm_offset_t *)&stack_addr,
364 SGROWSIZ, FALSE);
365 if (error)
366 return(error);
367
368 vmspace->vm_ssize = SGROWSIZ >> PAGE_SHIFT;
369
370 /* Initialize maximum stack address */
371 vmspace->vm_maxsaddr = (char *)USRSTACK - MAXSSIZ;
372

--- 200 unchanged lines hidden ---
365 if (error)
366 return(error);
367
368 vmspace->vm_ssize = SGROWSIZ >> PAGE_SHIFT;
369
370 /* Initialize maximum stack address */
371 vmspace->vm_maxsaddr = (char *)USRSTACK - MAXSSIZ;
372

--- 200 unchanged lines hidden ---