Skip to content

Commit

Permalink
Merge branch 'main' into eliza/constant-time
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw authored May 5, 2023
2 parents 6e1e2e5 + f011197 commit caec1b1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
4 changes: 2 additions & 2 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 hal-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ pub mod boot;
pub mod framebuffer;
pub mod interrupt;
pub mod mem;
mod local;
pub use self::addr::*;
pub use self::boot::BootInfo;
pub use self::local::CoreLocal;
19 changes: 19 additions & 0 deletions hal-core/src/local.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Abstractions for core-local storage.
/// A core-local storage cell.
///
/// This trait represents an architecture-specific mechanism for storing local
/// data for each CPU core.
pub trait CoreLocal<T: 'static> {
/// Returns a new instance of `Self`, using the provided `init` function to
/// generate the initial value for each CPU core.
fn new(init: fn() -> T) -> Self;

/// Accesses the value for the current CPU core.
///
/// This method invokes the provided closure `f` with a reference to the
/// `T`-typed local data for the current CPU core.
fn with<F, U>(&self, f: F) -> U
where
F: FnOnce(&T) -> U;
}
17 changes: 17 additions & 0 deletions hal-x86_64/src/cpu/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use core::{
sync::atomic::{AtomicPtr, AtomicUsize, Ordering},
};
use mycelium_util::{fmt, sync::Lazy};
use hal_core::CoreLocal;

#[repr(C)]
#[derive(Debug)]
Expand Down Expand Up @@ -140,6 +141,8 @@ impl GsLocalData {
}
}

// === impl LocalKey ===

impl<T: 'static> LocalKey<T> {
#[must_use]
#[track_caller]
Expand Down Expand Up @@ -177,3 +180,17 @@ impl<T> fmt::Debug for LocalKey<T> {
.finish()
}
}

impl<T: 'static> CoreLocal<T> for LocalKey<T> {
#[must_use]
fn new(initializer: fn() -> T) -> Self {
Self::new(initializer)
}


#[track_caller]
fn with<F, U>(&self, f: F) -> U
where F: FnOnce(&T) -> U {
self.with(f)
}
}
2 changes: 1 addition & 1 deletion inoculate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tracing-subscriber = "0.3.16"
tracing-error = "0.2"
color-eyre = "0.6"
bootloader = "0.11.2"
bootloader-boot-config = "0.11.2"
bootloader-boot-config = "0.11.3"
locate-cargo-manifest = "0.2"
wait-timeout = "0.2"
owo-colors = "3.5.0"
Expand Down

0 comments on commit caec1b1

Please sign in to comment.