diff options
-rw-r--r-- | sys/kern/exec_subr.c | 15 | ||||
-rw-r--r-- | sys/kern/init_main.c | 10 | ||||
-rw-r--r-- | sys/kern/kern_exec.c | 18 | ||||
-rw-r--r-- | sys/kern/kern_resource.c | 10 | ||||
-rw-r--r-- | sys/kern/kern_sig.c | 6 | ||||
-rw-r--r-- | sys/sys/exec.h | 13 |
6 files changed, 64 insertions, 8 deletions
diff --git a/sys/kern/exec_subr.c b/sys/kern/exec_subr.c index 054fae50571..d29f31884f6 100644 --- a/sys/kern/exec_subr.c +++ b/sys/kern/exec_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_subr.c,v 1.6 1999/02/26 05:14:27 art Exp $ */ +/* $OpenBSD: exec_subr.c,v 1.7 1999/11/05 01:18:01 mickey Exp $ */ /* $NetBSD: exec_subr.c,v 1.9 1994/12/04 03:10:42 mycroft Exp $ */ /* @@ -315,7 +315,11 @@ exec_setup_stack(p, epp) struct exec_package *epp; { +#ifdef MACHINE_STACK_GROWS_UP + epp->ep_maxsaddr = USRSTACK + MAXSSIZ; +#else epp->ep_maxsaddr = USRSTACK - MAXSSIZ; +#endif epp->ep_minsaddr = USRSTACK; epp->ep_ssize = round_page(p->p_rlimit[RLIMIT_STACK].rlim_cur); @@ -330,12 +334,21 @@ exec_setup_stack(p, epp) * note that in memory, things assumed to be: 0 ....... ep_maxsaddr * <stack> ep_minsaddr */ +#ifdef MACHINE_STACK_GROWS_UP + NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, + (epp->ep_maxsaddr - (epp->ep_minsaddr + epp->ep_ssize)), + epp->ep_minsaddr + epp->ep_ssize, NULLVP, 0, VM_PROT_NONE); + NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, epp->ep_ssize, + epp->ep_minsaddr, NULLVP, 0, + VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE); +#else NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, ((epp->ep_minsaddr - epp->ep_ssize) - epp->ep_maxsaddr), epp->ep_maxsaddr, NULLVP, 0, VM_PROT_NONE); NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, epp->ep_ssize, (epp->ep_minsaddr - epp->ep_ssize), NULLVP, 0, VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE); +#endif return 0; } diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index da3da993f9c..2f636410e40 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.41 1999/09/12 19:44:04 weingart Exp $ */ +/* $OpenBSD: init_main.c,v 1.42 1999/11/05 01:18:01 mickey Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -510,7 +510,11 @@ start_init(arg) /* * Need just enough stack to hold the faked-up "execve()" arguments. */ +#ifdef MACHINE_STACK_GROWS_UP + addr = USRSTACK; +#else addr = USRSTACK - PAGE_SIZE; +#endif #if defined(UVM) if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE, NULL, UVM_UNKNOWN_OFFSET, @@ -524,7 +528,11 @@ start_init(arg) FALSE) != 0) panic("init: couldn't allocate argument space"); #endif +#ifdef MACHINE_STACK_GROWS_UP + p->p_vmspace->vm_maxsaddr = (caddr_t)addr + PAGE_SIZE; +#else p->p_vmspace->vm_maxsaddr = (caddr_t)addr; +#endif for (pathp = &initpaths[0]; (path = *pathp) != NULL; pathp++) { ucp = (char *)(addr + PAGE_SIZE); diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 84ce9ec608c..fd3c9ff23c7 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exec.c,v 1.33 1999/08/09 12:19:07 millert Exp $ */ +/* $OpenBSD: kern_exec.c,v 1.34 1999/11/05 01:18:01 mickey Exp $ */ /* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */ /*- @@ -425,7 +425,11 @@ sys_execve(p, v, retval) arginfo.ps_nargvstr = argc; arginfo.ps_nenvstr = envc; +#ifdef MACHINE_STACK_GROWS_UP + stack = (char *)USRSTACK; +#else stack = (char *)(USRSTACK - len); +#endif /* Now copy argc, args & environ to new stack */ if (!(*pack.ep_emul->e_copyargs)(&pack, &arginfo, stack, argp)) goto exec_abort; @@ -434,10 +438,16 @@ sys_execve(p, v, retval) if (copyout(&arginfo, (char *)PS_STRINGS, sizeof(arginfo))) goto exec_abort; - /* copy out the process's signal trapoline code */ + /* copy out the process's signal trampoline code */ +#ifdef MACHINE_STACK_GROWS_UP + if (szsigcode && copyout((char *)pack.ep_emul->e_sigcode, + ((char *)PS_STRINGS) + sizeof(struct ps_strings), szsigcode)) + goto exec_abort; +#else if (szsigcode && copyout((char *)pack.ep_emul->e_sigcode, ((char *)PS_STRINGS) - szsigcode, szsigcode)) goto exec_abort; +#endif stopprofclock(p); /* stop profiling */ fdcloseexec(p); /* handle close on exec */ @@ -563,7 +573,11 @@ sys_execve(p, v, retval) if((*pack.ep_emul->e_fixup)(p, &pack) != 0) goto free_pack_abort; } +#ifdef MACHINE_STACK_GROWS_UP + (*pack.ep_emul->e_setregs)(p, &pack, (u_long)stack + len, retval); +#else (*pack.ep_emul->e_setregs)(p, &pack, (u_long)stack, retval); +#endif if (p->p_flag & P_TRACED) psignal(p, SIGTRAP); diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index 29ed4c743b2..4db024054c9 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_resource.c,v 1.9 1999/07/15 14:07:41 art Exp $ */ +/* $OpenBSD: kern_resource.c,v 1.10 1999/11/05 01:18:01 mickey Exp $ */ /* $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $ */ /*- @@ -282,11 +282,19 @@ dosetrlimit(p, which, limp) if (limp->rlim_cur > alimp->rlim_cur) { prot = VM_PROT_ALL; size = limp->rlim_cur - alimp->rlim_cur; +#ifdef MACHINE_STACK_GROWS_UP + addr = USRSTACK + alimp->rlim_cur; +#else addr = USRSTACK - limp->rlim_cur; +#endif } else { prot = VM_PROT_NONE; size = alimp->rlim_cur - limp->rlim_cur; +#ifdef MACHINE_STACK_GROWS_UP + addr = USRSTACK + limp->rlim_cur; +#else addr = USRSTACK - alimp->rlim_cur; +#endif } addr = trunc_page(addr); size = round_page(size); diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 0ec5566a79e..660b1603e95 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sig.c,v 1.34 1999/07/18 17:05:13 deraadt Exp $ */ +/* $OpenBSD: kern_sig.c,v 1.35 1999/11/05 01:18:01 mickey Exp $ */ /* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */ /* @@ -1255,7 +1255,11 @@ coredump(p) if (error) goto out; error = vn_rdwr(UIO_WRITE, vp, +#ifdef MACHINE_STACK_GROWS_UP + (caddr_t) USRSTACK, +#else (caddr_t) trunc_page(USRSTACK - ctob(vm->vm_ssize)), +#endif core.c_ssize, (off_t)(core.c_cpusize + core.c_dsize), UIO_USERSPACE, IO_NODELOCKED|IO_UNIT, cred, NULL, p); diff --git a/sys/sys/exec.h b/sys/sys/exec.h index eed26b009ba..e2dfda8fcab 100644 --- a/sys/sys/exec.h +++ b/sys/sys/exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.h,v 1.7 1999/09/25 10:59:24 kstailey Exp $ */ +/* $OpenBSD: exec.h,v 1.8 1999/11/05 01:18:01 mickey Exp $ */ /* $NetBSD: exec.h,v 1.59 1996/02/09 18:25:09 christos Exp $ */ /*- @@ -64,8 +64,12 @@ struct ps_strings { /* * Address of ps_strings structure (in user space). */ +#ifdef MACHINE_STACK_GROWS_UP +#define PS_STRINGS ((struct ps_strings *)(USRSTACK)) +#else #define PS_STRINGS \ ((struct ps_strings *)(USRSTACK - sizeof(struct ps_strings))) +#endif /* * Below the PS_STRINGS and sigtramp, we may require a gap on the stack @@ -79,10 +83,15 @@ struct ps_strings { #else #define STACKGAPLEN 0 #endif +#ifdef MACHINE_STACK_GROWS_UP +#define STACKGAPBASE_UNALIGNED \ + ((caddr_t)PS_STRINGS + sizeof(struct ps_strings) + (u_long)szsigcode) +#else #define STACKGAPBASE_UNALIGNED \ ((caddr_t)PS_STRINGS - szsigcode - STACKGAPLEN) +#endif #define STACKGAPBASE \ - ((caddr_t)(((unsigned long) STACKGAPBASE_UNALIGNED) & ~ALIGNBYTES)) + ((caddr_t)ALIGN(STACKGAPBASE_UNALIGNED)) /* * the following structures allow execve() to put together processes |