Date: Wed, 15 Apr 2015 08:13:53 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r281548 - in head/sys: kern sys Message-ID: <201504150813.t3F8Drjj021644@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Wed Apr 15 08:13:53 2015 New Revision: 281548 URL: https://svnweb.freebsd.org/changeset/base/281548 Log: 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 Modified: head/sys/kern/imgact_elf.c head/sys/kern/kern_exec.c head/sys/kern/kern_resource.c head/sys/sys/imgact.h Modified: head/sys/kern/imgact_elf.c ============================================================================== --- head/sys/kern/imgact_elf.c Wed Apr 15 06:59:53 2015 (r281547) +++ head/sys/kern/imgact_elf.c Wed Apr 15 08:13:53 2015 (r281548) @@ -782,6 +782,7 @@ __CONCAT(exec_, __elfN(imgact))(struct i if (__elfN(nxstack)) imgp->stack_prot = __elfN(trans_prot)(phdr[i].p_flags); + imgp->stack_sz = phdr[i].p_memsz; break; } } Modified: head/sys/kern/kern_exec.c ============================================================================== --- head/sys/kern/kern_exec.c Wed Apr 15 06:59:53 2015 (r281547) +++ head/sys/kern/kern_exec.c Wed Apr 15 08:13:53 2015 (r281548) @@ -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 : Modified: head/sys/kern/kern_resource.c ============================================================================== --- head/sys/kern/kern_resource.c Wed Apr 15 06:59:53 2015 (r281547) +++ head/sys/kern/kern_resource.c Wed Apr 15 08:13:53 2015 (r281548) @@ -745,7 +745,12 @@ kern_proc_setrlimit(struct thread *td, s 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 Modified: head/sys/sys/imgact.h ============================================================================== --- head/sys/sys/imgact.h Wed Apr 15 06:59:53 2015 (r281547) +++ head/sys/sys/imgact.h Wed Apr 15 08:13:53 2015 (r281548) @@ -80,6 +80,7 @@ struct image_params { unsigned long pagesizes; int pagesizeslen; vm_prot_t stack_prot; + u_long stack_sz; }; #ifdef _KERNEL
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201504150813.t3F8Drjj021644>