Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c18n: Set curthread->tcb to real tcb upon thread start #2110

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/libthr/thread/thr_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ thread_start(struct pthread *curthread)
bool restore_sigmask;

#if defined(__CHERI_PURE_CAPABILITY__) && defined(RTLD_SANDBOX)
/*
* At this point, curthread->tcb contains a fake wrapper TCB created by
* RTLD when the thread was created. The real TCB has now been installed
* by RTLD upon thread start, and the struct member should be set to it.
*/
curthread->tcb = _tcb_get();
restore_sigmask = true;
#else
restore_sigmask = curthread->attr.suspend == THR_CREATE_SUSPENDED;
Expand Down
6 changes: 6 additions & 0 deletions libexec/rtld-elf/rtld.c
Original file line number Diff line number Diff line change
Expand Up @@ -6110,6 +6110,12 @@ _rtld_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign)
ret = allocate_tls(globallist_curr(TAILQ_FIRST(&obj_list)), oldtls,
tcbsize, tcbalign);
#if defined(__CHERI_PURE_CAPABILITY__) && defined(RTLD_SANDBOX)
/*
* Create a fake wrapper TCB containing pointers to the real TCB and stack
* lookup table. This is passed to the new thread as its initial TCB. Once
* the thread starts executing in _rtld_thread_start, it will set the
* thread's TCB to the real TCB after installing the stack lookup table.
*/
if (C18N_ENABLED)
ret = c18n_allocate_tcb(ret);
#endif
Expand Down
Loading