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

Various language runtime improvements #213

Merged
merged 18 commits into from
Oct 24, 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
8 changes: 8 additions & 0 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 @@ -95,6 +95,7 @@ members = [
"crates/sel4-capdl-initializer/with-embedded-spec/build-env",
"crates/sel4-capdl-initializer/with-embedded-spec/embedded-spec",
"crates/sel4-capdl-initializer/with-embedded-spec/embedded-spec/validate",
"crates/sel4-ctors-dtors",
"crates/sel4-dlmalloc",
"crates/sel4-driver-interfaces",
"crates/sel4-elf-header",
Expand Down
1 change: 1 addition & 0 deletions crates/examples/root-task/spawn-task/child/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mk {
sel4-panicking-env
sel4-dlmalloc
sel4-sync
sel4-ctors-dtors
;
sel4-panicking = localCrates.sel4-panicking // {
features = [ "unwinding" "alloc" ];
Expand Down
1 change: 1 addition & 0 deletions crates/examples/root-task/spawn-task/child/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ license = "BSD-2-Clause"
[dependencies]
cfg-if = "1.0.0"
sel4 = { path = "../../../../sel4" }
sel4-ctors-dtors = { path = "../../../../sel4-ctors-dtors" }
sel4-dlmalloc = { path = "../../../../sel4-dlmalloc" }
sel4-panicking = { path = "../../../../sel4-panicking", features = ["unwinding", "alloc"] }
sel4-panicking-env = { path = "../../../../sel4-panicking/env" }
Expand Down
4 changes: 2 additions & 2 deletions crates/examples/root-task/spawn-task/child/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sel4_panicking_env::register_debug_put_char!(sel4::debug_put_char);

#[no_mangle]
unsafe extern "C" fn sel4_runtime_rust_entry() -> ! {
unsafe extern "C" fn cont_fn(_cont_arg: *mut sel4_runtime_common::ContArg) -> ! {
fn cont_fn(_cont_arg: *mut sel4_runtime_common::ContArg) -> ! {
inner_entry()
}

Expand All @@ -47,7 +47,7 @@ fn inner_entry() -> ! {

unsafe {
sel4::set_ipc_buffer(get_ipc_buffer().as_mut().unwrap());
sel4_runtime_common::run_ctors();
sel4_ctors_dtors::run_ctors();
}

match catch_unwind(main) {
Expand Down
2 changes: 1 addition & 1 deletion crates/examples/root-task/spawn-thread/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mk {
sel4-root-task
sel4-elf-header
sel4-stack
sel4-initialize-tls
;
sel4-initialize-tls = localCrates.sel4-initialize-tls // { features = [ "on-heap" ]; };
};
}
2 changes: 1 addition & 1 deletion crates/examples/root-task/spawn-thread/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ license = "BSD-2-Clause"
cfg-if = "1.0.0"
sel4 = { path = "../../../sel4" }
sel4-elf-header = { path = "../../../sel4-elf-header" }
sel4-initialize-tls = { path = "../../../sel4-initialize-tls" }
sel4-initialize-tls = { path = "../../../sel4-initialize-tls", features = ["on-heap"] }
sel4-root-task = { path = "../../../sel4-root-task" }
sel4-stack = { path = "../../../sel4-stack" }
32 changes: 2 additions & 30 deletions crates/examples/root-task/spawn-thread/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use core::ptr;
use cfg_if::cfg_if;

use sel4_elf_header::{ElfHeader, PT_TLS};
use sel4_initialize_tls::{TlsImage, TlsReservationLayout, UncheckedTlsImage};
use sel4_initialize_tls::{TlsImage, UncheckedTlsImage};
use sel4_root_task::{
abort, panicking::catch_unwind, root_task, set_global_allocator_mutex_notification, Never,
};
Expand Down Expand Up @@ -144,7 +144,7 @@ fn create_user_context(f: SecondaryThreadFn) -> sel4::UserContext {
*ctx.pc_mut() = (secondary_thread_entrypoint as usize).try_into().unwrap();
*ctx.c_param_mut(0) = f.into_arg();

let tls_reservation = TlsReservation::new(&get_tls_image());
let tls_reservation = get_tls_image().initialize_on_heap();
*user_context_thread_pointer_mut(&mut ctx) = tls_reservation.thread_pointer() as sel4::Word;
mem::forget(tls_reservation);

Expand Down Expand Up @@ -212,34 +212,6 @@ impl SecondaryThreadFn {

// // //

struct TlsReservation {
start: *mut u8,
layout: TlsReservationLayout,
}

impl TlsReservation {
fn new(tls_image: &TlsImage) -> Self {
let layout = tls_image.reservation_layout();
let start = unsafe { ::alloc::alloc::alloc(layout.footprint()) };
unsafe {
tls_image.initialize_tls_reservation(start);
};
Self { start, layout }
}

fn thread_pointer(&self) -> usize {
(self.start as usize) + self.layout.thread_pointer_offset()
}
}

impl Drop for TlsReservation {
fn drop(&mut self) {
unsafe {
::alloc::alloc::dealloc(self.start, self.layout.footprint());
}
}
}

fn get_tls_image() -> TlsImage {
extern "C" {
static __ehdr_start: ElfHeader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mk {
inherit (versions) cfg-if;
serde = serdeWith [ "derive" ];
};
target."cfg(target_env = \"sel4\")".dependencies = {
target."cfg(target_os = \"none\")".dependencies = {
inherit (localCrates)
sel4
sel4-simple-task-threading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ license = "BSD-2-Clause"
cfg-if = "1.0.0"
serde = { version = "1.0.147", default-features = false, features = ["derive"] }

[target."cfg(target_env = \"sel4\")".dependencies]
[target."cfg(target_os = \"none\")".dependencies]
sel4 = { path = "../../../../sel4" }
sel4-simple-task-threading = { path = "../threading" }
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use core::marker::PhantomData;
use serde::{Deserialize, Serialize};

cfg_if::cfg_if! {
if #[cfg(target_env = "sel4")] {
if #[cfg(target_os = "none")] {
mod when_sel4;
pub use when_sel4::*;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mk {
sel4-simple-task-runtime-macros
sel4-simple-task-threading
sel4-sync
sel4-ctors-dtors
;
sel4-runtime-common = localCrates.sel4-runtime-common // { features = [ "tls" "unwinding" ]; };
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ serde_json = ["dep:serde_json"]
[dependencies]
postcard = { version = "1.0.2", default-features = false }
sel4 = { path = "../../../../sel4" }
sel4-ctors-dtors = { path = "../../../../sel4-ctors-dtors" }
sel4-dlmalloc = { path = "../../../../sel4-dlmalloc" }
sel4-immediate-sync-once-cell = { path = "../../../../sel4-immediate-sync-once-cell" }
sel4-panicking = { path = "../../../../sel4-panicking" }
Expand Down
21 changes: 13 additions & 8 deletions crates/private/support/sel4-simple-task/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@ pub struct ContArg {
}

#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn cont_fn(cont_arg: *mut sel4_runtime_common::ContArg) -> ! {
let cont_arg: &ContArg = &*cont_arg.cast_const().cast();
pub fn cont_fn(cont_arg: *mut sel4_runtime_common::ContArg) -> ! {
let cont_arg: &ContArg = unsafe { &*cont_arg.cast_const().cast() };

let config = &cont_arg.config;
let thread_index = cont_arg.thread_index;
let thread_config = &config.threads()[thread_index];

THREAD_INDEX.set(thread_index).unwrap();

sel4::set_ipc_buffer(
sel4::set_ipc_buffer(unsafe {
(usize::try_from(thread_config.ipc_buffer_addr()).unwrap() as *mut sel4::IpcBuffer)
.as_mut()
.unwrap(),
);
.unwrap()
});

if thread_index == 0 {
CONFIG.set(config.clone()).unwrap();
Expand All @@ -88,8 +88,11 @@ pub unsafe extern "C" fn cont_fn(cont_arg: *mut sel4_runtime_common::ContArg) ->
}

sel4_panicking::set_hook(&panic_hook);
sel4_runtime_common::run_ctors();
__sel4_simple_task_main(config.arg());
sel4_ctors_dtors::run_ctors();

unsafe {
__sel4_simple_task_main(config.arg());
}
} else {
let endpoint =
sel4::cap::Endpoint::from_bits(thread_config.endpoint().unwrap().try_into().unwrap());
Expand All @@ -103,7 +106,9 @@ pub unsafe extern "C" fn cont_fn(cont_arg: *mut sel4_runtime_common::ContArg) ->
}
}
};
StaticThread::recv_and_run(endpoint, reply_authority);
unsafe {
StaticThread::recv_and_run(endpoint, reply_authority);
}
}

idle()
Expand Down
6 changes: 3 additions & 3 deletions crates/sel4-async/time/src/timer_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use crate::SubKey;
// actually need the scalability of something like a timer wheel, `tokio`'s implementation would be
// a good place to start.

// TODO: Add feature like `tokio::time::Interval`
// TODO
// Add feature like `tokio::time::Interval`

// NOTE(rustc_wishlist)
//
// NOTE
// Once #![feature(btree_cursors)] stabilizes, revert back to using it for a simpler, more
// lightweight, and more efficient (on the small scale) implementation. See git history for such an
// implementation.
Expand Down
12 changes: 4 additions & 8 deletions crates/sel4-bounce-buffer-allocator/src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ const GRANULE_SIZE: usize = 2048;
// TODO
// This is just a temporary implementation to serve as a stand-in.

// NOTE(rustc_wishlist)
//
// #![feature(allocator_api)] and #![feature(btreemap_alloc)]
//
// Should be parameterized with an allocator A, to enable this type to be used without a global
// allocator.
// NOTE
// Once #![feature(allocator_api)] and #![feature(btreemap_alloc)] land, Should be parameterized
// with an allocator A, to enable this type to be used without a global allocator.

// NOTE(rustc_wishlist)
//
// NOTE
// #![feature(btree_cursors)] would make this stand-in implementation simpler and more efficient.
// See git history.

Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-capdl-initializer/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mk {
sel4-logging
sel4-sync
;
sel4-root-task = localCrates.sel4-root-task // { default-features = false; features = [ "alloc" "single-threaded" ]; };
sel4-root-task = localCrates.sel4-root-task // { default-features = false; features = [ "single-threaded" ]; };
sel4-capdl-initializer-types = localCrates.sel4-capdl-initializer-types // { features = [ "alloc" "serde" "deflate" ]; };
};
# features = {
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-capdl-initializer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ sel4-sync = { path = "../sel4-sync" }
[dependencies.sel4-root-task]
path = "../sel4-root-task"
default-features = false
features = ["alloc", "single-threaded"]
features = ["single-threaded"]
1 change: 0 additions & 1 deletion crates/sel4-capdl-initializer/core/src/hold_slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ impl<T> HoldSlots<T> {
) -> Result<Self, CapDLInitializerError> {
Ok(Self {
slots: {
// NOTE(rustc_wishlist) array_try_from_fn
let mut f = || cslot_allocator.alloc();
[f()?, f()?]
},
Expand Down
11 changes: 11 additions & 0 deletions crates/sel4-ctors-dtors/Cargo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Copyright 2024, Colias Group, LLC
#
# SPDX-License-Identifier: BSD-2-Clause
#

{ mk }:

mk {
package.name = "sel4-ctors-dtors";
}
17 changes: 17 additions & 0 deletions crates/sel4-ctors-dtors/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# 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-ctors-dtors"
version = "0.1.0"
authors = ["Nick Spinale <nick.spinale@coliasgroup.com>"]
edition = "2021"
license = "BSD-2-Clause"
Loading
Loading