You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ch12-sjlj Why the program not execute the line println!("early return!");, set_jmp and long_jmp didn`t work. #87
changed the title [-]吃2[/-][+]ch12-sjlj Why the program not execute the line `println!("early return!");`, set_jmp and long_jmp didn`t work.[/+]on Sep 19, 2022
To provide a bit more context, at least as of 2023-01-14, Rust Nightly produces code that just crashes (Segementation Fault), instead of succeeding with the setjmp() / longjmp() trickery, in the ch12/ch12-sjlj example.
I'm not that surprised. Even in C setjmp() / longjmp() are wildly unsafe C library calls, that it's recomended never to use unless you have absolutely no other choice. And preferably you wouldn't be longjmp()ing from a signal handler back to other (non-signal handler) code, as is implemented here. FWIW, the idea of trying to setjmp()/longjmp() via a foreign function interface (ie, Rust to C) struck me as very unlikely to succeed; I guess there was maybe a rust compiler Nightly version/LLDB version where what was implemented happened to work, but it seems extremely fragile.
From a bit of debugging it is unsurprisingly crashing in the longjmp() call. And the fact that trying to read the franken_pointer value reports it couldn't read from address 0x18 strongly implies that's an offset from a NULL pointer. Presumably only the liberal use of unsafe here is preventing the compiler from saying "What? No, just no" to this :-)
(FTR, it looks like RETURN_HERE -- the jump buffer -- does have a valid address, and might even have plausible contents -- although there's a lot of 0 bytes in it.)
Activity
[-]吃2[/-][+]ch12-sjlj Why the program not execute the line `println!("early return!");`, set_jmp and long_jmp didn`t work.[/+]ewenmcneill commentedon Jan 14, 2023
To provide a bit more context, at least as of 2023-01-14, Rust Nightly produces code that just crashes (Segementation Fault), instead of succeeding with the
setjmp()/longjmp()trickery, in thech12/ch12-sjljexample.I'm not that surprised. Even in C
setjmp()/longjmp()are wildly unsafe C library calls, that it's recomended never to use unless you have absolutely no other choice. And preferably you wouldn't belongjmp()ing from a signal handler back to other (non-signal handler) code, as is implemented here. FWIW, the idea of trying tosetjmp()/longjmp()via a foreign function interface (ie, Rust to C) struck me as very unlikely to succeed; I guess there was maybe a rust compiler Nightly version/LLDB version where what was implemented happened to work, but it seems extremely fragile.From a bit of debugging it is unsurprisingly crashing in the
longjmp()call. And the fact that trying to read thefranken_pointervalue reports it couldn't read from address0x18strongly implies that's an offset from a NULL pointer. Presumably only the liberal use ofunsafehere is preventing the compiler from saying "What? No, just no" to this :-)(FTR, it looks like
RETURN_HERE-- the jump buffer -- does have a valid address, and might even have plausible contents -- although there's a lot of 0 bytes in it.)Ewen
Example core dump back trace
swkim01 commentedon Apr 18, 2023
Just remove attributes {#[link_name...]) of setjmp and longjmp signatures.
sm13 commentedon Sep 11, 2024
And this works because...