aboutsummaryrefslogtreecommitdiff
path: root/lib/libpthread/thread/thr_init.c
diff options
context:
space:
mode:
authorPeter Wemm <peter@FreeBSD.org>2001-10-26 21:19:22 +0000
committerPeter Wemm <peter@FreeBSD.org>2001-10-26 21:19:22 +0000
commiteb9053b12f317bc99d9e7733d0d18541d7d09e03 (patch)
treeeecbcf12bbd3734f9d86b3bf3acdc1a2169fece3 /lib/libpthread/thread/thr_init.c
parent0b9272be42bb1779a798e3e67c5f14c6f568488d (diff)
downloadsrc-eb9053b12f317bc99d9e7733d0d18541d7d09e03.tar.gz
src-eb9053b12f317bc99d9e7733d0d18541d7d09e03.zip
Make libc_r check the kern.usrstack sysctl instead of using internal
kernel #defines to figure out where the stack is located. This stops libc_r from exploding when the kernel is compiled with a different KVM size. IMHO this is all kinda bogus, it would be better to just check %esp and work from that.
Notes
Notes: svn path=/head/; revision=85567
Diffstat (limited to 'lib/libpthread/thread/thr_init.c')
-rw-r--r--lib/libpthread/thread/thr_init.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/libpthread/thread/thr_init.c b/lib/libpthread/thread/thr_init.c
index 7bf09e58bfa3..30ec765bfc24 100644
--- a/lib/libpthread/thread/thr_init.c
+++ b/lib/libpthread/thread/thr_init.c
@@ -266,6 +266,12 @@ _thread_init(void)
memcpy((void *) &_thread_initial->attr, &pthread_attr_default,
sizeof(struct pthread_attr));
+ /* Find the stack top */
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_USRSTACK;
+ len = sizeof (int);
+ if (sysctl(mib, 2, &_usrstack, &len, NULL, 0) == -1)
+ _usrstack = USRSTACK;
/*
* Create a red zone below the main stack. All other stacks are
* constrained to a maximum size by the paramters passed to
@@ -273,14 +279,13 @@ _thread_init(void)
* this stack needs an explicitly mapped red zone to protect the
* thread stack that is just beyond.
*/
- if (mmap((void *) USRSTACK - PTHREAD_STACK_INITIAL -
+ if (mmap(_usrstack - PTHREAD_STACK_INITIAL -
PTHREAD_GUARD_DEFAULT, PTHREAD_GUARD_DEFAULT, 0, MAP_ANON,
-1, 0) == MAP_FAILED)
PANIC("Cannot allocate red zone for initial thread");
/* Set the main thread stack pointer. */
- _thread_initial->stack = (void *) USRSTACK -
- PTHREAD_STACK_INITIAL;
+ _thread_initial->stack = _usrstack - PTHREAD_STACK_INITIAL;
/* Set the stack attributes: */
_thread_initial->attr.stackaddr_attr = _thread_initial->stack;