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

Improve thread-local storage handling #231

Merged
merged 8 commits into from
Nov 11, 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
19 changes: 16 additions & 3 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ members = [
"crates/private/tests/microkit/passive-server-with-deferred-action/pds/client",
"crates/private/tests/microkit/passive-server-with-deferred-action/pds/server",
"crates/private/tests/microkit/reset",
"crates/private/tests/microkit/unwind",
"crates/private/tests/root-task/backtrace",
"crates/private/tests/root-task/c",
"crates/private/tests/root-task/config",
Expand Down
16 changes: 16 additions & 0 deletions crates/private/tests/microkit/unwind/Cargo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright 2024, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#

{ mk, localCrates }:

mk {
package.name = "tests-microkit-unwind";
dependencies = {
inherit (localCrates)
sel4-microkit
;
};
}
20 changes: 20 additions & 0 deletions crates/private/tests/microkit/unwind/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Copyright 2023, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#
#
# This file is generated from './Cargo.nix'. You can edit this file directly
# if you are not using this project's Cargo manifest management tools.
# See 'hacking/cargo-manifest-management/README.md' for more information.
#

[package]
name = "tests-microkit-unwind"
version = "0.1.0"
authors = ["Nick Spinale <[email protected]>"]
edition = "2021"
license = "BSD-2-Clause"

[dependencies]
sel4-microkit = { path = "../../../../sel4-microkit" }
54 changes: 54 additions & 0 deletions crates/private/tests/microkit/unwind/src/bin/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// Copyright 2024, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

#![no_std]
#![no_main]

use core::sync::atomic::{AtomicBool, Ordering};

use sel4_microkit::{debug_println, panicking, protection_domain, NullHandler};

static F1_DROPPED: AtomicBool = AtomicBool::new(false);

#[protection_domain]
fn init() -> NullHandler {
let _ = panicking::catch_unwind(|| {
f1();
});
assert!(F1_DROPPED.load(Ordering::SeqCst));
let r = panicking::catch_unwind(|| {
panicking::panic_any(Foo(1337));
});
assert!(matches!(
r.err().unwrap().downcast::<Foo>().ok().unwrap(),
Foo(1337)
));
debug_println!("TEST_PASS");
NullHandler::new()
}

fn f1() {
[()].iter().for_each(f1_helper);
}

fn f1_helper(_: &()) {
let _ = F1Drop;
panic!("test");
}

struct F1Drop;

impl Drop for F1Drop {
fn drop(&mut self) {
debug_println!("F1Drop::drop()");
F1_DROPPED.store(true, Ordering::SeqCst);
}
}

#[derive(Copy, Clone)]
struct Foo(usize);

impl panicking::SmallPayload for Foo {}
11 changes: 11 additions & 0 deletions crates/private/tests/microkit/unwind/x.system
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2024, Colias Group, LLC

SPDX-License-Identifier: BSD-2-Clause
-->
<system>
<protection_domain name="test" priority="128">
<program_image path="test.elf" />
</protection_domain>
</system>
2 changes: 1 addition & 1 deletion crates/sel4-generate-target-specs/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mk {
inherit (versions) serde_json clap;
};
build-dependencies = {
inherit (versions) rustc_version;
inherit (versions) rustversion;
};
package.metadata.rust-analyzer = {
rustc_private = true;
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-generate-target-specs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ clap = "4.4.6"
serde_json = "1.0.87"

[build-dependencies]
rustc_version = "0.4.0"
rustversion = "1.0.18"
32 changes: 11 additions & 21 deletions crates/sel4-generate-target-specs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,18 @@
// SPDX-License-Identifier: BSD-2-Clause
//

use core::cmp::Reverse;

// Determine whether rustc includes https://github.com/rust-lang/rust/pull/122305

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())));
let target_spec_has_metadata = (1, 78, 0, order_date(Some("2024-03-15".to_owned())));
if key >= check_cfg_required {
println!("cargo:rustc-check-cfg=cfg(target_spec_has_metadata)");
let key = "target_spec_has_metadata";
if rustversion::cfg!(any(
all(not(nightly), since(1.80)),
all(nightly, since(2024 - 05 - 05))
)) {
println!("cargo:rustc-check-cfg=cfg({key})");
}
if key >= target_spec_has_metadata {
println!("cargo:rustc-cfg=target_spec_has_metadata");
if rustversion::cfg!(any(
all(not(nightly), since(1.78)),
all(nightly, since(2024 - 03 - 15))
)) {
println!("cargo:rustc-cfg={key}");
}
}

// no build date means more recent
fn order_date(date: Option<String>) -> Reverse<Option<Reverse<String>>> {
Reverse(date.map(Reverse))
}
2 changes: 1 addition & 1 deletion crates/sel4-generate-target-specs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl Context {
}

fn builtin(triple: &str) -> Target {
#[cfg_attr(not(target_spec_has_metadata), allow(unused_mut))]
#[allow(unused_mut)]
let mut target = Target::expect_builtin(&TargetTriple::from_triple(triple));
#[cfg(target_spec_has_metadata)]
{
Expand Down
Loading
Loading