-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also add sel4-root-task-with-std crate. Signed-off-by: Nick Spinale <nick@nickspinale.com>
- Loading branch information
Showing
11 changed files
with
497 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# | ||
# Copyright 2023, Colias Group, LLC | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
|
||
{ mk, localCrates }: | ||
|
||
mk { | ||
package.name = "sel4-root-task-with-std"; | ||
dependencies = { | ||
inherit (localCrates) | ||
sel4 | ||
sel4-panicking-env | ||
sel4-ctors-dtors | ||
; | ||
sel4-runtime-common = localCrates.sel4-runtime-common // { features = [ "start" "tls" "unwinding" ]; }; | ||
}; | ||
features = { | ||
single-threaded = [ | ||
"sel4/single-threaded" | ||
]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# | ||
# 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 = "sel4-root-task-with-std" | ||
version = "0.1.0" | ||
authors = ["Nick Spinale <nick.spinale@coliasgroup.com>"] | ||
edition = "2021" | ||
license = "BSD-2-Clause" | ||
|
||
[features] | ||
single-threaded = ["sel4/single-threaded"] | ||
|
||
[dependencies] | ||
sel4 = { path = "../../../sel4" } | ||
sel4-ctors-dtors = { path = "../../../sel4-ctors-dtors" } | ||
sel4-panicking-env = { path = "../../../sel4-panicking/env" } | ||
|
||
[dependencies.sel4-runtime-common] | ||
path = "../../../sel4-runtime-common" | ||
features = ["start", "tls", "unwinding"] |
77 changes: 77 additions & 0 deletions
77
crates/private/support/sel4-root-task-with-std/src/entry.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// Copyright 2024, Colias Group, LLC | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
// | ||
|
||
use core::panic::UnwindSafe; | ||
use std::panic::catch_unwind; | ||
|
||
use crate::{abort, Termination}; | ||
|
||
#[cfg(target_thread_local)] | ||
#[no_mangle] | ||
unsafe extern "C" fn sel4_runtime_rust_entry(bootinfo: *const sel4::BootInfo) -> ! { | ||
fn cont_fn(cont_arg: *mut sel4_runtime_common::ContArg) -> ! { | ||
inner_entry(cont_arg.cast_const().cast()) | ||
} | ||
|
||
sel4_runtime_common::initialize_tls_on_stack_and_continue(cont_fn, bootinfo.cast_mut().cast()) | ||
} | ||
|
||
#[cfg(not(target_thread_local))] | ||
#[no_mangle] | ||
unsafe extern "C" fn sel4_runtime_rust_entry(bootinfo: *const sel4::BootInfo) -> ! { | ||
inner_entry(bootinfo) | ||
} | ||
|
||
#[allow(unreachable_code)] | ||
fn inner_entry(bootinfo: *const sel4::BootInfo) -> ! { | ||
#[cfg(panic = "unwind")] | ||
{ | ||
sel4_runtime_common::set_eh_frame_finder().unwrap(); | ||
} | ||
|
||
let bootinfo = unsafe { sel4::BootInfoPtr::new(bootinfo) }; | ||
|
||
let ipc_buffer = unsafe { bootinfo.ipc_buffer().as_mut().unwrap() }; | ||
sel4::set_ipc_buffer(ipc_buffer); | ||
|
||
sel4_ctors_dtors::run_ctors(); | ||
|
||
unsafe { | ||
__sel4_root_task__main(&bootinfo); | ||
} | ||
|
||
abort!("__sel4_root_task__main returned") | ||
} | ||
|
||
extern "Rust" { | ||
fn __sel4_root_task__main(bootinfo: &sel4::BootInfoPtr) -> !; | ||
} | ||
|
||
#[doc(hidden)] | ||
#[macro_export] | ||
macro_rules! declare_main { | ||
($main:expr) => { | ||
#[allow(non_snake_case)] | ||
#[no_mangle] | ||
fn __sel4_root_task__main(bootinfo: &$crate::_private::BootInfoPtr) -> ! { | ||
$crate::_private::run_main($main, bootinfo); | ||
} | ||
}; | ||
} | ||
|
||
#[doc(hidden)] | ||
#[allow(clippy::missing_safety_doc)] | ||
pub fn run_main<F, T>(f: F, bootinfo: &sel4::BootInfoPtr) -> ! | ||
where | ||
F: FnOnce(&sel4::BootInfoPtr) -> T + UnwindSafe, | ||
T: Termination, | ||
{ | ||
let result = catch_unwind(move || f(bootinfo).report()); | ||
match result { | ||
Ok(err) => abort!("main thread terminated with error: {err:?}"), | ||
Err(_) => abort!("uncaught panic in main thread"), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// Copyright 2024, Colias Group, LLC | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
// | ||
|
||
#![feature(cfg_target_thread_local)] | ||
#![feature(linkage)] | ||
#![feature(never_type)] | ||
|
||
use sel4::sel4_cfg_if; | ||
|
||
pub use sel4_panicking_env::{abort, debug_print, debug_println}; | ||
|
||
mod entry; | ||
mod termination; | ||
|
||
pub use termination::{Never, Termination}; | ||
|
||
#[doc(hidden)] | ||
#[macro_export] | ||
macro_rules! declare_root_task { | ||
{ | ||
main = $main:expr $(,)? | ||
} => { | ||
$crate::_private::declare_root_task! { | ||
main = $main, | ||
stack_size = $crate::_private::DEFAULT_STACK_SIZE, | ||
} | ||
}; | ||
{ | ||
main = $main:expr, | ||
stack_size = $stack_size:expr $(,)? | ||
} => { | ||
$crate::_private::declare_main!($main); | ||
$crate::_private::declare_stack!($stack_size); | ||
}; | ||
} | ||
|
||
pub const DEFAULT_STACK_SIZE: usize = 1024 | ||
* if cfg!(panic = "unwind") && cfg!(debug_assertions) { | ||
128 | ||
} else { | ||
64 | ||
}; | ||
|
||
sel4_cfg_if! { | ||
if #[sel4_cfg(PRINTING)] { | ||
use sel4::debug_put_char; | ||
} else { | ||
fn debug_put_char(_: u8) {} | ||
} | ||
} | ||
|
||
sel4_panicking_env::register_debug_put_char!( | ||
#[linkage = "weak"] | ||
debug_put_char | ||
); | ||
|
||
// For macros | ||
#[doc(hidden)] | ||
pub mod _private { | ||
pub use sel4::BootInfoPtr; | ||
pub use sel4_runtime_common::declare_stack; | ||
|
||
pub use crate::{declare_main, declare_root_task, entry::run_main, DEFAULT_STACK_SIZE}; | ||
} |
68 changes: 68 additions & 0 deletions
68
crates/private/support/sel4-root-task-with-std/src/termination.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// Copyright 2023, Colias Group, LLC | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
// | ||
|
||
use core::fmt; | ||
|
||
/// Trait for the return type of [`#[root_task]`](crate::root_task) main functions. | ||
pub trait Termination { | ||
type Error: fmt::Debug; | ||
|
||
fn report(self) -> Self::Error; | ||
} | ||
|
||
impl Termination for ! { | ||
type Error = !; | ||
|
||
fn report(self) -> Self::Error { | ||
self | ||
} | ||
} | ||
|
||
impl Termination for Never { | ||
type Error = Never; | ||
|
||
fn report(self) -> Self::Error { | ||
self | ||
} | ||
} | ||
|
||
impl<E: fmt::Debug> Termination for Result<!, E> { | ||
type Error = E; | ||
|
||
fn report(self) -> Self::Error { | ||
match self { | ||
#[allow(unreachable_patterns)] | ||
Ok(absurdity) => match absurdity {}, | ||
Err(err) => err, | ||
} | ||
} | ||
} | ||
|
||
impl<E: fmt::Debug> Termination for Result<Never, E> { | ||
type Error = E; | ||
|
||
fn report(self) -> Self::Error { | ||
match self { | ||
#[allow(unreachable_patterns)] | ||
Ok(absurdity) => match absurdity {}, | ||
Err(err) => err, | ||
} | ||
} | ||
} | ||
|
||
/// Stable alternative to `!`. | ||
/// | ||
/// This type in uninhabited like `!`, but does not require the unstable `#[feature(never_type)]`. | ||
/// It implements [`Termination`], so it is useful in return types for | ||
/// [`#[root_task]`](crate::root_task) main functions. | ||
#[derive(Debug, Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)] | ||
pub enum Never {} | ||
|
||
impl fmt::Display for Never { | ||
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result { | ||
match *self {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
# | ||
|
||
{ mk, versions, localCrates }: | ||
|
||
mk { | ||
package.name = "tests-root-task-musl"; | ||
dependencies = { | ||
inherit (versions) | ||
dlmalloc | ||
lock_api | ||
; | ||
inherit (localCrates) | ||
sel4 | ||
sel4-root-task-with-std | ||
sel4-musl | ||
sel4-linux-syscall-types | ||
sel4-sync-trivial | ||
sel4-dlmalloc | ||
; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# 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-root-task-musl" | ||
version = "0.1.0" | ||
authors = ["Nick Spinale <nick.spinale@coliasgroup.com>"] | ||
edition = "2021" | ||
license = "BSD-2-Clause" | ||
|
||
[dependencies] | ||
dlmalloc = "0.2.3" | ||
lock_api = "0.4.12" | ||
sel4 = { path = "../../../../sel4" } | ||
sel4-dlmalloc = { path = "../../../../sel4-dlmalloc" } | ||
sel4-linux-syscall-types = { path = "../../../../sel4-linux-syscall-types" } | ||
sel4-musl = { path = "../../../../sel4-musl" } | ||
sel4-root-task-with-std = { path = "../../../support/sel4-root-task-with-std" } | ||
sel4-sync-trivial = { path = "../../../../sel4-sync/trivial" } |
Oops, something went wrong.