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

TLS accesses aren't async-signal-safe #43146

Open
alexcrichton opened this issue Jul 10, 2017 · 3 comments
Open

TLS accesses aren't async-signal-safe #43146

alexcrichton opened this issue Jul 10, 2017 · 3 comments
Labels
A-thread-locals Area: Thread local storage (TLS) C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@alexcrichton
Copy link
Member

On many Unix platforms we install a signal handler for SIGSEGV/SIGBUS to catch stack overflow. This starts off by accessing the thread-local stack guard which in turn will access a thread_local!. Unfortunately, though, thread_local! is not async-signal-safe due to a number of reasons:

Unfortunately I don't really know the best way to solve this...

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jul 10, 2017
@DemiMarie
Copy link
Contributor

Can we get the data from what the OS passes to the signal handler?

@joshlf
Copy link
Contributor

joshlf commented Jul 13, 2017

Would it be possible to not use the stdlib TLS mechanisms and instead implement a custom TLS access mechanism?

@alexcrichton
Copy link
Member Author

@DemiMarie oh the problem is that we currently use two thread-local pieces of information in the signal handler: the thread's name and the thread's guard page. We use the latter for determining whether we should print anything at all and the former for a nicer error message. Unfortunately the OS doesn't pass either of these to the signal handler, but we do currently extract the segfaulting address from the signal handler.

@joshlf AFAIK APIs like pthread_getspecific aren't async-signal safe, and even if #[thread_local] is async-signal-safe it's not available on all platforms we have this implemented for.

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 28, 2017
@alexcrichton alexcrichton added the A-thread-locals Area: Thread local storage (TLS) label Aug 25, 2017
@Enselic Enselic added T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-thread-locals Area: Thread local storage (TLS) C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants