From 7e96caa7cea3371986e54e0c8191ba395af885d1 Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Wed, 13 Feb 2008 19:31:23 +0000 Subject: Make sure we reserve enough stack space on MACHINE_STACK_GROWS_UP architectures by aligning the stack gap. Fixes gettext port build (and probably many others). ok miod@, tedu@, tested by sthen@ --- sys/kern/kern_exec.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 3fb29047c5a..801b69df0d4 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exec.c,v 1.105 2007/12/11 22:09:29 kettenis Exp $ */ +/* $OpenBSD: kern_exec.c,v 1.106 2008/02/13 19:31:22 kettenis Exp $ */ /* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */ /*- @@ -388,6 +388,9 @@ sys_execve(struct proc *p, void *v, register_t *retval) sgap = STACKGAPLEN; if (stackgap_random != 0) sgap += (arc4random() * ALIGNBYTES) & (stackgap_random - 1); +#ifdef MACHINE_STACK_GROWS_UP + sgap = ALIGN(sgap); +#endif /* Now check if args & environ fit into new stack */ len = ((argc + envc + 2 + pack.ep_emul->e_arglen) * sizeof(char *) + sizeof(long) + dp + sgap + sizeof(struct ps_strings)) - argp; @@ -435,8 +438,8 @@ sys_execve(struct proc *p, void *v, register_t *retval) arginfo.ps_nenvstr = envc; #ifdef MACHINE_STACK_GROWS_UP - stack = (char *)USRSTACK + sizeof(arginfo) + ALIGN(sgap); - slen = len - sizeof(arginfo) - ALIGN(sgap); + stack = (char *)USRSTACK + sizeof(arginfo) + sgap; + slen = len - sizeof(arginfo) - sgap; #else stack = (char *)(USRSTACK - len); #endif -- cgit v1.2.3