From c026973b9cb70a7506358b487480065313fa9c13 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Fri, 22 Sep 2023 08:37:34 +0000 Subject: [PATCH 1/7] crates/sel4/config: Don't use C libsel4 config Signed-off-by: Nick Spinale --- crates/sel4/config/data/build.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/crates/sel4/config/data/build.rs b/crates/sel4/config/data/build.rs index eed7edee4..ba5f5de78 100644 --- a/crates/sel4/config/data/build.rs +++ b/crates/sel4/config/data/build.rs @@ -1,25 +1,15 @@ use std::env; use std::fs::File; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use sel4_build_env::find_in_libsel4_include_dirs; use sel4_config_generic_types::Configuration; fn main() { - let config = { - let kernel_config = from_path(find_in_libsel4_include_dirs("kernel/gen_config.json")); - let libsel4_config = from_path(find_in_libsel4_include_dirs("sel4/gen_config.json")); - let mut this = Configuration::empty(); - this.append(kernel_config); - this.append(libsel4_config); - this - }; - + let config_json_path = find_in_libsel4_include_dirs("kernel/gen_config.json"); + let config = + Configuration::new(serde_json::from_reader(File::open(config_json_path).unwrap()).unwrap()); let out_dir = env::var("OUT_DIR").unwrap(); let out_path = PathBuf::from(&out_dir).join("kernel_config.json"); serde_json::to_writer_pretty(File::create(out_path).unwrap(), &config).unwrap() } - -fn from_path(path: impl AsRef) -> Configuration { - serde_json::from_reader(File::open(path).unwrap()).unwrap() -} From 858dc4f3f7aff709b38a923f72a14e462753c898 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Fri, 22 Sep 2023 08:35:07 +0000 Subject: [PATCH 2/7] crates/sel4/sys: Support passing object API XML file paths explicitly Signed-off-by: Nick Spinale --- crates/sel4/build-env/src/lib.rs | 20 ++++++++++++++++++++ crates/sel4/sys/build/main.rs | 20 +++++++++++--------- hacking/nix/scope/sources.nix | 2 +- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/crates/sel4/build-env/src/lib.rs b/crates/sel4/build-env/src/lib.rs index 760f20489..df6888be7 100644 --- a/crates/sel4/build-env/src/lib.rs +++ b/crates/sel4/build-env/src/lib.rs @@ -75,3 +75,23 @@ pub fn find_in_libsel4_include_dirs(relative_path: impl AsRef) -> PathBuf ) }) } + +pub fn try_get_or_find_in_libsel4_include_dirs( + var: &str, + relative_path: impl AsRef, +) -> Option { + get_asserting_valid_unicode(var) + .map(PathBuf::from) + .or_else(|| try_find_in_libsel4_include_dirs(relative_path)) +} + +pub fn get_or_find_in_libsel4_include_dirs(var: &str, relative_path: impl AsRef) -> PathBuf { + let relative_path = relative_path.as_ref(); + try_get_or_find_in_libsel4_include_dirs(var, relative_path).unwrap_or_else(|| { + panic!( + "{} not in env and {} not found in libsel4 include path", + var, + relative_path.display(), + ) + }) +} diff --git a/crates/sel4/sys/build/main.rs b/crates/sel4/sys/build/main.rs index ef5fd86d5..be124bf1f 100644 --- a/crates/sel4/sys/build/main.rs +++ b/crates/sel4/sys/build/main.rs @@ -7,7 +7,9 @@ use std::path::{Path, PathBuf}; use glob::glob; use proc_macro2::TokenStream; -use sel4_build_env::{find_in_libsel4_include_dirs, get_libsel4_include_dirs}; +use sel4_build_env::{ + find_in_libsel4_include_dirs, get_libsel4_include_dirs, get_or_find_in_libsel4_include_dirs, +}; use sel4_rustfmt_helper::Rustfmt; mod bf; @@ -43,15 +45,15 @@ fn main() { } { - let interface_definition_files = [ + let interface_definition_files = vec![ // order must be consistent with C libsel4 - "interfaces/sel4.xml", - "interfaces/sel4-sel4arch.xml", - "interfaces/sel4-arch.xml", - ] - .into_iter() - .map(find_in_libsel4_include_dirs) - .collect::>(); + get_or_find_in_libsel4_include_dirs("SEL4_OBJECT_API", "interfaces/sel4.xml"), + get_or_find_in_libsel4_include_dirs( + "SEL4_OBJECT_API_SEL4_ARCH", + "interfaces/sel4-sel4arch.xml", + ), + get_or_find_in_libsel4_include_dirs("SEL4_OBJECT_API_ARCH", "interfaces/sel4-arch.xml"), + ]; let (invocation_labels_fragment, native_fragment, wrappers_fragment) = xml::invocations::generate_rust( diff --git a/hacking/nix/scope/sources.nix b/hacking/nix/scope/sources.nix index 381412f83..e08073d4f 100644 --- a/hacking/nix/scope/sources.nix +++ b/hacking/nix/scope/sources.nix @@ -54,7 +54,7 @@ in rec { rust-sel4test = fetchGit { url = "https://github.com/coliasgroup/seL4.git"; - rev = "07266a57e1073e4dfb4a4f9dddc31b197abdb2a0"; # rust-sel4test + rev = "8e0d0f7f599720a134b5e710ac0433a175b2399b"; # rust-sel4test local = localRoot + "/seL4"; # useLocal = true; }; From 2e99f5f4c76fd4e6a4adc53825ff8a97cc2b8f60 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Fri, 22 Sep 2023 07:41:01 +0000 Subject: [PATCH 3/7] crates/sel4: Improve handling of IPC buffer Signed-off-by: Nick Spinale --- .../support/sel4-simple-task/rpc/src/easy.rs | 21 ++-- crates/sel4-microkit/src/handler.rs | 2 +- crates/sel4-microkit/src/message.rs | 8 +- crates/sel4/src/invocation_context.rs | 4 +- crates/sel4/src/ipc_buffer.rs | 3 + crates/sel4/src/lib.rs | 5 +- crates/sel4/src/state.rs | 108 ++++++++++++------ 7 files changed, 89 insertions(+), 62 deletions(-) diff --git a/crates/private/support/sel4-simple-task/rpc/src/easy.rs b/crates/private/support/sel4-simple-task/rpc/src/easy.rs index 0db2d7b3b..d5cb36f29 100644 --- a/crates/private/support/sel4-simple-task/rpc/src/easy.rs +++ b/crates/private/support/sel4-simple-task/rpc/src/easy.rs @@ -43,7 +43,7 @@ pub mod server { F: FnOnce(Reception) -> T, { let (info, badge) = endpoint.recv(()); - sel4::with_borrow_ipc_buffer(|ipc_buffer| { + sel4::with_ipc_buffer(|ipc_buffer| { let reception = Reception::new(info, badge, ipc_buffer); f(reception) }) @@ -57,7 +57,7 @@ pub mod server { pub fn reply(data: &T) -> Result<(), Error> { let info = prepare_data_for_send(data)?; - sel4::with_borrow_ipc_buffer_mut(|ipc_buffer| sel4::reply(ipc_buffer, info)); + sel4::with_ipc_buffer_mut(|ipc_buffer| sel4::reply(ipc_buffer, info)); Ok(()) } } @@ -90,14 +90,14 @@ impl<'a> Reception<'a> { } pub fn read Deserialize<'b>>(&self) -> Result { - recv_data_with_borrow_ipc_buffer(&self.info, self.ipc_buffer()) + recv_data_with_ipc_buffer(&self.info, self.ipc_buffer()) } } // // // pub fn prepare_data_for_send(data: &T) -> Result { - let used = sel4::with_borrow_ipc_buffer_mut(|ipc_buffer| { + let used = sel4::with_ipc_buffer_mut(|ipc_buffer| { postcard::to_slice(data, ipc_buffer.msg_bytes_mut()).map(|used| used.len()) })?; Ok(MessageInfoBuilder::default() @@ -106,7 +106,7 @@ pub fn prepare_data_for_send(data: &T) -> Result Result { - sel4::with_borrow_ipc_buffer_mut(|ipc_buffer| { + sel4::with_ipc_buffer_mut(|ipc_buffer| { ipc_buffer.msg_bytes_mut()[..bytes.len()].copy_from_slice(bytes); }); Ok(MessageInfoBuilder::default() @@ -115,20 +115,17 @@ pub fn prepare_bytes_for_send(bytes: &[u8]) -> Result { } fn recv_data Deserialize<'a>>(info: &MessageInfo) -> Result { - sel4::with_borrow_ipc_buffer(|ipc_buffer| recv_data_with_borrow_ipc_buffer(info, ipc_buffer)) + sel4::with_ipc_buffer(|ipc_buffer| recv_data_with_ipc_buffer(info, ipc_buffer)) } -fn recv_data_with_borrow_ipc_buffer Deserialize<'a>>( +fn recv_data_with_ipc_buffer Deserialize<'a>>( info: &MessageInfo, ipc_buffer: &IPCBuffer, ) -> Result { - postcard::from_bytes(recv_bytes_with_borrow_ipc_buffer(ipc_buffer, info)).map_err(Into::into) + postcard::from_bytes(recv_bytes_with_ipc_buffer(ipc_buffer, info)).map_err(Into::into) } -fn recv_bytes_with_borrow_ipc_buffer<'a>( - ipc_buffer: &'a IPCBuffer, - info: &MessageInfo, -) -> &'a [u8] { +fn recv_bytes_with_ipc_buffer<'a>(ipc_buffer: &'a IPCBuffer, info: &MessageInfo) -> &'a [u8] { &ipc_buffer.msg_bytes()[..BYTES_PER_WORD * usize::try_from(info.length()).unwrap()] } diff --git a/crates/sel4-microkit/src/handler.rs b/crates/sel4-microkit/src/handler.rs index 54e2b5f68..47e124684 100644 --- a/crates/sel4-microkit/src/handler.rs +++ b/crates/sel4-microkit/src/handler.rs @@ -45,7 +45,7 @@ pub(crate) fn run_handler(mut handler: T) -> Result { let mut reply_tag: Option = None; let mut prepared_deferred_action: Option = if pd_is_passive() { - sel4::with_borrow_ipc_buffer_mut(|ipc_buffer| ipc_buffer.msg_regs_mut()[0] = 0); + sel4::with_ipc_buffer_mut(|ipc_buffer| ipc_buffer.msg_regs_mut()[0] = 0); Some(PreparedDeferredAction::new( MONITOR_EP_CAP.cast(), sel4::MessageInfoBuilder::default().length(1).build(), diff --git a/crates/sel4-microkit/src/message.rs b/crates/sel4-microkit/src/message.rs index 18bb194ed..bf50457f0 100644 --- a/crates/sel4-microkit/src/message.rs +++ b/crates/sel4-microkit/src/message.rs @@ -41,19 +41,19 @@ impl Default for MessageInfo { } pub fn with_msg_regs(f: impl FnOnce(&[MessageRegisterValue]) -> T) -> T { - sel4::with_borrow_ipc_buffer(|ipc_buffer| f(ipc_buffer.msg_regs())) + sel4::with_ipc_buffer(|ipc_buffer| f(ipc_buffer.msg_regs())) } pub fn with_msg_regs_mut(f: impl FnOnce(&mut [MessageRegisterValue]) -> T) -> T { - sel4::with_borrow_ipc_buffer_mut(|ipc_buffer| f(ipc_buffer.msg_regs_mut())) + sel4::with_ipc_buffer_mut(|ipc_buffer| f(ipc_buffer.msg_regs_mut())) } pub fn with_msg_bytes(f: impl FnOnce(&[u8]) -> T) -> T { - sel4::with_borrow_ipc_buffer(|ipc_buffer| f(ipc_buffer.msg_bytes())) + sel4::with_ipc_buffer(|ipc_buffer| f(ipc_buffer.msg_bytes())) } pub fn with_msg_bytes_mut(f: impl FnOnce(&mut [u8]) -> T) -> T { - sel4::with_borrow_ipc_buffer_mut(|ipc_buffer| f(ipc_buffer.msg_bytes_mut())) + sel4::with_ipc_buffer_mut(|ipc_buffer| f(ipc_buffer.msg_bytes_mut())) } pub fn set_mr(i: usize, value: MessageRegisterValue) { diff --git a/crates/sel4/src/invocation_context.rs b/crates/sel4/src/invocation_context.rs index cfd8e61c9..c78ff375c 100644 --- a/crates/sel4/src/invocation_context.rs +++ b/crates/sel4/src/invocation_context.rs @@ -34,9 +34,7 @@ impl InvocationContext for &RefCell { cfg_if::cfg_if! { if #[cfg(feature = "state")] { - use crate::ImplicitInvocationContext; - - type NoExplicitInvocationContextInternal = ImplicitInvocationContext; + type NoExplicitInvocationContextInternal = crate::ImplicitInvocationContext; } else { type NoExplicitInvocationContextInternal = NoInvocationContext; } diff --git a/crates/sel4/src/ipc_buffer.rs b/crates/sel4/src/ipc_buffer.rs index 0a23117b0..6b2efc9ff 100644 --- a/crates/sel4/src/ipc_buffer.rs +++ b/crates/sel4/src/ipc_buffer.rs @@ -9,6 +9,9 @@ pub struct IPCBuffer { ptr: *mut sys::seL4_IPCBuffer, } +unsafe impl Send for IPCBuffer {} +unsafe impl Sync for IPCBuffer {} + impl IPCBuffer { #[allow(clippy::missing_safety_doc)] pub unsafe fn from_ptr(ptr: *mut sys::seL4_IPCBuffer) -> Self { diff --git a/crates/sel4/src/lib.rs b/crates/sel4/src/lib.rs index 43ff5a207..0cb8fc4c3 100644 --- a/crates/sel4/src/lib.rs +++ b/crates/sel4/src/lib.rs @@ -152,10 +152,7 @@ sel4_cfg_if! { mod state; #[cfg(feature = "state")] -pub use state::{ - set_ipc_buffer, with_borrow_ipc_buffer, with_borrow_ipc_buffer_mut, with_ipc_buffer, - ImplicitInvocationContext, -}; +pub use state::{set_ipc_buffer, with_ipc_buffer, with_ipc_buffer_mut, ImplicitInvocationContext}; /// Corresponds to `seL4_Word`. pub type Word = sys::seL4_Word; diff --git a/crates/sel4/src/state.rs b/crates/sel4/src/state.rs index 108b8a260..f934c3894 100644 --- a/crates/sel4/src/state.rs +++ b/crates/sel4/src/state.rs @@ -1,86 +1,118 @@ -use core::cell::RefCell; +use core::fmt; use crate::{IPCBuffer, InvocationContext}; -const fn ipc_buffer_init() -> RefCell> { - RefCell::new(None) -} +// For the sake of consistent behavior between configurations, re-entrancy is not supported even in +// the immutable case cfg_if::cfg_if! { if #[cfg(target_thread_local)] { + use core::cell::RefCell; + #[thread_local] - static IPC_BUFFER: RefCell> = ipc_buffer_init(); + static IPC_BUFFER: RefCell> = RefCell::new(None); - fn with_ipc_buffer_internal(f: F) -> T + fn try_with_ipc_buffer_internal(f: F) -> T where - F: FnOnce(&RefCell>) -> T, + F: FnOnce(Result<&mut Option, BorrowError>) -> T, { - f(&IPC_BUFFER) + match IPC_BUFFER.try_borrow_mut() { + Ok(mut buf) => f(Ok(&mut *buf)), + Err(_) => f(Err(BorrowError::new())), + } } } else if #[cfg(feature = "single-threaded")] { - static IPC_BUFFER: SingleThreaded>> = SingleThreaded(ipc_buffer_init()); + use core::sync::atomic::{AtomicBool, Ordering}; - struct SingleThreaded(T); + static mut IPC_BUFFER: Option = None; - unsafe impl Sync for SingleThreaded {} + static IPC_BUFFER_BORROWED: AtomicBool = AtomicBool::new(false); - fn with_ipc_buffer_internal(f: F) -> T + fn try_with_ipc_buffer_internal(f: F) -> T where - F: FnOnce(&RefCell>) -> T, + F: FnOnce(Result<&mut Option, BorrowError>) -> T, { - f(&IPC_BUFFER.0) + // release on panic + struct Guard; + + impl Drop for Guard { + fn drop(&mut self) { + IPC_BUFFER_BORROWED.store(false, Ordering::Release); + } + } + + if IPC_BUFFER_BORROWED.swap(true, Ordering::Acquire) { + f(Err(BorrowError::new())) + } else { + let _ = Guard; + unsafe { + f(Ok(&mut IPC_BUFFER)) + } + } } } else { compile_error!(r#"when #[cfg(feature = "state")], at least one of #[cfg(target_thread_local)] or #[cfg(feature = "single-threaded")] is required"#); } } -/// Provides access to this thread's IPC buffer. -/// -/// This function is a convenience wrapper around [`with_ipc_buffer`]. -/// -/// Requires the `"state"` feature to be enabled. -pub fn with_ipc_buffer(f: F) -> T +fn try_with_ipc_buffer_raw(f: F) -> T +where + F: FnOnce(Result<&mut Option, BorrowError>) -> T, +{ + try_with_ipc_buffer_internal(f) +} + +#[derive(Debug, Clone)] +pub struct BorrowError(()); + +impl BorrowError { + fn new() -> Self { + Self(()) + } +} + +impl fmt::Display for BorrowError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "IPC buffer already borrowed") + } +} + +fn with_ipc_buffer_raw(f: F) -> T where - F: FnOnce(&RefCell>) -> T, + F: FnOnce(&mut Option) -> T, { - with_ipc_buffer_internal(f) + try_with_ipc_buffer_raw(|r| f(r.unwrap())) } /// Sets the IPC buffer that this crate will use for this thread. /// -/// This function does not modify kernel state. It only this crate's thread-local state. -/// -/// This function is a convenience wrapper around [`with_ipc_buffer`]. +/// This function does not modify kernel state. It only affects this crate's thread-local state. /// /// Requires the `"state"` feature to be enabled. -#[allow(clippy::missing_safety_doc)] -pub unsafe fn set_ipc_buffer(ipc_buffer: IPCBuffer) { - with_ipc_buffer(|buf| { - let _ = buf.replace(Some(ipc_buffer)); +pub fn set_ipc_buffer(ipc_buffer: IPCBuffer) { + with_ipc_buffer_raw(|buf| { + let _ = buf.replace(ipc_buffer); }) } -/// Provides access to a borrowed reference to this thread's IPC buffer. -/// -/// This function is a convenience wrapper around [`with_ipc_buffer`]. +/// Provides access to this thread's IPC buffer. /// /// Requires the `"state"` feature to be enabled. -pub fn with_borrow_ipc_buffer(f: F) -> T +pub fn with_ipc_buffer(f: F) -> T where F: FnOnce(&IPCBuffer) -> T, { - with_ipc_buffer(|buf| f(buf.borrow().as_ref().unwrap())) + with_ipc_buffer_raw(|buf| f(buf.as_ref().unwrap())) } -/// Provides access to a mutably borrowed reference to this thread's IPC buffer. +/// Provides mutable access to this thread's IPC buffer. /// /// Requires the `"state"` feature to be enabled. -pub fn with_borrow_ipc_buffer_mut(f: F) -> T +pub fn with_ipc_buffer_mut(f: F) -> T where F: FnOnce(&mut IPCBuffer) -> T, { - with_ipc_buffer(|buf| f(buf.borrow_mut().as_mut().unwrap())) + with_ipc_buffer_raw(|buf| f(buf.as_mut().unwrap())) } /// The strategy for discovering the current thread's IPC buffer which uses thread-local state. @@ -99,6 +131,6 @@ impl ImplicitInvocationContext { impl InvocationContext for ImplicitInvocationContext { fn invoke(self, f: impl FnOnce(&mut IPCBuffer) -> T) -> T { - with_borrow_ipc_buffer_mut(f) + with_ipc_buffer_mut(f) } } From 732c48beef7c65d8f50faa9a3532e4928486cfac Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Fri, 22 Sep 2023 10:26:29 +0000 Subject: [PATCH 4/7] crates/sel4: Update for kernel aarch64 translation structure object simplification Signed-off-by: Nick Spinale --- .../src/arch/arm/arch/aarch64/invocations.rs | 36 +++---------------- .../sel4/src/arch/arm/arch/aarch64/object.rs | 15 +++----- .../sel4/src/arch/arm/arch/aarch64/vspace.rs | 10 ++---- crates/sel4/src/arch/arm/mod.rs | 18 +--------- crates/sel4/src/arch/arm/object.rs | 5 --- crates/sel4/src/arch/x86/arch/x64/vspace.rs | 8 ++--- hacking/nix/scope/sources.nix | 2 +- 7 files changed, 18 insertions(+), 76 deletions(-) diff --git a/crates/sel4/src/arch/arm/arch/aarch64/invocations.rs b/crates/sel4/src/arch/arm/arch/aarch64/invocations.rs index e8b841269..e371e4437 100644 --- a/crates/sel4/src/arch/arm/arch/aarch64/invocations.rs +++ b/crates/sel4/src/arch/arm/arch/aarch64/invocations.rs @@ -67,7 +67,7 @@ impl LocalCPtr { /// Corresponds to `seL4_ARM_Page_Map`. pub fn frame_map( self, - pgd: PGD, + vspace: VSpace, vaddr: usize, rights: CapRights, attrs: VMAttributes, @@ -75,7 +75,7 @@ impl LocalCPtr { Error::wrap(self.invoke(|cptr, ipc_buffer| { ipc_buffer.inner_mut().seL4_ARM_Page_Map( cptr.bits(), - pgd.bits(), + vspace.bits(), vaddr.try_into().unwrap(), rights.into_inner(), attrs.into_inner(), @@ -102,34 +102,8 @@ impl LocalCPtr { } } -impl PUD { - pub fn pud_map(self, vspace: PGD, vaddr: usize, attr: VMAttributes) -> Result<()> { - Error::wrap(self.invoke(|cptr, ipc_buffer| { - ipc_buffer.inner_mut().seL4_ARM_PageUpperDirectory_Map( - cptr.bits(), - vspace.bits(), - vaddr.try_into().unwrap(), - attr.into_inner(), - ) - })) - } -} - -impl PD { - pub fn pd_map(self, vspace: PGD, vaddr: usize, attr: VMAttributes) -> Result<()> { - Error::wrap(self.invoke(|cptr, ipc_buffer| { - ipc_buffer.inner_mut().seL4_ARM_PageDirectory_Map( - cptr.bits(), - vspace.bits(), - vaddr.try_into().unwrap(), - attr.into_inner(), - ) - })) - } -} - impl PT { - pub fn pt_map(self, vspace: PGD, vaddr: usize, attr: VMAttributes) -> Result<()> { + pub fn pt_map(self, vspace: VSpace, vaddr: usize, attr: VMAttributes) -> Result<()> { Error::wrap(self.invoke(|cptr, ipc_buffer| { ipc_buffer.inner_mut().seL4_ARM_PageTable_Map( cptr.bits(), @@ -202,11 +176,11 @@ impl ASIDControl { impl ASIDPool { /// Corresponds to `seL4_ARM_ASIDPool_Assign`. - pub fn asid_pool_assign(self, pd: PGD) -> Result<()> { + pub fn asid_pool_assign(self, vspace: VSpace) -> Result<()> { Error::wrap(self.invoke(|cptr, ipc_buffer| { ipc_buffer .inner_mut() - .seL4_ARM_ASIDPool_Assign(cptr.bits(), pd.bits()) + .seL4_ARM_ASIDPool_Assign(cptr.bits(), vspace.bits()) })) } } diff --git a/crates/sel4/src/arch/arm/arch/aarch64/object.rs b/crates/sel4/src/arch/arm/arch/aarch64/object.rs index 1ed92ae63..037241e70 100644 --- a/crates/sel4/src/arch/arm/arch/aarch64/object.rs +++ b/crates/sel4/src/arch/arm/arch/aarch64/object.rs @@ -12,16 +12,14 @@ pub type ObjectBlueprintSeL4Arch = ObjectBlueprintAArch64; #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum ObjectTypeAArch64 { HugePage, - PUD, - PGD, + VSpace, } impl ObjectTypeAArch64 { pub(crate) const fn into_sys(self) -> c_uint { match self { Self::HugePage => sys::_mode_object::seL4_ARM_HugePageObject, - Self::PUD => sys::_mode_object::seL4_ARM_PageUpperDirectoryObject, - Self::PGD => sys::_mode_object::seL4_ARM_PageGlobalDirectoryObject, + Self::VSpace => sys::_mode_object::seL4_ARM_VSpaceObject, } } } @@ -30,24 +28,21 @@ impl ObjectTypeAArch64 { #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum ObjectBlueprintAArch64 { HugePage, - PUD, - PGD, + VSpace, } impl ObjectBlueprintAArch64 { pub(crate) const fn ty(self) -> ObjectTypeAArch64 { match self { Self::HugePage => ObjectTypeAArch64::HugePage, - Self::PUD => ObjectTypeAArch64::PUD, - Self::PGD => ObjectTypeAArch64::PGD, + Self::VSpace => ObjectTypeAArch64::VSpace, } } pub(crate) const fn physical_size_bits(self) -> usize { match self { Self::HugePage => u32_into_usize(sys::seL4_HugePageBits), - Self::PUD => u32_into_usize(sys::seL4_PUDBits), - Self::PGD => u32_into_usize(sys::seL4_PGDBits), + Self::VSpace => u32_into_usize(sys::seL4_VSpaceBits), } } } diff --git a/crates/sel4/src/arch/arm/arch/aarch64/vspace.rs b/crates/sel4/src/arch/arm/arch/aarch64/vspace.rs index fcec52735..cae9d5c03 100644 --- a/crates/sel4/src/arch/arm/arch/aarch64/vspace.rs +++ b/crates/sel4/src/arch/arm/arch/aarch64/vspace.rs @@ -41,14 +41,10 @@ impl FrameType for cap_type::HugePage { // -impl cap_type::PUD { - pub const SPAN_BITS: usize = cap_type::PD::SPAN_BITS + (sys::seL4_PUDIndexBits as usize); -} - -impl cap_type::PD { - pub const SPAN_BITS: usize = cap_type::PT::SPAN_BITS + (sys::seL4_PageDirIndexBits as usize); +impl cap_type::VSpace { + pub const INDEX_BITS: usize = sys::seL4_VSpaceIndexBits as usize; } impl cap_type::PT { - pub const SPAN_BITS: usize = FrameSize::Small.bits() + (sys::seL4_PageTableIndexBits as usize); + pub const INDEX_BITS: usize = sys::seL4_PageTableIndexBits as usize; } diff --git a/crates/sel4/src/arch/arm/mod.rs b/crates/sel4/src/arch/arm/mod.rs index 3452de985..c0ffa6d34 100644 --- a/crates/sel4/src/arch/arm/mod.rs +++ b/crates/sel4/src/arch/arm/mod.rs @@ -44,17 +44,7 @@ pub(crate) mod cap_type_arch { declare_cap_type! { /// Corresponds to `seL4_ARM_VSpace`. - PGD - } - - declare_cap_type! { - /// Corresponds to `seL4_ARM_PageUpperDirectory`. - PUD - } - - declare_cap_type! { - /// Corresponds to `seL4_ARM_PageDirectory`. - PD + VSpace } declare_cap_type! { @@ -62,9 +52,6 @@ pub(crate) mod cap_type_arch { PT } - /// Alias for [`cap_type::PGD`](PGD). - pub type VSpace = PGD; - /// Alias for [`cap_type::SmallPage`](SmallPage). pub type Granule = SmallPage; } @@ -78,8 +65,5 @@ pub(crate) mod local_cptr_arch { declare_local_cptr_alias!(SmallPage); declare_local_cptr_alias!(LargePage); declare_local_cptr_alias!(HugePage); - declare_local_cptr_alias!(PGD); - declare_local_cptr_alias!(PUD); - declare_local_cptr_alias!(PD); declare_local_cptr_alias!(PT); } diff --git a/crates/sel4/src/arch/arm/object.rs b/crates/sel4/src/arch/arm/object.rs index 4746897e1..7819475a5 100644 --- a/crates/sel4/src/arch/arm/object.rs +++ b/crates/sel4/src/arch/arm/object.rs @@ -20,7 +20,6 @@ pub enum ObjectTypeArm { SmallPage, LargePage, PT, - PD, #[sel4_cfg(ARM_HYPERVISOR_SUPPORT)] VCPU, SeL4Arch(ObjectTypeSeL4Arch), @@ -33,7 +32,6 @@ impl ObjectTypeArm { Self::SmallPage => sys::_object::seL4_ARM_SmallPageObject, Self::LargePage => sys::_object::seL4_ARM_LargePageObject, Self::PT => sys::_object::seL4_ARM_PageTableObject, - Self::PD => sys::_object::seL4_ARM_PageDirectoryObject, #[sel4_cfg(ARM_HYPERVISOR_SUPPORT)] Self::VCPU => sys::_object::seL4_ARM_VCPUObject, Self::SeL4Arch(sel4_arch) => sel4_arch.into_sys(), @@ -60,7 +58,6 @@ pub enum ObjectBlueprintArm { SmallPage, LargePage, PT, - PD, #[sel4_cfg(ARM_HYPERVISOR_SUPPORT)] VCPU, SeL4Arch(ObjectBlueprintSeL4Arch), @@ -73,7 +70,6 @@ impl ObjectBlueprintArm { Self::SmallPage => ObjectTypeArm::SmallPage, Self::LargePage => ObjectTypeArm::LargePage, Self::PT => ObjectTypeArm::PT, - Self::PD => ObjectTypeArm::PD, #[sel4_cfg(ARM_HYPERVISOR_SUPPORT)] Self::VCPU => ObjectTypeArm::VCPU, Self::SeL4Arch(sel4_arch) => ObjectTypeArch::SeL4Arch(sel4_arch.ty()), @@ -86,7 +82,6 @@ impl ObjectBlueprintArm { Self::SmallPage => u32_into_usize(sys::seL4_PageBits), Self::LargePage => u32_into_usize(sys::seL4_LargePageBits), Self::PT => u32_into_usize(sys::seL4_PageTableBits), - Self::PD => u32_into_usize(sys::seL4_PageDirBits), #[sel4_cfg(ARM_HYPERVISOR_SUPPORT)] Self::VCPU => u32_into_usize(sys::seL4_VCPUBits), Self::SeL4Arch(sel4_arch) => sel4_arch.physical_size_bits(), diff --git a/crates/sel4/src/arch/x86/arch/x64/vspace.rs b/crates/sel4/src/arch/x86/arch/x64/vspace.rs index 94229138e..cf2a08786 100644 --- a/crates/sel4/src/arch/x86/arch/x64/vspace.rs +++ b/crates/sel4/src/arch/x86/arch/x64/vspace.rs @@ -39,15 +39,13 @@ impl FrameType for cap_type::HugePage { // impl cap_type::PDPT { - pub const SPAN_BITS: usize = - cap_type::PageDirectory::SPAN_BITS + (sys::seL4_PDPTIndexBits as usize); + pub const INDEX_BITS: usize = sys::seL4_PDPTIndexBits; } impl cap_type::PageDirectory { - pub const SPAN_BITS: usize = - cap_type::PageTable::SPAN_BITS + (sys::seL4_PageDirIndexBits as usize); + pub const INDEX_BITS: usize = sys::seL4_PageDirIndexBits as usize; } impl cap_type::PageTable { - pub const SPAN_BITS: usize = FrameSize::_4K.bits() + (sys::seL4_PageTableIndexBits as usize); + pub const INDEX_BITS: usize = sys::seL4_PageTableIndexBits as usize; } diff --git a/hacking/nix/scope/sources.nix b/hacking/nix/scope/sources.nix index e08073d4f..0d566030b 100644 --- a/hacking/nix/scope/sources.nix +++ b/hacking/nix/scope/sources.nix @@ -42,7 +42,7 @@ in rec { url = "https://github.com/coliasgroup/seL4.git"; rev = "656f11fd66139e1102c8bae0b07639a2ada9af78"; # branch "rust" local = localRoot + "/seL4"; - # useLocal = true; + useLocal = true; }; rust-microkit = fetchGit { From 1a9ffe924c0ec7af7047054b552d4ecae4d44e40 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Fri, 22 Sep 2023 23:30:31 +0000 Subject: [PATCH 5/7] crates/sel4: Add support for aarch32 Signed-off-by: Nick Spinale --- .../sel4/src/arch/arm/arch/aarch32/fault.rs | 21 +++++ crates/sel4/src/arch/arm/arch/aarch32/mod.rs | 18 +++++ .../sel4/src/arch/arm/arch/aarch32/object.rs | 43 ++++++++++ .../src/arch/arm/arch/aarch32/user_context.rs | 73 +++++++++++++++++ .../src/arch/arm/arch/aarch32/vcpu_reg.rs | 17 ++++ .../sel4/src/arch/arm/arch/aarch64/fault.rs | 78 +------------------ crates/sel4/src/arch/arm/arch/aarch64/mod.rs | 3 - crates/sel4/src/arch/arm/arch/mod.rs | 4 + crates/sel4/src/arch/arm/fault.rs | 70 ++++++++++++++++- .../arm/{arch/aarch64 => }/invocations.rs | 0 crates/sel4/src/arch/arm/mod.rs | 21 +++++ .../src/arch/arm/{arch/aarch64 => }/vspace.rs | 22 +++++- 12 files changed, 287 insertions(+), 83 deletions(-) create mode 100644 crates/sel4/src/arch/arm/arch/aarch32/fault.rs create mode 100644 crates/sel4/src/arch/arm/arch/aarch32/mod.rs create mode 100644 crates/sel4/src/arch/arm/arch/aarch32/object.rs create mode 100644 crates/sel4/src/arch/arm/arch/aarch32/user_context.rs create mode 100644 crates/sel4/src/arch/arm/arch/aarch32/vcpu_reg.rs rename crates/sel4/src/arch/arm/{arch/aarch64 => }/invocations.rs (100%) rename crates/sel4/src/arch/arm/{arch/aarch64 => }/vspace.rs (70%) diff --git a/crates/sel4/src/arch/arm/arch/aarch32/fault.rs b/crates/sel4/src/arch/arm/arch/aarch32/fault.rs new file mode 100644 index 000000000..680156561 --- /dev/null +++ b/crates/sel4/src/arch/arm/arch/aarch32/fault.rs @@ -0,0 +1,21 @@ +use crate::{fault::UnknownSyscall, Word}; + +impl UnknownSyscall { + pub fn cpsr(&self) -> Word { + self.inner().get_CPSR() + } + + pub fn gpr(&self, ix: usize) -> Word { + match ix { + 0 => self.inner().get_R0(), + 1 => self.inner().get_R1(), + 2 => self.inner().get_R2(), + 3 => self.inner().get_R3(), + 4 => self.inner().get_R4(), + 5 => self.inner().get_R5(), + 6 => self.inner().get_R6(), + 7 => self.inner().get_R7(), + _ => panic!(), + } + } +} diff --git a/crates/sel4/src/arch/arm/arch/aarch32/mod.rs b/crates/sel4/src/arch/arm/arch/aarch32/mod.rs new file mode 100644 index 000000000..02d366eac --- /dev/null +++ b/crates/sel4/src/arch/arm/arch/aarch32/mod.rs @@ -0,0 +1,18 @@ +mod fault; +mod object; +mod user_context; + +#[sel4_config::sel4_cfg(ARM_HYPERVISOR_SUPPORT)] +mod vcpu_reg; + +pub(crate) mod top_level { + pub use super::{ + object::{ + ObjectBlueprintAArch64, ObjectBlueprintSeL4Arch, ObjectTypeAArch64, ObjectTypeSeL4Arch, + }, + user_context::UserContext, + }; + + #[sel4_config::sel4_cfg(ARM_HYPERVISOR_SUPPORT)] + pub use super::vcpu_reg::VCPUReg; +} diff --git a/crates/sel4/src/arch/arm/arch/aarch32/object.rs b/crates/sel4/src/arch/arm/arch/aarch32/object.rs new file mode 100644 index 000000000..c9e647acc --- /dev/null +++ b/crates/sel4/src/arch/arm/arch/aarch32/object.rs @@ -0,0 +1,43 @@ +use core::ffi::c_uint; + +use crate::{const_helpers::u32_into_usize, sys}; + +/// Alias for [`ObjectTypeAArch64`]. +pub type ObjectTypeSeL4Arch = ObjectTypeAArch64; + +/// Alias for [`ObjectBlueprintAArch64`]. +pub type ObjectBlueprintSeL4Arch = ObjectBlueprintAArch64; + +/// Corresponds to `seL4_ModeObjectType`. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum ObjectTypeAArch64 { + PD, +} + +impl ObjectTypeAArch64 { + pub(crate) const fn into_sys(self) -> c_uint { + match self { + Self::PD => sys::_mode_object::seL4_ARM_PageDirectoryObject, + } + } +} + +/// AArch64-specific variants of [`ObjectBlueprint`](crate::ObjectBlueprint). +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +pub enum ObjectBlueprintAArch64 { + PD, +} + +impl ObjectBlueprintAArch64 { + pub(crate) const fn ty(self) -> ObjectTypeAArch64 { + match self { + Self::PD => ObjectTypeAArch64::PD, + } + } + + pub(crate) const fn physical_size_bits(self) -> usize { + match self { + Self::PD => u32_into_usize(sys::seL4_PageDirBits), + } + } +} diff --git a/crates/sel4/src/arch/arm/arch/aarch32/user_context.rs b/crates/sel4/src/arch/arm/arch/aarch32/user_context.rs new file mode 100644 index 000000000..f23e48277 --- /dev/null +++ b/crates/sel4/src/arch/arm/arch/aarch32/user_context.rs @@ -0,0 +1,73 @@ +use crate::{newtype_methods, sys, Word}; + +/// Corresponds to `seL4_UserContext`. +#[derive(Debug, Clone, PartialEq, Eq, Default)] +pub struct UserContext(sys::seL4_UserContext); + +impl UserContext { + newtype_methods!(sys::seL4_UserContext); + + pub fn pc(&self) -> &Word { + &self.0.pc + } + + pub fn pc_mut(&mut self) -> &mut Word { + &mut self.0.pc + } + + pub fn sp(&self) -> &Word { + &self.0.sp + } + + pub fn sp_mut(&mut self) -> &mut Word { + &mut self.0.sp + } + + pub fn cpsr(&self) -> &Word { + &self.0.cpsr + } + + pub fn cpsr_mut(&mut self) -> &mut Word { + &mut self.0.cpsr + } + + pub fn gpr(&self, ix: Word) -> &Word { + match ix { + 0 => &self.inner().r0, + 1 => &self.inner().r1, + 2 => &self.inner().r2, + 3 => &self.inner().r3, + 4 => &self.inner().r4, + 5 => &self.inner().r5, + 6 => &self.inner().r6, + 7 => &self.inner().r7, + 8 => &self.inner().r8, + 9 => &self.inner().r9, + 10 => &self.inner().r10, + 11 => &self.inner().r11, + 12 => &self.inner().r12, + 14 => &self.inner().r14, + _ => panic!(), + } + } + + pub fn gpr_mut(&mut self, ix: Word) -> &mut Word { + match ix { + 0 => &mut self.inner_mut().r0, + 1 => &mut self.inner_mut().r1, + 2 => &mut self.inner_mut().r2, + 3 => &mut self.inner_mut().r3, + 4 => &mut self.inner_mut().r4, + 5 => &mut self.inner_mut().r5, + 6 => &mut self.inner_mut().r6, + 7 => &mut self.inner_mut().r7, + 8 => &mut self.inner_mut().r8, + 9 => &mut self.inner_mut().r9, + 10 => &mut self.inner_mut().r10, + 11 => &mut self.inner_mut().r11, + 12 => &mut self.inner_mut().r12, + 14 => &mut self.inner_mut().r14, + _ => panic!(), + } + } +} diff --git a/crates/sel4/src/arch/arm/arch/aarch32/vcpu_reg.rs b/crates/sel4/src/arch/arm/arch/aarch32/vcpu_reg.rs new file mode 100644 index 000000000..716a748f3 --- /dev/null +++ b/crates/sel4/src/arch/arm/arch/aarch32/vcpu_reg.rs @@ -0,0 +1,17 @@ +use sel4_config::sel4_cfg_enum; + +use crate::sys; + +/// Corresponds to `seL4_VCPUReg`. +#[repr(u32)] +#[allow(non_camel_case_types)] +#[sel4_cfg_enum] +pub enum VCPUReg { + // TODO +} + +impl VCPUReg { + pub const fn into_sys(self) -> sys::seL4_VCPUReg::Type { + self as sys::seL4_VCPUReg::Type + } +} diff --git a/crates/sel4/src/arch/arm/arch/aarch64/fault.rs b/crates/sel4/src/arch/arm/arch/aarch64/fault.rs index ee15e68ae..23a87dca7 100644 --- a/crates/sel4/src/arch/arm/arch/aarch64/fault.rs +++ b/crates/sel4/src/arch/arm/arch/aarch64/fault.rs @@ -1,39 +1,11 @@ -use sel4_config::sel4_cfg; - -use crate::{ - fault::{CapFault, UnknownSyscall, UserException, VMFault}, - Word, -}; - -#[sel4_cfg(ARM_HYPERVISOR_SUPPORT)] -use crate::fault::{VCPUFault, VGICMaintenance, VPPIEvent}; - -impl CapFault { - // TODO -} +use crate::{fault::UnknownSyscall, Word}; impl UnknownSyscall { - pub fn fault_ip(&self) -> Word { - self.inner().get_FaultIP() - } - - pub fn sp(&self) -> Word { - self.inner().get_SP() - } - - pub fn lr(&self) -> Word { - self.inner().get_LR() - } - pub fn spsr(&self) -> Word { self.inner().get_SPSR() } - pub fn syscall(&self) -> Word { - self.inner().get_Syscall() - } - - pub fn gpr(&self, ix: usize) -> u64 { + pub fn gpr(&self, ix: usize) -> Word { match ix { 0 => self.inner().get_X0(), 1 => self.inner().get_X1(), @@ -47,49 +19,3 @@ impl UnknownSyscall { } } } - -impl UserException { - // TODO -} - -impl VMFault { - pub fn ip(&self) -> Word { - self.inner().get_IP() - } - - pub fn addr(&self) -> Word { - self.inner().get_Addr() - } - - pub fn is_prefetch(&self) -> bool { - self.inner().get_PrefetchFault() != 0 - } - - pub fn fsr(&self) -> Word { - self.inner().get_FSR() - } -} - -#[sel4_cfg(ARM_HYPERVISOR_SUPPORT)] -impl VGICMaintenance { - pub fn idx(&self) -> Option { - match self.inner().get_IDX() { - Word::MAX => None, - idx => Some(idx), - } - } -} - -#[sel4_cfg(ARM_HYPERVISOR_SUPPORT)] -impl VCPUFault { - pub fn hsr(&self) -> Word { - self.inner().get_HSR() - } -} - -#[sel4_cfg(ARM_HYPERVISOR_SUPPORT)] -impl VPPIEvent { - pub fn irq(&self) -> Word { - self.inner().get_irq() - } -} diff --git a/crates/sel4/src/arch/arm/arch/aarch64/mod.rs b/crates/sel4/src/arch/arm/arch/aarch64/mod.rs index 8effed682..02d366eac 100644 --- a/crates/sel4/src/arch/arm/arch/aarch64/mod.rs +++ b/crates/sel4/src/arch/arm/arch/aarch64/mod.rs @@ -1,8 +1,6 @@ mod fault; -mod invocations; mod object; mod user_context; -mod vspace; #[sel4_config::sel4_cfg(ARM_HYPERVISOR_SUPPORT)] mod vcpu_reg; @@ -13,7 +11,6 @@ pub(crate) mod top_level { ObjectBlueprintAArch64, ObjectBlueprintSeL4Arch, ObjectTypeAArch64, ObjectTypeSeL4Arch, }, user_context::UserContext, - vspace::FrameSize, }; #[sel4_config::sel4_cfg(ARM_HYPERVISOR_SUPPORT)] diff --git a/crates/sel4/src/arch/arm/arch/mod.rs b/crates/sel4/src/arch/arm/arch/mod.rs index 157aad529..258fe7064 100644 --- a/crates/sel4/src/arch/arm/arch/mod.rs +++ b/crates/sel4/src/arch/arm/arch/mod.rs @@ -4,4 +4,8 @@ use sel4_config::sel4_cfg; #[path = "aarch64/mod.rs"] mod imp; +#[sel4_cfg(ARCH_AARCH32)] +#[path = "aarch32/mod.rs"] +mod imp; + pub(crate) use imp::*; diff --git a/crates/sel4/src/arch/arm/fault.rs b/crates/sel4/src/arch/arm/fault.rs index 547da3283..8ba23fca9 100644 --- a/crates/sel4/src/arch/arm/fault.rs +++ b/crates/sel4/src/arch/arm/fault.rs @@ -1,6 +1,6 @@ use sel4_config::{sel4_cfg, sel4_cfg_enum, sel4_cfg_if, sel4_cfg_match}; -use crate::{declare_fault_newtype, sys}; +use crate::{declare_fault_newtype, sys, Word}; declare_fault_newtype!(NullFault, sys::seL4_Fault_NullFault); declare_fault_newtype!(CapFault, sys::seL4_Fault_CapFault); @@ -69,3 +69,71 @@ impl Fault { } } } + +impl CapFault { + // TODO +} + +impl UnknownSyscall { + pub fn fault_ip(&self) -> Word { + self.inner().get_FaultIP() + } + + pub fn sp(&self) -> Word { + self.inner().get_SP() + } + + pub fn lr(&self) -> Word { + self.inner().get_LR() + } + + pub fn syscall(&self) -> Word { + self.inner().get_Syscall() + } +} + +impl UserException { + // TODO +} + +impl VMFault { + pub fn ip(&self) -> Word { + self.inner().get_IP() + } + + pub fn addr(&self) -> Word { + self.inner().get_Addr() + } + + pub fn is_prefetch(&self) -> bool { + self.inner().get_PrefetchFault() != 0 + } + + pub fn fsr(&self) -> Word { + self.inner().get_FSR() + } +} + +#[sel4_cfg(ARM_HYPERVISOR_SUPPORT)] +impl VGICMaintenance { + pub fn idx(&self) -> Option { + match self.inner().get_IDX() { + Word::MAX => None, + idx => Some(idx), + } + } +} + +#[sel4_cfg(ARM_HYPERVISOR_SUPPORT)] +impl VCPUFault { + pub fn hsr(&self) -> Word { + self.inner().get_HSR() + } +} + +#[sel4_cfg(ARM_HYPERVISOR_SUPPORT)] +impl VPPIEvent { + pub fn irq(&self) -> Word { + self.inner().get_irq() + } +} diff --git a/crates/sel4/src/arch/arm/arch/aarch64/invocations.rs b/crates/sel4/src/arch/arm/invocations.rs similarity index 100% rename from crates/sel4/src/arch/arm/arch/aarch64/invocations.rs rename to crates/sel4/src/arch/arm/invocations.rs diff --git a/crates/sel4/src/arch/arm/mod.rs b/crates/sel4/src/arch/arm/mod.rs index c0ffa6d34..5fe058d15 100644 --- a/crates/sel4/src/arch/arm/mod.rs +++ b/crates/sel4/src/arch/arm/mod.rs @@ -1,8 +1,10 @@ use crate::sys; mod arch; +mod invocations; mod object; mod vm_attributes; +mod vspace; pub(crate) mod fault; @@ -11,6 +13,7 @@ pub(crate) mod top_level { arch::top_level::*, object::{ObjectBlueprintArch, ObjectBlueprintArm, ObjectTypeArch, ObjectTypeArm}, vm_attributes::VMAttributes, + vspace::FrameSize, NUM_FAST_MESSAGE_REGISTERS, }; } @@ -37,16 +40,24 @@ pub(crate) mod cap_type_arch { LargePage } + #[sel4_cfg(ARCH_AARCH64)] declare_cap_type! { /// Corresponds to `seL4_ARM_Page` with `size_bits = 30`. HugePage } + #[sel4_cfg(ARCH_AARCH64)] declare_cap_type! { /// Corresponds to `seL4_ARM_VSpace`. VSpace } + #[sel4_cfg(ARCH_AARCH32)] + declare_cap_type! { + /// Corresponds to `seL4_ARM_PD`. + PD + } + declare_cap_type! { /// Corresponds to `seL4_ARM_PageTable`. PT @@ -54,6 +65,10 @@ pub(crate) mod cap_type_arch { /// Alias for [`cap_type::SmallPage`](SmallPage). pub type Granule = SmallPage; + + #[sel4_cfg(ARCH_AARCH32)] + /// Alias for [`cap_type::PD`](PD). + pub type VSpace = PD; } pub(crate) mod local_cptr_arch { @@ -64,6 +79,12 @@ pub(crate) mod local_cptr_arch { declare_local_cptr_alias!(SmallPage); declare_local_cptr_alias!(LargePage); + + #[sel4_cfg(ARCH_AARCH64)] declare_local_cptr_alias!(HugePage); + + #[sel4_cfg(ARCH_AARCH32)] + declare_local_cptr_alias!(PD); + declare_local_cptr_alias!(PT); } diff --git a/crates/sel4/src/arch/arm/arch/aarch64/vspace.rs b/crates/sel4/src/arch/arm/vspace.rs similarity index 70% rename from crates/sel4/src/arch/arm/arch/aarch64/vspace.rs rename to crates/sel4/src/arch/arm/vspace.rs index cae9d5c03..1210cb6c1 100644 --- a/crates/sel4/src/arch/arm/arch/aarch64/vspace.rs +++ b/crates/sel4/src/arch/arm/vspace.rs @@ -1,20 +1,27 @@ -use crate::{ - cap_type, sys, FrameType, ObjectBlueprint, ObjectBlueprintAArch64, ObjectBlueprintArm, -}; +use sel4_config::{sel4_cfg, sel4_cfg_enum, sel4_cfg_match}; + +use crate::{cap_type, sys, FrameType, ObjectBlueprint, ObjectBlueprintArm}; + +#[sel4_cfg(ARCH_AARCH64)] +use crate::ObjectBlueprintAArch64; /// Frame sizes for AArch64. +#[sel4_cfg_enum] #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum FrameSize { Small, Large, + #[sel4_cfg(ARCH_AARCH64)] Huge, } impl FrameSize { pub const fn blueprint(self) -> ObjectBlueprint { + #[sel4_cfg_match] match self { Self::Small => ObjectBlueprint::Arch(ObjectBlueprintArm::SmallPage), Self::Large => ObjectBlueprint::Arch(ObjectBlueprintArm::LargePage), + #[sel4_cfg(ARCH_AARCH64)] Self::Huge => ObjectBlueprint::Arch(ObjectBlueprintArm::SeL4Arch( ObjectBlueprintAArch64::HugePage, )), @@ -24,6 +31,8 @@ impl FrameSize { // For match arm LHS's, as we can't call const fn's pub const SMALL_BITS: usize = Self::Small.bits(); pub const LARGE_BITS: usize = Self::Large.bits(); + + #[sel4_cfg(ARCH_AARCH64)] pub const HUGE_BITS: usize = Self::Huge.bits(); } @@ -35,16 +44,23 @@ impl FrameType for cap_type::LargePage { const FRAME_SIZE: FrameSize = FrameSize::Large; } +#[sel4_cfg(ARCH_AARCH64)] impl FrameType for cap_type::HugePage { const FRAME_SIZE: FrameSize = FrameSize::Huge; } // +#[sel4_cfg(ARCH_AARCH64)] impl cap_type::VSpace { pub const INDEX_BITS: usize = sys::seL4_VSpaceIndexBits as usize; } +#[sel4_cfg(ARCH_AARCH32)] +impl cap_type::PD { + pub const INDEX_BITS: usize = sys::seL4_PageDirIndexBits as usize; +} + impl cap_type::PT { pub const INDEX_BITS: usize = sys::seL4_PageTableIndexBits as usize; } From c535b930470078360ab4e3f9c14c3a3434fa29c5 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Fri, 22 Sep 2023 23:30:50 +0000 Subject: [PATCH 6/7] crates/sel4-capdl-initializer: Update for kernel aarch64 translation structure object simplification Signed-off-by: Nick Spinale --- .../core/src/arch/mod.rs | 65 ++++- crates/sel4-capdl-initializer/core/src/lib.rs | 222 ++++-------------- .../sel4-capdl-initializer/core/src/memory.rs | 2 +- .../types/src/when_sel4.rs | 15 +- .../with-embedded-spec/src/main.rs | 5 +- crates/sel4/src/arch/arm/vspace.rs | 15 +- crates/sel4/src/arch/riscv/vspace.rs | 15 +- crates/sel4/src/arch/x86/arch/x64/vspace.rs | 19 +- crates/sel4/src/cptr.rs | 5 + crates/sel4/src/lib.rs | 2 +- crates/sel4/src/vspace.rs | 6 +- hacking/nix/scope/sel4test/default.nix | 4 +- hacking/nix/scope/sources.nix | 15 +- 13 files changed, 175 insertions(+), 215 deletions(-) diff --git a/crates/sel4-capdl-initializer/core/src/arch/mod.rs b/crates/sel4-capdl-initializer/core/src/arch/mod.rs index c0c36f823..5f6d333ed 100644 --- a/crates/sel4-capdl-initializer/core/src/arch/mod.rs +++ b/crates/sel4-capdl-initializer/core/src/arch/mod.rs @@ -5,6 +5,25 @@ mod imp { pub(crate) type FrameType1 = sel4::cap_type::LargePage; pub(crate) type FrameType2 = sel4::cap_type::HugePage; + pub(crate) type PageTableType = sel4::cap_type::PT; + + pub(crate) const VSPACE_LEVELS: usize = if sel4::sel4_cfg_bool!(ARCH_AARCH64) { + 4 + } else { + 2 + }; + + pub(crate) fn map_page_table( + vspace: sel4::VSpace, + _level: usize, + vaddr: usize, + cap: sel4::Unspecified, + vm_attributes: sel4::VMAttributes, + ) -> sel4::Result<()> { + cap.downcast::() + .pt_map(vspace, vaddr, vm_attributes) + } + pub(crate) fn init_user_context( regs: &mut sel4::UserContext, extra: &sel4_capdl_initializer_types::object::TCBExtraInfo, @@ -23,6 +42,35 @@ mod imp { pub(crate) type FrameType1 = sel4::cap_type::LargePage; pub(crate) type FrameType2 = sel4::cap_type::HugePage; + pub(crate) const VSPACE_LEVELS: usize = if sel4::sel4_cfg_bool!(ARCH_X86_64) { + 4 + } else { + 2 + }; + + pub(crate) fn map_page_table( + vspace: sel4::VSpace, + level: usize, + vaddr: usize, + cap: sel4::Unspecified, + vm_attributes: sel4::VMAttributes, + ) -> sel4::Result<()> { + match level { + 1 => cap + .downcast::() + .pdpt_map(vspace, vaddr, vm_attributes), + 2 => cap + .downcast::() + .page_directory_map(vspace, vaddr, vm_attributes), + 3 => cap.downcast::().page_table_map( + vspace, + vaddr, + vm_attributes, + ), + _ => panic!(), + } + } + pub(crate) fn init_user_context( regs: &mut sel4::UserContext, extra: &sel4_capdl_initializer_types::object::TCBExtraInfo, @@ -40,6 +88,21 @@ mod imp { pub(crate) type FrameType1 = sel4::cap_type::MegaPage; pub(crate) type FrameType2 = sel4::cap_type::GigaPage; + pub(crate) type PageTableType = sel4::cap_type::PageTable; + + pub(crate) const VSPACE_LEVELS: usize = sel4::sel4_cfg_usize!(PT_LEVELS); + + pub(crate) fn map_page_table( + vspace: sel4::VSpace, + _level: usize, + vaddr: usize, + cap: sel4::Unspecified, + vm_attributes: sel4::VMAttributes, + ) -> sel4::Result<()> { + cap.downcast::() + .page_table_map(vspace, vaddr, vm_attributes) + } + pub(crate) fn init_user_context( regs: &mut sel4::UserContext, extra: &sel4_capdl_initializer_types::object::TCBExtraInfo, @@ -55,7 +118,7 @@ mod imp { pub(crate) use imp::*; pub(crate) mod frame_types { - use sel4::FrameType; + use sel4::SizedFrameType; pub(crate) use super::{FrameType1, FrameType2}; diff --git a/crates/sel4-capdl-initializer/core/src/lib.rs b/crates/sel4-capdl-initializer/core/src/lib.rs index 382bebf9b..69abdea5c 100644 --- a/crates/sel4-capdl-initializer/core/src/lib.rs +++ b/crates/sel4-capdl-initializer/core/src/lib.rs @@ -21,11 +21,14 @@ use core::sync::atomic::{self, Ordering}; use log::{debug, info, trace}; use sel4::{ - cap_type, AbsoluteCPtr, BootInfo, CNodeCapData, CPtr, CapRights, CapType, FrameSize, FrameType, - InitCSpaceSlot, LocalCPtr, ObjectBlueprint, Untyped, UserContext, + cap_type, AbsoluteCPtr, BootInfo, CNodeCapData, CPtr, CapRights, CapType, InitCSpaceSlot, + LocalCPtr, ObjectBlueprint, SizedFrameType, Untyped, UserContext, }; use sel4_capdl_initializer_types::*; +#[allow(unused_imports)] +use sel4::{FrameSize, FrameType, VSpace}; + mod arch; mod buffers; mod cslot_allocator; @@ -40,6 +43,9 @@ pub use error::CapDLInitializerError; use hold_slots::HoldSlots; use memory::{get_user_image_frame_slot, init_copy_addrs}; +#[sel4::sel4_cfg(all(ARCH_RISCV64, not(PT_LEVELS = "3")))] +compile_error!("unsupported configuration"); + type Result = result::Result; pub struct Initializer<'a, N: ObjectName, D: Content, M: GetEmbeddedFrame, B> { @@ -441,7 +447,11 @@ impl<'a, N: ObjectName, D: Content, M: GetEmbeddedFrame, B: BorrowMut<[PerObject Ok(()) } - fn fill_frame(&self, frame: LocalCPtr, fill: &[FillEntry]) -> Result<()> { + fn fill_frame( + &self, + frame: LocalCPtr, + fill: &[FillEntry], + ) -> Result<()> { frame.frame_map( BootInfo::init_thread_vspace(), self.copy_addr::(), @@ -486,193 +496,45 @@ impl<'a, N: ObjectName, D: Content, M: GetEmbeddedFrame, B: BorrowMut<[PerObject fn init_vspaces(&mut self) -> Result<()> { debug!("Initializing VSpaces"); - self.init_vspaces_arch() - } - - #[sel4::sel4_cfg(ARCH_AARCH64)] - fn init_vspaces_arch(&mut self) -> Result<()> { - // TODO - // Add support for uncached non-device mappings. - // See note about seL4_ARM_Page_CleanInvalidate_Data/seL4_ARM_Page_Unify_Instruction in upstream. - for (obj_id, obj) in self .spec() .filter_objects_with::<&object::PageTable>(|obj| obj.is_root) { let vspace = self.orig_local_cptr::(obj_id); - for (i, cap) in obj.page_tables() { - let pud = self.orig_local_cptr::(cap.object); - let vaddr = i << cap_type::PUD::SPAN_BITS; - pud.pud_map(vspace, vaddr, cap.vm_attributes())?; - for (i, cap) in self - .spec() - .lookup_object::<&object::PageTable>(cap.object)? - .page_tables() - { - let pd = self.orig_local_cptr::(cap.object); - let vaddr = vaddr + (i << cap_type::PD::SPAN_BITS); - pd.pd_map(vspace, vaddr, cap.vm_attributes())?; - for (i, cap) in self - .spec() - .lookup_object::<&object::PageTable>(cap.object)? - .entries() - { - let vaddr = vaddr + (i << cap_type::PT::SPAN_BITS); - match cap { - PageTableEntry::Frame(cap) => { - let frame = self.orig_local_cptr::(cap.object); - let rights = (&cap.rights).into(); - self.copy(frame)?.frame_map( - vspace, - vaddr, - rights, - cap.vm_attributes(), - )?; - } - PageTableEntry::PageTable(cap) => { - let pt = self.orig_local_cptr::(cap.object); - pt.pt_map(vspace, vaddr, cap.vm_attributes())?; - for (i, cap) in self - .spec() - .lookup_object::<&object::PageTable>(cap.object)? - .frames() - { - let frame = - self.orig_local_cptr::(cap.object); - let vaddr = vaddr + (i << FrameSize::Small.bits()); - let rights = (&cap.rights).into(); - self.copy(frame)?.frame_map( - vspace, - vaddr, - rights, - cap.vm_attributes(), - )?; - } - } - } - } - } - } + self.init_vspace(vspace, 0, 0, obj)?; } Ok(()) } - #[sel4::sel4_cfg(ARCH_RISCV64)] - fn init_vspaces_arch(&mut self) -> Result<()> { - #[sel4::sel4_cfg(not(PT_LEVELS = "3"))] - compile_error!("unsupported configuration"); - - for (obj_id, obj) in self - .spec() - .filter_objects_with::<&object::PageTable>(|obj| obj.is_root) - { - let vspace = self.orig_local_cptr::(obj_id); - for (i, cap) in obj.page_tables() { - let pud = self.orig_local_cptr::(cap.object); - let vaddr = i << 30; - pud.page_table_map(vspace, vaddr, cap.vm_attributes())?; - for (i, cap) in self - .spec() - .lookup_object::<&object::PageTable>(cap.object)? - .entries() - { - let vaddr = vaddr + (i << 21); - match cap { - PageTableEntry::Frame(cap) => { - let frame = self.orig_local_cptr::(cap.object); - let rights = (&cap.rights).into(); - self.copy(frame)?.frame_map( - vspace, - vaddr, - rights, - cap.vm_attributes(), - )?; - } - PageTableEntry::PageTable(cap) => { - let pt = self.orig_local_cptr::(cap.object); - pt.page_table_map(vspace, vaddr, cap.vm_attributes())?; - for (i, cap) in self - .spec() - .lookup_object::<&object::PageTable>(cap.object)? - .frames() - { - let frame = self.orig_local_cptr::(cap.object); - let vaddr = vaddr + (i << FrameSize::_4K.bits()); - let rights = (&cap.rights).into(); - self.copy(frame)?.frame_map( - vspace, - vaddr, - rights, - cap.vm_attributes(), - )?; - } - } - } + fn init_vspace( + &mut self, + vspace: VSpace, + level: usize, + vaddr: usize, + obj: &object::PageTable, + ) -> Result<()> { + for (i, entry) in obj.entries() { + let vaddr = vaddr + (i << ((arch::VSPACE_LEVELS - level - 1) * 9 + 12)); + match entry { + PageTableEntry::Frame(cap) => { + let frame = self.orig_local_cptr::(cap.object); + let rights = (&cap.rights).into(); + self.copy(frame)? + .frame_map(vspace, vaddr, rights, cap.vm_attributes())?; } - } - } - Ok(()) - } - - #[sel4::sel4_cfg(ARCH_X86_64)] - fn init_vspaces_arch(&mut self) -> Result<()> { - for (obj_id, obj) in self - .spec() - .filter_objects_with::<&object::PageTable>(|obj| obj.is_root) - { - let vspace = self.orig_local_cptr::(obj_id); - for (i, cap) in obj.page_tables() { - let pdpt = self.orig_local_cptr::(cap.object); - let vaddr = i << cap_type::PDPT::SPAN_BITS; - pdpt.pdpt_map(vspace, vaddr, cap.vm_attributes())?; - for (i, cap) in self - .spec() - .lookup_object::<&object::PageTable>(cap.object)? - .page_tables() - { - let page_directory = - self.orig_local_cptr::(cap.object); - let vaddr = vaddr + (i << cap_type::PageDirectory::SPAN_BITS); - page_directory.page_directory_map(vspace, vaddr, cap.vm_attributes())?; - for (i, cap) in self + PageTableEntry::PageTable(cap) => { + let page_table = self.orig_local_cptr::(cap.object); + arch::map_page_table( + vspace, + level + 1, + vaddr, + page_table, + cap.vm_attributes(), + )?; + let obj = self .spec() - .lookup_object::<&object::PageTable>(cap.object)? - .entries() - { - let vaddr = vaddr + (i << cap_type::PageTable::SPAN_BITS); - match cap { - PageTableEntry::Frame(cap) => { - let frame = self.orig_local_cptr::(cap.object); - let rights = (&cap.rights).into(); - self.copy(frame)?.frame_map( - vspace, - vaddr, - rights, - cap.vm_attributes(), - )?; - } - PageTableEntry::PageTable(cap) => { - let page_table = - self.orig_local_cptr::(cap.object); - page_table.page_table_map(vspace, vaddr, cap.vm_attributes())?; - for (i, cap) in self - .spec() - .lookup_object::<&object::PageTable>(cap.object)? - .frames() - { - let frame = self.orig_local_cptr::(cap.object); - let vaddr = vaddr + (i << FrameSize::_4K.bits()); - let rights = (&cap.rights).into(); - self.copy(frame)?.frame_map( - vspace, - vaddr, - rights, - cap.vm_attributes(), - )?; - } - } - } - } + .lookup_object::<&object::PageTable>(cap.object)?; + self.init_vspace(vspace, level + 1, vaddr, obj)?; } } } @@ -868,7 +730,7 @@ impl<'a, N: ObjectName, D: Content, M: GetEmbeddedFrame, B: BorrowMut<[PerObject // - fn copy_addr(&self) -> usize { + fn copy_addr(&self) -> usize { match U::FRAME_SIZE { frame_types::FrameType0::FRAME_SIZE => self.small_frame_copy_addr, frame_types::FrameType1::FRAME_SIZE => self.large_frame_copy_addr, diff --git a/crates/sel4-capdl-initializer/core/src/memory.rs b/crates/sel4-capdl-initializer/core/src/memory.rs index b07af14d6..ea402b106 100644 --- a/crates/sel4-capdl-initializer/core/src/memory.rs +++ b/crates/sel4-capdl-initializer/core/src/memory.rs @@ -1,6 +1,6 @@ use core::ops::Range; -use sel4::FrameType; +use sel4::SizedFrameType; use super::frame_types; diff --git a/crates/sel4-capdl-initializer/types/src/when_sel4.rs b/crates/sel4-capdl-initializer/types/src/when_sel4.rs index a3f7b39ff..77e45882e 100644 --- a/crates/sel4-capdl-initializer/types/src/when_sel4.rs +++ b/crates/sel4-capdl-initializer/types/src/when_sel4.rs @@ -39,14 +39,11 @@ impl<'a, D, M> Object<'a, D, M> { }, #[sel4_cfg(ARCH_AARCH64)] Object::PageTable(obj) => { - let level = obj.level.unwrap(); - assert_eq!(obj.is_root, level == 0); // sanity check - match level { - 0 => sel4::ObjectBlueprintSeL4Arch::PGD.into(), - 1 => sel4::ObjectBlueprintSeL4Arch::PUD.into(), - 2 => sel4::ObjectBlueprintArch::PD.into(), - 3 => sel4::ObjectBlueprintArch::PT.into(), - _ => panic!(), + // assert!(obj.level.is_none()); // sanity check // TODO + if obj.is_root { + sel4::ObjectBlueprintSeL4Arch::VSpace.into() + } else { + sel4::ObjectBlueprintArch::PT.into() } } #[sel4_cfg(ARCH_RISCV64)] @@ -135,7 +132,7 @@ sel4::sel4_cfg_if! { if #[cfg(ARCH_AARCH64)] { const CACHED: VMAttributes = VMAttributes::PAGE_CACHEABLE; const UNCACHED: VMAttributes = VMAttributes::DEFAULT; - } else if #[cfg(ARCH_RISCV64)] { + } else if #[cfg(any(ARCH_RISCV64, ARCH_RISCV32))] { const CACHED: VMAttributes = VMAttributes::DEFAULT; const UNCACHED: VMAttributes = VMAttributes::NONE; } else if #[cfg(ARCH_X86_64)] { diff --git a/crates/sel4-capdl-initializer/with-embedded-spec/src/main.rs b/crates/sel4-capdl-initializer/with-embedded-spec/src/main.rs index 63597abed..38c125b0d 100644 --- a/crates/sel4-capdl-initializer/with-embedded-spec/src/main.rs +++ b/crates/sel4-capdl-initializer/with-embedded-spec/src/main.rs @@ -11,7 +11,10 @@ use sel4_capdl_initializer_types::SpecWithSources; use sel4_capdl_initializer_with_embedded_spec_embedded_spec::SPEC; use sel4_logging::{LevelFilter, Logger, LoggerBuilder}; -const LOG_LEVEL: LevelFilter = LevelFilter::Info; +const LOG_LEVEL: LevelFilter = + // LevelFilter::Trace + // LevelFilter::Debug + LevelFilter::Info; static LOGGER: Logger = LoggerBuilder::const_default() .level_filter(LOG_LEVEL) diff --git a/crates/sel4/src/arch/arm/vspace.rs b/crates/sel4/src/arch/arm/vspace.rs index 1210cb6c1..615316418 100644 --- a/crates/sel4/src/arch/arm/vspace.rs +++ b/crates/sel4/src/arch/arm/vspace.rs @@ -1,6 +1,6 @@ use sel4_config::{sel4_cfg, sel4_cfg_enum, sel4_cfg_match}; -use crate::{cap_type, sys, FrameType, ObjectBlueprint, ObjectBlueprintArm}; +use crate::{cap_type, sys, FrameType, ObjectBlueprint, ObjectBlueprintArm, SizedFrameType}; #[sel4_cfg(ARCH_AARCH64)] use crate::ObjectBlueprintAArch64; @@ -36,16 +36,23 @@ impl FrameSize { pub const HUGE_BITS: usize = Self::Huge.bits(); } -impl FrameType for cap_type::SmallPage { +impl FrameType for cap_type::SmallPage {} + +impl SizedFrameType for cap_type::SmallPage { const FRAME_SIZE: FrameSize = FrameSize::Small; } -impl FrameType for cap_type::LargePage { +impl FrameType for cap_type::LargePage {} + +impl SizedFrameType for cap_type::LargePage { const FRAME_SIZE: FrameSize = FrameSize::Large; } #[sel4_cfg(ARCH_AARCH64)] -impl FrameType for cap_type::HugePage { +impl FrameType for cap_type::HugePage {} + +#[sel4_cfg(ARCH_AARCH64)] +impl SizedFrameType for cap_type::HugePage { const FRAME_SIZE: FrameSize = FrameSize::Huge; } diff --git a/crates/sel4/src/arch/riscv/vspace.rs b/crates/sel4/src/arch/riscv/vspace.rs index f0df65999..63cc06e37 100644 --- a/crates/sel4/src/arch/riscv/vspace.rs +++ b/crates/sel4/src/arch/riscv/vspace.rs @@ -1,5 +1,5 @@ #[allow(unused_imports)] -use crate::{cap_type, sys, FrameType, ObjectBlueprint, ObjectBlueprintRISCV}; +use crate::{cap_type, sys, FrameType, ObjectBlueprint, ObjectBlueprintRISCV, SizedFrameType}; #[sel4_config::sel4_cfg_enum] #[derive(Copy, Clone, Debug, PartialEq, Eq)] @@ -30,16 +30,23 @@ impl FrameSize { pub const GIGA_BITS: usize = Self::Giga.bits(); } -impl FrameType for cap_type::_4KPage { +impl FrameType for cap_type::_4KPage {} + +impl SizedFrameType for cap_type::_4KPage { const FRAME_SIZE: FrameSize = FrameSize::_4K; } -impl FrameType for cap_type::MegaPage { +impl FrameType for cap_type::MegaPage {} + +impl SizedFrameType for cap_type::MegaPage { const FRAME_SIZE: FrameSize = FrameSize::Mega; } #[sel4_config::sel4_cfg(any(PT_LEVELS = "3", PT_LEVELS = "4"))] -impl FrameType for cap_type::GigaPage { +impl FrameType for cap_type::GigaPage {} + +#[sel4_config::sel4_cfg(any(PT_LEVELS = "3", PT_LEVELS = "4"))] +impl SizedFrameType for cap_type::GigaPage { const FRAME_SIZE: FrameSize = FrameSize::Giga; } diff --git a/crates/sel4/src/arch/x86/arch/x64/vspace.rs b/crates/sel4/src/arch/x86/arch/x64/vspace.rs index cf2a08786..8d5540b98 100644 --- a/crates/sel4/src/arch/x86/arch/x64/vspace.rs +++ b/crates/sel4/src/arch/x86/arch/x64/vspace.rs @@ -1,4 +1,7 @@ -use crate::{cap_type, sys, FrameType, ObjectBlueprint, ObjectBlueprintX64, ObjectBlueprintX86}; +use crate::{ + cap_type, sys, FrameType, ObjectBlueprint, ObjectBlueprintX64, ObjectBlueprintX86, + SizedFrameType, +}; #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum FrameSize { @@ -24,22 +27,28 @@ impl FrameSize { pub const HUGE_BITS: usize = Self::Huge.bits(); } -impl FrameType for cap_type::_4K { +impl FrameType for cap_type::_4K {} + +impl SizedFrameType for cap_type::_4K { const FRAME_SIZE: FrameSize = FrameSize::_4K; } -impl FrameType for cap_type::LargePage { +impl FrameType for cap_type::LargePage {} + +impl SizedFrameType for cap_type::LargePage { const FRAME_SIZE: FrameSize = FrameSize::Large; } -impl FrameType for cap_type::HugePage { +impl FrameType for cap_type::HugePage {} + +impl SizedFrameType for cap_type::HugePage { const FRAME_SIZE: FrameSize = FrameSize::Huge; } // impl cap_type::PDPT { - pub const INDEX_BITS: usize = sys::seL4_PDPTIndexBits; + pub const INDEX_BITS: usize = sys::seL4_PDPTIndexBits as usize; } impl cap_type::PageDirectory { diff --git a/crates/sel4/src/cptr.rs b/crates/sel4/src/cptr.rs index e53a4d257..2cf87c6c0 100644 --- a/crates/sel4/src/cptr.rs +++ b/crates/sel4/src/cptr.rs @@ -213,6 +213,11 @@ pub mod cap_type { Unspecified } + declare_cap_type! { + /// Any frame capability. + UnspecifiedFrame + } + sel4_cfg_if! { if #[cfg(KERNEL_MCS)] { declare_cap_type! { diff --git a/crates/sel4/src/lib.rs b/crates/sel4/src/lib.rs index 0cb8fc4c3..6f4977672 100644 --- a/crates/sel4/src/lib.rs +++ b/crates/sel4/src/lib.rs @@ -88,7 +88,7 @@ pub use reply_authority::{ConveysReplyAuthority, ReplyAuthority}; pub use syscalls::{ r#yield, Badge, CallWithMRs, FastMessages, IPCCapType, RecvWithMRs, NUM_MESSAGE_REGISTERS, }; -pub use vspace::{FrameType, GRANULE_SIZE}; +pub use vspace::{FrameType, SizedFrameType, GRANULE_SIZE}; sel4_cfg_if! { if #[cfg(KERNEL_MCS)] { diff --git a/crates/sel4/src/vspace.rs b/crates/sel4/src/vspace.rs index 35c8ea0f8..ae3f675f3 100644 --- a/crates/sel4/src/vspace.rs +++ b/crates/sel4/src/vspace.rs @@ -13,6 +13,10 @@ impl FrameSize { } } -pub trait FrameType: CapType { +pub trait FrameType: CapType {} + +impl FrameType for cap_type::UnspecifiedFrame {} + +pub trait SizedFrameType: FrameType { const FRAME_SIZE: FrameSize; } diff --git a/hacking/nix/scope/sel4test/default.nix b/hacking/nix/scope/sel4test/default.nix index 3e583aaa5..6fa473ae4 100644 --- a/hacking/nix/scope/sel4test/default.nix +++ b/hacking/nix/scope/sel4test/default.nix @@ -129,8 +129,8 @@ let src = fetchRepoProject { name = "sel4test"; manifest = "https://github.com/seL4/sel4test-manifest.git"; - rev = "cfc1195ba8fd0de1a0e179aef1314b8f402ff74c"; - sha256 = "sha256-JspN1A/w5XIV+XCj5/oj7NABsKXVdr+UZOTJWvfJPUY="; + rev = "8bf6fd506a0546866ba5fbd7396f497d5a056f5c"; + sha256 = "sha256-1Gmbksgh2VTUggM6qcawRC9b+g/bwB8tWGfUzCg1A0U="; }; LIBCLANG_PATH = libclangPath; diff --git a/hacking/nix/scope/sources.nix b/hacking/nix/scope/sources.nix index 0d566030b..95c5adb7f 100644 --- a/hacking/nix/scope/sources.nix +++ b/hacking/nix/scope/sources.nix @@ -22,7 +22,7 @@ let capdlCommon = { url = "https://github.com/coliasgroup/capdl.git"; - rev = "dcad98b8a6665c8ea2b822e97cf9bffbd3c349fe"; + rev = "6e1c2fe0637e01b303506cfbad8ed5f863c2446a"; # branch coliasgroup local = localRoot + "/capdl"; }; @@ -40,21 +40,21 @@ in rec { seL4 = { rust = fetchGit { url = "https://github.com/coliasgroup/seL4.git"; - rev = "656f11fd66139e1102c8bae0b07639a2ada9af78"; # branch "rust" + rev = "b170676396064a45e88a8394ae5f463ab792b63a"; # branch "rust" local = localRoot + "/seL4"; - useLocal = true; + # useLocal = true; }; rust-microkit = fetchGit { url = "https://github.com/coliasgroup/seL4.git"; - rev = "fc80c9ad05d33e77a6b850dae8eb4b8317ec32a1"; # branch "rust-microkit" + rev = "d5196f79d696f74ce40ad13c393a525d1b83ae1f"; # branch "rust-microkit" local = localRoot + "/seL4"; # useLocal = true; }; rust-sel4test = fetchGit { url = "https://github.com/coliasgroup/seL4.git"; - rev = "8e0d0f7f599720a134b5e710ac0433a175b2399b"; # rust-sel4test + rev = "06fc7f562f7a78d753687d9dcfda852b834169c5"; # rust-sel4test local = localRoot + "/seL4"; # useLocal = true; }; @@ -62,20 +62,23 @@ in rec { microkit = fetchGit { url = "https://github.com/coliasgroup/microkit.git"; - rev = "b0a82657af8f340f418295bae158f5132294ce4b"; # branch "rust-nix" + rev = "80069432ef126411128f2e2c3c95a6d171cb83fe"; # branch "rust-nix" local = localRoot + "/microkit"; # useLocal = true; }; capdlTool = fetchGit (capdlCommon // { andThen = "/capDL-tool"; + # useLocal = true; }); pythonCapDLTool = fetchGit (capdlCommon // { andThen = "/python-capdl-tool"; + # useLocal = true; }); objectSizes = fetchGit (capdlCommon // { andThen = "/object_sizes"; + # useLocal = true; }); } From 92156f78ad8d132332c46dd87afcde4dfddfb5ce Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Sat, 23 Sep 2023 00:23:05 +0000 Subject: [PATCH 7/7] crates/sel4-capdl-initializer: Improve consistency in type variables Signed-off-by: Nick Spinale --- crates/sel4-capdl-initializer/types/src/frame_init.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/sel4-capdl-initializer/types/src/frame_init.rs b/crates/sel4-capdl-initializer/types/src/frame_init.rs index 7f8891478..72b95161e 100644 --- a/crates/sel4-capdl-initializer/types/src/frame_init.rs +++ b/crates/sel4-capdl-initializer/types/src/frame_init.rs @@ -16,12 +16,12 @@ use crate::{object, Indirect, SelfContained}; #[derive(Debug, Clone, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub enum FrameInit<'a, D, T> { +pub enum FrameInit<'a, D, M> { Fill(Fill<'a, D>), - Embedded(T), + Embedded(M), } -impl<'a, D, E> FrameInit<'a, D, E> { +impl<'a, D, M> FrameInit<'a, D, M> { pub const fn as_fill(&self) -> Option<&Fill<'a, D>> { match self { Self::Fill(fill) => Some(fill), @@ -29,7 +29,7 @@ impl<'a, D, E> FrameInit<'a, D, E> { } } - pub const fn as_embedded(&self) -> Option<&E> { + pub const fn as_embedded(&self) -> Option<&M> { match self { Self::Embedded(embedded) => Some(embedded), _ => None,