Skip to content

Commit 20a1b8b

Browse files
author
Johnathan Van Why
committed
Update the Rust toolchain to nightly-2023-08-22.
The semantics of int-to-pointer casts under strict provenance has changed. Ideally, we would update our `From<usize> for Register` implementation to use the `sptr` crate, but `sptr` does not currently have a suitable license. There is a [PR](Gankra/sptr#14) to change that, but it hasn't gotten a response in 7 months, so I don't think we can use it. Instead, this copies the implementation of `core::ptr::invalid`. This also bumps our `thiserror` dependency, which forces Cargo to pick a newer version of `proc-macro2` that is compatible with recently nightly toolchains.
1 parent b61d048 commit 20a1b8b

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

platform/src/register.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use core::mem::transmute;
2+
13
/// In order to work with Miri's `-Zmiri-track-raw-pointers` flag, we cannot
24
/// pass pointers to the kernel through `usize` values (as casting to and from
35
/// `usize` drops the pointer`s tag). Instead, `RawSyscalls` uses the `Register`
@@ -16,19 +18,28 @@ pub struct Register(pub *mut ());
1618

1719
impl From<crate::ErrorCode> for Register {
1820
fn from(value: crate::ErrorCode) -> Register {
19-
Register(value as u16 as *mut ())
21+
(value as usize).into()
2022
}
2123
}
2224

2325
impl From<u32> for Register {
2426
fn from(value: u32) -> Register {
25-
Register(value as *mut ())
27+
(value as usize).into()
2628
}
2729
}
2830

2931
impl From<usize> for Register {
3032
fn from(value: usize) -> Register {
31-
Register(value as *mut ())
33+
// Note: clippy is wrong here; transmute has different semantics than
34+
// `as` casts under strict provenance.
35+
#[allow(clippy::useless_transmute)]
36+
// We want to convert using the same semantics as core::ptr::invalid:
37+
// convert the usize into a pointer with that address without attaching
38+
// provenance to it. However, core::ptr::invalid is a nightly-only
39+
// function. In order to build on stable, we copy its implementation.
40+
// Safety: Raw pointers do not have any validity invariants that usize
41+
// does not have; a raw pointer can point to any address.
42+
Register(unsafe { transmute(value) })
3243
}
3344
}
3445

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[toolchain]
22
# See https://rust-lang.github.io/rustup-components-history/ for a list of
33
# recently nightlies and what components are available for them.
4-
channel = "nightly-2022-06-10"
4+
channel = "nightly-2023-08-22"
55
components = ["clippy", "miri", "rustfmt"]
66
targets = ["thumbv6m-none-eabi",
77
"thumbv7em-none-eabi",

unittest/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ version = "0.1.0"
1010

1111
[dependencies]
1212
libtock_platform = { path = "../platform" }
13-
thiserror = "1.0"
13+
thiserror = "1.0.44"

0 commit comments

Comments
 (0)