Don't allocated the stackgap during exec (but do allocate 32 bytes

for 'stack grows up' systems for the _rtld interface).
This commit is contained in:
dsl 2008-01-20 10:15:50 +00:00
parent 56cba2eaaa
commit 46e566819b
2 changed files with 18 additions and 17 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_exec.c,v 1.266 2008/01/03 14:36:58 yamt Exp $ */
/* $NetBSD: kern_exec.c,v 1.267 2008/01/20 10:15:50 dsl Exp $ */
/*-
* Copyright (C) 1993, 1994, 1996 Christopher G. Demetriou
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.266 2008/01/03 14:36:58 yamt Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.267 2008/01/20 10:15:50 dsl Exp $");
#include "opt_ktrace.h"
#include "opt_syscall_debug.h"
@ -575,15 +575,22 @@ execve1(struct lwp *l, const char *path, char * const *args,
szsigcode = pack.ep_esch->es_emul->e_esigcode -
pack.ep_esch->es_emul->e_sigcode;
#ifdef __MACHINE_STACK_GROWS_UP
/* See big comment lower down */
#define RTLD_GAP 32
#else
#define RTLD_GAP 0
#endif
/* Now check if args & environ fit into new stack */
if (pack.ep_flags & EXEC_32)
len = ((argc + envc + 2 + pack.ep_esch->es_arglen) *
sizeof(int) + sizeof(int) + dp + STACKGAPLEN +
sizeof(int) + sizeof(int) + dp + RTLD_GAP +
szsigcode + sizeof(struct ps_strings) + STACK_PTHREADSPACE)
- argp;
else
len = ((argc + envc + 2 + pack.ep_esch->es_arglen) *
sizeof(char *) + sizeof(int) + dp + STACKGAPLEN +
sizeof(char *) + sizeof(int) + dp + RTLD_GAP +
szsigcode + sizeof(struct ps_strings) + STACK_PTHREADSPACE)
- argp;
@ -741,15 +748,15 @@ execve1(struct lwp *l, const char *path, char * const *args,
stack = (char *)STACK_ALLOC(STACK_GROW(vm->vm_minsaddr,
STACK_PTHREADSPACE + sizeof(struct ps_strings) + szsigcode),
len - (sizeof(struct ps_strings) + szsigcode));
#ifdef __MACHINE_STACK_GROWS_UP
/*
* The copyargs call always copies into lower addresses
* first, moving towards higher addresses, starting with
* the stack pointer that we give. When the stack grows
* down, this puts argc/argv/envp very shallow on the
* stack, right at the first user stack pointer, and puts
* STACKGAPLEN very deep in the stack. When the stack
* grows up, the situation is reversed.
* stack, right at the first user stack pointer.
* When the stack grows up, the situation is reversed.
*
* Normally, this is no big deal. But the ld_elf.so _rtld()
* function expects to be called with a single pointer to
@ -762,10 +769,10 @@ execve1(struct lwp *l, const char *path, char * const *args,
* so we have a problem.
*
* Instead of changing how _rtld works, we take the easy way
* out and steal 32 bytes before we call copyargs. This
* space is effectively stolen from STACKGAPLEN.
* out and steal 32 bytes before we call copyargs.
* This extra space was allowed for when 'len' was calculated.
*/
stack += 32;
stack += RTLD_GAP;
#endif /* __MACHINE_STACK_GROWS_UP */
/* Now copy argc, args & environ to new stack */

View File

@ -1,4 +1,4 @@
/* $NetBSD: exec.h,v 1.122 2008/01/03 14:36:57 yamt Exp $ */
/* $NetBSD: exec.h,v 1.123 2008/01/20 10:15:50 dsl Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -112,12 +112,6 @@ struct ps_strings {
int ps_nenvstr; /* the number of environment strings */
};
/*
* Below the ps_strings and sigtramp, we may require a gap on the stack
* (used to copyin/copyout various emulation data structures).
*/
#define STACKGAPLEN 4096 /* plenty enough for now */
/*
* the following structures allow execve() to put together processes
* in a more extensible and cleaner way.