- /* create anonymous memory region for new stack */
- vs = p->p_vmspace;
- if ((unsigned)vs->vm_maxsaddr + MAXSSIZ < USRSTACK)
- newframe = (caddr_t) USRSTACK - MAXSSIZ;
- else
- vs->vm_maxsaddr = newframe = (caddr_t) USRSTACK - 2*MAXSSIZ;
-
- /* don't do stack limit checking on traps temporarily XXX*/
- dostacklimits = 0;
-
- rv = vm_allocate(&vs->vm_map, &newframe, MAXSSIZ, FALSE);
- if (rv) goto exec_fail;
-
- /* allocate string buffer and arg buffer */
- argbuf = (char **) (newframe + MAXSSIZ - 3*ARG_MAX);
- stringbuf = stringbufp = ((char *)argbuf) + 2*ARG_MAX;
- argbufp = argbuf;
-
- /* first, do args */
- vectp = uap->argp;
- needsenv = 1;
- limitonargs = ARG_MAX;
- cnt = 0;
-
- /* first, do (shell name if any then) args */
- if (indir) {
- ep = shellname;
-thrice:
- if (ep) {
- /* did we outgrow initial argbuf, if so, die */
- if (argbufp >= (char **)stringbuf) {
- rv = E2BIG;
- goto exec_dealloc;
- }
-
- if (rv = copyoutstr(ep, stringbufp,
- (u_int)limitonargs, (u_int *)&stringlen)) {
- if (rv == ENAMETOOLONG)
- rv = E2BIG;
- goto exec_dealloc;
- }
- suword(argbufp++, (int)stringbufp);
- cnt++;
- stringbufp += stringlen;
- limitonargs -= stringlen;
- }
-
- if (shellargs) {
- ep = shellargs;
- shellargs = 0;
- goto thrice;
- }
-
- if (indir) {
- indir = 0;
- /* orginal executable is 1st argument with scripts */
- ep = uap->fname;
- goto thrice;
- }
- /* terminate in case no more args to script */
- suword(argbufp, 0);
- if (vectp = uap->argp) vectp++; /* manually doing the first
- argument with scripts */
- }