Skip to content

Commit

Permalink
Merge pull request #874 from jannic/issue-864
Browse files Browse the repository at this point in the history
Fix unsoundness in definition of stack for spawning core1
  • Loading branch information
thejpster authored Nov 23, 2024
2 parents e87e2ac + 4d206b5 commit 25f0918
Show file tree
Hide file tree
Showing 22 changed files with 240 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/on_target_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-01-30
toolchain: nightly-2024-11-14
target: thumbv6m-none-eabi
- name: Install cargo-hack
run: |
Expand All @@ -38,7 +38,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.77
toolchain: 1.79
target: thumbv6m-none-eabi
- name: Install cargo-hack
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rp2040_hal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-01-30
toolchain: nightly-2024-11-14
target: ${{ env.TARGET }}
- name: Install cargo-hack
run: |
Expand All @@ -61,7 +61,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.77
toolchain: 1.79
target: ${{ env.TARGET }}
- name: Install cargo-hack
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rp2040_hal_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-01-30
toolchain: nightly-2024-11-14
target: ${{ env.TARGET }}
- name: Install cargo-udeps
run: |
Expand All @@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.77
toolchain: 1.79
target: ${{ env.TARGET }}
- name: Use older version of regex
run: cd ${PACKAGE} && cargo update -p regex --precise 1.9.3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rp235x_hal_arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-01-30
toolchain: nightly-2024-11-14
target: ${{ env.TARGET }}
- name: Install cargo-hack
run: |
Expand All @@ -61,7 +61,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.77
toolchain: 1.79
target: ${{ env.TARGET }}
- name: Install cargo-hack
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rp235x_hal_examples_arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-01-30
toolchain: nightly-2024-11-14
target: ${{ env.TARGET }}
- name: Install cargo-udeps
run: |
Expand All @@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.77
toolchain: 1.79
target: ${{ env.TARGET }}
- name: Use older version of regex
run: cd ${PACKAGE} && cargo update -p regex --precise 1.9.3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rp235x_hal_examples_riscv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.77
toolchain: 1.79
target: ${{ env.TARGET }}
- name: Use older version of regex
run: cd ${PACKAGE} && cargo update -p regex --precise 1.9.3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rp235x_hal_riscv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-01-30
toolchain: nightly-2024-11-14
target: ${{ env.TARGET }}
- name: Install cargo-hack
run: |
Expand All @@ -61,7 +61,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.77
toolchain: 1.79
target: ${{ env.TARGET }}
- name: Install cargo-hack
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rp_binary_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-01-30
toolchain: nightly-2024-11-14
- name: Install cargo-hack
run: |
curl -sSL https://github.com/taiki-e/cargo-hack/releases/download/v0.6.17/cargo-hack-x86_64-unknown-linux-gnu.tar.gz | tar xvzf - -C ~/.cargo/bin
Expand All @@ -47,7 +47,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.77
toolchain: 1.79
- name: Install cargo-hack
run: |
curl -sSL https://github.com/taiki-e/cargo-hack/releases/download/v0.6.17/cargo-hack-x86_64-unknown-linux-gnu.tar.gz | tar xvzf - -C ~/.cargo/bin
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rp_hal_common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-01-30
toolchain: nightly-2024-11-14
- name: Install cargo-hack
run: |
curl -sSL https://github.com/taiki-e/cargo-hack/releases/download/v0.6.17/cargo-hack-x86_64-unknown-linux-gnu.tar.gz | tar xvzf - -C ~/.cargo/bin
Expand All @@ -47,7 +47,7 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.77
toolchain: 1.79
- name: Install cargo-hack
run: |
curl -sSL https://github.com/taiki-e/cargo-hack/releases/download/v0.6.17/cargo-hack-x86_64-unknown-linux-gnu.tar.gz | tar xvzf - -C ~/.cargo/bin
Expand Down
2 changes: 1 addition & 1 deletion rp-binary-info/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["The rp-rs Developers"]
homepage = "https://github.com/rp-rs/rp-hal"
description = "Code and types for creating Picotool compatible Binary Info metadata"
license = "MIT OR Apache-2.0"
rust-version = "1.77"
rust-version = "1.79"
repository = "https://github.com/rp-rs/rp-hal"
categories = ["embedded", "hardware-support", "no-std", "no-std::no-alloc"]
keywords = ["embedded", "raspberry-pi", "rp2040", "rp2350", "picotool"]
Expand Down
2 changes: 1 addition & 1 deletion rp-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage = "https://github.com/rp-rs/rp-hal"
license = "MIT OR Apache-2.0"
name = "rp-hal-common"
repository = "https://github.com/rp-rs/rp-hal"
rust-version = "1.77"
rust-version = "1.79"
version = "0.1.0"

# DO NOT LIST ANY PAC CRATES OR ARCHITECTURE CRATES HERE
Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ keywords = ["embedded", "hal", "raspberry-pi", "rp2040", "embedded-hal"]
license = "MIT OR Apache-2.0"
name = "rp2040-hal-examples"
repository = "https://github.com/rp-rs/rp-hal"
rust-version = "1.77"
rust-version = "1.79"
version = "0.1.0"

[dependencies]
Expand Down
7 changes: 2 additions & 5 deletions rp2040-hal-examples/src/bin/multicore_fifo_blink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const CORE1_TASK_COMPLETE: u32 = 0xEE;
/// So instead, core1.spawn takes a [usize] which gets used for the stack.
/// NOTE: We use the `Stack` struct here to ensure that it has 32-byte alignment, which allows
/// the stack guard to take up the least amount of usable RAM.
static mut CORE1_STACK: Stack<4096> = Stack::new();
static CORE1_STACK: Stack<4096> = Stack::new();

fn core1_task(sys_freq: u32) -> ! {
let mut pac = unsafe { pac::Peripherals::steal() };
Expand Down Expand Up @@ -115,10 +115,7 @@ fn main() -> ! {
let mut mc = Multicore::new(&mut pac.PSM, &mut pac.PPB, &mut sio.fifo);
let cores = mc.cores();
let core1 = &mut cores[1];
#[allow(static_mut_refs)]
let _test = core1.spawn(unsafe { &mut CORE1_STACK.mem }, move || {
core1_task(sys_freq)
});
let _test = core1.spawn(CORE1_STACK.take().unwrap(), move || core1_task(sys_freq));

/// How much we adjust the LED period every cycle
const LED_PERIOD_INCREMENT: i32 = 2;
Expand Down
5 changes: 2 additions & 3 deletions rp2040-hal-examples/src/bin/multicore_polyblink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const CORE1_DELAY: u32 = 1_000_000 / CORE1_FREQ;
/// NOTE: We use the `Stack` struct here to ensure that it has 32-byte
/// alignment, which allows the stack guard to take up the least amount of
/// usable RAM.
static mut CORE1_STACK: Stack<4096> = Stack::new();
static CORE1_STACK: Stack<4096> = Stack::new();

/// Entry point to our bare-metal application.
///
Expand Down Expand Up @@ -105,9 +105,8 @@ fn main() -> ! {
let mut mc = Multicore::new(&mut pac.PSM, &mut pac.PPB, &mut sio.fifo);
let cores = mc.cores();
let core1 = &mut cores[1];
#[allow(static_mut_refs)]
core1
.spawn(unsafe { &mut CORE1_STACK.mem }, move || {
.spawn(CORE1_STACK.take().unwrap(), move || {
// Get the second core's copy of the `CorePeripherals`, which are per-core.
// Unfortunately, `cortex-m` doesn't support this properly right now,
// so we have to use `steal`.
Expand Down
4 changes: 3 additions & 1 deletion rp2040-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### MSRV

The Minimum-Supported Rust Version (MSRV) for the next release is 1.77
The Minimum-Supported Rust Version (MSRV) for the next release is 1.79

### Added

- Support for *binary info*, which is metadata that `picotool` can read from your binary.
- Bump MSRV to 1.77, because *binary info* examples need C-Strings.
- Bump MSRV to 1.79 to enable inline\_const, used for static asserts.

### Fixed

- Let UART embedded\_io::Write::write return some bytes were written.
- Fix unsoundness in definition of stack for spawning core1.

## [0.10.0] - 2024-03-10

Expand Down
2 changes: 1 addition & 1 deletion rp2040-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ keywords = ["embedded", "hal", "raspberry-pi", "rp2040", "embedded-hal"]
license = "MIT OR Apache-2.0"
name = "rp2040-hal"
repository = "https://github.com/rp-rs/rp-hal"
rust-version = "1.77"
rust-version = "1.79"
version = "0.10.0"

[package.metadata.docs.rs]
Expand Down
Loading

0 comments on commit 25f0918

Please sign in to comment.