-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Make exit_on_sigint work again #17727
Conversation
// (Only a few actually needs these but doesn't hurt to do on all of them). | ||
rsp &= -16; // ensure 16-byte alignment | ||
rsp -= 128; // 128bytes red zone | ||
#if defined(_CPU_X86_64_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tkelman's going to complain that MSVC doesn't support the asm
keyword
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this is in ...-unix.c, I'll be happy to learn how to write this in msvc compatible way when we support using MSVC to build for unix =)
looks like a good improvement to me |
@@ -105,6 +105,7 @@ suppress_excp_printing(t::Task) = isa(t.storage, ObjectIdDict) ? get(get_task_tl | |||
|
|||
# runtime system hook called when a task finishes | |||
function task_done_hook(t::Task) | |||
# `finish_task` set `sigatomic` before entering this function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sets?
3c56850
to
9648228
Compare
Go back to modifying the ucontext since the concern I had was mainly due to a misunderstanding of a LWN article.... I'll need to repeat the test on the 5 architectures again. |
Tests (make sure Ctrl-C with I left |
// Do not use the main stack if this is a stack overflow since that will | ||
// not work.... | ||
if (e == jl_stackovf_exception) | ||
jl_rethrow(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on mach
, we re-use the signal stack for the rethrow call. should we eventually do that here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set sp
to the top of the signal stack and jmp
to the function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it does jl_call_in_ctx
with sp
set to the top of the signal stack (ptls2->signal_stack + sig_stack_size
), to preserve call to sigreturn (and in the mach
case, to get back to the right tid
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, Just need quite a bit of signal stack space for this to be reliable.
9648228
to
81ca3e6
Compare
Increase the signal stack size and use that stack for every call from the signal handler now. |
kern_return_t ret = thread_suspend(thread); | ||
HANDLE_MACH_ERROR("thread_suspend", ret); | ||
|
||
// This abort `sleep` and other syscall. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aborts sleep
and other syscalls
bf8479e
to
82f0b93
Compare
I would probably not put this in 0.5.0 but can go in 0.5.x once we're confident that it works well. |
what's left on this? it lgtm, and it's after branching now so that resolves the question of whether to do it before. |
Should be ready. I guess I need to rebase though. |
So that we don't need to run `jl_exit` in strange (signal handler) context due to missing exception handler.
Use it to make sure that `jl_rethrow` and `jl_exit` are running on the right thread and right stack when an exception/exit is caused by a signal. Fix #17706
82f0b93
to
03c3c70
Compare
Rebased. |
This makes the SIGINT signal handler work in combination with ASAN.
Yeah, should be fine and it should fix most of the symptoms. |
Add more
try
-catch
and sigatomic for top-level code/new tasksSo that we don't need to run
jl_exit
in strange (signal handler) contextdue to missing exception handler.
Implement
jl_call_in_ctx
on unix.Use it to make sure that
jl_rethrow
andjl_exit
are running on the rightthread and right stack when an exception/exit is caused by a signal.
Fix Unreliable SIGINT delivery #17706
Tested locally on Linux x86/x64/aarch64/arm and Mac (windows sigint handling seems to be really unreliable in general). According to musl source code, it should work there too. Implementation on platforms that I don't have access to (FreeBSD, PowerPC) is left as an exercise for people who do. =)
This uses assembly to set the register values instead of using sigreturn since it doesn't work reliably on Mac and may not work in the future due to mitigation of sigreturn oriented programming. (Just like all other low level features that we want to use that is blocked by security fixes....)
The final implementation is on the edge of what I'm happy to merge during feature freeze/backport after branching so I'll let others decide when this should be merge and whether it should be backported to 0.5 branch.