From fbd29fc7fe75ec9e906d8e961ab08cf66794d305 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 6 Sep 2018 00:25:45 +0200 Subject: add compile-fail tests; test only on nightly we'll test on beta when 1.30-beta is out --- .../tests/compile-fail/default-handler-hidden.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 cortex-m-rt/tests/compile-fail/default-handler-hidden.rs (limited to 'cortex-m-rt/tests/compile-fail/default-handler-hidden.rs') diff --git a/cortex-m-rt/tests/compile-fail/default-handler-hidden.rs b/cortex-m-rt/tests/compile-fail/default-handler-hidden.rs new file mode 100644 index 0000000..059c10b --- /dev/null +++ b/cortex-m-rt/tests/compile-fail/default-handler-hidden.rs @@ -0,0 +1,22 @@ +// ignore-test :sadface: it's not possible to prevent this user error at compile time +// see rust-lang/rust#53975 for details + +#![no_main] +#![no_std] + +extern crate cortex_m_rt; +extern crate panic_semihosting; + +use cortex_m_rt::{entry, exception}; + +#[entry] +fn foo() -> ! { + loop {} +} + +mod hidden { + use cortex_m_rt::exception; + + #[exception] + fn DefaultHandler(_irqn: i16) {} +} -- cgit v1.2.3 From 85ba898dc80d14dc35dd21abab7684bb1ea0f4c8 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 17 Sep 2018 23:38:18 +0200 Subject: use panic-halt instead of panic-{abort,semihosting} the former requires a feature gate; the later pulls in the cortex-m crate --- cortex-m-rt/Cargo.toml | 3 +-- cortex-m-rt/examples/alignment.rs | 2 +- cortex-m-rt/examples/data_overflow.rs | 2 +- cortex-m-rt/examples/device.rs | 2 +- cortex-m-rt/examples/divergent-default-handler.rs | 2 +- cortex-m-rt/examples/divergent-exception.rs | 2 +- cortex-m-rt/examples/entry-static.rs | 2 +- cortex-m-rt/examples/main.rs | 2 +- cortex-m-rt/examples/minimal.rs | 2 +- cortex-m-rt/examples/override-exception.rs | 2 +- cortex-m-rt/examples/pre_init.rs | 2 +- cortex-m-rt/examples/rand.rs | 2 +- cortex-m-rt/examples/state.rs | 2 +- cortex-m-rt/examples/unsafe-default-handler.rs | 2 +- cortex-m-rt/examples/unsafe-entry.rs | 2 +- cortex-m-rt/examples/unsafe-exception.rs | 2 +- cortex-m-rt/examples/unsafe-hard-fault.rs | 2 +- cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs | 2 +- cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs | 2 +- cortex-m-rt/tests/compile-fail/default-handler-hidden.rs | 2 +- cortex-m-rt/tests/compile-fail/default-handler-twice.rs | 2 +- cortex-m-rt/tests/compile-fail/entry-args.rs | 2 +- cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs | 2 +- cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs | 2 +- cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs | 2 +- cortex-m-rt/tests/compile-fail/entry-hidden.rs | 2 +- cortex-m-rt/tests/compile-fail/entry-soundness.rs | 2 +- cortex-m-rt/tests/compile-fail/entry-twice.rs | 2 +- cortex-m-rt/tests/compile-fail/exception-args.rs | 2 +- cortex-m-rt/tests/compile-fail/exception-bad-signature-1.rs | 2 +- cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs | 2 +- cortex-m-rt/tests/compile-fail/exception-hidden.rs | 2 +- cortex-m-rt/tests/compile-fail/exception-soundness.rs | 2 +- cortex-m-rt/tests/compile-fail/exception-twice.rs | 2 +- cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs | 2 +- cortex-m-rt/tests/compile-fail/hard-fault-hidden.rs | 2 +- cortex-m-rt/tests/compile-fail/hard-fault-twice.rs | 2 +- cortex-m-rt/tests/compile-fail/pre-init-args.rs | 2 +- cortex-m-rt/tests/compile-fail/pre-init-bad-signature-1.rs | 2 +- cortex-m-rt/tests/compile-fail/pre-init-bad-signature-2.rs | 2 +- cortex-m-rt/tests/compile-fail/pre-init-hidden.rs | 2 +- cortex-m-rt/tests/compile-fail/pre-init-twice.rs | 2 +- 42 files changed, 42 insertions(+), 43 deletions(-) (limited to 'cortex-m-rt/tests/compile-fail/default-handler-hidden.rs') diff --git a/cortex-m-rt/Cargo.toml b/cortex-m-rt/Cargo.toml index 41a958d..ae72260 100644 --- a/cortex-m-rt/Cargo.toml +++ b/cortex-m-rt/Cargo.toml @@ -16,8 +16,7 @@ cortex-m-rt-macros = { path = "macros", version = "0.1.1" } [dev-dependencies] cortex-m = "0.5.4" -panic-abort = "0.3.0" -panic-semihosting = "0.4.0" +panic-halt = "0.2.0" [dev-dependencies.rand] default-features = false diff --git a/cortex-m-rt/examples/alignment.rs b/cortex-m-rt/examples/alignment.rs index 25d755d..4421e69 100644 --- a/cortex-m-rt/examples/alignment.rs +++ b/cortex-m-rt/examples/alignment.rs @@ -5,7 +5,7 @@ #![no_std] extern crate cortex_m_rt as rt; -extern crate panic_abort; +extern crate panic_halt; use core::ptr; diff --git a/cortex-m-rt/examples/data_overflow.rs b/cortex-m-rt/examples/data_overflow.rs index ceec18b..ea48b23 100644 --- a/cortex-m-rt/examples/data_overflow.rs +++ b/cortex-m-rt/examples/data_overflow.rs @@ -6,7 +6,7 @@ #![no_std] extern crate cortex_m_rt as rt; -extern crate panic_abort; +extern crate panic_halt; use core::ptr; diff --git a/cortex-m-rt/examples/device.rs b/cortex-m-rt/examples/device.rs index 950a564..dc1c738 100644 --- a/cortex-m-rt/examples/device.rs +++ b/cortex-m-rt/examples/device.rs @@ -6,7 +6,7 @@ #![no_std] extern crate cortex_m_rt as rt; -extern crate panic_semihosting; +extern crate panic_halt; use rt::entry; diff --git a/cortex-m-rt/examples/divergent-default-handler.rs b/cortex-m-rt/examples/divergent-default-handler.rs index cbb8bb1..22fa437 100644 --- a/cortex-m-rt/examples/divergent-default-handler.rs +++ b/cortex-m-rt/examples/divergent-default-handler.rs @@ -4,7 +4,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception}; diff --git a/cortex-m-rt/examples/divergent-exception.rs b/cortex-m-rt/examples/divergent-exception.rs index 9998884..cb2247b 100644 --- a/cortex-m-rt/examples/divergent-exception.rs +++ b/cortex-m-rt/examples/divergent-exception.rs @@ -3,7 +3,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception}; diff --git a/cortex-m-rt/examples/entry-static.rs b/cortex-m-rt/examples/entry-static.rs index 1b2e118..55e7a89 100644 --- a/cortex-m-rt/examples/entry-static.rs +++ b/cortex-m-rt/examples/entry-static.rs @@ -6,7 +6,7 @@ #![no_std] extern crate cortex_m_rt as rt; -extern crate panic_semihosting; +extern crate panic_halt; use rt::entry; diff --git a/cortex-m-rt/examples/main.rs b/cortex-m-rt/examples/main.rs index e5ce3d1..b8ab66e 100644 --- a/cortex-m-rt/examples/main.rs +++ b/cortex-m-rt/examples/main.rs @@ -5,7 +5,7 @@ #![no_std] extern crate cortex_m_rt as rt; -extern crate panic_semihosting; +extern crate panic_halt; #[no_mangle] pub unsafe extern "C" fn main() -> ! { diff --git a/cortex-m-rt/examples/minimal.rs b/cortex-m-rt/examples/minimal.rs index 6f60180..bd0a6ad 100644 --- a/cortex-m-rt/examples/minimal.rs +++ b/cortex-m-rt/examples/minimal.rs @@ -6,7 +6,7 @@ #![no_std] extern crate cortex_m_rt as rt; -extern crate panic_semihosting; +extern crate panic_halt; use rt::entry; diff --git a/cortex-m-rt/examples/override-exception.rs b/cortex-m-rt/examples/override-exception.rs index 3e0af25..6da6c5e 100644 --- a/cortex-m-rt/examples/override-exception.rs +++ b/cortex-m-rt/examples/override-exception.rs @@ -7,7 +7,7 @@ extern crate cortex_m; extern crate cortex_m_rt as rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m::asm; use rt::{entry, exception, ExceptionFrame}; diff --git a/cortex-m-rt/examples/pre_init.rs b/cortex-m-rt/examples/pre_init.rs index 00e2f2c..2c931bb 100644 --- a/cortex-m-rt/examples/pre_init.rs +++ b/cortex-m-rt/examples/pre_init.rs @@ -5,7 +5,7 @@ #![no_std] extern crate cortex_m_rt as rt; -extern crate panic_semihosting; +extern crate panic_halt; use rt::{entry, pre_init}; diff --git a/cortex-m-rt/examples/rand.rs b/cortex-m-rt/examples/rand.rs index e0cfd31..ec3afaa 100644 --- a/cortex-m-rt/examples/rand.rs +++ b/cortex-m-rt/examples/rand.rs @@ -7,7 +7,7 @@ extern crate cortex_m_rt as rt; use rt::entry; -extern crate panic_semihosting; +extern crate panic_halt; extern crate rand; use rand::Rng; diff --git a/cortex-m-rt/examples/state.rs b/cortex-m-rt/examples/state.rs index 573914f..ee6224d 100644 --- a/cortex-m-rt/examples/state.rs +++ b/cortex-m-rt/examples/state.rs @@ -6,7 +6,7 @@ #![no_std] extern crate cortex_m_rt as rt; -extern crate panic_semihosting; +extern crate panic_halt; use rt::{entry, exception}; diff --git a/cortex-m-rt/examples/unsafe-default-handler.rs b/cortex-m-rt/examples/unsafe-default-handler.rs index 48bd31e..a805c12 100644 --- a/cortex-m-rt/examples/unsafe-default-handler.rs +++ b/cortex-m-rt/examples/unsafe-default-handler.rs @@ -3,7 +3,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception}; diff --git a/cortex-m-rt/examples/unsafe-entry.rs b/cortex-m-rt/examples/unsafe-entry.rs index feb6f44..9dcbf33 100644 --- a/cortex-m-rt/examples/unsafe-entry.rs +++ b/cortex-m-rt/examples/unsafe-entry.rs @@ -3,7 +3,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::entry; diff --git a/cortex-m-rt/examples/unsafe-exception.rs b/cortex-m-rt/examples/unsafe-exception.rs index d67f06f..4212610 100644 --- a/cortex-m-rt/examples/unsafe-exception.rs +++ b/cortex-m-rt/examples/unsafe-exception.rs @@ -3,7 +3,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception}; diff --git a/cortex-m-rt/examples/unsafe-hard-fault.rs b/cortex-m-rt/examples/unsafe-hard-fault.rs index b091d47..b1d48f3 100644 --- a/cortex-m-rt/examples/unsafe-hard-fault.rs +++ b/cortex-m-rt/examples/unsafe-hard-fault.rs @@ -3,7 +3,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception, ExceptionFrame}; diff --git a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs index 037e9c8..72ea0fa 100644 --- a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs +++ b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception}; diff --git a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs index 8fc4a7e..2e46a6b 100644 --- a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs +++ b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception}; diff --git a/cortex-m-rt/tests/compile-fail/default-handler-hidden.rs b/cortex-m-rt/tests/compile-fail/default-handler-hidden.rs index 059c10b..e57cb31 100644 --- a/cortex-m-rt/tests/compile-fail/default-handler-hidden.rs +++ b/cortex-m-rt/tests/compile-fail/default-handler-hidden.rs @@ -5,7 +5,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception}; diff --git a/cortex-m-rt/tests/compile-fail/default-handler-twice.rs b/cortex-m-rt/tests/compile-fail/default-handler-twice.rs index 7d6ad98..ad1c3f9 100644 --- a/cortex-m-rt/tests/compile-fail/default-handler-twice.rs +++ b/cortex-m-rt/tests/compile-fail/default-handler-twice.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception}; diff --git a/cortex-m-rt/tests/compile-fail/entry-args.rs b/cortex-m-rt/tests/compile-fail/entry-args.rs index 07cb4bd..b0d293c 100644 --- a/cortex-m-rt/tests/compile-fail/entry-args.rs +++ b/cortex-m-rt/tests/compile-fail/entry-args.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::entry; diff --git a/cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs index 5eeb49f..5fe9a1a 100644 --- a/cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs +++ b/cortex-m-rt/tests/compile-fail/entry-bad-signature-1.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::entry; diff --git a/cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs index 18bbaed..2b71a57 100644 --- a/cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs +++ b/cortex-m-rt/tests/compile-fail/entry-bad-signature-2.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::entry; diff --git a/cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs b/cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs index 09b75e9..463e5b7 100644 --- a/cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs +++ b/cortex-m-rt/tests/compile-fail/entry-bad-signature-3.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::entry; diff --git a/cortex-m-rt/tests/compile-fail/entry-hidden.rs b/cortex-m-rt/tests/compile-fail/entry-hidden.rs index 7d74063..836db0d 100644 --- a/cortex-m-rt/tests/compile-fail/entry-hidden.rs +++ b/cortex-m-rt/tests/compile-fail/entry-hidden.rs @@ -5,7 +5,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; mod hidden { use cortex_m_rt::entry; diff --git a/cortex-m-rt/tests/compile-fail/entry-soundness.rs b/cortex-m-rt/tests/compile-fail/entry-soundness.rs index 5e40a8f..9fc8ec1 100644 --- a/cortex-m-rt/tests/compile-fail/entry-soundness.rs +++ b/cortex-m-rt/tests/compile-fail/entry-soundness.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception}; diff --git a/cortex-m-rt/tests/compile-fail/entry-twice.rs b/cortex-m-rt/tests/compile-fail/entry-twice.rs index b2819f6..757083a 100644 --- a/cortex-m-rt/tests/compile-fail/entry-twice.rs +++ b/cortex-m-rt/tests/compile-fail/entry-twice.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::entry; diff --git a/cortex-m-rt/tests/compile-fail/exception-args.rs b/cortex-m-rt/tests/compile-fail/exception-args.rs index 85613ff..472a583 100644 --- a/cortex-m-rt/tests/compile-fail/exception-args.rs +++ b/cortex-m-rt/tests/compile-fail/exception-args.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception}; diff --git a/cortex-m-rt/tests/compile-fail/exception-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/exception-bad-signature-1.rs index 966493e..e1fbf31 100644 --- a/cortex-m-rt/tests/compile-fail/exception-bad-signature-1.rs +++ b/cortex-m-rt/tests/compile-fail/exception-bad-signature-1.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception}; diff --git a/cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs index 8504771..ed46cf6 100644 --- a/cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs +++ b/cortex-m-rt/tests/compile-fail/exception-bad-signature-2.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception}; diff --git a/cortex-m-rt/tests/compile-fail/exception-hidden.rs b/cortex-m-rt/tests/compile-fail/exception-hidden.rs index 053c81c..6f57089 100644 --- a/cortex-m-rt/tests/compile-fail/exception-hidden.rs +++ b/cortex-m-rt/tests/compile-fail/exception-hidden.rs @@ -5,7 +5,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception}; diff --git a/cortex-m-rt/tests/compile-fail/exception-soundness.rs b/cortex-m-rt/tests/compile-fail/exception-soundness.rs index 07d73fa..aae2476 100644 --- a/cortex-m-rt/tests/compile-fail/exception-soundness.rs +++ b/cortex-m-rt/tests/compile-fail/exception-soundness.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception}; diff --git a/cortex-m-rt/tests/compile-fail/exception-twice.rs b/cortex-m-rt/tests/compile-fail/exception-twice.rs index 5377fce..aabbe5a 100644 --- a/cortex-m-rt/tests/compile-fail/exception-twice.rs +++ b/cortex-m-rt/tests/compile-fail/exception-twice.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception}; diff --git a/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs index 83fda5f..c2e9c31 100644 --- a/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs +++ b/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception, ExceptionFrame}; diff --git a/cortex-m-rt/tests/compile-fail/hard-fault-hidden.rs b/cortex-m-rt/tests/compile-fail/hard-fault-hidden.rs index 31237c4..956310b 100644 --- a/cortex-m-rt/tests/compile-fail/hard-fault-hidden.rs +++ b/cortex-m-rt/tests/compile-fail/hard-fault-hidden.rs @@ -5,7 +5,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception, ExceptionFrame}; diff --git a/cortex-m-rt/tests/compile-fail/hard-fault-twice.rs b/cortex-m-rt/tests/compile-fail/hard-fault-twice.rs index 90270e5..0bb6c8c 100644 --- a/cortex-m-rt/tests/compile-fail/hard-fault-twice.rs +++ b/cortex-m-rt/tests/compile-fail/hard-fault-twice.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, exception, ExceptionFrame}; diff --git a/cortex-m-rt/tests/compile-fail/pre-init-args.rs b/cortex-m-rt/tests/compile-fail/pre-init-args.rs index 716b211..94d87bd 100644 --- a/cortex-m-rt/tests/compile-fail/pre-init-args.rs +++ b/cortex-m-rt/tests/compile-fail/pre-init-args.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, pre_init}; diff --git a/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-1.rs index 58d3022..249f477 100644 --- a/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-1.rs +++ b/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-1.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, pre_init}; diff --git a/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-2.rs index e47ed59..e942542 100644 --- a/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-2.rs +++ b/cortex-m-rt/tests/compile-fail/pre-init-bad-signature-2.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, pre_init}; diff --git a/cortex-m-rt/tests/compile-fail/pre-init-hidden.rs b/cortex-m-rt/tests/compile-fail/pre-init-hidden.rs index f512d62..63ab90b 100644 --- a/cortex-m-rt/tests/compile-fail/pre-init-hidden.rs +++ b/cortex-m-rt/tests/compile-fail/pre-init-hidden.rs @@ -5,7 +5,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; mod hidden { use cortex_m_rt::pre_init; diff --git a/cortex-m-rt/tests/compile-fail/pre-init-twice.rs b/cortex-m-rt/tests/compile-fail/pre-init-twice.rs index 5fb1ade..74a3f6b 100644 --- a/cortex-m-rt/tests/compile-fail/pre-init-twice.rs +++ b/cortex-m-rt/tests/compile-fail/pre-init-twice.rs @@ -2,7 +2,7 @@ #![no_std] extern crate cortex_m_rt; -extern crate panic_semihosting; +extern crate panic_halt; use cortex_m_rt::{entry, pre_init}; -- cgit v1.2.3 From 679d42223fe79759bc634675694c46ae8ba0ce62 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sun, 23 Aug 2020 21:57:08 +0200 Subject: Make it unsafe to define NMI handlers --- cortex-m-rt/macros/src/lib.rs | 42 +++++++++++++++------- .../default-handler-bad-signature-1.rs | 4 +-- .../default-handler-bad-signature-2.rs | 4 +-- .../tests/compile-fail/default-handler-hidden.rs | 2 +- .../tests/compile-fail/default-handler-twice.rs | 4 +-- .../tests/compile-fail/exception-nmi-unsafe.rs | 24 +++++++++++++ .../compile-fail/hard-fault-bad-signature-1.rs | 4 +-- cortex-m-rt/tests/compile-fail/hard-fault-twice.rs | 4 +-- .../tests/compile-fail/unsafe-init-static.rs | 4 +-- 9 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 cortex-m-rt/tests/compile-fail/exception-nmi-unsafe.rs (limited to 'cortex-m-rt/tests/compile-fail/default-handler-hidden.rs') diff --git a/cortex-m-rt/macros/src/lib.rs b/cortex-m-rt/macros/src/lib.rs index 3c532c0..7e54a5c 100644 --- a/cortex-m-rt/macros/src/lib.rs +++ b/cortex-m-rt/macros/src/lib.rs @@ -113,6 +113,14 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { .into() } +#[derive(Debug, PartialEq)] +enum Exception { + DefaultHandler, + HardFault, + NonMaskableInt, + Other, +} + #[proc_macro_attribute] pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { let mut f = parse_macro_input!(input as ItemFn); @@ -130,20 +138,15 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { let fspan = f.span(); let ident = f.sig.ident.clone(); - enum Exception { - DefaultHandler, - HardFault, - Other, - } - let ident_s = ident.to_string(); let exn = match &*ident_s { "DefaultHandler" => Exception::DefaultHandler, "HardFault" => Exception::HardFault, + "NonMaskableInt" => Exception::NonMaskableInt, // NOTE that at this point we don't check if the exception is available on the target (e.g. // MemoryManagement is not available on Cortex-M0) - "NonMaskableInt" | "MemoryManagement" | "BusFault" | "UsageFault" | "SecureFault" - | "SVCall" | "DebugMonitor" | "PendSV" | "SysTick" => Exception::Other, + "MemoryManagement" | "BusFault" | "UsageFault" | "SecureFault" | "SVCall" + | "DebugMonitor" | "PendSV" | "SysTick" => Exception::Other, _ => { return parse::Error::new(ident.span(), "This is not a valid exception name") .to_compile_error() @@ -151,7 +154,22 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { } }; - // XXX should we blacklist other attributes? + if f.sig.unsafety.is_none() { + match exn { + Exception::DefaultHandler | Exception::HardFault | Exception::NonMaskableInt => { + // These are unsafe to define. + let name = if exn == Exception::DefaultHandler { + format!("`DefaultHandler`") + } else { + format!("`{:?}` handler", exn) + }; + return parse::Error::new(ident.span(), format_args!("defining a {} is unsafe and requires an `unsafe fn` (see the cortex-m-rt docs)", name)) + .to_compile_error() + .into(); + } + Exception::Other => {} + } + } match exn { Exception::DefaultHandler => { @@ -174,7 +192,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { if !valid_signature { return parse::Error::new( fspan, - "`DefaultHandler` must have signature `[unsafe] fn(i16) [-> !]`", + "`DefaultHandler` must have signature `unsafe fn(i16) [-> !]`", ) .to_compile_error() .into(); @@ -231,7 +249,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { if !valid_signature { return parse::Error::new( fspan, - "`HardFault` handler must have signature `[unsafe] fn(&ExceptionFrame) -> !`", + "`HardFault` handler must have signature `unsafe fn(&ExceptionFrame) -> !`", ) .to_compile_error() .into(); @@ -257,7 +275,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { ) .into() } - Exception::Other => { + Exception::NonMaskableInt | Exception::Other => { let valid_signature = f.sig.constness.is_none() && f.vis == Visibility::Inherited && f.sig.abi.is_none() diff --git a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs index 5436115..b590883 100644 --- a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs +++ b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-1.rs @@ -12,5 +12,5 @@ fn foo() -> ! { } #[exception] -fn DefaultHandler(_irqn: i16, undef: u32) {} -//~^ ERROR `DefaultHandler` must have signature `[unsafe] fn(i16) [-> !]` +unsafe fn DefaultHandler(_irqn: i16, undef: u32) {} +//~^ ERROR `DefaultHandler` must have signature `unsafe fn(i16) [-> !]` diff --git a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs index 1cca10c..0dadd6a 100644 --- a/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs +++ b/cortex-m-rt/tests/compile-fail/default-handler-bad-signature-2.rs @@ -12,7 +12,7 @@ fn foo() -> ! { } #[exception] -fn DefaultHandler(_irqn: i16) -> u32 { - //~^ ERROR `DefaultHandler` must have signature `[unsafe] fn(i16) [-> !]` +unsafe fn DefaultHandler(_irqn: i16) -> u32 { + //~^ ERROR `DefaultHandler` must have signature `unsafe fn(i16) [-> !]` 0 } diff --git a/cortex-m-rt/tests/compile-fail/default-handler-hidden.rs b/cortex-m-rt/tests/compile-fail/default-handler-hidden.rs index e57cb31..c658e2b 100644 --- a/cortex-m-rt/tests/compile-fail/default-handler-hidden.rs +++ b/cortex-m-rt/tests/compile-fail/default-handler-hidden.rs @@ -18,5 +18,5 @@ mod hidden { use cortex_m_rt::exception; #[exception] - fn DefaultHandler(_irqn: i16) {} + unsafe fn DefaultHandler(_irqn: i16) {} } diff --git a/cortex-m-rt/tests/compile-fail/default-handler-twice.rs b/cortex-m-rt/tests/compile-fail/default-handler-twice.rs index ad1c3f9..bbf2edd 100644 --- a/cortex-m-rt/tests/compile-fail/default-handler-twice.rs +++ b/cortex-m-rt/tests/compile-fail/default-handler-twice.rs @@ -12,11 +12,11 @@ fn foo() -> ! { } #[exception] -fn DefaultHandler(_irqn: i16) {} +unsafe fn DefaultHandler(_irqn: i16) {} pub mod reachable { use cortex_m_rt::exception; #[exception] //~ ERROR symbol `DefaultHandler` is already defined - fn DefaultHandler(_irqn: i16) {} + unsafe fn DefaultHandler(_irqn: i16) {} } diff --git a/cortex-m-rt/tests/compile-fail/exception-nmi-unsafe.rs b/cortex-m-rt/tests/compile-fail/exception-nmi-unsafe.rs new file mode 100644 index 0000000..f5de2f8 --- /dev/null +++ b/cortex-m-rt/tests/compile-fail/exception-nmi-unsafe.rs @@ -0,0 +1,24 @@ +#![no_main] +#![no_std] + +extern crate cortex_m_rt; +extern crate panic_halt; + +use cortex_m_rt::{entry, exception}; + +#[entry] +fn foo() -> ! { + loop {} +} + +#[exception] +fn DefaultHandler(_irq: i16) {} +//~^ ERROR defining a `DefaultHandler` is unsafe and requires an `unsafe fn` + +#[exception] +fn HardFault() {} +//~^ ERROR defining a `HardFault` handler is unsafe and requires an `unsafe fn` + +#[exception] +fn NonMaskableInt() {} +//~^ ERROR defining a `NonMaskableInt` handler is unsafe and requires an `unsafe fn` diff --git a/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs b/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs index d3b4392..11b53dc 100644 --- a/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs +++ b/cortex-m-rt/tests/compile-fail/hard-fault-bad-signature-1.rs @@ -12,7 +12,7 @@ fn foo() -> ! { } #[exception] -fn HardFault(_ef: &ExceptionFrame, undef: u32) -> ! { - //~^ ERROR `HardFault` handler must have signature `[unsafe] fn(&ExceptionFrame) -> !` +unsafe fn HardFault(_ef: &ExceptionFrame, undef: u32) -> ! { + //~^ ERROR `HardFault` handler must have signature `unsafe fn(&ExceptionFrame) -> !` loop {} } diff --git a/cortex-m-rt/tests/compile-fail/hard-fault-twice.rs b/cortex-m-rt/tests/compile-fail/hard-fault-twice.rs index 030b54c..03b79a5 100644 --- a/cortex-m-rt/tests/compile-fail/hard-fault-twice.rs +++ b/cortex-m-rt/tests/compile-fail/hard-fault-twice.rs @@ -12,7 +12,7 @@ fn foo() -> ! { } #[exception] -fn HardFault(_ef: &ExceptionFrame) -> ! { +unsafe fn HardFault(_ef: &ExceptionFrame) -> ! { loop {} } @@ -20,7 +20,7 @@ pub mod reachable { use cortex_m_rt::{exception, ExceptionFrame}; #[exception] //~ ERROR symbol `HardFault` is already defined - fn HardFault(_ef: &ExceptionFrame) -> ! { + unsafe fn HardFault(_ef: &ExceptionFrame) -> ! { loop {} } } diff --git a/cortex-m-rt/tests/compile-fail/unsafe-init-static.rs b/cortex-m-rt/tests/compile-fail/unsafe-init-static.rs index c040173..23105f1 100644 --- a/cortex-m-rt/tests/compile-fail/unsafe-init-static.rs +++ b/cortex-m-rt/tests/compile-fail/unsafe-init-static.rs @@ -29,12 +29,12 @@ fn SVCall() { } #[exception] -fn DefaultHandler(_irq: i16) { +unsafe fn DefaultHandler(_irq: i16) { static mut X: u32 = init(); //~ ERROR requires unsafe } #[exception] -fn HardFault(_frame: &cortex_m_rt::ExceptionFrame) -> ! { +unsafe fn HardFault(_frame: &cortex_m_rt::ExceptionFrame) -> ! { static mut X: u32 = init(); //~ ERROR requires unsafe loop {} } -- cgit v1.2.3