Skip to content

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

Not planned
Not planned
@alexcrichton

Description

@alexcrichton
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...

Activity

added
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Jul 10, 2017
DemiMarie

DemiMarie commented on Jul 13, 2017

@DemiMarie
Contributor

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

joshlf

joshlf commented on Jul 13, 2017

@joshlf
Contributor

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

alexcrichton

alexcrichton commented on Jul 13, 2017

@alexcrichton
MemberAuthor

@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.

added
T-libsRelevant to the library team, which will review and decide on the PR/issue.
and removed
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Sep 26, 2023
joboet

joboet commented on Dec 1, 2024

@joboet
Member

Closing in favour of #133698.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-thread-localsArea: Thread local storage (TLS)C-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @alexcrichton@Enselic@joshlf@Mark-Simulacrum@DemiMarie

        Issue actions

          TLS accesses aren't async-signal-safe · Issue #43146 · rust-lang/rust