summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_fork.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/kern/kern_fork.c')
-rw-r--r--sys/kern/kern_fork.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 4e2eaa9..03d8cbc 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
#include "opt_kdtrace.h"
#include "opt_ktrace.h"
+#include "opt_kstack_pages.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -276,25 +277,29 @@ norfproc_fail:
mem_charged = 0;
vm2 = NULL;
+ if (pages == 0)
+ pages = KSTACK_PAGES;
/* Allocate new proc. */
newproc = uma_zalloc(proc_zone, M_WAITOK);
- if (TAILQ_EMPTY(&newproc->p_threads)) {
- td2 = thread_alloc();
+ td2 = FIRST_THREAD_IN_PROC(newproc);
+ if (td2 == NULL) {
+ td2 = thread_alloc(pages);
if (td2 == NULL) {
error = ENOMEM;
goto fail1;
}
proc_linkup(newproc, td2);
- } else
- td2 = FIRST_THREAD_IN_PROC(newproc);
-
- /* Allocate and switch to an alternate kstack if specified. */
- if (pages != 0) {
- if (!vm_thread_new_altkstack(td2, pages)) {
- error = ENOMEM;
- goto fail1;
+ } else {
+ if (td2->td_kstack == 0 || td2->td_kstack_pages != pages) {
+ if (td2->td_kstack != 0)
+ vm_thread_dispose(td2);
+ if (!thread_alloc_stack(td2, pages)) {
+ error = ENOMEM;
+ goto fail1;
+ }
}
}
+
if ((flags & RFMEM) == 0) {
vm2 = vmspace_fork(p1->p_vmspace, &mem_charged);
if (vm2 == NULL) {
OpenPOWER on IntegriCloud