svn commit: r281848 - in stable/10/sys: kern sys
Konstantin Belousov
kib at FreeBSD.org
Wed Apr 22 10:57:02 UTC 2015
Author: kib
Date: Wed Apr 22 10:57:00 2015
New Revision: 281848
URL: https://svnweb.freebsd.org/changeset/base/281848
Log:
MFC r281548:
Implement support for binary to request specific stack size for the
initial thread.
Modified:
stable/10/sys/kern/imgact_elf.c
stable/10/sys/kern/kern_exec.c
stable/10/sys/kern/kern_resource.c
stable/10/sys/sys/imgact.h
Directory Properties:
stable/10/ (props changed)
Modified: stable/10/sys/kern/imgact_elf.c
==============================================================================
--- stable/10/sys/kern/imgact_elf.c Wed Apr 22 10:25:08 2015 (r281847)
+++ stable/10/sys/kern/imgact_elf.c Wed Apr 22 10:57:00 2015 (r281848)
@@ -776,6 +776,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: stable/10/sys/kern/kern_exec.c
==============================================================================
--- stable/10/sys/kern/kern_exec.c Wed Apr 22 10:25:08 2015 (r281847)
+++ stable/10/sys/kern/kern_exec.c Wed Apr 22 10:57:00 2015 (r281848)
@@ -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 :
Modified: stable/10/sys/kern/kern_resource.c
==============================================================================
--- stable/10/sys/kern/kern_resource.c Wed Apr 22 10:25:08 2015 (r281847)
+++ stable/10/sys/kern/kern_resource.c Wed Apr 22 10:57:00 2015 (r281848)
@@ -757,7 +757,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: stable/10/sys/sys/imgact.h
==============================================================================
--- stable/10/sys/sys/imgact.h Wed Apr 22 10:25:08 2015 (r281847)
+++ stable/10/sys/sys/imgact.h Wed Apr 22 10:57:00 2015 (r281848)
@@ -80,6 +80,7 @@ struct image_params {
unsigned long pagesizes;
int pagesizeslen;
vm_prot_t stack_prot;
+ u_long stack_sz;
};
#ifdef _KERNEL
More information about the svn-src-stable-10
mailing list