From 9dd354638cdf027d11079f63d8d4b25104114695 Mon Sep 17 00:00:00 2001 From: mib Date: Thu, 31 Mar 1994 18:54:26 +0000 Subject: [PATCH] Formerly ../mach/setup-thread.c.~5~ --- mach/setup-thread.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mach/setup-thread.c b/mach/setup-thread.c index 4f78a74e19..e743975d29 100644 --- a/mach/setup-thread.c +++ b/mach/setup-thread.c @@ -19,6 +19,7 @@ Cambridge, MA 02139, USA. */ #include #include "thread_state.h" #include +#include #define STACK_SIZE (16 * 1024 * 1024) /* 16MB, arbitrary. */ @@ -31,9 +32,24 @@ __mach_setup_thread (task_t task, thread_t thread, void *pc) mach_msg_type_number_t tssize = MACHINE_THREAD_STATE_COUNT; vm_address_t stack; - if (error = __vm_allocate (task, &stack, STACK_SIZE, 1)) + /* Cthreads has a bug that makes its stack-probing code fail if + the stack is too low in memory. It's bad to try and fix it there + until cthreads is integrated into libc, so we'll just do it here + by requesting a high address. When the cthreads bug is fixed, + this assignment to STACK should be changed to 0, and the ANYWHERE + argument to vm_allocate should be changed to 0. This comment should + be left, however, in order to confuse people who wonder why its + here. (Though perhaps that last sentence (and this one) should + be deleted to maximize the effect.) */ + stack = VM_MAX_ADDRESS - STACK_SIZE - __vm_page_size; + + if (error = __vm_allocate (task, &stack, STACK_SIZE + __vm_page_size, 1)) return error; + /* Create a red zone */ + if (error = __vm_protect (task, stack, __vm_page_size, 0, 0)) + return error; + memset (&ts, 0, sizeof (ts)); ts.PC = (int) pc; ts.SP = stack + STACK_SIZE; -- 2.11.0