Skip to content

Signal rewrite#473

Merged
OFFTKP merged 7 commits intomasterfrom
signalssss
Mar 28, 2026
Merged

Signal rewrite#473
OFFTKP merged 7 commits intomasterfrom
signalssss

Conversation

@OFFTKP
Copy link
Copy Markdown
Owner

@OFFTKP OFFTKP commented Mar 11, 2026

Signal handling has been rewritten to defer asynchronous signals to "safepoints".

Documented here: https://felix86.com/docs/devs/signals/

In short, asynchronous signals are always deferred to a safepoint and never handled immediately. A safepoint is a store instruction to a page. If there's deferred signals, the page is non-writeable, if there's not, the page is writeable so the store goes through and nothing happens. If there's deferred signals, a segmentation fault happens which gets handled and prepares a frame and the signal handler arguments. Then, it returns from the host signal handler, setting the PC to the dispatcher and the RIP to the signal handler.

To account for syscalls like sigsuspend, a safepoint is placed after each syscall instruction. This matches the x86 behavior of the signal happening and the ucontext RIP pointing to right after the syscall instruction and RAX having the value of -EINTR. From the POV of the guest application, it's as if the signal got handled during the sigsuspend.

This makes applications that would previously crash now work and improves general signal stability. For example, golang applications no longer need to disable asynchronous signal preemption to be functional. Additionally, we don't have to block signals when enterring C++ code, and we don't handle signals from inside host signal handlers or from inside C++ code, which leaks stack memory if the signal doesn't return via sigreturn.

New signal related tests have been added in https://github.com/felix86-emu/signal_tests and are now part of the CI via https://github.com/felix86-emu/binary_tests

@OFFTKP OFFTKP marked this pull request as ready for review March 26, 2026 17:28
@OFFTKP OFFTKP changed the title [WIP] Signal rewrite Signal rewrite Mar 26, 2026
@OFFTKP OFFTKP merged commit 79de835 into master Mar 28, 2026
4 of 6 checks passed
@OFFTKP OFFTKP deleted the signalssss branch March 28, 2026 13:53
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.

1 participant