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

Commit

Permalink
Merge #96
Browse files Browse the repository at this point in the history
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 <jorge@japaric.io>
  • Loading branch information
bors[bot] and japaric committed Aug 25, 2018
2 parents a331853 + 903e97a commit f126dd8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions link.x.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ PROVIDE(DebugMonitor = DefaultHandler);
PROVIDE(PendSV = DefaultHandler);
PROVIDE(SysTick = DefaultHandler);

PROVIDE(DefaultHandler = DefaultDefaultHandler);
PROVIDE(UserHardFault = DefaultUserHardFault);
PROVIDE(DefaultHandler = DefaultHandler_);
PROVIDE(UserHardFault = UserHardFault_);

/* # Interrupt vectors */
EXTERN(__INTERRUPTS); /* `static` variable similar to `__EXCEPTIONS` */
Expand Down
18 changes: 10 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@

extern crate r0;

use core::{fmt, ptr};
use core::fmt;
use core::sync::atomic::{self, Ordering};

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

#[allow(unused_variables)]
#[doc(hidden)]
#[no_mangle]
pub unsafe extern "C" fn DefaultDefaultHandler() {
pub unsafe extern "C" fn UserHardFault_(ef: &ExceptionFrame) -> ! {
loop {
// add some side effect to prevent this from turning into a UDF instruction
// see rust-lang/rust#28728
ptr::read_volatile(&0u8);
// see rust-lang/rust#28728 for details
atomic::compiler_fence(Ordering::SeqCst);
}
}

#[doc(hidden)]
#[no_mangle]
pub unsafe extern "C" fn DefaultUserHardFault() {
pub unsafe extern "C" fn DefaultHandler_() -> ! {
loop {
// add some side effect to prevent this from turning into a UDF instruction
// see rust-lang/rust#28728
ptr::read_volatile(&0u8);
// see rust-lang/rust#28728 for details
atomic::compiler_fence(Ordering::SeqCst);
}
}

Expand Down Expand Up @@ -924,5 +926,5 @@ macro_rules! pre_init {
let f: unsafe fn() = $handler;
f();
}
}
};
}

0 comments on commit f126dd8

Please sign in to comment.