Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i#5256 sigprocmask: enable linux.sigaction on MacOS #5258

Merged
merged 38 commits into from
Dec 22, 2021

Conversation

abhinav92003
Copy link
Contributor

@abhinav92003 abhinav92003 commented Dec 17, 2021

Fixes and enables the linux.sigaction test on MacOS.

On MacOS, sigprocmask has different behaviour than Linux. It
does not fail for an unreadable or unwriteable old sigset. Also,
it does not need a size arg.

Fixes terminate_via_kill on MacOS. We need to add a constant
for Unix syscalls on Mac. Otherwise it results in a hang due to
the debug infinite loop at global_do_syscall_syscall when we
attempt to SIGTERM the process in linux.sigaction.

Fixes is_sys_kill detection on Mac. Things seem to work without
this, but the latest Mac documentation shows that the method
we use for non-MacOS (si_code <= 0) would work on Mac too:
https://www.unix.com/man-page/osx/3HEAD/siginfo.h

Fixes sigaction mask comparison in the linux.sigaction test.

Fixes a corner case where a bad old sigset fails the syscall with
EFAULT, but still succeeds in setting the new sigset.

Also adds a native execution test for linux.sigaction. This is to
verify kernel's behaviour in the CI.

Adds a -no_intercept_all_signals test for linux.sigaction.This is to
verify write faults in the path where DR has to manually modify
the old sigset returned by the kernel in sigprocmask.

Issue: #5257, #5254
Fixes: #5256

@abhinav92003 abhinav92003 changed the title i#5256 sigprocmask: add tests for MacOS. i#5256 sigprocmask: enable linux.sigaction on MacOS Dec 18, 2021
@abhinav92003
Copy link
Contributor Author

I'm seeing a hang in the linux.sigaction test on MacOS: https://gist.github.com/abhinav92003/3e59ff8fa71872d398890ff37293dd2f. It works fine till the end, but hangs at the SIGTERM. It also hangs when I remove everything but the kill(SIGTERM... from the test.

The test ends up succeeding after 90s but that's just because of the timeout.

It works fine when the test is run with -no_code_api -no_intercept_all_signals.

https://www.unix.com/man-page/osx/3HEAD/siginfo.h/
si_info <= 0 denotes user-sent signals on Mac as well.
@abhinav92003
Copy link
Contributor Author

The problem seems to be that the is_sys_kill call at

is_sys_kill(dcontext, pc, (byte *)sc->SC_XSP, &frame->info)) {

does not return true on Mac.

On Linux, the SIGTERM is recognised as a user-generated signal at

if (info->si_code <= 0)
. So it returns true early.
The second condition in is_sys_kill also returns false because is_at_do_syscall is false, but the syscall is a SYS_kill.

@abhinav92003
Copy link
Contributor Author

abhinav92003 commented Dec 19, 2021

I made a fix to is_sys_kill to allow detecting user-sent signals on Mac, but then I realised that it doesn't make a difference because the if-block executes even if is_sys_kill returns false.

Following the bug more, I see that this may be the loop it's hitting:

jmp GLOBAL_REF(debug_infinite_loop)

This could be because SYS_kill is failing.

@abhinav92003
Copy link
Contributor Author

run arm tests

@abhinav92003 abhinav92003 marked this pull request as ready for review December 19, 2021 18:59
core/unix/include/syscall_mach.h Outdated Show resolved Hide resolved
core/unix/os.c Show resolved Hide resolved
core/unix/signal.c Show resolved Hide resolved
core/unix/signal.c Show resolved Hide resolved
core/unix/signal.c Show resolved Hide resolved
suite/tests/CMakeLists.txt Outdated Show resolved Hide resolved
suite/tests/CMakeLists.txt Outdated Show resolved Hide resolved
suite/tests/linux/sigaction.c Outdated Show resolved Hide resolved
suite/tests/linux/sigaction.c Show resolved Hide resolved
core/unix/include/syscall_mach.h Outdated Show resolved Hide resolved
core/unix/os.c Outdated Show resolved Hide resolved
core/unix/signal.c Show resolved Hide resolved
core/unix/signal.c Show resolved Hide resolved
suite/tests/linux/sigaction.c Show resolved Hide resolved
@abhinav92003 abhinav92003 merged commit 2719382 into master Dec 22, 2021
@abhinav92003 abhinav92003 deleted the i5256-sigprocmask-macos branch December 22, 2021 03:47
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.

sigprocmask handling not being invoked on Mac
2 participants