Next Generation WASM Microkernel Operating System

fix CI checks

+66 -57
+30 -17
libs/kmem/src/address.rs
··· 5 5 // http://opensource.org/licenses/MIT>, at your option. This file may not be 6 6 // copied, modified, or distributed except according to those terms. 7 7 8 - use core::num::NonZeroUsize; 9 - use core::ptr::NonNull; 10 - 11 8 use crate::arch::Arch; 12 9 13 10 macro_rules! impl_address_from { ··· 64 61 #[inline] 65 62 pub fn from_non_null<T: ?Sized>(ptr: ::core::ptr::NonNull<T>) -> Self { 66 63 Self(ptr.addr().get()) 64 + } 65 + 66 + #[inline] 67 + pub fn as_ptr(self) -> *const u8 { 68 + ::core::ptr::with_exposed_provenance(self.0) 69 + } 70 + 71 + #[inline] 72 + pub fn as_mut_ptr(self) -> *mut u8 { 73 + ::core::ptr::with_exposed_provenance_mut(self.0) 74 + } 75 + 76 + #[inline] 77 + pub fn as_non_null(self) -> Option<::core::ptr::NonNull<u8>> { 78 + ::core::num::NonZeroUsize::new(self.0) 79 + .map(::core::ptr::NonNull::with_exposed_provenance) 67 80 } 68 81 69 82 /// Adds an unsigned offset to this address, panicking if overflow occurred. ··· 253 266 impl_address!(VirtualAddress); 254 267 255 268 impl VirtualAddress { 256 - #[inline] 257 - pub fn as_ptr(self) -> *const u8 { 258 - core::ptr::with_exposed_provenance(self.0) 259 - } 260 - 261 - #[inline] 262 - pub fn as_mut_ptr(self) -> *mut u8 { 263 - core::ptr::with_exposed_provenance_mut(self.0) 264 - } 265 - 266 - #[inline] 267 - pub fn as_non_null(self) -> Option<NonNull<u8>> { 268 - NonZeroUsize::new(self.0).map(NonNull::with_exposed_provenance) 269 - } 269 + // #[inline] 270 + // pub fn as_ptr(self) -> *const u8 { 271 + // core::ptr::with_exposed_provenance(self.0) 272 + // } 273 + // 274 + // #[inline] 275 + // pub fn as_mut_ptr(self) -> *mut u8 { 276 + // core::ptr::with_exposed_provenance_mut(self.0) 277 + // } 278 + // 279 + // #[inline] 280 + // pub fn as_non_null(self) -> Option<NonNull<u8>> { 281 + // NonZeroUsize::new(self.0).map(NonNull::with_exposed_provenance) 282 + // } 270 283 271 284 #[expect( 272 285 clippy::cast_sign_loss,
+4 -4
libs/kmem/src/address_space.rs
··· 5 5 use crate::bootstrap::{Bootstrap, BootstrapAllocator}; 6 6 use crate::flush::Flush; 7 7 use crate::physmap::PhysicalMemoryMapping; 8 - use crate::table::{marker, Table}; 9 - use crate::utils::{page_table_entries_for, PageTableEntries}; 8 + use crate::table::{Table, marker}; 9 + use crate::utils::{PageTableEntries, page_table_entries_for}; 10 10 use crate::{ 11 11 AddressRangeExt, AllocError, FrameAllocator, MemoryAttributes, PhysicalAddress, VirtualAddress, 12 12 }; ··· 431 431 432 432 use crate::address_range::AddressRangeExt; 433 433 use crate::arch::Arch; 434 + use crate::emulate::{BootstrapResult, MachineBuilder}; 434 435 use crate::flush::Flush; 435 436 use crate::frame_allocator::FrameAllocator; 436 - use crate::test_utils::{BootstrapResult, MachineBuilder}; 437 - use crate::{archtest, MemoryAttributes, WriteOrExecute, VirtualAddress}; 437 + use crate::{MemoryAttributes, VirtualAddress, WriteOrExecute, archtest}; 438 438 439 439 archtest! { 440 440 #[test]
+4 -7
libs/kmem/src/arch/emulate.rs libs/kmem/src/emulate/arch.rs
··· 1 - use core::ops::Range; 2 1 use core::fmt; 2 + use core::ops::Range; 3 3 use std::mem; 4 + 4 5 use crate::arch::{Arch, PageTableLevel}; 5 - use crate::{ 6 - PhysicalAddress 7 - , VirtualAddress, 8 - }; 9 - use crate::test_utils::Machine; 6 + use crate::emulate::Machine; 7 + use crate::{PhysicalAddress, VirtualAddress}; 10 8 11 9 pub struct EmulateArch<A: Arch, R: lock_api::RawMutex> { 12 10 machine: Machine<A, R>, ··· 89 87 } 90 88 } 91 89 } 92 -
+2 -3
libs/kmem/src/arch/mod.rs
··· 1 - #[cfg(feature = "emulate")] 2 - pub mod emulate; 3 1 pub mod riscv64; 4 2 5 3 use core::alloc::Layout; ··· 236 234 237 235 /// Extracts the page table entry (PTE) for a table at this level from the given address. 238 236 pub(crate) fn pte_index_of(&self, address: VirtualAddress) -> u16 { 239 - let idx = u16::try_from(address.get() >> self.index_shift & (self.entries as usize - 1)).unwrap() ; 237 + let idx = 238 + u16::try_from(address.get() >> self.index_shift & (self.entries as usize - 1)).unwrap(); 240 239 debug_assert!(idx < self.entries); 241 240 idx 242 241 }
+2 -2
libs/kmem/src/arch/riscv64.rs
··· 5 5 6 6 use crate::arch::PageTableLevel; 7 7 use crate::{ 8 - AddressRangeExt, MemoryAttributes, PhysicalAddress, VirtualAddress, WriteOrExecute, GIB, KIB, MIB, 9 - TIB, 8 + AddressRangeExt, GIB, KIB, MIB, MemoryAttributes, PhysicalAddress, TIB, VirtualAddress, 9 + WriteOrExecute, 10 10 }; 11 11 12 12 pub struct Riscv64Sv39 {
+1 -1
libs/kmem/src/bootstrap.rs
··· 3 3 use core::mem; 4 4 use core::ops::Range; 5 5 6 - pub use frame_allocator::{BootstrapAllocator, FreeRegions, UsedRegions, DEFAULT_MAX_REGIONS}; 6 + pub use frame_allocator::{BootstrapAllocator, DEFAULT_MAX_REGIONS, FreeRegions, UsedRegions}; 7 7 8 8 use crate::arch::Arch; 9 9 use crate::flush::Flush;
+5 -4
libs/kmem/src/bootstrap/frame_allocator.rs
··· 2 2 use core::fmt; 3 3 use core::num::NonZeroUsize; 4 4 use core::ops::Range; 5 + 5 6 use arrayvec::ArrayVec; 6 7 use lock_api::Mutex; 7 8 ··· 236 237 237 238 #[cfg(test)] 238 239 mod tests { 239 - use crate::arch::emulate::EmulateArch; 240 240 use crate::arch::Arch; 241 241 use crate::bootstrap::BootstrapAllocator; 242 + use crate::emulate::MachineBuilder; 243 + use crate::emulate::arch::EmulateArch; 242 244 use crate::frame_allocator::FrameAllocator; 243 - use crate::{archtest, PhysicalMemoryMapping}; 244 - use crate::test_utils::MachineBuilder; 245 + use crate::{PhysicalMemoryMapping, archtest}; 245 246 246 247 archtest! { 247 248 // Assert that the BootstrapAllocator can allocate frames ··· 275 276 .unwrap_err(); 276 277 } 277 278 278 - // Assert that the BootstrapAllocator can allocate zeored frames in 279 + // Assert that the BootstrapAllocator can allocate zeroed frames in 279 280 // bootstrap (bare, before paging is enabled) mode. 280 281 #[test] 281 282 fn allocate_contiguous_zeroed_bare<A: Arch>() {
+1 -1
libs/kmem/src/flush.rs
··· 3 3 4 4 use arrayvec::ArrayVec; 5 5 6 - use crate::arch::Arch; 7 6 use crate::VirtualAddress; 7 + use crate::arch::Arch; 8 8 9 9 pub enum Flush<const CAP: usize = 16> { 10 10 Ranges(ArrayVec<Range<VirtualAddress>, CAP>),
+3 -1
libs/kmem/src/lib.rs
··· 15 15 mod physmap; 16 16 mod table; 17 17 mod utils; 18 - mod test_utils; 18 + 19 + #[cfg(feature = "emulate")] 20 + mod emulate; 19 21 20 22 pub use address::{PhysicalAddress, VirtualAddress}; 21 23 pub use address_range::AddressRangeExt;
+1 -1
libs/kmem/src/physmap.rs
··· 1 + use core::cmp; 1 2 use core::ops::Range; 2 - use std::cmp; 3 3 4 4 use crate::{AddressRangeExt, PhysicalAddress, VirtualAddress}; 5 5
+1 -1
libs/kmem/src/table.rs
··· 5 5 6 6 use crate::arch::{Arch, PageTableEntry, PageTableLevel}; 7 7 use crate::physmap::PhysicalMemoryMapping; 8 - use crate::utils::{page_table_entries_for, PageTableEntries}; 8 + use crate::utils::{PageTableEntries, page_table_entries_for}; 9 9 use crate::{AllocError, FrameAllocator, PhysicalAddress, VirtualAddress}; 10 10 11 11 /// A page table. Essentially a fixed-sized list of `A::PageTableEntry`s.
+5 -3
libs/kmem/src/test_utils.rs libs/kmem/src/emulate.rs
··· 1 - mod memory; 1 + #[cfg(feature = "emulate")] 2 + pub mod arch; 2 3 mod machine; 4 + mod memory; 3 5 4 6 // pub use memory::Memory; 5 - pub use machine::{Machine, MachineBuilder, Cpu, BootstrapResult}; 7 + pub use machine::{BootstrapResult, Cpu, Machine, MachineBuilder}; 6 8 7 9 #[macro_export] 8 10 macro_rules! archtest { ··· 55 57 } 56 58 )* 57 59 } 58 - } 60 + }
+5 -10
libs/kmem/src/test_utils/machine.rs libs/kmem/src/emulate/machine.rs
··· 1 - use std::cell::Ref; 2 - use std::cell::{RefCell, RefMut}; 1 + use std::cell::{Ref, RefCell, RefMut}; 3 2 use std::collections::BTreeMap; 4 3 use std::marker::PhantomData; 5 4 use std::ops::Range; ··· 10 9 use cpu_local::collection::CpuLocal; 11 10 use lock_api::Mutex; 12 11 13 - use crate::arch::emulate::EmulateArch; 14 12 use crate::arch::{Arch, PageTableEntry, PageTableLevel}; 15 13 use crate::bootstrap::BootstrapAllocator; 14 + use crate::emulate::arch::EmulateArch; 15 + use crate::emulate::memory::Memory; 16 16 use crate::flush::Flush; 17 - use crate::test_utils::memory::Memory; 18 17 use crate::utils::page_table_entries_for; 19 18 use crate::{ 20 19 AddressRangeExt, AllocError, HardwareAddressSpace, MemoryAttributes, PhysicalAddress, ··· 112 111 } 113 112 114 113 pub unsafe fn set_active_table(&self, address: PhysicalAddress) { 115 - self.cpu_mut() 116 - .set_active_page_table(address); 114 + self.cpu_mut().set_active_page_table(address); 117 115 } 118 116 119 117 pub fn invalidate(&self, asid: u16, address_range: Range<VirtualAddress>) { ··· 300 298 cpus: CpuLocal::with_capacity(std::thread::available_parallelism().unwrap().get()), 301 299 }; 302 300 303 - ( 304 - Machine(Arc::new(inner)), 305 - physmap 306 - ) 301 + (Machine(Arc::new(inner)), physmap) 307 302 } 308 303 309 304 pub fn finish_and_bootstrap(self) -> Result<BootstrapResult<A, R>, AllocError> {
+1 -1
libs/kmem/src/test_utils/memory.rs libs/kmem/src/emulate/memory.rs
··· 4 4 use std::ptr::NonNull; 5 5 use std::{fmt, mem}; 6 6 7 - use crate::arch::Arch; 8 7 use crate::PhysicalAddress; 8 + use crate::arch::Arch; 9 9 10 10 pub struct Memory { 11 11 regions: BTreeMap<PhysicalAddress, (PhysicalAddress, NonNull<[u8]>, Layout)>,
+1 -1
libs/kmem/src/utils.rs
··· 1 1 use core::marker::PhantomData; 2 2 use core::ops::{Range, RangeInclusive}; 3 3 4 - use crate::arch::{Arch, PageTableLevel}; 5 4 use crate::VirtualAddress; 5 + use crate::arch::{Arch, PageTableLevel}; 6 6 7 7 pub(crate) fn page_table_entries_for<A: Arch>( 8 8 range: Range<VirtualAddress>,