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

Miscellaneous c18n improvements #2088

Merged
merged 3 commits into from
Apr 24, 2024
Merged

Miscellaneous c18n improvements #2088

merged 3 commits into from
Apr 24, 2024

Conversation

dpgao
Copy link
Contributor

@dpgao dpgao commented Apr 20, 2024

The PR bundles together three minor improvements to c18n.

  1. When c18n is disabled, the _rtld_setjmp helper (and its counterparts for libunwind) must not access the trusted stack but should tail-call an epilogue assembly function.
  2. Trampoline tables are now allocated with malloc instead of mmap.
  3. Block all signals when a new thread is created and only restore the signal mask when the actual thread function is about to be called. This is need for full interrupted safety which will be implemented in the future.

@@ -210,14 +210,24 @@ _pthread_create(pthread_t * __restrict thread,
param.rtp = &rtp;
}

/*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a smaller diff that is a bit easier to understand might be to add this at the top-level of the file:

/*
 * c18n: Always block all signals when creating a new thread to allow
 * RTLD to setup the environment to handle signals.
 */
#if defined(__CHERI_PURE_CAPABILITY) && defined(RTLD_SANDBOX)
#define CREATE_SUSPENDED(thr) 1
#else
#define CREATE_SUSPENDED(thr) ((thr)->attr.suspend == THR_CREATE_SUSPENDED)
#endif

And then replace the place that check for THR_CREATE_SUSPENDED with this new helper macro.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that cause this line to run even though THR_CREATE_SUSPENDED is not actually set?

In my latest patch I just set create_suspended always to 1 when RTLD_SANDBOX is defined.

@dpgao dpgao merged commit 187bfb5 into dev Apr 24, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants