Skip to content

Commit

Permalink
c18n: Block all signals when creating a new thread
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgao committed Apr 23, 2024
1 parent 3ce5b25 commit 187bfb5
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/libthr/thread/thr_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,15 @@ _pthread_create(pthread_t * __restrict thread,
new_thread->flags = THR_FLAGS_NEED_SUSPEND;
create_suspended = 1;
} else {
#if defined(__CHERI_PURE_CAPABILITY__) && defined(RTLD_SANDBOX)
/*
* c18n: Always block all signals when creating a new thread to
* allow RTLD to set up the environment to handle signals.
*/
create_suspended = 1;
#else
create_suspended = 0;
#endif
}

new_thread->state = PS_RUNNING;
Expand Down Expand Up @@ -289,8 +297,15 @@ static void
thread_start(struct pthread *curthread)
{
sigset_t set;
bool restore_sigmask;

#if defined(__CHERI_PURE_CAPABILITY__) && defined(RTLD_SANDBOX)
restore_sigmask = true;
#else
restore_sigmask = curthread->attr.suspend == THR_CREATE_SUSPENDED;
#endif

if (curthread->attr.suspend == THR_CREATE_SUSPENDED)
if (restore_sigmask)
set = curthread->sigmask;
_thr_signal_block_setup(curthread);

Expand All @@ -305,7 +320,7 @@ thread_start(struct pthread *curthread)
if (curthread->force_exit)
_pthread_exit(PTHREAD_CANCELED);

if (curthread->attr.suspend == THR_CREATE_SUSPENDED) {
if (restore_sigmask) {
#if 0
/* Done in THR_UNLOCK() */
_thr_ast(curthread);
Expand Down

0 comments on commit 187bfb5

Please sign in to comment.