diff options
author | kib <kib@FreeBSD.org> | 2015-04-15 08:13:53 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2015-04-15 08:13:53 +0000 |
commit | b4924fbf83604538d55749f84455609e996af642 (patch) | |
tree | 1dc78418affbe0ee664f368e20352ee110739672 /sys/kern/kern_exec.c | |
parent | 4f67ee3ab1353f7312518f813656cf856cd7775c (diff) | |
download | FreeBSD-src-b4924fbf83604538d55749f84455609e996af642.zip FreeBSD-src-b4924fbf83604538d55749f84455609e996af642.tar.gz |
Implement support for binary to requesting specific stack size for the
initial thread. It is read by the ELF image activator as the virtual
size of the PT_GNU_STACK program header entry, and can be specified by
the linker option -z stack-size in newer binutils.
The soft RLIMIT_STACK is auto-increased if possible, to satisfy the
binary' request.
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Diffstat (limited to 'sys/kern/kern_exec.c')
-rw-r--r-- | sys/kern/kern_exec.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 388ed19..ecc2651 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1009,6 +1009,7 @@ exec_new_vmspace(imgp, sv) struct proc *p = imgp->proc; struct vmspace *vmspace = p->p_vmspace; vm_object_t obj; + struct rlimit rlim_stack; vm_offset_t sv_minuser, stack_addr; vm_map_t map; u_long ssiz; @@ -1058,10 +1059,22 @@ exec_new_vmspace(imgp, sv) } /* Allocate a new stack */ - if (sv->sv_maxssiz != NULL) + if (imgp->stack_sz != 0) { + ssiz = imgp->stack_sz; + PROC_LOCK(p); + lim_rlimit(p, RLIMIT_STACK, &rlim_stack); + PROC_UNLOCK(p); + if (ssiz > rlim_stack.rlim_max) + ssiz = rlim_stack.rlim_max; + if (ssiz > rlim_stack.rlim_cur) { + rlim_stack.rlim_cur = ssiz; + kern_setrlimit(curthread, RLIMIT_STACK, &rlim_stack); + } + } else if (sv->sv_maxssiz != NULL) { ssiz = *sv->sv_maxssiz; - else + } else { ssiz = maxssiz; + } stack_addr = sv->sv_usrstack - ssiz; error = vm_map_stack(map, stack_addr, (vm_size_t)ssiz, obj != NULL && imgp->stack_prot != 0 ? imgp->stack_prot : |