diff options
author | 2018-09-06 16:09:01 +0200 | |
---|---|---|
committer | 2018-09-06 16:09:01 +0200 | |
commit | 5fd25ff084daf914207193d15a7ade53cff7411e (patch) | |
tree | aef38f623c0f75f8921d9936b5b83f43dbde5239 | |
parent | 7854e96f69f98570504c701ae860175efc7a25d9 (diff) | |
download | cortex-m-5fd25ff084daf914207193d15a7ade53cff7411e.tar.gz cortex-m-5fd25ff084daf914207193d15a7ade53cff7411e.tar.zst cortex-m-5fd25ff084daf914207193d15a7ade53cff7411e.zip |
v0.6.0
this also adds compile-fail soundness tests and patches a soundness issue in
`#[entry]`
-rw-r--r-- | cortex-m-rt/CHANGELOG.md | 9 | ||||
-rw-r--r-- | cortex-m-rt/Cargo.toml | 2 | ||||
-rw-r--r-- | cortex-m-rt/macros/src/lib.rs | 6 | ||||
-rw-r--r-- | cortex-m-rt/tests/compile-fail/entry-soundness.rs | 26 | ||||
-rw-r--r-- | cortex-m-rt/tests/compile-fail/exception-soundness.rs | 29 |
5 files changed, 67 insertions, 5 deletions
diff --git a/cortex-m-rt/CHANGELOG.md b/cortex-m-rt/CHANGELOG.md index 7027d5a..dce4dfc 100644 --- a/cortex-m-rt/CHANGELOG.md +++ b/cortex-m-rt/CHANGELOG.md @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## [v0.6.0] - 2018-09-06 + +### Changed + +- [breaking-change] the `entry!`, `pre_init!` and `exception!` macros have been + replaced with attributes: `#[entry]`, `#[pre_init]` and `#[exception]`, + respectively. This also changes the toolchain requirement to 1.30-beta or + newer. + ## [v0.5.3] - 2018-08-27 ### Changed diff --git a/cortex-m-rt/Cargo.toml b/cortex-m-rt/Cargo.toml index 9cf2c14..dd55bb5 100644 --- a/cortex-m-rt/Cargo.toml +++ b/cortex-m-rt/Cargo.toml @@ -8,7 +8,7 @@ keywords = ["arm", "cortex-m", "runtime", "startup"] license = "MIT OR Apache-2.0" name = "cortex-m-rt" repository = "https://github.com/japaric/cortex-m-rt" -version = "0.5.3" +version = "0.6.0" [dependencies] r0 = "0.2.1" diff --git a/cortex-m-rt/macros/src/lib.rs b/cortex-m-rt/macros/src/lib.rs index bd34b04..3435756 100644 --- a/cortex-m-rt/macros/src/lib.rs +++ b/cortex-m-rt/macros/src/lib.rs @@ -99,7 +99,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { // XXX should we blacklist other attributes? let attrs = f.attrs; - let ident = f.ident; + let hash = random_ident(); let (statics, stmts) = extract_static_muts(f.block.stmts); let vars = statics @@ -123,11 +123,9 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { }).collect::<Vec<_>>(); quote!( - // TODO(forbid) see tests/compile-fail/entry-hidden.rs - // #[forbid(dead_code)] #[export_name = "main"] #(#attrs)* - pub fn #ident() -> ! { + pub fn #hash() -> ! { #(#vars)* #(#stmts)* diff --git a/cortex-m-rt/tests/compile-fail/entry-soundness.rs b/cortex-m-rt/tests/compile-fail/entry-soundness.rs new file mode 100644 index 0000000..5e40a8f --- /dev/null +++ b/cortex-m-rt/tests/compile-fail/entry-soundness.rs @@ -0,0 +1,26 @@ +#![no_main] +#![no_std] + +extern crate cortex_m_rt; +extern crate panic_semihosting; + +use cortex_m_rt::{entry, exception}; + +#[entry] +fn foo() -> ! { + static mut COUNT: u64 = 0; + + loop { + if *COUNT % 2 == 0 { + *COUNT += 1; + } else { + *COUNT *= 2; + } + } +} + +#[exception] +fn SysTick() { + // If this was allowed it would lead to a data race as `SysTick` can preempt `foo` + foo(); //~ ERROR cannot find function `foo` in this scope +} diff --git a/cortex-m-rt/tests/compile-fail/exception-soundness.rs b/cortex-m-rt/tests/compile-fail/exception-soundness.rs new file mode 100644 index 0000000..07d73fa --- /dev/null +++ b/cortex-m-rt/tests/compile-fail/exception-soundness.rs @@ -0,0 +1,29 @@ +#![no_main] +#![no_std] + +extern crate cortex_m_rt; +extern crate panic_semihosting; + +use cortex_m_rt::{entry, exception}; + +#[entry] +fn foo() -> ! { + loop {} +} + +#[exception] +fn SysTick() { + static mut COUNT: u64 = 0; + + if *COUNT % 2 == 0 { + *COUNT += 1; + } else { + *COUNT *= 2; + } +} + +#[exception] +fn SVCall() { + // If this was allowed it would lead to a data race as `SVCall` could preempt `SysTick` + SysTick(); //~ ERROR cannot find function `SysTick` in this scope +} |