Uh oh!
There was an error while loading. Please reload this page.
Print stack overflow messages for Linux and OS X - #16388
Conversation
huonw
commented
Aug 10, 2014
Is there a particular reason this can't be in Rust? |
alexcrichton
commented
Aug 10, 2014
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. |
Zoxc
commented
Aug 10, 2014
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? |
huonw
commented
Aug 10, 2014
You can easily write the necessary bindings (or extend the ones that exist already), e.g. structstack_t{ss_sp:*mut libc::c_void,ss_flags: libc::c_int,ss_size: libc::size_t}extern{fnsigaltstack(ss:*conststack_t,oss:*mutstack_t) -> libc::c_int}
The in-tree extern bindings are hand-written, not created with rust-bindgen. |
pcwalton
commented
Aug 11, 2014
I'm fine with making this Linux-only for now, as I prefer things to be in
|
Zoxc
commented
Aug 11, 2014
This works on Linux and OS X now. |
There was a problem hiding this comment.
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_tsa_mask; /* signal mask to apply */intsa_flags; /* see signal options below */
}; How come you changed it?
There was a problem hiding this comment.
That's __sigaction not sigaction.
There was a problem hiding this comment.
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.
alexcrichton
commented
Aug 11, 2014
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 |
Zoxc
commented
Aug 13, 2014
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). |
There was a problem hiding this comment.
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?
alexcrichton
commented
Aug 15, 2014
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. |
alexcrichton
commented
Aug 16, 2014
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
f56cef3CompareZoxc
commented
Oct 23, 2014
This passes tests on try now (with the exception of BSD, which I hopefully fixed) |
Zoxc
commented
Oct 24, 2014
I see you test for Android too, so I added (untested) support for it. |
Zoxc
commented
Oct 24, 2014
All Android test fails with |
Zoxc
commented
Oct 24, 2014
I'm just disabling Android for now. We can fix that later. |
alexcrichton
commented
Oct 24, 2014
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_tbsd_signal(int, __sighandler_t); /* the default is bsd */static __inline__ __sighandler_tsignal(ints, __sighandler_tf)
{ returnbsd_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.