Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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