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

Add more OS-independent synchronization abstractions and utilities #170

Merged
merged 13 commits into from
Jul 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
15 changes: 15 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ members = [
"crates/private/tests/root-task/verus/core",
"crates/private/tests/root-task/verus/task",
"crates/sel4",
"crates/sel4-abstract-rc",
"crates/sel4-async/block-io",
"crates/sel4-async/block-io/fat",
"crates/sel4-async/io",
Expand Down Expand Up @@ -136,6 +137,7 @@ members = [
"crates/sel4-shared-ring-buffer/smoltcp",
"crates/sel4-stack",
"crates/sel4-sync",
"crates/sel4-sync/trivial",
"crates/sel4-synthetic-elf",
"crates/sel4-test-harness",
"crates/sel4/bitfield-ops",
Expand Down
17 changes: 7 additions & 10 deletions crates/drivers/virtio/hal-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use virtio_drivers::{BufferDirection, Hal, PhysAddr, PAGE_SIZE};
use sel4_bounce_buffer_allocator::{Basic, BounceBufferAllocator};
use sel4_externally_shared::{ExternallySharedRef, ExternallySharedRefExt};
use sel4_immediate_sync_once_cell::ImmediateSyncOnceCell;
use sel4_sync::{lock_api::Mutex, GenericRawMutex, PanickingMutexSyncOps};
use sel4_sync::{lock_api::Mutex, PanickingRawMutex};

static GLOBAL_STATE: ImmediateSyncOnceCell<Mutex<GenericRawMutex<PanickingMutexSyncOps>, State>> =
static GLOBAL_STATE: ImmediateSyncOnceCell<Mutex<PanickingRawMutex, State>> =
ImmediateSyncOnceCell::new();

struct State {
Expand Down Expand Up @@ -56,14 +56,11 @@ impl HalImpl {
BounceBufferAllocator::new(Basic::new(dma_region_size), max_alignment);

GLOBAL_STATE
.set(Mutex::from_raw(
GenericRawMutex::new(PanickingMutexSyncOps::new()),
State {
dma_region,
dma_region_paddr,
bounce_buffer_allocator,
},
))
.set(Mutex::new(State {
dma_region,
dma_region_paddr,
bounce_buffer_allocator,
}))
.ok()
.unwrap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ fn init() -> impl Handler {
BounceBufferAllocator::new(Basic::new(dma_region.as_ptr().len()), 1);

DeviceImpl::new(
Default::default(),
dma_region,
bounce_buffer_allocator,
RingBuffers::from_ptrs_using_default_initialization_strategy_for_role(
Expand Down
9 changes: 3 additions & 6 deletions crates/examples/root-task/spawn-task/child/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sel4::CapTypeForFrameObjectOfFixedSize;
use sel4_dlmalloc::{StaticDlmallocGlobalAlloc, StaticHeap};
use sel4_panicking::catch_unwind;
use sel4_panicking_env::abort;
use sel4_sync::{GenericRawMutex, PanickingMutexSyncOps};
use sel4_sync::PanickingRawMutex;

use crate::main;

Expand All @@ -24,12 +24,9 @@ static STATIC_HEAP: StaticHeap<HEAP_SIZE> = StaticHeap::new();

#[global_allocator]
static GLOBAL_ALLOCATOR: StaticDlmallocGlobalAlloc<
GenericRawMutex<PanickingMutexSyncOps>,
PanickingRawMutex,
&'static StaticHeap<HEAP_SIZE>,
> = StaticDlmallocGlobalAlloc::new(
GenericRawMutex::new(PanickingMutexSyncOps::new()),
&STATIC_HEAP,
);
> = StaticDlmallocGlobalAlloc::new(PanickingRawMutex::new(), &STATIC_HEAP);

sel4_panicking_env::register_debug_put_char!(sel4::debug_put_char);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@
//

use sel4_dlmalloc::{StaticDlmallocGlobalAlloc, StaticHeapBounds};
use sel4_sync::{AbstractMutexSyncOps, GenericRawMutex};
use sel4_sync::{GenericRawMutex, MutexSyncOps};

use crate::{get_static_heap_bounds, get_static_heap_mutex_notification};

#[global_allocator]
#[allow(clippy::type_complexity)]
static GLOBAL_ALLOCATOR: StaticDlmallocGlobalAlloc<
GenericRawMutex<AbstractMutexSyncOps<fn(), fn()>>,
GenericRawMutex<MutexSyncOpsImpl>,
fn() -> StaticHeapBounds,
> = StaticDlmallocGlobalAlloc::new(
GenericRawMutex::new(AbstractMutexSyncOps {
signal: || {
get_static_heap_mutex_notification().signal();
},
wait: || {
get_static_heap_mutex_notification().wait();
},
}),
GenericRawMutex::new(MutexSyncOpsImpl),
get_static_heap_bounds,
);

struct MutexSyncOpsImpl;

impl MutexSyncOps for MutexSyncOpsImpl {
fn signal(&self) {
get_static_heap_mutex_notification().signal();
}

fn wait(&self) {
get_static_heap_mutex_notification().wait();
}
}
11 changes: 11 additions & 0 deletions crates/sel4-abstract-rc/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-abstract-rc";
}
17 changes: 17 additions & 0 deletions crates/sel4-abstract-rc/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-abstract-rc"
version = "0.1.0"
authors = ["Nick Spinale <[email protected]>"]
edition = "2021"
license = "BSD-2-Clause"
35 changes: 35 additions & 0 deletions crates/sel4-abstract-rc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Copyright 2024, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

#![no_std]

extern crate alloc;

use alloc::rc::Rc;
use alloc::sync::Arc;
use core::ops::Deref;

pub trait AbstractRcT {
type Rc<T>: AbstractRc<T>;
}

pub struct RcT(());

impl AbstractRcT for RcT {
type Rc<T> = Rc<T>;
}

pub struct ArcT(());

impl AbstractRcT for ArcT {
type Rc<T> = Arc<T>;
}

pub trait AbstractRc<T>: Deref<Target = T> + From<T> + Clone {}

impl<T> AbstractRc<T> for Rc<T> {}

impl<T> AbstractRc<T> for Arc<T> {}
9 changes: 3 additions & 6 deletions crates/sel4-capdl-initializer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,13 @@ fn static_heap_bounds() -> StaticHeapBounds {

mod heap {
use sel4_dlmalloc::{StaticDlmallocGlobalAlloc, StaticHeapBounds};
use sel4_sync::{GenericRawMutex, PanickingMutexSyncOps};
use sel4_sync::PanickingRawMutex;

use super::static_heap_bounds;

#[global_allocator]
static GLOBAL_ALLOCATOR: StaticDlmallocGlobalAlloc<
GenericRawMutex<PanickingMutexSyncOps>,
PanickingRawMutex,
fn() -> StaticHeapBounds,
> = StaticDlmallocGlobalAlloc::new(
GenericRawMutex::new(PanickingMutexSyncOps::new()),
static_heap_bounds,
);
> = StaticDlmallocGlobalAlloc::new(PanickingRawMutex::new(), static_heap_bounds);
}
9 changes: 3 additions & 6 deletions crates/sel4-microkit/src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ macro_rules! declare_heap {

#[global_allocator]
static GLOBAL_ALLOCATOR: StaticDlmallocGlobalAlloc<
GenericRawMutex<PanickingMutexSyncOps>,
PanickingRawMutex,
&'static StaticHeap<{ $size }>,
> = StaticDlmallocGlobalAlloc::new(
GenericRawMutex::new(PanickingMutexSyncOps::new()),
&STATIC_HEAP,
);
> = StaticDlmallocGlobalAlloc::new(PanickingRawMutex::new(), &STATIC_HEAP);
}
}
};
Expand All @@ -37,5 +34,5 @@ macro_rules! declare_heap {

pub mod _private {
pub use sel4_dlmalloc::{StaticDlmallocGlobalAlloc, StaticHeap};
pub use sel4_sync::{GenericRawMutex, PanickingMutexSyncOps};
pub use sel4_sync::PanickingRawMutex;
}
10 changes: 3 additions & 7 deletions crates/sel4-root-task/src/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,10 @@ macro_rules! declare_heap {

#[global_allocator]
static GLOBAL_ALLOCATOR: StaticDlmallocGlobalAlloc<
GenericRawMutex<
IndirectNotificationMutexSyncOps<fn() -> sel4::cap::Notification>,
>,
GenericRawMutex<fn() -> sel4::cap::Notification>,
&'static StaticHeap<{ SIZE }>,
> = StaticDlmallocGlobalAlloc::new(
GenericRawMutex::new(IndirectNotificationMutexSyncOps::new(
get_global_allocator_mutex_notification,
)),
GenericRawMutex::new(get_global_allocator_mutex_notification),
&STATIC_HEAP,
);
}
Expand All @@ -62,7 +58,7 @@ macro_rules! declare_heap {

pub mod _private {
pub use sel4_dlmalloc::{StaticDlmallocGlobalAlloc, StaticHeap};
pub use sel4_sync::{GenericRawMutex, IndirectNotificationMutexSyncOps};
pub use sel4_sync::GenericRawMutex;

pub use super::get_global_allocator_mutex_notification;
}
4 changes: 3 additions & 1 deletion crates/sel4-shared-ring-buffer/smoltcp/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
mk {
package.name = "sel4-shared-ring-buffer-smoltcp";
dependencies = {
inherit (versions) log;
inherit (versions) log lock_api;
smoltcp = smoltcpWith [];
inherit (localCrates)
sel4-abstract-rc
sel4-sync-trivial
sel4-shared-ring-buffer
sel4-shared-ring-buffer-bookkeeping
sel4-bounce-buffer-allocator
Expand Down
3 changes: 3 additions & 0 deletions crates/sel4-shared-ring-buffer/smoltcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ edition = "2021"
license = "BSD-2-Clause"

[dependencies]
lock_api = "0.4.12"
log = "0.4.17"
sel4-abstract-rc = { path = "../../sel4-abstract-rc" }
sel4-bounce-buffer-allocator = { path = "../../sel4-bounce-buffer-allocator" }
sel4-externally-shared = { path = "../../sel4-externally-shared", features = ["unstable"] }
sel4-shared-ring-buffer = { path = ".." }
sel4-shared-ring-buffer-bookkeeping = { path = "../bookkeeping" }
sel4-sync-trivial = { path = "../../sel4-sync/trivial" }

[dependencies.smoltcp]
version = "0.10.0"
Expand Down
Loading
Loading