First, is there another way to do this in Rust? I'm calling assembly and I need to be able to bail out. So assembly would call Rust which would longjmp to unwind the stack back into Rust.
I don't think Rust's ownership semantics are well-defined if you longjmp either into or out of Rust code.
The thing that leaps to mind for me is the Drop trait. The LLVM intrinsics have no knowledge of Rust's drop flags, so traversing, or leaving a stack frame with Droppable values in it using longjmp will leak the associated resources, while entering a frame that way will cause any Droppable values to be inappropriately drop()ped without being initialized first.
If you're careful to only ever longjmp out of code that cannot have such values on the stack, and to only ever longjmp into code prepared to be reentered in the middle in ways that aren't formally possible in Rust, you might be able to get away with it anyways, though.
You could, of course, perform the moral equivalent of a longjmpwithin your asm-language code to return to immediately inside of the call boundary, then return normally to Rust from there…
I guess when I said unwind the stack it sounded like I was longjmp'ing from deep in Rust+asm back into a top level routine. No, I'm calling asm and bailing out of that with a longjmp. So this falls under your careful to only ever longjmp out of code that cannot have such values on the stack category.
I don't want to craft my own longjmp because I'm also using setjmp/longjmp for normal signal handling.
So it looks like I'll be a little on the bleeding edge and use LLVMINT. longjmp is a pretty standard system programming tool and Rust is a systems programming language. I'll figure this out and write it up. I'm a little surprised it hasn't been done already.
C++ is also a systems programming language that doesn't mix well with setjmp/longjmp. You can do it, if you're careful, but you can say the same about Rust. The fact that there aren't bindings is surely just because nobody wanted them yet.
I'm using nightly and I'm not writing a Crate. This is in main.rs and I'll self identify as being fairly new to Rust.
I moved the feature gate to the first line of main.rs:
#![feature(link_llvm_intrinsics)]
and now I get:
error[E0554]: #[feature] may not be used on the beta release channel
The other errors finally went away.
I know what nightly is but I don't know what the beta release channel is. Also, would this be the same error if I used LLVMINT as a crate rather cut+paste the few lines I need?
Yes, I pasted that text into a file and compiled it and got the same error:
error[E0554]: #[feature] may not be used on the beta release channel
--> x.rs:1:1
|
1 | #![feature(link_llvm_intrinsics)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error