summaryrefslogtreecommitdiffstats
path: root/lib/libc_r/uthread/uthread_init.c
diff options
context:
space:
mode:
authorjasone <jasone@FreeBSD.org>2000-01-19 07:04:50 +0000
committerjasone <jasone@FreeBSD.org>2000-01-19 07:04:50 +0000
commit0b9957ff21dc2a9c577ff23b99d36d1787633701 (patch)
treefd1e0fc8602718af3b54f1661587a1462b98ccdd /lib/libc_r/uthread/uthread_init.c
parent2c6582da15d1ca764e0434cfacf0ab1cc7fe11f0 (diff)
downloadFreeBSD-src-0b9957ff21dc2a9c577ff23b99d36d1787633701.zip
FreeBSD-src-0b9957ff21dc2a9c577ff23b99d36d1787633701.tar.gz
Implement continuations to correctly handle [sig|_]longjmp() inside of a
signal handler. Explicitly check for jumps to anywhere other than the current stack, since such jumps are undefined according to POSIX. While we're at it, convert thread cancellation to use continuations, since it's cleaner than the original cancellation code. Avoid delivering a signal to a thread twice. This was a pre-existing bug, but was likely unexposed until these other changes were made. Defer signals generated by pthread_kill() so that they can be delivered on the appropriate stack. deischen claims that this is unnecessary, which is likely true, but without this change, pthread_kill() can cause undefined priority queue states and/or PANICs in [sig|_]longjmp(), so I'm leaving this in for now. To compile this code out and exercise the bug, define the _NO_UNDISPATCH cpp macro. Defining _PTHREADS_INVARIANTS as well will cause earlier crashes. PR: kern/14685 Collaboration with: deischen
Diffstat (limited to 'lib/libc_r/uthread/uthread_init.c')
-rw-r--r--lib/libc_r/uthread/uthread_init.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/libc_r/uthread/uthread_init.c b/lib/libc_r/uthread/uthread_init.c
index b6429bb..dd5f53f 100644
--- a/lib/libc_r/uthread/uthread_init.c
+++ b/lib/libc_r/uthread/uthread_init.c
@@ -184,6 +184,10 @@ _thread_init(void)
/* Initialize the scheduling switch hook routine: */
_sched_switch_hook = NULL;
+ /* Give this thread default attributes: */
+ memcpy((void *) &_thread_initial->attr, &pthread_attr_default,
+ sizeof(struct pthread_attr));
+
/* Initialize the thread stack cache: */
SLIST_INIT(&_stackq);
@@ -199,6 +203,14 @@ _thread_init(void)
-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;
+
+ /* Set the stack attributes: */
+ _thread_initial->attr.stackaddr_attr = _thread_initial->stack;
+ _thread_initial->attr.stacksize_attr = PTHREAD_STACK_INITIAL;
+
/*
* Write a magic value to the thread structure
* to help identify valid ones:
OpenPOWER on IntegriCloud