diff --git a/Cargo.lock b/Cargo.lock index 55a4a1c89..3a84d7181 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2041,6 +2041,9 @@ dependencies = [ [[package]] name = "sel4-bitfield-ops" version = "0.1.0" +dependencies = [ + "rustc_version", +] [[package]] name = "sel4-bitfield-parser" diff --git a/crates/examples/root-task/example-root-task-without-runtime/src/main.rs b/crates/examples/root-task/example-root-task-without-runtime/src/main.rs index 6f635370a..f0e86b3c4 100644 --- a/crates/examples/root-task/example-root-task-without-runtime/src/main.rs +++ b/crates/examples/root-task/example-root-task-without-runtime/src/main.rs @@ -225,6 +225,7 @@ cfg_if::cfg_if! { unsafe extern "C" fn __rust_entry(bootinfo: *const sel4::BootInfo) -> ! { let bootinfo = sel4::BootInfoPtr::new(bootinfo); match main(&bootinfo) { + #[allow(unreachable_patterns)] Ok(absurdity) => match absurdity {}, Err(err) => panic!("Error: {}", err), } diff --git a/crates/sel4-microkit/base/src/symbols.rs b/crates/sel4-microkit/base/src/symbols.rs index d92de2867..a7cf6a48c 100644 --- a/crates/sel4-microkit/base/src/symbols.rs +++ b/crates/sel4-microkit/base/src/symbols.rs @@ -137,5 +137,5 @@ pub fn ipc_buffer_ptr() -> *mut sel4::IpcBuffer { static mut __sel4_ipc_buffer_obj: sel4::IpcBuffer; } - unsafe { ptr::addr_of_mut!(__sel4_ipc_buffer_obj) } + ptr::addr_of_mut!(__sel4_ipc_buffer_obj) } diff --git a/crates/sel4-microkit/src/entry.rs b/crates/sel4-microkit/src/entry.rs index cec94cd95..ea06c7bd0 100644 --- a/crates/sel4-microkit/src/entry.rs +++ b/crates/sel4-microkit/src/entry.rs @@ -65,6 +65,7 @@ macro_rules! declare_init { #[allow(clippy::missing_safety_doc)] pub fn run_main(init: impl FnOnce() -> T + UnwindSafe) -> ! { let result = catch_unwind(|| match init().run() { + #[allow(unreachable_patterns)] Ok(absurdity) => match absurdity {}, Err(err) => err, }); diff --git a/crates/sel4-panicking/build.rs b/crates/sel4-panicking/build.rs index 1b110f35e..5ff5e56e6 100644 --- a/crates/sel4-panicking/build.rs +++ b/crates/sel4-panicking/build.rs @@ -6,20 +6,34 @@ use core::cmp::Reverse; -// Determine whether rustc includes https://github.com/rust-lang/rust/pull/121598 +// Determine whether rustc includes the following changes: +// - https://blog.rust-lang.org/2024/05/06/check-cfg.html +// - https://github.com/rust-lang/rust/pull/121598 +// - https://github.com/rust-lang/rust/pull/126732 fn main() { - let version_meta = rustc_version::version_meta().unwrap(); - let semver = version_meta.semver; - let commit_date = order_date(version_meta.commit_date); - let key = (semver.major, semver.minor, semver.patch, commit_date); - let first_with_change = (1, 78, 0, order_date(Some("2024-02-28".to_owned()))); - if key < first_with_change { + let key = { + let version_meta = rustc_version::version_meta().unwrap(); + let semver = version_meta.semver; + let commit_date = order_date(version_meta.commit_date); + (semver.major, semver.minor, semver.patch, commit_date) + }; + let check_cfg_required = (1, 80, 0, order_date(Some("2024-05-05".to_owned()))); + let unwind_intrinsic_renamed = (1, 78, 0, order_date(Some("2024-02-28".to_owned()))); + let panic_info_message_stabilized = (1, 81, 0, order_date(Some("2024-07-01".to_owned()))); + if key >= check_cfg_required { + println!("cargo:rustc-check-cfg=cfg(catch_unwind_intrinsic_still_named_try)"); + println!("cargo:rustc-check-cfg=cfg(panic_info_message_stable)"); + } + if key < unwind_intrinsic_renamed { println!("cargo:rustc-cfg=catch_unwind_intrinsic_still_named_try"); } + if key >= panic_info_message_stabilized { + println!("cargo:rustc-cfg=panic_info_message_stable"); + } } -// assume no build date means more recent +// no build date means more recent fn order_date(date: Option) -> Reverse>> { Reverse(date.map(Reverse)) } diff --git a/crates/sel4-panicking/src/lib.rs b/crates/sel4-panicking/src/lib.rs index a16fd34a9..33a1563d1 100644 --- a/crates/sel4-panicking/src/lib.rs +++ b/crates/sel4-panicking/src/lib.rs @@ -9,8 +9,8 @@ #![feature(core_intrinsics)] #![feature(lang_items)] #![feature(panic_can_unwind)] -#![feature(panic_info_message)] #![feature(thread_local)] +#![cfg_attr(not(panic_info_message_stable), feature(panic_info_message))] #![allow(internal_features)] #[cfg(feature = "alloc")] @@ -21,6 +21,9 @@ use core::mem::ManuallyDrop; use core::panic::Location; use core::panic::{PanicInfo, UnwindSafe}; +#[cfg(panic_info_message_stable)] +use core::panic::PanicMessage; + use cfg_if::cfg_if; use sel4_panicking_env::abort; @@ -38,9 +41,12 @@ use strategy::{panic_cleanup, start_panic}; pub use hook::{set_hook, PanicHook}; pub use payload::{Payload, SmallPayload, UpcastIntoPayload, SMALL_PAYLOAD_MAX_SIZE}; +#[cfg(not(panic_info_message_stable))] +type PanicMessage<'a> = &'a fmt::Arguments<'a>; + pub struct ExternalPanicInfo<'a> { payload: Payload, - message: Option<&'a fmt::Arguments<'a>>, + message: Option>, location: Option<&'a Location<'a>>, can_unwind: bool, } @@ -50,8 +56,8 @@ impl<'a> ExternalPanicInfo<'a> { &self.payload } - pub fn message(&self) -> Option<&fmt::Arguments> { - self.message + pub fn message(&self) -> Option<&PanicMessage> { + self.message.as_ref() } pub fn location(&self) -> Option<&Location> { @@ -66,14 +72,14 @@ impl<'a> ExternalPanicInfo<'a> { impl fmt::Display for ExternalPanicInfo<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str("panicked at ")?; - if let Some(location) = self.location { + if let Some(location) = self.location() { location.fmt(f)?; } else { f.write_str("unknown location")?; } - if let Some(message) = self.message { + if let Some(message) = self.message() { f.write_str(":\n")?; - f.write_fmt(*message)?; + message.fmt(f)?; } Ok(()) } @@ -83,6 +89,9 @@ impl fmt::Display for ExternalPanicInfo<'_> { fn panic(info: &PanicInfo) -> ! { do_panic(ExternalPanicInfo { payload: NoPayload.upcast_into_payload(), + #[cfg(panic_info_message_stable)] + message: Some(info.message()), + #[cfg(not(panic_info_message_stable))] message: info.message(), location: info.location(), can_unwind: info.can_unwind(), diff --git a/crates/sel4-root-task/src/termination.rs b/crates/sel4-root-task/src/termination.rs index 80f7c0965..9be7a38cf 100644 --- a/crates/sel4-root-task/src/termination.rs +++ b/crates/sel4-root-task/src/termination.rs @@ -33,6 +33,7 @@ impl Termination for Result { fn report(self) -> Self::Error { match self { + #[allow(unreachable_patterns)] Ok(absurdity) => match absurdity {}, Err(err) => err, } @@ -44,6 +45,7 @@ impl Termination for Result { fn report(self) -> Self::Error { match self { + #[allow(unreachable_patterns)] Ok(absurdity) => match absurdity {}, Err(err) => err, } diff --git a/crates/sel4/bitfield-ops/Cargo.nix b/crates/sel4/bitfield-ops/Cargo.nix index b09917c91..6faedbead 100644 --- a/crates/sel4/bitfield-ops/Cargo.nix +++ b/crates/sel4/bitfield-ops/Cargo.nix @@ -4,8 +4,11 @@ # SPDX-License-Identifier: BSD-2-Clause # -{ mk }: +{ mk, versions }: mk { package.name = "sel4-bitfield-ops"; + build-dependencies = { + inherit (versions) rustc_version; + }; } diff --git a/crates/sel4/bitfield-ops/Cargo.toml b/crates/sel4/bitfield-ops/Cargo.toml index 5d5920187..30ff03652 100644 --- a/crates/sel4/bitfield-ops/Cargo.toml +++ b/crates/sel4/bitfield-ops/Cargo.toml @@ -15,3 +15,6 @@ version = "0.1.0" authors = ["Nick Spinale "] edition = "2021" license = "BSD-2-Clause" + +[build-dependencies] +rustc_version = "0.4.0" diff --git a/crates/sel4/bitfield-ops/build.rs b/crates/sel4/bitfield-ops/build.rs new file mode 100644 index 000000000..ea87b9449 --- /dev/null +++ b/crates/sel4/bitfield-ops/build.rs @@ -0,0 +1,27 @@ +// +// Copyright 2024, Colias Group, LLC +// +// SPDX-License-Identifier: BSD-2-Clause +// + +use core::cmp::Reverse; + +// Determine whether rustc includes https://github.com/rust-lang/rust/pull/121598 + +fn main() { + let key = { + let version_meta = rustc_version::version_meta().unwrap(); + let semver = version_meta.semver; + let commit_date = order_date(version_meta.commit_date); + (semver.major, semver.minor, semver.patch, commit_date) + }; + let check_cfg_required = (1, 80, 0, order_date(Some("2024-05-05".to_owned()))); + if key >= check_cfg_required { + println!("cargo:rustc-check-cfg=cfg(kani)"); + } +} + +// no build date means more recent +fn order_date(date: Option) -> Reverse>> { + Reverse(date.map(Reverse)) +}