Skip to content
This repository was archived by the owner on Jan 24, 2022. It is now read-only.

Commit f126dd8

Browse files
bors[bot]japaric
andcommitted
Merge #96
96: reduce the size of default handlers r=adamgreig a=japaric this commit replaces the two default handler (DefaultDefaultHandler and DefaultUserHardFault) by a single handler named `EndlessLoop`. This results in one less symbol being generated. Also this new handler uses `compiler_fence` to avoid the "infinite loops w/o side effects are undef values" bug in LLVM. `compiler_fence` is guaranteed to generate no code so this reduces the size of the handler (when compiler in release). --- As far as I could test this new handler doesn't generate abort instructions when optimized so it seems like a safe replacement. If we are feeling paranoid then once #95 we could implement EndlessLoop in assembly. r? @rust-embedded/cortex-m (anyone) Co-authored-by: Jorge Aparicio <[email protected]>
2 parents a331853 + 903e97a commit f126dd8

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

link.x.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ PROVIDE(DebugMonitor = DefaultHandler);
4545
PROVIDE(PendSV = DefaultHandler);
4646
PROVIDE(SysTick = DefaultHandler);
4747

48-
PROVIDE(DefaultHandler = DefaultDefaultHandler);
49-
PROVIDE(UserHardFault = DefaultUserHardFault);
48+
PROVIDE(DefaultHandler = DefaultHandler_);
49+
PROVIDE(UserHardFault = UserHardFault_);
5050

5151
/* # Interrupt vectors */
5252
EXTERN(__INTERRUPTS); /* `static` variable similar to `__EXCEPTIONS` */

src/lib.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@
403403

404404
extern crate r0;
405405

406-
use core::{fmt, ptr};
406+
use core::fmt;
407+
use core::sync::atomic::{self, Ordering};
407408

408409
/// Registers stacked (pushed into the stack) during an exception
409410
#[derive(Clone, Copy)]
@@ -529,23 +530,24 @@ pub unsafe extern "C" fn Reset() -> ! {
529530
}
530531
}
531532

533+
#[allow(unused_variables)]
532534
#[doc(hidden)]
533535
#[no_mangle]
534-
pub unsafe extern "C" fn DefaultDefaultHandler() {
536+
pub unsafe extern "C" fn UserHardFault_(ef: &ExceptionFrame) -> ! {
535537
loop {
536538
// add some side effect to prevent this from turning into a UDF instruction
537-
// see rust-lang/rust#28728
538-
ptr::read_volatile(&0u8);
539+
// see rust-lang/rust#28728 for details
540+
atomic::compiler_fence(Ordering::SeqCst);
539541
}
540542
}
541543

542544
#[doc(hidden)]
543545
#[no_mangle]
544-
pub unsafe extern "C" fn DefaultUserHardFault() {
546+
pub unsafe extern "C" fn DefaultHandler_() -> ! {
545547
loop {
546548
// add some side effect to prevent this from turning into a UDF instruction
547-
// see rust-lang/rust#28728
548-
ptr::read_volatile(&0u8);
549+
// see rust-lang/rust#28728 for details
550+
atomic::compiler_fence(Ordering::SeqCst);
549551
}
550552
}
551553

@@ -924,5 +926,5 @@ macro_rules! pre_init {
924926
let f: unsafe fn() = $handler;
925927
f();
926928
}
927-
}
929+
};
928930
}

0 commit comments

Comments
 (0)