rust-embedded / embedonomicon

How to bootstrap support for a no_std target
https://docs.rust-embedded.org/embedonomicon/
Apache License 2.0
206 stars 32 forks source link

New topic: Unwinding #17

Open japaric opened 6 years ago

japaric commented 6 years ago

We should add a topic about implementing your own panic_unwind crate. I know this involves the "eh_personality" lang item but I have never done this myself. If someone has a working example that would be very useful!

As unwinding depends on an unstable feature this topic is not a blocker for the edition release.

ianjfrosst commented 5 years ago

The "Writing an OS in Rust" blog has a short example. Redox OS also has a more thorough implementation. Not sure about embedded Rust projects, though.

jethrogb commented 5 years ago

On a related note: has anyone considered writing an unwinder in Rust? Now that compiler-builtins is largely finished, this seems one of the last pieces of C dependencies for many platforms.

therealprof commented 5 years ago

Just curious: What's the use case for unwinding in embedded scenarios?

japaric commented 5 years ago

@therealprof running unit tests on the device. Even with a CTF (Custom Test Framework) that uses Result::Err to signal errors panics can still occur during any unit test (e.g. debug_assert!) and that would cause the test runner to stop (e.g. panic-halt). With catch_unwind functionality it would be possible to catch the panic, mark the unit test as failed and continue to run the unit tests.

therealprof commented 5 years ago

Makes sense, thanks for the explanation.

ryankurte commented 5 years ago

it's super cursed but i think it'd be useful to document the implications of unwinding across ffi boundaries for c/rust interop and supporting the piecewise approach to moving to rust.

ideally they never happen, but, when they do on a desktop the errors are incomprehensible, and i haven't been bold enough to see what happens in an embedded context.