kern_exec.c revision 1.125 1 /* $NetBSD: kern_exec.c,v 1.125 2000/11/27 08:39:43 chs Exp $ */
2
3 /*-
4 * Copyright (C) 1993, 1994, 1996 Christopher G. Demetriou
5 * Copyright (C) 1992 Wolfgang Solfrank.
6 * Copyright (C) 1992 TooLs GmbH.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by TooLs GmbH.
20 * 4. The name of TooLs GmbH may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include "opt_ktrace.h"
36 #include "opt_syscall_debug.h"
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/filedesc.h>
41 #include <sys/kernel.h>
42 #include <sys/proc.h>
43 #include <sys/mount.h>
44 #include <sys/malloc.h>
45 #include <sys/namei.h>
46 #include <sys/vnode.h>
47 #include <sys/file.h>
48 #include <sys/acct.h>
49 #include <sys/exec.h>
50 #include <sys/ktrace.h>
51 #include <sys/resourcevar.h>
52 #include <sys/wait.h>
53 #include <sys/mman.h>
54 #include <sys/signalvar.h>
55 #include <sys/stat.h>
56 #include <sys/syscall.h>
57
58 #include <sys/syscallargs.h>
59
60 #include <uvm/uvm_extern.h>
61
62 #include <machine/cpu.h>
63 #include <machine/reg.h>
64
65 extern char sigcode[], esigcode[];
66 #ifdef SYSCALL_DEBUG
67 extern const char * const syscallnames[];
68 #endif
69
70 const struct emul emul_netbsd = {
71 "netbsd",
72 NULL,
73 sendsig,
74 SYS_syscall,
75 SYS_MAXSYSCALL,
76 sysent,
77 #ifdef SYSCALL_DEBUG
78 syscallnames,
79 #else
80 NULL,
81 #endif
82 sigcode,
83 esigcode,
84 };
85
86 /*
87 * check exec:
88 * given an "executable" described in the exec package's namei info,
89 * see what we can do with it.
90 *
91 * ON ENTRY:
92 * exec package with appropriate namei info
93 * proc pointer of exec'ing proc
94 * NO SELF-LOCKED VNODES
95 *
96 * ON EXIT:
97 * error: nothing held, etc. exec header still allocated.
98 * ok: filled exec package, executable's vnode (unlocked).
99 *
100 * EXEC SWITCH ENTRY:
101 * Locked vnode to check, exec package, proc.
102 *
103 * EXEC SWITCH EXIT:
104 * ok: return 0, filled exec package, executable's vnode (unlocked).
105 * error: destructive:
106 * everything deallocated execept exec header.
107 * non-destructive:
108 * error code, executable's vnode (unlocked),
109 * exec header unmodified.
110 */
111 int
112 check_exec(struct proc *p, struct exec_package *epp)
113 {
114 int error, i;
115 struct vnode *vp;
116 struct nameidata *ndp;
117 size_t resid;
118
119 ndp = epp->ep_ndp;
120 ndp->ni_cnd.cn_nameiop = LOOKUP;
121 ndp->ni_cnd.cn_flags = FOLLOW | LOCKLEAF | SAVENAME;
122 /* first get the vnode */
123 if ((error = namei(ndp)) != 0)
124 return error;
125 epp->ep_vp = vp = ndp->ni_vp;
126
127 /* check access and type */
128 if (vp->v_type != VREG) {
129 error = EACCES;
130 goto bad1;
131 }
132 if ((error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p)) != 0)
133 goto bad1;
134
135 /* get attributes */
136 if ((error = VOP_GETATTR(vp, epp->ep_vap, p->p_ucred, p)) != 0)
137 goto bad1;
138
139 /* Check mount point */
140 if (vp->v_mount->mnt_flag & MNT_NOEXEC) {
141 error = EACCES;
142 goto bad1;
143 }
144 if ((vp->v_mount->mnt_flag & MNT_NOSUID) || (p->p_flag & P_TRACED))
145 epp->ep_vap->va_mode &= ~(S_ISUID | S_ISGID);
146
147 /* try to open it */
148 if ((error = VOP_OPEN(vp, FREAD, p->p_ucred, p)) != 0)
149 goto bad1;
150
151 /* unlock vp, since we need it unlocked from here on out. */
152 VOP_UNLOCK(vp, 0);
153
154 /* now we have the file, get the exec header */
155 uvn_attach(vp, VM_PROT_READ);
156 error = vn_rdwr(UIO_READ, vp, epp->ep_hdr, epp->ep_hdrlen, 0,
157 UIO_SYSSPACE, 0, p->p_ucred, &resid, p);
158 if (error)
159 goto bad2;
160 epp->ep_hdrvalid = epp->ep_hdrlen - resid;
161
162 /*
163 * set up the vmcmds for creation of the process
164 * address space
165 */
166 error = ENOEXEC;
167 for (i = 0; i < nexecs && error != 0; i++) {
168 int newerror;
169
170 if (execsw[i].es_check == NULL)
171 continue;
172
173 epp->ep_esch = &execsw[i];
174 newerror = (*execsw[i].es_check)(p, epp);
175 /* make sure the first "interesting" error code is saved. */
176 if (!newerror || error == ENOEXEC)
177 error = newerror;
178
179 /* if es_check call was successful, update epp->ep_es */
180 if (!newerror && (epp->ep_flags & EXEC_HASES) == 0)
181 epp->ep_es = &execsw[i];
182
183 if (epp->ep_flags & EXEC_DESTR && error != 0)
184 return error;
185 }
186 if (!error) {
187 /* check that entry point is sane */
188 if (epp->ep_entry > VM_MAXUSER_ADDRESS)
189 error = ENOEXEC;
190
191 /* check limits */
192 if ((epp->ep_tsize > MAXTSIZ) ||
193 (epp->ep_dsize > p->p_rlimit[RLIMIT_DATA].rlim_cur))
194 error = ENOMEM;
195
196 if (!error)
197 return (0);
198 }
199
200 /*
201 * free any vmspace-creation commands,
202 * and release their references
203 */
204 kill_vmcmds(&epp->ep_vmcmds);
205
206 bad2:
207 /*
208 * close and release the vnode, restore the old one, free the
209 * pathname buf, and punt.
210 */
211 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
212 VOP_CLOSE(vp, FREAD, p->p_ucred, p);
213 vput(vp);
214 PNBUF_PUT(ndp->ni_cnd.cn_pnbuf);
215 return error;
216
217 bad1:
218 /*
219 * free the namei pathname buffer, and put the vnode
220 * (which we don't yet have open).
221 */
222 vput(vp); /* was still locked */
223 PNBUF_PUT(ndp->ni_cnd.cn_pnbuf);
224 return error;
225 }
226
227 /*
228 * exec system call
229 */
230 /* ARGSUSED */
231 int
232 sys_execve(struct proc *p, void *v, register_t *retval)
233 {
234 struct sys_execve_args /* {
235 syscallarg(const char *) path;
236 syscallarg(char * const *) argp;
237 syscallarg(char * const *) envp;
238 } */ *uap = v;
239 int error, i;
240 struct exec_package pack;
241 struct nameidata nid;
242 struct vattr attr;
243 struct ucred *cred = p->p_ucred;
244 char *argp;
245 char * const *cpp;
246 char *dp, *sp;
247 long argc, envc;
248 size_t len;
249 char *stack;
250 struct ps_strings arginfo;
251 struct vmspace *vm;
252 char **tmpfap;
253 int szsigcode;
254 struct exec_vmcmd *base_vcp = NULL;
255
256 /*
257 * figure out the maximum size of an exec header, if necessary.
258 * XXX should be able to keep LKM code from modifying exec switch
259 * when we're still using it, but...
260 */
261 if (exec_maxhdrsz == 0) {
262 for (i = 0; i < nexecs; i++)
263 if (execsw[i].es_check != NULL
264 && execsw[i].es_hdrsz > exec_maxhdrsz)
265 exec_maxhdrsz = execsw[i].es_hdrsz;
266 }
267
268 /* init the namei data to point the file user's program name */
269 /* XXX cgd 960926: why do this here? most will be clobbered. */
270 NDINIT(&nid, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
271
272 /*
273 * initialize the fields of the exec package.
274 */
275 pack.ep_name = SCARG(uap, path);
276 pack.ep_hdr = malloc(exec_maxhdrsz, M_EXEC, M_WAITOK);
277 pack.ep_hdrlen = exec_maxhdrsz;
278 pack.ep_hdrvalid = 0;
279 pack.ep_ndp = &nid;
280 pack.ep_emul_arg = NULL;
281 pack.ep_vmcmds.evs_cnt = 0;
282 pack.ep_vmcmds.evs_used = 0;
283 pack.ep_vap = &attr;
284 pack.ep_flags = 0;
285
286 /* see if we can run it. */
287 if ((error = check_exec(p, &pack)) != 0)
288 goto freehdr;
289
290 /* XXX -- THE FOLLOWING SECTION NEEDS MAJOR CLEANUP */
291
292 /* allocate an argument buffer */
293 argp = (char *) uvm_km_valloc_wait(exec_map, NCARGS);
294 #ifdef DIAGNOSTIC
295 if (argp == (vaddr_t) 0)
296 panic("execve: argp == NULL");
297 #endif
298 dp = argp;
299 argc = 0;
300
301 /* copy the fake args list, if there's one, freeing it as we go */
302 if (pack.ep_flags & EXEC_HASARGL) {
303 tmpfap = pack.ep_fa;
304 while (*tmpfap != NULL) {
305 char *cp;
306
307 cp = *tmpfap;
308 while (*cp)
309 *dp++ = *cp++;
310 dp++;
311
312 FREE(*tmpfap, M_EXEC);
313 tmpfap++; argc++;
314 }
315 FREE(pack.ep_fa, M_EXEC);
316 pack.ep_flags &= ~EXEC_HASARGL;
317 }
318
319 /* Now get argv & environment */
320 if (!(cpp = SCARG(uap, argp))) {
321 error = EINVAL;
322 goto bad;
323 }
324
325 if (pack.ep_flags & EXEC_SKIPARG)
326 cpp++;
327
328 while (1) {
329 len = argp + ARG_MAX - dp;
330 if ((error = copyin(cpp, &sp, sizeof(sp))) != 0)
331 goto bad;
332 if (!sp)
333 break;
334 if ((error = copyinstr(sp, dp, len, &len)) != 0) {
335 if (error == ENAMETOOLONG)
336 error = E2BIG;
337 goto bad;
338 }
339 dp += len;
340 cpp++;
341 argc++;
342 }
343
344 envc = 0;
345 /* environment need not be there */
346 if ((cpp = SCARG(uap, envp)) != NULL ) {
347 while (1) {
348 len = argp + ARG_MAX - dp;
349 if ((error = copyin(cpp, &sp, sizeof(sp))) != 0)
350 goto bad;
351 if (!sp)
352 break;
353 if ((error = copyinstr(sp, dp, len, &len)) != 0) {
354 if (error == ENAMETOOLONG)
355 error = E2BIG;
356 goto bad;
357 }
358 dp += len;
359 cpp++;
360 envc++;
361 }
362 }
363
364 dp = (char *) ALIGN(dp);
365
366 szsigcode = pack.ep_es->es_emul->e_esigcode - pack.ep_es->es_emul->e_sigcode;
367
368 /* Now check if args & environ fit into new stack */
369 if (pack.ep_flags & EXEC_32)
370 len = ((argc + envc + 2 + pack.ep_es->es_arglen) * sizeof(int) +
371 sizeof(int) + dp + STACKGAPLEN + szsigcode +
372 sizeof(struct ps_strings)) - argp;
373 else
374 len = ((argc + envc + 2 + pack.ep_es->es_arglen) * sizeof(char *) +
375 sizeof(int) + dp + STACKGAPLEN + szsigcode +
376 sizeof(struct ps_strings)) - argp;
377
378 len = ALIGN(len); /* make the stack "safely" aligned */
379
380 if (len > pack.ep_ssize) { /* in effect, compare to initial limit */
381 error = ENOMEM;
382 goto bad;
383 }
384
385 /* adjust "active stack depth" for process VSZ */
386 pack.ep_ssize = len; /* maybe should go elsewhere, but... */
387
388 /*
389 * Do whatever is necessary to prepare the address space
390 * for remapping. Note that this might replace the current
391 * vmspace with another!
392 */
393 uvmspace_exec(p);
394
395 /* Now map address space */
396 vm = p->p_vmspace;
397 vm->vm_taddr = (char *) pack.ep_taddr;
398 vm->vm_tsize = btoc(pack.ep_tsize);
399 vm->vm_daddr = (char *) pack.ep_daddr;
400 vm->vm_dsize = btoc(pack.ep_dsize);
401 vm->vm_ssize = btoc(pack.ep_ssize);
402 vm->vm_maxsaddr = (char *) pack.ep_maxsaddr;
403 vm->vm_minsaddr = (char *) pack.ep_minsaddr;
404
405 /* create the new process's VM space by running the vmcmds */
406 #ifdef DIAGNOSTIC
407 if (pack.ep_vmcmds.evs_used == 0)
408 panic("execve: no vmcmds");
409 #endif
410 for (i = 0; i < pack.ep_vmcmds.evs_used && !error; i++) {
411 struct exec_vmcmd *vcp;
412
413 vcp = &pack.ep_vmcmds.evs_cmds[i];
414 if (vcp->ev_flags & VMCMD_RELATIVE) {
415 #ifdef DIAGNOSTIC
416 if (base_vcp == NULL)
417 panic("execve: relative vmcmd with no base");
418 if (vcp->ev_flags & VMCMD_BASE)
419 panic("execve: illegal base & relative vmcmd");
420 #endif
421 vcp->ev_addr += base_vcp->ev_addr;
422 }
423 error = (*vcp->ev_proc)(p, vcp);
424 #ifdef DEBUG
425 if (error) {
426 if (i > 0)
427 printf("vmcmd[%d] = %#lx/%#lx @ %#lx\n", i-1,
428 vcp[-1].ev_addr, vcp[-1].ev_len,
429 vcp[-1].ev_offset);
430 printf("vmcmd[%d] = %#lx/%#lx @ %#lx\n", i,
431 vcp->ev_addr, vcp->ev_len, vcp->ev_offset);
432 }
433 #endif
434 if (vcp->ev_flags & VMCMD_BASE)
435 base_vcp = vcp;
436 }
437
438 /* free the vmspace-creation commands, and release their references */
439 kill_vmcmds(&pack.ep_vmcmds);
440
441 /* if an error happened, deallocate and punt */
442 if (error) {
443 #ifdef DEBUG
444 printf("execve: vmcmd %i failed: %d\n", i-1, error);
445 #endif
446 goto exec_abort;
447 }
448
449 /* remember information about the process */
450 arginfo.ps_nargvstr = argc;
451 arginfo.ps_nenvstr = envc;
452
453 stack = (char *) (vm->vm_minsaddr - len);
454 /* Now copy argc, args & environ to new stack */
455 if (!(*pack.ep_es->es_copyargs)(&pack, &arginfo, stack, argp)) {
456 #ifdef DEBUG
457 printf("execve: copyargs failed\n");
458 #endif
459 goto exec_abort;
460 }
461
462 /* fill process ps_strings info */
463 p->p_psstr = (struct ps_strings *)(vm->vm_minsaddr
464 - sizeof(struct ps_strings));
465 p->p_psargv = offsetof(struct ps_strings, ps_argvstr);
466 p->p_psnargv = offsetof(struct ps_strings, ps_nargvstr);
467 p->p_psenv = offsetof(struct ps_strings, ps_envstr);
468 p->p_psnenv = offsetof(struct ps_strings, ps_nenvstr);
469
470 /* copy out the process's ps_strings structure */
471 if (copyout(&arginfo, (char *)p->p_psstr, sizeof(arginfo))) {
472 #ifdef DEBUG
473 printf("execve: ps_strings copyout failed\n");
474 #endif
475 goto exec_abort;
476 }
477
478 /* copy out the process's signal trapoline code */
479 if (szsigcode) {
480 if (copyout((char *)pack.ep_es->es_emul->e_sigcode,
481 p->p_sigacts->ps_sigcode = (char *)p->p_psstr - szsigcode,
482 szsigcode)) {
483 #ifdef DEBUG
484 printf("execve: sig trampoline copyout failed\n");
485 #endif
486 goto exec_abort;
487 }
488 #ifdef PMAP_NEED_PROCWR
489 /* This is code. Let the pmap do what is needed. */
490 pmap_procwr(p, (vaddr_t)p->p_sigacts->ps_sigcode, szsigcode);
491 #endif
492 }
493
494 stopprofclock(p); /* stop profiling */
495 fdcloseexec(p); /* handle close on exec */
496 execsigs(p); /* reset catched signals */
497 p->p_ctxlink = NULL; /* reset ucontext link */
498
499 /* set command name & other accounting info */
500 len = min(nid.ni_cnd.cn_namelen, MAXCOMLEN);
501 memcpy(p->p_comm, nid.ni_cnd.cn_nameptr, len);
502 p->p_comm[len] = 0;
503 p->p_acflag &= ~AFORK;
504
505 /* record proc's vnode, for use by procfs and others */
506 if (p->p_textvp)
507 vrele(p->p_textvp);
508 VREF(pack.ep_vp);
509 p->p_textvp = pack.ep_vp;
510
511 p->p_flag |= P_EXEC;
512 if (p->p_flag & P_PPWAIT) {
513 p->p_flag &= ~P_PPWAIT;
514 wakeup((caddr_t) p->p_pptr);
515 }
516
517 /*
518 * deal with set[ug]id.
519 * MNT_NOSUID and P_TRACED have already been used to disable s[ug]id.
520 */
521 if (((attr.va_mode & S_ISUID) != 0 && p->p_ucred->cr_uid != attr.va_uid)
522 || ((attr.va_mode & S_ISGID) != 0 && p->p_ucred->cr_gid != attr.va_gid)){
523 p->p_ucred = crcopy(cred);
524 #ifdef KTRACE
525 /*
526 * If process is being ktraced, turn off - unless
527 * root set it.
528 */
529 if (p->p_tracep && !(p->p_traceflag & KTRFAC_ROOT))
530 ktrderef(p);
531 #endif
532 if (attr.va_mode & S_ISUID)
533 p->p_ucred->cr_uid = attr.va_uid;
534 if (attr.va_mode & S_ISGID)
535 p->p_ucred->cr_gid = attr.va_gid;
536 p_sugid(p);
537 } else
538 p->p_flag &= ~P_SUGID;
539 p->p_cred->p_svuid = p->p_ucred->cr_uid;
540 p->p_cred->p_svgid = p->p_ucred->cr_gid;
541
542 doexechooks(p);
543
544 uvm_km_free_wakeup(exec_map, (vaddr_t) argp, NCARGS);
545
546 PNBUF_PUT(nid.ni_cnd.cn_pnbuf);
547 vn_lock(pack.ep_vp, LK_EXCLUSIVE | LK_RETRY);
548 VOP_CLOSE(pack.ep_vp, FREAD, cred, p);
549 vput(pack.ep_vp);
550
551 /* setup new registers and do misc. setup. */
552 (*pack.ep_es->es_setregs)(p, &pack, (u_long) stack);
553
554 if (p->p_flag & P_TRACED)
555 psignal(p, SIGTRAP);
556
557 free(pack.ep_hdr, M_EXEC);
558
559 /*
560 * Call emulation specific exec hook. This can setup setup per-process
561 * p->p_emuldata or do any other per-process stuff an emulation needs.
562 *
563 * If we are executing process of different emulation than the
564 * original forked process, call e_proc_exit() of the old emulation
565 * first, then e_proc_exec() of new emulation. If the emulation is
566 * same, the exec hook code should deallocate any old emulation
567 * resources held previously by this process.
568 */
569 if (p->p_emul && p->p_emul->e_proc_exit
570 && p->p_emul != pack.ep_es->es_emul)
571 (*p->p_emul->e_proc_exit)(p);
572
573 /*
574 * Call exec hook. Emulation code may NOT store reference to anything
575 * from &pack.
576 */
577 if (pack.ep_es->es_emul->e_proc_exec)
578 (*pack.ep_es->es_emul->e_proc_exec)(p, &pack);
579
580 /* update p_emul, the old value is no longer needed */
581 p->p_emul = pack.ep_es->es_emul;
582
583 #ifdef KTRACE
584 if (KTRPOINT(p, KTR_EMUL))
585 ktremul(p);
586 #endif
587
588 return (EJUSTRETURN);
589
590 bad:
591 /* free the vmspace-creation commands, and release their references */
592 kill_vmcmds(&pack.ep_vmcmds);
593 /* kill any opened file descriptor, if necessary */
594 if (pack.ep_flags & EXEC_HASFD) {
595 pack.ep_flags &= ~EXEC_HASFD;
596 (void) fdrelease(p, pack.ep_fd);
597 }
598 /* close and put the exec'd file */
599 vn_lock(pack.ep_vp, LK_EXCLUSIVE | LK_RETRY);
600 VOP_CLOSE(pack.ep_vp, FREAD, cred, p);
601 vput(pack.ep_vp);
602 PNBUF_PUT(nid.ni_cnd.cn_pnbuf);
603 uvm_km_free_wakeup(exec_map, (vaddr_t) argp, NCARGS);
604
605 freehdr:
606 free(pack.ep_hdr, M_EXEC);
607 return error;
608
609 exec_abort:
610 /*
611 * the old process doesn't exist anymore. exit gracefully.
612 * get rid of the (new) address space we have created, if any, get rid
613 * of our namei data and vnode, and exit noting failure
614 */
615 uvm_deallocate(&vm->vm_map, VM_MIN_ADDRESS,
616 VM_MAXUSER_ADDRESS - VM_MIN_ADDRESS);
617 if (pack.ep_emul_arg)
618 FREE(pack.ep_emul_arg, M_TEMP);
619 PNBUF_PUT(nid.ni_cnd.cn_pnbuf);
620 vn_lock(pack.ep_vp, LK_EXCLUSIVE | LK_RETRY);
621 VOP_CLOSE(pack.ep_vp, FREAD, cred, p);
622 vput(pack.ep_vp);
623 uvm_km_free_wakeup(exec_map, (vaddr_t) argp, NCARGS);
624 free(pack.ep_hdr, M_EXEC);
625 exit1(p, W_EXITCODE(0, SIGABRT));
626 exit1(p, -1);
627
628 /* NOTREACHED */
629 return 0;
630 }
631
632
633 void *
634 copyargs(struct exec_package *pack, struct ps_strings *arginfo,
635 void *stack, void *argp)
636 {
637 char **cpp = stack;
638 char *dp, *sp;
639 size_t len;
640 void *nullp = NULL;
641 long argc = arginfo->ps_nargvstr;
642 long envc = arginfo->ps_nenvstr;
643
644 #ifdef __sparc_v9__
645 /* XXX Temporary hack for argc format conversion. */
646 argc <<= 32;
647 #endif
648 if (copyout(&argc, cpp++, sizeof(argc)))
649 return NULL;
650 #ifdef __sparc_v9__
651 /* XXX Temporary hack for argc format conversion. */
652 argc >>= 32;
653 #endif
654
655 dp = (char *) (cpp + argc + envc + 2 + pack->ep_es->es_arglen);
656 sp = argp;
657
658 /* XXX don't copy them out, remap them! */
659 arginfo->ps_argvstr = cpp; /* remember location of argv for later */
660
661 for (; --argc >= 0; sp += len, dp += len)
662 if (copyout(&dp, cpp++, sizeof(dp)) ||
663 copyoutstr(sp, dp, ARG_MAX, &len))
664 return NULL;
665
666 if (copyout(&nullp, cpp++, sizeof(nullp)))
667 return NULL;
668
669 arginfo->ps_envstr = cpp; /* remember location of envp for later */
670
671 for (; --envc >= 0; sp += len, dp += len)
672 if (copyout(&dp, cpp++, sizeof(dp)) ||
673 copyoutstr(sp, dp, ARG_MAX, &len))
674 return NULL;
675
676 if (copyout(&nullp, cpp++, sizeof(nullp)))
677 return NULL;
678
679 return cpp;
680 }
681