libcore
libcore copied to clipboard
Use proper halting sequence for the panic handler
Currently the current panic handler simply is loop { }
. In release builds, this will likely optimize out and it also has problems because interrupts will still execute.
We should probably do something like this
asm!("cli"); // disable interrupts
loop {
asm!( "" ::::: "volatile"); // wrong syntax, I'm going from memory
}
This is a pretty big bug because if our panic handler halting loop gets optimized out, the panic handler will do nothing (and continue?)
our panic handler
libcore shouldn't have a panic handler at all — that's up to the application.
In certain cases, the panic handler may wish to try to write to a serial device to print the error, for example. Putting it in the core prevents that.
See also https://github.com/avr-rust/libcore/blob/874fbe3de745ba27e46b4334f1a47307f23bbae8/src/panicking.rs#L13-L16
I have reenabled the panic handler (without formatting) on my fork: panicking.rs
This allows me to write a panic handler in my crate. The only issue is that somewhere an overhead of 193 bytes is generated. I guess this is code from formatting the panic arguments but I have not found the offending part of libcore yet.