From 8c292bf7359c62680c76423d106aa1fa6bd0c50d Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Tue, 25 Jun 2024 05:11:14 +0000 Subject: [PATCH 01/13] crates/sel4-sync/abstractions: Introduce Signed-off-by: Nick Spinale --- Cargo.lock | 8 +++++ Cargo.toml | 1 + crates/sel4-sync/Cargo.nix | 1 + crates/sel4-sync/Cargo.toml | 1 + crates/sel4-sync/abstractions/Cargo.nix | 14 +++++++++ crates/sel4-sync/abstractions/Cargo.toml | 20 ++++++++++++ crates/sel4-sync/abstractions/src/lib.rs | 39 ++++++++++++++++++++++++ crates/sel4-sync/src/lib.rs | 4 +-- crates/sel4-sync/src/mutex.rs | 30 +----------------- 9 files changed, 87 insertions(+), 31 deletions(-) create mode 100644 crates/sel4-sync/abstractions/Cargo.nix create mode 100644 crates/sel4-sync/abstractions/Cargo.toml create mode 100644 crates/sel4-sync/abstractions/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index e8134d2f3..ae397f20a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2735,6 +2735,14 @@ dependencies = [ "lock_api", "sel4", "sel4-immediate-sync-once-cell", + "sel4-sync-abstractions", +] + +[[package]] +name = "sel4-sync-abstractions" +version = "0.1.0" +dependencies = [ + "lock_api", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 729ca3173..71445894f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -136,6 +136,7 @@ members = [ "crates/sel4-shared-ring-buffer/smoltcp", "crates/sel4-stack", "crates/sel4-sync", + "crates/sel4-sync/abstractions", "crates/sel4-synthetic-elf", "crates/sel4-test-harness", "crates/sel4/bitfield-ops", diff --git a/crates/sel4-sync/Cargo.nix b/crates/sel4-sync/Cargo.nix index ad9706cee..c1b544e94 100644 --- a/crates/sel4-sync/Cargo.nix +++ b/crates/sel4-sync/Cargo.nix @@ -17,6 +17,7 @@ mk rec { inherit (localCrates) sel4 sel4-immediate-sync-once-cell + sel4-sync-abstractions ; }; } diff --git a/crates/sel4-sync/Cargo.toml b/crates/sel4-sync/Cargo.toml index fe344833f..95c0d2b6e 100644 --- a/crates/sel4-sync/Cargo.toml +++ b/crates/sel4-sync/Cargo.toml @@ -20,3 +20,4 @@ license = "MIT" lock_api = "0.4.12" sel4 = { path = "../sel4" } sel4-immediate-sync-once-cell = { path = "../sel4-immediate-sync-once-cell" } +sel4-sync-abstractions = { path = "abstractions" } diff --git a/crates/sel4-sync/abstractions/Cargo.nix b/crates/sel4-sync/abstractions/Cargo.nix new file mode 100644 index 000000000..3c27461c6 --- /dev/null +++ b/crates/sel4-sync/abstractions/Cargo.nix @@ -0,0 +1,14 @@ +# +# Copyright 2023, Colias Group, LLC +# +# SPDX-License-Identifier: MIT +# + +{ mk, versions }: + +mk { + package.name = "sel4-sync-abstractions"; + dependencies = { + inherit (versions) lock_api; + }; +} diff --git a/crates/sel4-sync/abstractions/Cargo.toml b/crates/sel4-sync/abstractions/Cargo.toml new file mode 100644 index 000000000..1a5322225 --- /dev/null +++ b/crates/sel4-sync/abstractions/Cargo.toml @@ -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 = "sel4-sync-abstractions" +version = "0.1.0" +authors = ["Nick Spinale "] +edition = "2021" +license = "BSD-2-Clause" + +[dependencies] +lock_api = "0.4.12" diff --git a/crates/sel4-sync/abstractions/src/lib.rs b/crates/sel4-sync/abstractions/src/lib.rs new file mode 100644 index 000000000..08d793b22 --- /dev/null +++ b/crates/sel4-sync/abstractions/src/lib.rs @@ -0,0 +1,39 @@ +// +// Copyright 2024, Colias Group, LLC +// +// SPDX-License-Identifier: BSD-2-Clause +// + +#![no_std] + +use core::sync::atomic::{AtomicBool, Ordering}; + +pub use lock_api; + +pub struct PanickingRawMutex { + locked: AtomicBool, +} + +unsafe impl lock_api::RawMutex for PanickingRawMutex { + type GuardMarker = lock_api::GuardNoSend; // TODO + + #[allow(clippy::declare_interior_mutable_const)] + const INIT: Self = Self { + locked: AtomicBool::new(false), + }; + + fn lock(&self) { + if !self.try_lock() { + panic!("lock contention") + } + } + + fn try_lock(&self) -> bool { + let was_locked = self.locked.swap(true, Ordering::Acquire); + !was_locked + } + + unsafe fn unlock(&self) { + self.locked.store(false, Ordering::Release) + } +} diff --git a/crates/sel4-sync/src/lib.rs b/crates/sel4-sync/src/lib.rs index 656cdccba..62c950bb7 100644 --- a/crates/sel4-sync/src/lib.rs +++ b/crates/sel4-sync/src/lib.rs @@ -6,12 +6,12 @@ #![no_std] -pub use lock_api; +pub use sel4_sync_abstractions::*; mod mutex; pub use mutex::{ AbstractMutexSyncOps, DeferredNotificationMutexSyncOps, GenericRawMutex, IndirectNotificationMutexSyncOps, MutexSyncOps, MutexSyncOpsWithInteriorMutability, - MutexSyncOpsWithNotification, PanickingMutexSyncOps, PanickingRawMutex, + MutexSyncOpsWithNotification, PanickingMutexSyncOps, }; diff --git a/crates/sel4-sync/src/mutex.rs b/crates/sel4-sync/src/mutex.rs index 301855f0e..148a49c16 100644 --- a/crates/sel4-sync/src/mutex.rs +++ b/crates/sel4-sync/src/mutex.rs @@ -5,38 +5,10 @@ // SPDX-License-Identifier: MIT // -use core::sync::atomic::{fence, AtomicBool, AtomicIsize, Ordering}; +use core::sync::atomic::{fence, AtomicIsize, Ordering}; use sel4_immediate_sync_once_cell::ImmediateSyncOnceCell; -pub struct PanickingRawMutex { - locked: AtomicBool, -} - -unsafe impl lock_api::RawMutex for PanickingRawMutex { - type GuardMarker = lock_api::GuardNoSend; // TODO - - #[allow(clippy::declare_interior_mutable_const)] - const INIT: Self = Self { - locked: AtomicBool::new(false), - }; - - fn lock(&self) { - if !self.try_lock() { - panic!("lock contention") - } - } - - fn try_lock(&self) -> bool { - let was_locked = self.locked.swap(true, Ordering::Acquire); - !was_locked - } - - unsafe fn unlock(&self) { - self.locked.store(false, Ordering::Release) - } -} - pub struct GenericRawMutex { sync_ops: O, value: AtomicIsize, From df7350dac552a01b2c55f2ff2527548ebb1fef5d Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Tue, 25 Jun 2024 05:16:12 +0000 Subject: [PATCH 02/13] crates/sel4-sync: Remove AbstractMutexSyncOps Signed-off-by: Nick Spinale --- .../runtime/src/global_allocator.rs | 25 +++++++++++-------- crates/sel4-sync/src/lib.rs | 6 ++--- crates/sel4-sync/src/mutex.rs | 21 ---------------- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/crates/private/support/sel4-simple-task/runtime/src/global_allocator.rs b/crates/private/support/sel4-simple-task/runtime/src/global_allocator.rs index a6159f7f1..e634e8aa2 100644 --- a/crates/private/support/sel4-simple-task/runtime/src/global_allocator.rs +++ b/crates/private/support/sel4-simple-task/runtime/src/global_allocator.rs @@ -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>, + GenericRawMutex, 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(); + } +} diff --git a/crates/sel4-sync/src/lib.rs b/crates/sel4-sync/src/lib.rs index 62c950bb7..03bdc4ddb 100644 --- a/crates/sel4-sync/src/lib.rs +++ b/crates/sel4-sync/src/lib.rs @@ -11,7 +11,7 @@ pub use sel4_sync_abstractions::*; mod mutex; pub use mutex::{ - AbstractMutexSyncOps, DeferredNotificationMutexSyncOps, GenericRawMutex, - IndirectNotificationMutexSyncOps, MutexSyncOps, MutexSyncOpsWithInteriorMutability, - MutexSyncOpsWithNotification, PanickingMutexSyncOps, + DeferredNotificationMutexSyncOps, GenericRawMutex, IndirectNotificationMutexSyncOps, + MutexSyncOps, MutexSyncOpsWithInteriorMutability, MutexSyncOpsWithNotification, + PanickingMutexSyncOps, }; diff --git a/crates/sel4-sync/src/mutex.rs b/crates/sel4-sync/src/mutex.rs index 148a49c16..984db0bdf 100644 --- a/crates/sel4-sync/src/mutex.rs +++ b/crates/sel4-sync/src/mutex.rs @@ -137,27 +137,6 @@ impl sel4::cap::Notification> MutexSyncOpsWithNotification } } -pub struct AbstractMutexSyncOps { - pub signal: T, - pub wait: U, -} - -impl AbstractMutexSyncOps { - pub const fn new(signal: T, wait: U) -> Self { - Self { signal, wait } - } -} - -impl MutexSyncOps for AbstractMutexSyncOps { - fn signal(&self) { - (self.signal)() - } - - fn wait(&self) { - (self.wait)() - } -} - pub struct PanickingMutexSyncOps(()); impl PanickingMutexSyncOps { From 678b3f534d9ff14c25362013b327a4ddbac29187 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Tue, 25 Jun 2024 05:21:43 +0000 Subject: [PATCH 03/13] crates/sel4-sync: Remove IndirectNotificationMutexSyncOps Signed-off-by: Nick Spinale --- crates/sel4-root-task/src/heap.rs | 10 +++------- crates/sel4-sync/src/lib.rs | 5 ++--- crates/sel4-sync/src/mutex.rs | 16 ++-------------- 3 files changed, 7 insertions(+), 24 deletions(-) diff --git a/crates/sel4-root-task/src/heap.rs b/crates/sel4-root-task/src/heap.rs index 5fa6a153b..69c249cfb 100644 --- a/crates/sel4-root-task/src/heap.rs +++ b/crates/sel4-root-task/src/heap.rs @@ -44,14 +44,10 @@ macro_rules! declare_heap { #[global_allocator] static GLOBAL_ALLOCATOR: StaticDlmallocGlobalAlloc< - GenericRawMutex< - IndirectNotificationMutexSyncOps sel4::cap::Notification>, - >, + GenericRawMutex 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, ); } @@ -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; } diff --git a/crates/sel4-sync/src/lib.rs b/crates/sel4-sync/src/lib.rs index 03bdc4ddb..57ce373ac 100644 --- a/crates/sel4-sync/src/lib.rs +++ b/crates/sel4-sync/src/lib.rs @@ -11,7 +11,6 @@ pub use sel4_sync_abstractions::*; mod mutex; pub use mutex::{ - DeferredNotificationMutexSyncOps, GenericRawMutex, IndirectNotificationMutexSyncOps, - MutexSyncOps, MutexSyncOpsWithInteriorMutability, MutexSyncOpsWithNotification, - PanickingMutexSyncOps, + DeferredNotificationMutexSyncOps, GenericRawMutex, MutexSyncOps, + MutexSyncOpsWithInteriorMutability, MutexSyncOpsWithNotification, PanickingMutexSyncOps, }; diff --git a/crates/sel4-sync/src/mutex.rs b/crates/sel4-sync/src/mutex.rs index 984db0bdf..407050efa 100644 --- a/crates/sel4-sync/src/mutex.rs +++ b/crates/sel4-sync/src/mutex.rs @@ -119,21 +119,9 @@ impl MutexSyncOpsWithInteriorMutability for DeferredNotificationMutexSyncOps { } } -pub struct IndirectNotificationMutexSyncOps { - get_notification: T, -} - -impl sel4::cap::Notification> IndirectNotificationMutexSyncOps { - pub const fn new(get_notification: T) -> Self { - Self { get_notification } - } -} - -impl sel4::cap::Notification> MutexSyncOpsWithNotification - for IndirectNotificationMutexSyncOps -{ +impl sel4::cap::Notification> MutexSyncOpsWithNotification for F { fn notification(&self) -> sel4::cap::Notification { - (self.get_notification)() + (self)() } } From c5efedcd6e3908b84bf556d97274077e30686bff Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Tue, 25 Jun 2024 05:23:23 +0000 Subject: [PATCH 04/13] crates/sel4-sync: Move code around Signed-off-by: Nick Spinale --- crates/sel4-sync/src/mutex.rs | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/crates/sel4-sync/src/mutex.rs b/crates/sel4-sync/src/mutex.rs index 407050efa..702f6819b 100644 --- a/crates/sel4-sync/src/mutex.rs +++ b/crates/sel4-sync/src/mutex.rs @@ -23,12 +23,24 @@ impl GenericRawMutex { } } +pub trait MutexSyncOpsWithInteriorMutability { + type ModifyInput; + type ModifyOutput; + + fn modify(&self, input: Self::ModifyInput) -> Self::ModifyOutput; +} + impl GenericRawMutex { pub fn modify(&self, input: O::ModifyInput) -> O::ModifyOutput { self.sync_ops.modify(input) } } +pub trait MutexSyncOps { + fn signal(&self); + fn wait(&self); +} + unsafe impl lock_api::RawMutex for GenericRawMutex { type GuardMarker = lock_api::GuardNoSend; // TODO @@ -54,18 +66,6 @@ unsafe impl lock_api::RawMutex for GenericRawMutex { } } -pub trait MutexSyncOps { - fn signal(&self); - fn wait(&self); -} - -pub trait MutexSyncOpsWithInteriorMutability { - type ModifyInput; - type ModifyOutput; - - fn modify(&self, input: Self::ModifyInput) -> Self::ModifyOutput; -} - pub trait MutexSyncOpsWithNotification { fn notification(&self) -> sel4::cap::Notification; } @@ -86,6 +86,12 @@ impl MutexSyncOpsWithNotification for sel4::cap::Notification { } } +impl sel4::cap::Notification> MutexSyncOpsWithNotification for F { + fn notification(&self) -> sel4::cap::Notification { + (self)() + } +} + pub struct DeferredNotificationMutexSyncOps { inner: ImmediateSyncOnceCell, } @@ -119,12 +125,6 @@ impl MutexSyncOpsWithInteriorMutability for DeferredNotificationMutexSyncOps { } } -impl sel4::cap::Notification> MutexSyncOpsWithNotification for F { - fn notification(&self) -> sel4::cap::Notification { - (self)() - } -} - pub struct PanickingMutexSyncOps(()); impl PanickingMutexSyncOps { From 736f63265929de7a602c67b15c282656e26adf6c Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Tue, 25 Jun 2024 05:29:06 +0000 Subject: [PATCH 05/13] crates/sel4-sync: Remove PanickingMutexSyncOps Signed-off-by: Nick Spinale --- crates/drivers/virtio/hal-impl/src/lib.rs | 17 ++++++------- .../root-task/spawn-task/child/src/runtime.rs | 9 +++---- crates/sel4-capdl-initializer/src/main.rs | 9 +++---- crates/sel4-microkit/src/heap.rs | 9 +++---- crates/sel4-sync/src/lib.rs | 2 +- crates/sel4-sync/src/mutex.rs | 24 ------------------- 6 files changed, 17 insertions(+), 53 deletions(-) diff --git a/crates/drivers/virtio/hal-impl/src/lib.rs b/crates/drivers/virtio/hal-impl/src/lib.rs index 521312c0b..151ba122e 100644 --- a/crates/drivers/virtio/hal-impl/src/lib.rs +++ b/crates/drivers/virtio/hal-impl/src/lib.rs @@ -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, State>> = +static GLOBAL_STATE: ImmediateSyncOnceCell> = ImmediateSyncOnceCell::new(); struct State { @@ -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(); } diff --git a/crates/examples/root-task/spawn-task/child/src/runtime.rs b/crates/examples/root-task/spawn-task/child/src/runtime.rs index e3a6ada98..4779aacc4 100644 --- a/crates/examples/root-task/spawn-task/child/src/runtime.rs +++ b/crates/examples/root-task/spawn-task/child/src/runtime.rs @@ -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; @@ -24,12 +24,9 @@ static STATIC_HEAP: StaticHeap = StaticHeap::new(); #[global_allocator] static GLOBAL_ALLOCATOR: StaticDlmallocGlobalAlloc< - GenericRawMutex, + PanickingRawMutex, &'static StaticHeap, -> = 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); diff --git a/crates/sel4-capdl-initializer/src/main.rs b/crates/sel4-capdl-initializer/src/main.rs index 8158617b3..2e0770713 100644 --- a/crates/sel4-capdl-initializer/src/main.rs +++ b/crates/sel4-capdl-initializer/src/main.rs @@ -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, + PanickingRawMutex, fn() -> StaticHeapBounds, - > = StaticDlmallocGlobalAlloc::new( - GenericRawMutex::new(PanickingMutexSyncOps::new()), - static_heap_bounds, - ); + > = StaticDlmallocGlobalAlloc::new(PanickingRawMutex::new(), static_heap_bounds); } diff --git a/crates/sel4-microkit/src/heap.rs b/crates/sel4-microkit/src/heap.rs index 221033b6e..722d6c66d 100644 --- a/crates/sel4-microkit/src/heap.rs +++ b/crates/sel4-microkit/src/heap.rs @@ -23,12 +23,9 @@ macro_rules! declare_heap { #[global_allocator] static GLOBAL_ALLOCATOR: StaticDlmallocGlobalAlloc< - GenericRawMutex, + PanickingRawMutex, &'static StaticHeap<{ $size }>, - > = StaticDlmallocGlobalAlloc::new( - GenericRawMutex::new(PanickingMutexSyncOps::new()), - &STATIC_HEAP, - ); + > = StaticDlmallocGlobalAlloc::new(PanickingRawMutex::new(), &STATIC_HEAP); } } }; @@ -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; } diff --git a/crates/sel4-sync/src/lib.rs b/crates/sel4-sync/src/lib.rs index 57ce373ac..bc36752c1 100644 --- a/crates/sel4-sync/src/lib.rs +++ b/crates/sel4-sync/src/lib.rs @@ -12,5 +12,5 @@ mod mutex; pub use mutex::{ DeferredNotificationMutexSyncOps, GenericRawMutex, MutexSyncOps, - MutexSyncOpsWithInteriorMutability, MutexSyncOpsWithNotification, PanickingMutexSyncOps, + MutexSyncOpsWithInteriorMutability, MutexSyncOpsWithNotification, }; diff --git a/crates/sel4-sync/src/mutex.rs b/crates/sel4-sync/src/mutex.rs index 702f6819b..bbeb260e2 100644 --- a/crates/sel4-sync/src/mutex.rs +++ b/crates/sel4-sync/src/mutex.rs @@ -124,27 +124,3 @@ impl MutexSyncOpsWithInteriorMutability for DeferredNotificationMutexSyncOps { self.inner.set(input).unwrap() } } - -pub struct PanickingMutexSyncOps(()); - -impl PanickingMutexSyncOps { - pub const fn new() -> Self { - Self(()) - } -} - -impl Default for PanickingMutexSyncOps { - fn default() -> Self { - Self::new() - } -} - -impl MutexSyncOps for PanickingMutexSyncOps { - fn signal(&self) { - panic!("unexpected contention: signal") - } - - fn wait(&self) { - panic!("unexpected contention: wait") - } -} From 86a9776e05c11f4c439d1d919991431924119e34 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Tue, 25 Jun 2024 06:36:54 +0000 Subject: [PATCH 06/13] crates/sel4-sync/abstractions: Add PanickingRawMutex::new() Signed-off-by: Nick Spinale --- crates/sel4-sync/abstractions/src/lib.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/crates/sel4-sync/abstractions/src/lib.rs b/crates/sel4-sync/abstractions/src/lib.rs index 08d793b22..325c35411 100644 --- a/crates/sel4-sync/abstractions/src/lib.rs +++ b/crates/sel4-sync/abstractions/src/lib.rs @@ -14,13 +14,25 @@ pub struct PanickingRawMutex { locked: AtomicBool, } +impl PanickingRawMutex { + pub const fn new() -> Self { + Self { + locked: AtomicBool::new(false), + } + } +} + +impl Default for PanickingRawMutex { + fn default() -> Self { + Self::new() + } +} + unsafe impl lock_api::RawMutex for PanickingRawMutex { type GuardMarker = lock_api::GuardNoSend; // TODO #[allow(clippy::declare_interior_mutable_const)] - const INIT: Self = Self { - locked: AtomicBool::new(false), - }; + const INIT: Self = Self::new(); fn lock(&self) { if !self.try_lock() { From 3d5bfefe46e6093e0fe3f21155dce8bf6b24b0bb Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Thu, 11 Jul 2024 20:48:14 +0000 Subject: [PATCH 07/13] crates/sel4-sync/abstractions: Add UnsyncPanickingRawMutex Signed-off-by: Nick Spinale --- crates/sel4-sync/abstractions/src/lib.rs | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/crates/sel4-sync/abstractions/src/lib.rs b/crates/sel4-sync/abstractions/src/lib.rs index 325c35411..8ca18c113 100644 --- a/crates/sel4-sync/abstractions/src/lib.rs +++ b/crates/sel4-sync/abstractions/src/lib.rs @@ -6,6 +6,7 @@ #![no_std] +use core::cell::Cell; use core::sync::atomic::{AtomicBool, Ordering}; pub use lock_api; @@ -49,3 +50,43 @@ unsafe impl lock_api::RawMutex for PanickingRawMutex { self.locked.store(false, Ordering::Release) } } + +pub struct UnsyncPanickingRawMutex { + locked: Cell, +} + +impl UnsyncPanickingRawMutex { + pub const fn new() -> Self { + Self { + locked: Cell::new(false), + } + } +} + +impl Default for UnsyncPanickingRawMutex { + fn default() -> Self { + Self::new() + } +} + +unsafe impl lock_api::RawMutex for UnsyncPanickingRawMutex { + type GuardMarker = lock_api::GuardNoSend; // TODO + + #[allow(clippy::declare_interior_mutable_const)] + const INIT: Self = Self::new(); + + fn lock(&self) { + if !self.try_lock() { + panic!("lock contention") + } + } + + fn try_lock(&self) -> bool { + let was_locked = self.locked.replace(true); + !was_locked + } + + unsafe fn unlock(&self) { + self.locked.set(false) + } +} From 198a4f3ff775dc47e80c776be25f72f139a45154 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Thu, 11 Jul 2024 21:08:59 +0000 Subject: [PATCH 08/13] crates/sel4-sync/abstractions: Introduce and apply AbstractRcT Signed-off-by: Nick Spinale --- Cargo.lock | 2 + .../http-server/pds/server/src/main.rs | 1 + .../sel4-shared-ring-buffer/smoltcp/Cargo.nix | 3 +- .../smoltcp/Cargo.toml | 2 + .../smoltcp/src/lib.rs | 108 +++++++++--------- crates/sel4-sync/abstractions/Cargo.nix | 3 + crates/sel4-sync/abstractions/Cargo.toml | 3 + crates/sel4-sync/abstractions/src/lib.rs | 7 ++ crates/sel4-sync/abstractions/src/rc.rs | 31 +++++ 9 files changed, 103 insertions(+), 57 deletions(-) create mode 100644 crates/sel4-sync/abstractions/src/rc.rs diff --git a/Cargo.lock b/Cargo.lock index ae397f20a..c50114831 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2635,11 +2635,13 @@ dependencies = [ name = "sel4-shared-ring-buffer-smoltcp" version = "0.1.0" dependencies = [ + "lock_api", "log", "sel4-bounce-buffer-allocator", "sel4-externally-shared", "sel4-shared-ring-buffer", "sel4-shared-ring-buffer-bookkeeping", + "sel4-sync-abstractions", "smoltcp", ] diff --git a/crates/examples/microkit/http-server/pds/server/src/main.rs b/crates/examples/microkit/http-server/pds/server/src/main.rs index f9418f30e..5957f0483 100644 --- a/crates/examples/microkit/http-server/pds/server/src/main.rs +++ b/crates/examples/microkit/http-server/pds/server/src/main.rs @@ -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( diff --git a/crates/sel4-shared-ring-buffer/smoltcp/Cargo.nix b/crates/sel4-shared-ring-buffer/smoltcp/Cargo.nix index 71de65be2..50d7367eb 100644 --- a/crates/sel4-shared-ring-buffer/smoltcp/Cargo.nix +++ b/crates/sel4-shared-ring-buffer/smoltcp/Cargo.nix @@ -9,13 +9,14 @@ mk { package.name = "sel4-shared-ring-buffer-smoltcp"; dependencies = { - inherit (versions) log; + inherit (versions) log lock_api; smoltcp = smoltcpWith []; inherit (localCrates) sel4-shared-ring-buffer sel4-shared-ring-buffer-bookkeeping sel4-bounce-buffer-allocator ; + sel4-sync-abstractions = localCrates.sel4-sync-abstractions // { features = [ "alloc" ]; }; sel4-externally-shared = localCrates.sel4-externally-shared // { features = [ "unstable" ]; }; }; } diff --git a/crates/sel4-shared-ring-buffer/smoltcp/Cargo.toml b/crates/sel4-shared-ring-buffer/smoltcp/Cargo.toml index b75aad137..9f6022b5d 100644 --- a/crates/sel4-shared-ring-buffer/smoltcp/Cargo.toml +++ b/crates/sel4-shared-ring-buffer/smoltcp/Cargo.toml @@ -17,11 +17,13 @@ edition = "2021" license = "BSD-2-Clause" [dependencies] +lock_api = "0.4.12" log = "0.4.17" 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-abstractions = { path = "../../sel4-sync/abstractions", features = ["alloc"] } [dependencies.smoltcp] version = "0.10.0" diff --git a/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs b/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs index c389de489..0eda792b5 100644 --- a/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs +++ b/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs @@ -8,26 +8,25 @@ extern crate alloc; -use alloc::rc::Rc; -use core::cell::RefCell; - +use lock_api::{Mutex, RawMutex}; use smoltcp::phy::{self, Device, DeviceCapabilities}; use smoltcp::time::Instant; use sel4_bounce_buffer_allocator::{AbstractBounceBufferAllocator, BounceBufferAllocator}; use sel4_externally_shared::ExternallySharedRef; use sel4_shared_ring_buffer::{roles::Provide, RingBuffers}; +use sel4_sync_abstractions::{AbstractRcT, RcT, UnsyncPanickingRawMutex}; mod inner; pub use inner::{Error, PeerMisbehaviorError}; use inner::{Inner, RxBufferIndex, TxBufferIndex}; -pub struct DeviceImpl { - inner: Rc>>, +pub struct DeviceImpl { + inner: P::Rc>>, } -impl Clone for DeviceImpl { +impl Clone for DeviceImpl { fn clone(&self) -> Self { Self { inner: self.inner.clone(), @@ -35,8 +34,9 @@ impl Clone for DeviceImpl { } } -impl DeviceImpl { +impl DeviceImpl { pub fn new( + raw_mutex: R, dma_region: ExternallySharedRef<'static, [u8]>, bounce_buffer_allocator: BounceBufferAllocator, rx_ring_buffers: RingBuffers<'static, Provide, fn()>, @@ -46,42 +46,45 @@ impl DeviceImpl { caps: DeviceCapabilities, ) -> Result { Ok(Self { - inner: Rc::new(RefCell::new(Inner::new( - dma_region, - bounce_buffer_allocator, - rx_ring_buffers, - tx_ring_buffers, - num_rx_buffers, - rx_buffer_size, - caps, - )?)), + inner: P::Rc::from(Mutex::from_raw( + raw_mutex, + Inner::new( + dma_region, + bounce_buffer_allocator, + rx_ring_buffers, + tx_ring_buffers, + num_rx_buffers, + rx_buffer_size, + caps, + )?, + )), }) } - fn inner(&self) -> &Rc>> { + fn inner(&self) -> &P::Rc>> { &self.inner } pub fn poll(&self) -> bool { - self.inner().borrow_mut().poll().unwrap() + self.inner().lock().poll().unwrap() } pub fn can_receive(&self) -> bool { - self.inner().borrow_mut().can_receive() + self.inner().lock().can_receive() } pub fn can_transmit(&self) -> bool { - self.inner().borrow_mut().can_transmit() + self.inner().lock().can_transmit() } - fn new_rx_token(&self, rx_buffer: RxBufferIndex) -> RxToken { + fn new_rx_token(&self, rx_buffer: RxBufferIndex) -> RxToken { RxToken { buffer: rx_buffer, shared: self.clone(), } } - fn new_tx_token(&self, tx_buffer: TxBufferIndex) -> TxToken { + fn new_tx_token(&self, tx_buffer: TxBufferIndex) -> TxToken { TxToken { buffer: tx_buffer, shared: self.clone(), @@ -89,83 +92,76 @@ impl DeviceImpl { } } -impl Device for DeviceImpl { - type RxToken<'a> = RxToken where A: 'a; - type TxToken<'a> = TxToken where A: 'a; +impl Device for DeviceImpl { + type RxToken<'a> = RxToken where A: 'a, R: 'a, P: 'a; + type TxToken<'a> = TxToken where A: 'a, R: 'a, P: 'a; fn capabilities(&self) -> DeviceCapabilities { - self.inner().borrow().caps().clone() + self.inner().lock().caps().clone() } fn receive(&mut self, _timestamp: Instant) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { self.inner() - .borrow_mut() + .lock() .receive() .map(|(rx_ix, tx_ix)| (self.new_rx_token(rx_ix), self.new_tx_token(tx_ix))) } fn transmit(&mut self, _timestamp: Instant) -> Option> { self.inner() - .borrow_mut() + .lock() .transmit() .map(|ix| self.new_tx_token(ix)) } } -pub struct RxToken { +pub struct RxToken { buffer: RxBufferIndex, - shared: DeviceImpl, + shared: DeviceImpl, } -impl phy::RxToken for RxToken { - fn consume(self, f: F) -> R +impl phy::RxToken + for RxToken +{ + fn consume(self, f: F) -> T where - F: FnOnce(&mut [u8]) -> R, + F: FnOnce(&mut [u8]) -> T, { - let mut ptr = self - .shared - .inner() - .borrow_mut() - .consume_rx_start(self.buffer); + let mut ptr = self.shared.inner().lock().consume_rx_start(self.buffer); let r = f(unsafe { ptr.as_mut() }); - self.shared - .inner() - .borrow_mut() - .consume_rx_finish(self.buffer); + self.shared.inner().lock().consume_rx_finish(self.buffer); r } } -impl Drop for RxToken { +impl Drop for RxToken { fn drop(&mut self) { - self.shared - .inner() - .borrow_mut() - .drop_rx(self.buffer) - .unwrap() + self.shared.inner().lock().drop_rx(self.buffer).unwrap() } } -pub struct TxToken { +pub struct TxToken { buffer: TxBufferIndex, - shared: DeviceImpl, + shared: DeviceImpl, } -impl phy::TxToken for TxToken { - fn consume(self, len: usize, f: F) -> R +impl phy::TxToken + for TxToken +{ + fn consume(self, len: usize, f: F) -> T where - F: FnOnce(&mut [u8]) -> R, + F: FnOnce(&mut [u8]) -> T, { self.shared .inner() - .borrow_mut() + .lock() .consume_tx(self.buffer, len, f) .unwrap() } } -impl Drop for TxToken { +impl Drop for TxToken { fn drop(&mut self) { - self.shared.inner().borrow_mut().drop_tx(self.buffer) + self.shared.inner().lock().drop_tx(self.buffer) } } diff --git a/crates/sel4-sync/abstractions/Cargo.nix b/crates/sel4-sync/abstractions/Cargo.nix index 3c27461c6..d7c05d77a 100644 --- a/crates/sel4-sync/abstractions/Cargo.nix +++ b/crates/sel4-sync/abstractions/Cargo.nix @@ -11,4 +11,7 @@ mk { dependencies = { inherit (versions) lock_api; }; + features = { + alloc = []; + }; } diff --git a/crates/sel4-sync/abstractions/Cargo.toml b/crates/sel4-sync/abstractions/Cargo.toml index 1a5322225..fa4e1e433 100644 --- a/crates/sel4-sync/abstractions/Cargo.toml +++ b/crates/sel4-sync/abstractions/Cargo.toml @@ -16,5 +16,8 @@ authors = ["Nick Spinale "] edition = "2021" license = "BSD-2-Clause" +[features] +alloc = [] + [dependencies] lock_api = "0.4.12" diff --git a/crates/sel4-sync/abstractions/src/lib.rs b/crates/sel4-sync/abstractions/src/lib.rs index 8ca18c113..a9cbb4cd7 100644 --- a/crates/sel4-sync/abstractions/src/lib.rs +++ b/crates/sel4-sync/abstractions/src/lib.rs @@ -6,11 +6,18 @@ #![no_std] +#[cfg(feature = "alloc")] +extern crate alloc; + use core::cell::Cell; use core::sync::atomic::{AtomicBool, Ordering}; pub use lock_api; +mod rc; + +pub use rc::{AbstractRc, AbstractRcT, ArcT, RcT}; + pub struct PanickingRawMutex { locked: AtomicBool, } diff --git a/crates/sel4-sync/abstractions/src/rc.rs b/crates/sel4-sync/abstractions/src/rc.rs new file mode 100644 index 000000000..85fc3c7aa --- /dev/null +++ b/crates/sel4-sync/abstractions/src/rc.rs @@ -0,0 +1,31 @@ +// +// Copyright 2024, Colias Group, LLC +// +// SPDX-License-Identifier: BSD-2-Clause +// + +use alloc::rc::Rc; +use alloc::sync::Arc; +use core::ops::Deref; + +pub trait AbstractRcT { + type Rc: AbstractRc; +} + +pub struct RcT(()); + +impl AbstractRcT for RcT { + type Rc = Rc; +} + +pub struct ArcT(()); + +impl AbstractRcT for ArcT { + type Rc = Arc; +} + +pub trait AbstractRc: Deref + From + Clone {} + +impl AbstractRc for Rc {} + +impl AbstractRc for Arc {} From 2678df0ac0d2ffa904484ab84c851486b8aade74 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Thu, 11 Jul 2024 22:22:52 +0000 Subject: [PATCH 09/13] crates/sel4-abstract-rc: Introduce Signed-off-by: Nick Spinale --- Cargo.lock | 5 +++++ Cargo.toml | 1 + crates/sel4-abstract-rc/Cargo.nix | 11 +++++++++++ crates/sel4-abstract-rc/Cargo.toml | 17 +++++++++++++++++ .../src/rc.rs => sel4-abstract-rc/src/lib.rs} | 4 ++++ .../sel4-shared-ring-buffer/smoltcp/Cargo.nix | 3 ++- .../sel4-shared-ring-buffer/smoltcp/Cargo.toml | 3 ++- .../sel4-shared-ring-buffer/smoltcp/src/lib.rs | 3 ++- crates/sel4-sync/abstractions/Cargo.nix | 3 --- crates/sel4-sync/abstractions/Cargo.toml | 3 --- crates/sel4-sync/abstractions/src/lib.rs | 7 ------- 11 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 crates/sel4-abstract-rc/Cargo.nix create mode 100644 crates/sel4-abstract-rc/Cargo.toml rename crates/{sel4-sync/abstractions/src/rc.rs => sel4-abstract-rc/src/lib.rs} (93%) diff --git a/Cargo.lock b/Cargo.lock index c50114831..1e1c847dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1866,6 +1866,10 @@ dependencies = [ "sel4-sys", ] +[[package]] +name = "sel4-abstract-rc" +version = "0.1.0" + [[package]] name = "sel4-async-block-io" version = "0.1.0" @@ -2637,6 +2641,7 @@ version = "0.1.0" dependencies = [ "lock_api", "log", + "sel4-abstract-rc", "sel4-bounce-buffer-allocator", "sel4-externally-shared", "sel4-shared-ring-buffer", diff --git a/Cargo.toml b/Cargo.toml index 71445894f..fbee1aaed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", diff --git a/crates/sel4-abstract-rc/Cargo.nix b/crates/sel4-abstract-rc/Cargo.nix new file mode 100644 index 000000000..42bc6755e --- /dev/null +++ b/crates/sel4-abstract-rc/Cargo.nix @@ -0,0 +1,11 @@ +# +# Copyright 2024, Colias Group, LLC +# +# SPDX-License-Identifier: MIT +# + +{ mk }: + +mk { + package.name = "sel4-abstract-rc"; +} diff --git a/crates/sel4-abstract-rc/Cargo.toml b/crates/sel4-abstract-rc/Cargo.toml new file mode 100644 index 000000000..bf88087e1 --- /dev/null +++ b/crates/sel4-abstract-rc/Cargo.toml @@ -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 "] +edition = "2021" +license = "BSD-2-Clause" diff --git a/crates/sel4-sync/abstractions/src/rc.rs b/crates/sel4-abstract-rc/src/lib.rs similarity index 93% rename from crates/sel4-sync/abstractions/src/rc.rs rename to crates/sel4-abstract-rc/src/lib.rs index 85fc3c7aa..d1790edfe 100644 --- a/crates/sel4-sync/abstractions/src/rc.rs +++ b/crates/sel4-abstract-rc/src/lib.rs @@ -4,6 +4,10 @@ // SPDX-License-Identifier: BSD-2-Clause // +#![no_std] + +extern crate alloc; + use alloc::rc::Rc; use alloc::sync::Arc; use core::ops::Deref; diff --git a/crates/sel4-shared-ring-buffer/smoltcp/Cargo.nix b/crates/sel4-shared-ring-buffer/smoltcp/Cargo.nix index 50d7367eb..d7d4e586e 100644 --- a/crates/sel4-shared-ring-buffer/smoltcp/Cargo.nix +++ b/crates/sel4-shared-ring-buffer/smoltcp/Cargo.nix @@ -12,11 +12,12 @@ mk { inherit (versions) log lock_api; smoltcp = smoltcpWith []; inherit (localCrates) + sel4-abstract-rc + sel4-sync-abstractions sel4-shared-ring-buffer sel4-shared-ring-buffer-bookkeeping sel4-bounce-buffer-allocator ; - sel4-sync-abstractions = localCrates.sel4-sync-abstractions // { features = [ "alloc" ]; }; sel4-externally-shared = localCrates.sel4-externally-shared // { features = [ "unstable" ]; }; }; } diff --git a/crates/sel4-shared-ring-buffer/smoltcp/Cargo.toml b/crates/sel4-shared-ring-buffer/smoltcp/Cargo.toml index 9f6022b5d..43c0fcdcf 100644 --- a/crates/sel4-shared-ring-buffer/smoltcp/Cargo.toml +++ b/crates/sel4-shared-ring-buffer/smoltcp/Cargo.toml @@ -19,11 +19,12 @@ 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-abstractions = { path = "../../sel4-sync/abstractions", features = ["alloc"] } +sel4-sync-abstractions = { path = "../../sel4-sync/abstractions" } [dependencies.smoltcp] version = "0.10.0" diff --git a/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs b/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs index 0eda792b5..c5bfe7362 100644 --- a/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs +++ b/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs @@ -12,10 +12,11 @@ use lock_api::{Mutex, RawMutex}; use smoltcp::phy::{self, Device, DeviceCapabilities}; use smoltcp::time::Instant; +use sel4_abstract_rc::{AbstractRcT, RcT}; use sel4_bounce_buffer_allocator::{AbstractBounceBufferAllocator, BounceBufferAllocator}; use sel4_externally_shared::ExternallySharedRef; use sel4_shared_ring_buffer::{roles::Provide, RingBuffers}; -use sel4_sync_abstractions::{AbstractRcT, RcT, UnsyncPanickingRawMutex}; +use sel4_sync_abstractions::UnsyncPanickingRawMutex; mod inner; diff --git a/crates/sel4-sync/abstractions/Cargo.nix b/crates/sel4-sync/abstractions/Cargo.nix index d7c05d77a..3c27461c6 100644 --- a/crates/sel4-sync/abstractions/Cargo.nix +++ b/crates/sel4-sync/abstractions/Cargo.nix @@ -11,7 +11,4 @@ mk { dependencies = { inherit (versions) lock_api; }; - features = { - alloc = []; - }; } diff --git a/crates/sel4-sync/abstractions/Cargo.toml b/crates/sel4-sync/abstractions/Cargo.toml index fa4e1e433..1a5322225 100644 --- a/crates/sel4-sync/abstractions/Cargo.toml +++ b/crates/sel4-sync/abstractions/Cargo.toml @@ -16,8 +16,5 @@ authors = ["Nick Spinale "] edition = "2021" license = "BSD-2-Clause" -[features] -alloc = [] - [dependencies] lock_api = "0.4.12" diff --git a/crates/sel4-sync/abstractions/src/lib.rs b/crates/sel4-sync/abstractions/src/lib.rs index a9cbb4cd7..8ca18c113 100644 --- a/crates/sel4-sync/abstractions/src/lib.rs +++ b/crates/sel4-sync/abstractions/src/lib.rs @@ -6,18 +6,11 @@ #![no_std] -#[cfg(feature = "alloc")] -extern crate alloc; - use core::cell::Cell; use core::sync::atomic::{AtomicBool, Ordering}; pub use lock_api; -mod rc; - -pub use rc::{AbstractRc, AbstractRcT, ArcT, RcT}; - pub struct PanickingRawMutex { locked: AtomicBool, } From f047a0f9d58e8bc48937c8d932daa9485c36b4f3 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Thu, 11 Jul 2024 22:25:11 +0000 Subject: [PATCH 10/13] crates/sel4-sync/trivial: Rename from sel4-sync-abstractions Signed-off-by: Nick Spinale --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- crates/sel4-shared-ring-buffer/smoltcp/Cargo.nix | 2 +- crates/sel4-shared-ring-buffer/smoltcp/Cargo.toml | 2 +- crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs | 2 +- crates/sel4-sync/Cargo.nix | 2 +- crates/sel4-sync/Cargo.toml | 2 +- crates/sel4-sync/src/lib.rs | 2 +- crates/sel4-sync/{abstractions => trivial}/Cargo.nix | 2 +- crates/sel4-sync/{abstractions => trivial}/Cargo.toml | 2 +- crates/sel4-sync/{abstractions => trivial}/src/lib.rs | 0 11 files changed, 12 insertions(+), 12 deletions(-) rename crates/sel4-sync/{abstractions => trivial}/Cargo.nix (78%) rename crates/sel4-sync/{abstractions => trivial}/Cargo.toml (93%) rename crates/sel4-sync/{abstractions => trivial}/src/lib.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 1e1c847dd..55a4a1c89 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2646,7 +2646,7 @@ dependencies = [ "sel4-externally-shared", "sel4-shared-ring-buffer", "sel4-shared-ring-buffer-bookkeeping", - "sel4-sync-abstractions", + "sel4-sync-trivial", "smoltcp", ] @@ -2742,11 +2742,11 @@ dependencies = [ "lock_api", "sel4", "sel4-immediate-sync-once-cell", - "sel4-sync-abstractions", + "sel4-sync-trivial", ] [[package]] -name = "sel4-sync-abstractions" +name = "sel4-sync-trivial" version = "0.1.0" dependencies = [ "lock_api", diff --git a/Cargo.toml b/Cargo.toml index fbee1aaed..98f10643f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -137,7 +137,7 @@ members = [ "crates/sel4-shared-ring-buffer/smoltcp", "crates/sel4-stack", "crates/sel4-sync", - "crates/sel4-sync/abstractions", + "crates/sel4-sync/trivial", "crates/sel4-synthetic-elf", "crates/sel4-test-harness", "crates/sel4/bitfield-ops", diff --git a/crates/sel4-shared-ring-buffer/smoltcp/Cargo.nix b/crates/sel4-shared-ring-buffer/smoltcp/Cargo.nix index d7d4e586e..c94617542 100644 --- a/crates/sel4-shared-ring-buffer/smoltcp/Cargo.nix +++ b/crates/sel4-shared-ring-buffer/smoltcp/Cargo.nix @@ -13,7 +13,7 @@ mk { smoltcp = smoltcpWith []; inherit (localCrates) sel4-abstract-rc - sel4-sync-abstractions + sel4-sync-trivial sel4-shared-ring-buffer sel4-shared-ring-buffer-bookkeeping sel4-bounce-buffer-allocator diff --git a/crates/sel4-shared-ring-buffer/smoltcp/Cargo.toml b/crates/sel4-shared-ring-buffer/smoltcp/Cargo.toml index 43c0fcdcf..99ab3ebcb 100644 --- a/crates/sel4-shared-ring-buffer/smoltcp/Cargo.toml +++ b/crates/sel4-shared-ring-buffer/smoltcp/Cargo.toml @@ -24,7 +24,7 @@ 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-abstractions = { path = "../../sel4-sync/abstractions" } +sel4-sync-trivial = { path = "../../sel4-sync/trivial" } [dependencies.smoltcp] version = "0.10.0" diff --git a/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs b/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs index c5bfe7362..47efe486c 100644 --- a/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs +++ b/crates/sel4-shared-ring-buffer/smoltcp/src/lib.rs @@ -16,7 +16,7 @@ use sel4_abstract_rc::{AbstractRcT, RcT}; use sel4_bounce_buffer_allocator::{AbstractBounceBufferAllocator, BounceBufferAllocator}; use sel4_externally_shared::ExternallySharedRef; use sel4_shared_ring_buffer::{roles::Provide, RingBuffers}; -use sel4_sync_abstractions::UnsyncPanickingRawMutex; +use sel4_sync_trivial::UnsyncPanickingRawMutex; mod inner; diff --git a/crates/sel4-sync/Cargo.nix b/crates/sel4-sync/Cargo.nix index c1b544e94..537f90dc3 100644 --- a/crates/sel4-sync/Cargo.nix +++ b/crates/sel4-sync/Cargo.nix @@ -17,7 +17,7 @@ mk rec { inherit (localCrates) sel4 sel4-immediate-sync-once-cell - sel4-sync-abstractions + sel4-sync-trivial ; }; } diff --git a/crates/sel4-sync/Cargo.toml b/crates/sel4-sync/Cargo.toml index 95c0d2b6e..5624d6604 100644 --- a/crates/sel4-sync/Cargo.toml +++ b/crates/sel4-sync/Cargo.toml @@ -20,4 +20,4 @@ license = "MIT" lock_api = "0.4.12" sel4 = { path = "../sel4" } sel4-immediate-sync-once-cell = { path = "../sel4-immediate-sync-once-cell" } -sel4-sync-abstractions = { path = "abstractions" } +sel4-sync-trivial = { path = "trivial" } diff --git a/crates/sel4-sync/src/lib.rs b/crates/sel4-sync/src/lib.rs index bc36752c1..ec4922a49 100644 --- a/crates/sel4-sync/src/lib.rs +++ b/crates/sel4-sync/src/lib.rs @@ -6,7 +6,7 @@ #![no_std] -pub use sel4_sync_abstractions::*; +pub use sel4_sync_trivial::*; mod mutex; diff --git a/crates/sel4-sync/abstractions/Cargo.nix b/crates/sel4-sync/trivial/Cargo.nix similarity index 78% rename from crates/sel4-sync/abstractions/Cargo.nix rename to crates/sel4-sync/trivial/Cargo.nix index 3c27461c6..59c851a2e 100644 --- a/crates/sel4-sync/abstractions/Cargo.nix +++ b/crates/sel4-sync/trivial/Cargo.nix @@ -7,7 +7,7 @@ { mk, versions }: mk { - package.name = "sel4-sync-abstractions"; + package.name = "sel4-sync-trivial"; dependencies = { inherit (versions) lock_api; }; diff --git a/crates/sel4-sync/abstractions/Cargo.toml b/crates/sel4-sync/trivial/Cargo.toml similarity index 93% rename from crates/sel4-sync/abstractions/Cargo.toml rename to crates/sel4-sync/trivial/Cargo.toml index 1a5322225..5f256f946 100644 --- a/crates/sel4-sync/abstractions/Cargo.toml +++ b/crates/sel4-sync/trivial/Cargo.toml @@ -10,7 +10,7 @@ # [package] -name = "sel4-sync-abstractions" +name = "sel4-sync-trivial" version = "0.1.0" authors = ["Nick Spinale "] edition = "2021" diff --git a/crates/sel4-sync/abstractions/src/lib.rs b/crates/sel4-sync/trivial/src/lib.rs similarity index 100% rename from crates/sel4-sync/abstractions/src/lib.rs rename to crates/sel4-sync/trivial/src/lib.rs From 09f720eaa2e600812f6074c725f6ddc8daf3efdc Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Thu, 11 Jul 2024 22:26:19 +0000 Subject: [PATCH 11/13] crates/sel4-sync/trivial: Fix license identifier Signed-off-by: Nick Spinale --- crates/sel4-sync/trivial/Cargo.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/sel4-sync/trivial/Cargo.nix b/crates/sel4-sync/trivial/Cargo.nix index 59c851a2e..1e59fd716 100644 --- a/crates/sel4-sync/trivial/Cargo.nix +++ b/crates/sel4-sync/trivial/Cargo.nix @@ -1,7 +1,7 @@ # # Copyright 2023, Colias Group, LLC # -# SPDX-License-Identifier: MIT +# SPDX-License-Identifier: BSD-2-Clause # { mk, versions }: From 632a145b97fc0710e71e36596c1da3a6b1363958 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Thu, 11 Jul 2024 22:45:29 +0000 Subject: [PATCH 12/13] crates/sel4-abstract-rc: Fix license identifier Signed-off-by: Nick Spinale --- crates/sel4-abstract-rc/Cargo.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/sel4-abstract-rc/Cargo.nix b/crates/sel4-abstract-rc/Cargo.nix index 42bc6755e..599593c12 100644 --- a/crates/sel4-abstract-rc/Cargo.nix +++ b/crates/sel4-abstract-rc/Cargo.nix @@ -1,7 +1,7 @@ # # Copyright 2024, Colias Group, LLC # -# SPDX-License-Identifier: MIT +# SPDX-License-Identifier: BSD-2-Clause # { mk }: From 94873b94d40e8f4b0e3b3238868f7906f9e11efc Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Thu, 11 Jul 2024 22:47:10 +0000 Subject: [PATCH 13/13] crates/sel4-sync: Re-export lock_api Signed-off-by: Nick Spinale --- crates/sel4-sync/src/lib.rs | 2 ++ crates/sel4-sync/trivial/src/lib.rs | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/sel4-sync/src/lib.rs b/crates/sel4-sync/src/lib.rs index ec4922a49..dbdfdbe67 100644 --- a/crates/sel4-sync/src/lib.rs +++ b/crates/sel4-sync/src/lib.rs @@ -6,6 +6,8 @@ #![no_std] +pub use lock_api; + pub use sel4_sync_trivial::*; mod mutex; diff --git a/crates/sel4-sync/trivial/src/lib.rs b/crates/sel4-sync/trivial/src/lib.rs index 8ca18c113..4b85309f3 100644 --- a/crates/sel4-sync/trivial/src/lib.rs +++ b/crates/sel4-sync/trivial/src/lib.rs @@ -9,8 +9,6 @@ use core::cell::Cell; use core::sync::atomic::{AtomicBool, Ordering}; -pub use lock_api; - pub struct PanickingRawMutex { locked: AtomicBool, }