Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HardFaultTrampoline now passes &mut ExceptionFrame #515

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cortex-m-rt/examples/override-exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ unsafe fn DefaultHandler(_irqn: i16) {
}

#[exception]
unsafe fn HardFault(_ef: &ExceptionFrame) -> ! {
unsafe fn HardFault(_ef: &mut ExceptionFrame) -> ! {
asm::bkpt();

loop {}
Expand Down
2 changes: 1 addition & 1 deletion cortex-m-rt/examples/unsafe-hard-fault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ fn foo() -> ! {
}

#[exception]
unsafe fn HardFault(_ef: &ExceptionFrame) -> ! {
unsafe fn HardFault(_ef: &mut ExceptionFrame) -> ! {
loop {}
}
2 changes: 1 addition & 1 deletion cortex-m-rt/examples/unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ unsafe fn DefaultHandler(_irqn: i16) {
}

#[exception]
unsafe fn HardFault(_ef: &ExceptionFrame) -> ! {
unsafe fn HardFault(_ef: &mut ExceptionFrame) -> ! {
foo();

loop {}
Expand Down
6 changes: 3 additions & 3 deletions cortex-m-rt/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
&& match &f.sig.inputs[0] {
FnArg::Typed(arg) => match arg.ty.as_ref() {
Type::Reference(r) => {
r.lifetime.is_none() && r.mutability.is_none()
r.lifetime.is_none() && r.mutability.is_some()
}
_ => false,
},
Expand All @@ -346,7 +346,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
return parse::Error::new(
fspan,
if args.trampoline {
"`HardFault` handler must have signature `unsafe fn(&ExceptionFrame) -> !`"
"`HardFault` handler must have signature `unsafe fn(&mut ExceptionFrame) -> !`"
} else {
"`HardFault` handler must have signature `unsafe fn() -> !`"
},
Expand All @@ -368,7 +368,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
#(#attrs)*
#[doc(hidden)]
#[export_name = "_HardFault"]
unsafe extern "C" fn #tramp_ident(frame: &::cortex_m_rt::ExceptionFrame) {
unsafe extern "C" fn #tramp_ident(frame: &mut ::cortex_m_rt::ExceptionFrame) {
#ident(frame)
}

Expand Down
2 changes: 1 addition & 1 deletion cortex-m-rt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ pub use macros::entry;
/// ## HardFault handler
///
/// `#[exception(trampoline = true)] unsafe fn HardFault(..` sets the hard fault handler.
/// If the trampoline parameter is set to true, the handler must have signature `unsafe fn(&ExceptionFrame) -> !`.
/// If the trampoline parameter is set to true, the handler must have signature `unsafe fn(&mut ExceptionFrame) -> !`.
/// If set to false, the handler must have signature `unsafe fn() -> !`.
///
/// This handler is not allowed to return as that can cause undefined behavior.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ fn foo() -> ! {

#[exception]
unsafe fn HardFault(_ef: &ExceptionFrame, undef: u32) -> ! {
//~^ ERROR `HardFault` handler must have signature `unsafe fn(&ExceptionFrame) -> !`
//~^ ERROR `HardFault` handler must have signature `unsafe fn(&mut ExceptionFrame) -> !`
loop {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ fn foo() -> ! {

#[exception(trampoline = true)]
unsafe fn HardFault() -> ! {
//~^ ERROR `HardFault` handler must have signature `unsafe fn(&ExceptionFrame) -> !`
//~^ ERROR `HardFault` handler must have signature `unsafe fn(&mut ExceptionFrame) -> !`
loop {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn foo() -> ! {
}

#[exception(trampoline = false)]
unsafe fn HardFault(_ef: &ExceptionFrame) -> ! {
unsafe fn HardFault(_ef: &mut ExceptionFrame) -> ! {
//~^ ERROR `HardFault` handler must have signature `unsafe fn() -> !`
loop {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub mod reachable {
use cortex_m_rt::{exception, ExceptionFrame};

#[exception] //~ ERROR symbol `_HardFault` is already defined
unsafe fn HardFault(_ef: &ExceptionFrame) -> ! {
unsafe fn HardFault(_ef: &mut ExceptionFrame) -> ! {
loop {}
}
}
4 changes: 2 additions & 2 deletions cortex-m-rt/tests/compile-fail/hard-fault-twice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ fn foo() -> ! {
}

#[exception]
unsafe fn HardFault(_ef: &ExceptionFrame) -> ! {
unsafe fn HardFault(_ef: &mut ExceptionFrame) -> ! {
loop {}
}

pub mod reachable {
use cortex_m_rt::{exception, ExceptionFrame};

#[exception] //~ ERROR symbol `_HardFault` is already defined
unsafe fn HardFault(_ef: &ExceptionFrame) -> ! {
unsafe fn HardFault(_ef: &mut ExceptionFrame) -> ! {
loop {}
}
}
2 changes: 1 addition & 1 deletion cortex-m-rt/tests/compile-fail/unsafe-init-static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ unsafe fn DefaultHandler(_irq: i16) {
}

#[exception]
unsafe fn HardFault(_frame: &cortex_m_rt::ExceptionFrame) -> ! {
unsafe fn HardFault(_frame: &mut cortex_m_rt::ExceptionFrame) -> ! {
static mut X: u32 = init(); //~ ERROR requires unsafe
loop {}
}
Expand Down
Loading