diff options
author | kib <kib@FreeBSD.org> | 2015-04-22 10:57:00 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2015-04-22 10:57:00 +0000 |
commit | 62ec6c0a01ffc399b8cadcc4c1b284631824842c (patch) | |
tree | 1064c906e0245cfde566bcbfd2d1e61a54e53d19 | |
parent | 8ed3961fe98e02304ea1d2af9be36898cef91a1f (diff) | |
download | FreeBSD-src-62ec6c0a01ffc399b8cadcc4c1b284631824842c.zip FreeBSD-src-62ec6c0a01ffc399b8cadcc4c1b284631824842c.tar.gz |
MFC r281548:
Implement support for binary to request specific stack size for the
initial thread.
-rw-r--r-- | sys/kern/imgact_elf.c | 1 | ||||
-rw-r--r-- | sys/kern/kern_exec.c | 17 | ||||
-rw-r--r-- | sys/kern/kern_resource.c | 7 | ||||
-rw-r--r-- | sys/sys/imgact.h | 1 |
4 files changed, 23 insertions, 3 deletions
diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index 1cf71ed..c8ad50e 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -776,6 +776,7 @@ __CONCAT(exec_, __elfN(imgact))(struct image_params *imgp) if (__elfN(nxstack)) imgp->stack_prot = __elfN(trans_prot)(phdr[i].p_flags); + imgp->stack_sz = phdr[i].p_memsz; break; } } diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index fc47700..eeef572 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1038,6 +1038,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; @@ -1087,10 +1088,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 : diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index 51b66f4..b8b8fee 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -757,7 +757,12 @@ kern_proc_setrlimit(struct thread *td, struct proc *p, u_int which, if (newlim != NULL) lim_free(oldlim); - if (which == RLIMIT_STACK) { + if (which == RLIMIT_STACK && + /* + * Skip calls from exec_new_vmspace(), done when stack is + * not mapped yet. + */ + (td != curthread || (p->p_flag & P_INEXEC) == 0)) { /* * Stack is allocated to the max at exec time with only * "rlim_cur" bytes accessible. If stack limit is going diff --git a/sys/sys/imgact.h b/sys/sys/imgact.h index 8440939..ac88a14 100644 --- a/sys/sys/imgact.h +++ b/sys/sys/imgact.h @@ -80,6 +80,7 @@ struct image_params { unsigned long pagesizes; int pagesizeslen; vm_prot_t stack_prot; + u_long stack_sz; }; #ifdef _KERNEL |