diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 81ca808a28bc..7d7de13f5b1c 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_exec.c,v 1.56 1994/10/20 04:22:43 cgd Exp $ */ +/* $NetBSD: kern_exec.c,v 1.57 1994/10/24 05:32:34 deraadt Exp $ */ /*- * Copyright (C) 1993, 1994 Christopher G. Demetriou @@ -246,7 +246,9 @@ execve(p, uap, retval) pack.ep_hdrlen = exec_maxhdrsz; pack.ep_hdrvalid = 0; pack.ep_ndp = &nid; - pack.ep_setup = NULL; /* assume no setup function */ + pack.ep_setup = NULL; /* assume no setup function */ + pack.ep_setup_arg = NULL; + pack.ep_setup_arglen = 0; pack.ep_vmcmds.evs_cnt = 0; pack.ep_vmcmds.evs_used = 0; pack.ep_vap = &attr; @@ -332,8 +334,9 @@ execve(p, uap, retval) } /* Now check if args & environ fit into new stack */ - len = ((argc + envc + 2) * sizeof(char *) + sizeof(int) + - dp + STACKGAPLEN + szsigcode + sizeof(struct ps_strings)) - argp; + len = ((argc + envc + 2 + pack.ep_setup_arglen) * sizeof(char *) + + sizeof(int) + dp + STACKGAPLEN + szsigcode + + sizeof(struct ps_strings)) - argp; len = ALIGN(len); /* make the stack "safely" aligned */ if (len > pack.ep_ssize) { /* in effect, compare to initial limit */ @@ -393,7 +396,7 @@ execve(p, uap, retval) if (copyout(&argc, cpp++, sizeof(argc))) goto exec_abort; - dp = (char *) (cpp + argc + envc + 2); + dp = (char *) (cpp + argc + envc + 2 + pack.ep_setup_arglen); /* XXX don't copy them out, remap them! */ arginfo.ps_argvstr = dp; /* remember location of argv for later */ @@ -414,9 +417,13 @@ execve(p, uap, retval) || copyoutstr(sp, dp, len, 0)) goto exec_abort; } - if (copyout(&np, cpp, sizeof(np))) + + if (copyout(&np, cpp++, sizeof(np))) goto exec_abort; + if (pack.ep_setup != NULL) + (*pack.ep_setup)(EXEC_SETUP_ADDARGS, p, &pack, cpp); + /* copy out the process's ps_strings structure */ if (copyout(&arginfo, (char *) PS_STRINGS, sizeof(arginfo))) goto exec_abort; @@ -489,7 +496,7 @@ execve(p, uap, retval) /* setup new registers and do misc. setup. */ setregs(p, pack.ep_entry, (u_long) stack, retval); if (pack.ep_setup != NULL) - (*pack.ep_setup)(p, &pack); + (*pack.ep_setup)(EXEC_SETUP_FINISH, p, &pack, NULL); if (p->p_flag & P_TRACED) psignal(p, SIGTRAP); @@ -499,6 +506,8 @@ execve(p, uap, retval) return 0; bad: + if (pack.ep_setup != NULL) + (*pack.ep_setup)(EXEC_SETUP_CLEANUP, p, &pack, dp); /* free the vmspace-creation commands, and release their references */ kill_vmcmds(&pack.ep_vmcmds); /* kill any opened file descriptor, if necessary */ diff --git a/sys/sys/exec.h b/sys/sys/exec.h index 295e75d1a873..edc5f9878278 100644 --- a/sys/sys/exec.h +++ b/sys/sys/exec.h @@ -1,4 +1,4 @@ -/* $NetBSD: exec.h,v 1.47 1994/10/20 04:27:44 cgd Exp $ */ +/* $NetBSD: exec.h,v 1.48 1994/10/24 05:32:19 deraadt Exp $ */ /*- * Copyright (c) 1994 Christopher G. Demetriou @@ -67,7 +67,8 @@ struct ps_strings { * Below the PS_STRINGS and sigtramp, we may require a gap on the stack * (used to copyin/copyout various emulation data structures). */ -#if defined(COMPAT_SUNOS) || defined(COMPAT_ULTRIX) || defined(COMPAT_IBCS2) +#if defined(COMPAT_SUNOS) || defined(COMPAT_ULTRIX) || \ + defined(COMPAT_IBCS2) || defined(COMPAT_SVR4) #define STACKGAPLEN 400 /* plenty enough for now */ #else #define STACKGAPLEN 0 @@ -92,7 +93,8 @@ struct proc; struct exec_package; typedef int (*exec_makecmds_fcn) __P((struct proc *, struct exec_package *)); -typedef void (*exec_setup_fcn) __P((struct proc *, struct exec_package *)); +typedef void (*exec_setup_fcn) __P((int, struct proc *, struct exec_package *, + void *)); struct execsw { u_int es_hdrsz; /* size of header for this format */ @@ -114,7 +116,6 @@ struct exec_package { u_int ep_hdrlen; /* length of ep_hdr */ u_int ep_hdrvalid; /* bytes of ep_hdr that are valid */ struct nameidata *ep_ndp; /* namei data pointer for lookups */ - exec_setup_fcn ep_setup; /* special setup fn for exec type */ struct exec_vmcmd_set ep_vmcmds; /* vmcmds used to build vmspace */ struct vnode *ep_vp; /* executable's vnode */ struct vattr *ep_vap; /* executable's attributes */ @@ -130,6 +131,9 @@ struct exec_package { u_int ep_flags; /* flags; see below. */ char **ep_fa; /* a fake args vector for scripts */ int ep_fd; /* a file descriptor we're holding */ + exec_setup_fcn ep_setup; /* special setup fn for exec type */ + void *ep_setup_arg; /* setup argument */ + u_long ep_setup_arglen; /* size of extra arguments */ }; #define EXEC_INDIR 0x0001 /* script handling already done */ #define EXEC_HASFD 0x0002 /* holding a shell script */ @@ -137,6 +141,10 @@ struct exec_package { #define EXEC_SKIPARG 0x0008 /* don't copy user-supplied argv[0] */ #define EXEC_DESTR 0x0010 /* destructive ops performed */ +#define EXEC_SETUP_ADDARGS 0 /* add arguments on the stack */ +#define EXEC_SETUP_FINISH 1 /* final setup before exec */ +#define EXEC_SETUP_CLEANUP 2 /* called to cleanup things */ + struct exec_vmcmd { int (*ev_proc) __P((struct proc *p, struct exec_vmcmd *cmd)); /* procedure to run for region of vmspace */