-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Print stack overflow messages for Linux and OS X #16388
Conversation
Is there a particular reason this can't be in Rust? |
Yes, I believe this should all largely be written in rust rather than in C (other signal handlers are already written in rust). I'm also hesitant to land linux-only support for this feature. I would much rather implement everything in one sweep than be in a confusing state for awhile while we're waiting on the next few patches. |
I wrote it in C since I don't find bindings for signal things. I see there's some in libnative (why are those there?), but that's still missing sigaltstack, SIGSTKSZ, stack_t, siginfo_t.si_addr. Isn't rust-bindgen good enough to handle system headers? |
You can easily write the necessary bindings (or extend the ones that exist already), e.g. struct stack_t {
ss_sp: *mut libc::c_void,
ss_flags: libc::c_int,
ss_size: libc::size_t
}
extern {
fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> libc::c_int
}
The in-tree extern bindings are hand-written, not created with rust-bindgen. |
I'm fine with making this Linux-only for now, as I prefer things to be in
|
This works on Linux and OS X now. |
@@ -249,6 +248,7 @@ mod signal { | |||
pub sa_flags: libc::c_int, | |||
} | |||
|
|||
#[cfg(target_os = "macos")] |
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.
My system (OSX 10.9) has this definition:
struct __sigaction {
union __sigaction_u __sigaction_u; /* signal handler */
void (*sa_tramp)(void *, int, int, siginfo_t *, void *);
sigset_t sa_mask; /* signal mask to apply */
int sa_flags; /* see signal options below */
};
How come you changed it?
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.
That's __sigaction not sigaction.
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.
Aha! I should remind myself that I have eyes! I suspect that ios is the same in this regard in that case and the upper one should probably just be deleted.
I'll try to take a closer look at this soon (sadly not before next week), but how much of an effort do you think this will be to extend this strategy to windows? I would hate to commit to a unix-only design only to find out later that it isn't compatible with windows for one reason or another. You may also want to download the arm/android toolchain as you should be able to just tweak a |
This should be simpler on Windows (with the exception of green threads which would need the same handling as Unix). However it Windows does not install guard pages on threads created by CreateThread, nor will it call the vectored exception handler I installed. I think we're doing something bad in the runtime somewhere (excluding writing to fs:0x14). |
ops.stack_guard = rt::thread::main_guard_page(); | ||
task.put_runtime(ops); | ||
return task; | ||
} |
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.
I'd rather not add a new public function for this, and this seems like something that callers of new
need to worry about, so could you add an Option<uint>
parameter to new
instead?
Also, can you add tests for all the functionality added here? You should be able to just spawn a subprocess and then inspect the output to ensure that the handlers were triggered correctly. Some tests that should be written:
You can ignore the test for unimplemented platforms for now. |
Another idea I thought of today is that you may be able to remove a good portion of the guard page logic by using |
4dade58
to
f56cef3
Compare
This passes tests on try now (with the exception of BSD, which I hopefully fixed) |
I see you test for Android too, so I added (untested) support for it. |
All Android test fails with |
I'm just disabling Android for now. We can fix that later. |
Sure, we can land this for now with android disabled. Could you open an issue on enabling for android @Zoxc? FYI this is the definition in the header file: extern __sighandler_t bsd_signal(int, __sighandler_t);
/* the default is bsd */
static __inline__ __sighandler_t signal(int s, __sighandler_t f)
{
return bsd_signal(s,f);
} |
This installs signal handlers to print out stack overflow messages on Linux. It also ensures the main thread has a guard page. This will catch stack overflows in external code. It's done in preparation of switching to stack probes (#16012). I've done some simple tests with overflowing the main thread, native threads and green threads (with and without UV) on x86-64. This might work on ARM, MIPS and x86-32. I've been unable to run the test suite on this because of #16305.
Both c.rs and stack_overflow.rs had bindings of libc's signal-handling routines. It looks like the split dated from rust-lang#16388, when (what is now) c.rs was in libnative but not libgreen. Nobody is currently using the c.rs bindings, but they're a bit more accurate in some places. Move everything to c.rs (since I'll need signal handling in process.rs, and we should avoid duplication), clean up the bindings, and manually double-check everything against the relevant system headers (fixing a few things in the process). Between the last commit and this one, we can now drop `#![allow(dead_code)]` from c.rs, which should help avoid binding rot in the future.
Both c.rs and stack_overflow.rs had bindings of libc's signal-handling routines. It looks like the split dated from rust-lang#16388, when (what is now) c.rs was in libnative but not libgreen. Nobody is currently using the c.rs bindings, but they're a bit more accurate in some places. Move everything to c.rs (since I'll need signal handling in process.rs, and we should avoid duplication), clean up the bindings, and manually double-check everything against the relevant system headers (fixing a few things in the process). Between the last commit and this one, we can now drop `#![allow(dead_code)]` from c.rs, which should help avoid binding rot in the future.
Both c.rs and stack_overflow.rs had bindings of libc's signal-handling routines. It looks like the split dated from rust-lang#16388, when (what is now) c.rs was in libnative but not libgreen. Nobody is currently using the c.rs bindings, but they're a bit more accurate in some places. Move everything to c.rs (since I'll need signal handling in process.rs, and we should avoid duplication), clean up the bindings, and manually double-check everything against the relevant system headers (fixing a few things in the process).
Both c.rs and stack_overflow.rs had bindings of libc's signal-handling routines. It looks like the split dated from rust-lang#16388, when (what is now) c.rs was in libnative but not libgreen. Nobody is currently using the c.rs bindings, but they're a bit more accurate in some places. Move everything to c.rs (since I'll need signal handling in process.rs, and we should avoid duplication), clean up the bindings, and manually double-check everything against the relevant system headers (fixing a few things in the process).
internal: Record FnAbi This unfortunately breaks our lub coercions, so will need to look into fixing that first, though I am not sure what is going wrong where... Stubbed some stuff out for the time being.
This installs signal handlers to print out stack overflow messages on Linux. It also ensures the main thread has a guard page.
This will catch stack overflows in external code. It's done in preparation of switching to stack probes (#16012).
I've done some simple tests with overflowing the main thread, native threads and green threads (with and without UV) on x86-64.
This might work on ARM, MIPS and x86-32.
I've been unable to run the test suite on this because of #16305.