libcore icon indicating copy to clipboard operation
libcore copied to clipboard

Use proper halting sequence for the panic handler

Open dylanmckay opened this issue 7 years ago • 4 comments

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
}

dylanmckay avatar Nov 24 '17 12:11 dylanmckay

This is a pretty big bug because if our panic handler halting loop gets optimized out, the panic handler will do nothing (and continue?)

dylanmckay avatar Nov 24 '17 12:11 dylanmckay

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.

shepmaster avatar Nov 24 '17 13:11 shepmaster

See also https://github.com/avr-rust/libcore/blob/874fbe3de745ba27e46b4334f1a47307f23bbae8/src/panicking.rs#L13-L16

shepmaster avatar Nov 24 '17 13:11 shepmaster

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.

Rahix avatar Sep 18 '18 19:09 Rahix