Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable sel4-panicking crate to work with more rustc versions #101

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/sel4-panicking/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ mk {
sel4-immediate-sync-once-cell
;
};
build-dependencies = {
inherit (versions) rustc_version;
};
target."cfg(not(target_arch = \"arm\"))".dependencies = {
unwinding = unwindingWith [ "personality" ] // { optional = true; };
};
Expand Down
3 changes: 3 additions & 0 deletions crates/sel4-panicking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ cfg-if = "1.0.0"
sel4-immediate-sync-once-cell = { path = "../sel4-immediate-sync-once-cell" }
sel4-panicking-env = { path = "env" }

[build-dependencies]
rustc_version = "0.4.0"

[target."cfg(not(target_arch = \"arm\"))".dependencies.unwinding]
version = "0.1.6"
default-features = false
Expand Down
25 changes: 25 additions & 0 deletions crates/sel4-panicking/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// 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 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 {
println!("cargo:rustc-cfg=catch_unwind_intrinsic_still_named_try");
}
}

// assume no build date means more recent
fn order_date(date: Option<String>) -> Reverse<Option<Reverse<String>>> {
Reverse(date.map(Reverse))
}
12 changes: 11 additions & 1 deletion crates/sel4-panicking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use core::mem::ManuallyDrop;
use core::panic::Location;
use core::panic::{PanicInfo, UnwindSafe};

use cfg_if::cfg_if;

use sel4_panicking_env::abort;

mod count;
Expand Down Expand Up @@ -108,6 +110,14 @@ fn do_panic(info: ExternalPanicInfo) -> ! {
}
}

cfg_if! {
if #[cfg(catch_unwind_intrinsic_still_named_try)] {
use core::intrinsics::r#try as catch_unwind_intrinsic;
} else {
use core::intrinsics::catch_unwind as catch_unwind_intrinsic;
}
}

pub fn catch_unwind<R, F: FnOnce() -> R + UnwindSafe>(f: F) -> Result<R, Payload> {
union Data<F, R> {
f: ManuallyDrop<F>,
Expand All @@ -121,7 +131,7 @@ pub fn catch_unwind<R, F: FnOnce() -> R + UnwindSafe>(f: F) -> Result<R, Payload

let data_ptr = &mut data as *mut _ as *mut u8;
unsafe {
return if core::intrinsics::r#try(do_call::<F, R>, data_ptr, do_catch::<F, R>) == 0 {
return if catch_unwind_intrinsic(do_call::<F, R>, data_ptr, do_catch::<F, R>) == 0 {
Ok(ManuallyDrop::into_inner(data.r))
} else {
Err(ManuallyDrop::into_inner(data.p))
Expand Down
1 change: 1 addition & 0 deletions hacking/cargo-manifest-management/manifest-scope.nix
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ in rec {
proc-macro2 = "1.0.50";
quote = "1.0.23";
rand = "0.8.5";
rustc_version = "0.4.0";
serde = "1.0.147";
serde_json = "1.0.87";
serde_yaml = "0.9.14";
Expand Down
Loading