-
Notifications
You must be signed in to change notification settings - Fork 89
Description
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:
-
At the end of the handler, it calls
sigaction()to installSIG_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 ifSA_RESETHANDwas used. -
If the siginfo has a non-zero si_addr but isn't a stack overflow, then the handler calls
with_current_infowithout 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.