Skip to content

SIGBUS handler conflicts with rust's stack overflow handler #204

@singron

Description

@singron

Rust sets up a SIGBUS/SIGSEGV handler (See fn signal_handler in stack_overflow.rs). This handler prints out a message when a stack overflow occurs.

Unfortunately, this handler doesn't work well when chain called by signal-hook-registry for two reasons:

  1. At the end of the handler, it calls sigaction() to install SIG_DFL (the default signal handler). When it's chain called, this effectively unregisters signal-hook-registry's handler. For user code, it will appear as if your handler works the first time and then mysteriously becomes unregistered, as if SA_RESETHAND was used.

  2. If the siginfo has a non-zero si_addr but isn't a stack overflow, then the handler calls with_current_info without terminating the program. This can leave threads in an inconsistent internal state. In practice, I noticed that this could cause deadlocks on a later thread join.

If you want to register a handler for SIGBUS, you probably want to first use sigaction() to remove rust's handler or avoid signal-hook-registry entirely. The handler isn't load-bearing, and your program will still crash on a stack overflow.

Considering all the issues with SIGBUS and the similarity with some of the other FORBIDDEN signals (SIGSEGV, SIGILL, SIGFPE), it might be worth adding SIGBUS to FORBIDDEN or adding a note in the docs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions