From e371f47f51ad3bdc53c9cbb1150b4d660d186efe Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 25 Oct 2025 19:59:27 +0200 Subject: [PATCH 1/4] Remove let_chain feature gate It is now stable. --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e4dc8ff060..b0615774d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ #![cfg_attr(not(feature = "std"), no_std)] #![feature(doc_cfg)] -#![feature(let_chains)] pub use crate::{allocator::*, arch::*, page::*}; From 5b5bbe5643906ff4e84aaf8b2ad0b241fe98013d Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 25 Oct 2025 20:01:28 +0200 Subject: [PATCH 2/4] Remove VirtualAddress::is_canonical This way the last remaining feature gate can be removed. It also matches how other architectures handle this functionality. --- src/arch/x86_64.rs | 13 +++---------- src/lib.rs | 1 - 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/arch/x86_64.rs b/src/arch/x86_64.rs index 6bc5022388..d8b44357cc 100644 --- a/src/arch/x86_64.rs +++ b/src/arch/x86_64.rs @@ -57,14 +57,7 @@ impl Arch for X8664Arch { // On x86_64, an address is valid if and only if it is canonical. It may still point to // unmapped memory, but will always be valid once translated via the page table has // suceeded. - address.is_canonical() - } -} - -impl VirtualAddress { - #[doc(cfg(target_arch = "x86_64"))] - pub fn is_canonical(self) -> bool { - let masked = self.data() & 0xFFFF_8000_0000_0000; + let masked = address.data() & 0xFFFF_8000_0000_0000; // TODO: 5-level paging masked == 0xFFFF_8000_0000_0000 || masked == 0 } @@ -96,10 +89,10 @@ mod tests { #[test] fn is_canonical() { fn yes(address: usize) { - assert!(VirtualAddress::new(address).is_canonical()); + assert!(X8664Arch::virt_is_valid(VirtualAddress::new(address))); } fn no(address: usize) { - assert!(!VirtualAddress::new(address).is_canonical()); + assert!(!X8664Arch::virt_is_valid(VirtualAddress::new(address))); } yes(0xFFFF_8000_1337_1337); diff --git a/src/lib.rs b/src/lib.rs index b0615774d7..0cc0beb2d7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,4 @@ #![cfg_attr(not(feature = "std"), no_std)] -#![feature(doc_cfg)] pub use crate::{allocator::*, arch::*, page::*}; From e6d42dda1918b891f0584acf8d1f4711cba3ff8f Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 26 Oct 2025 11:55:42 +0100 Subject: [PATCH 3/4] Fix compilation of EmulateArch --- src/arch/emulate.rs | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/arch/emulate.rs b/src/arch/emulate.rs index f6f33cd171..5e8bdb3c2a 100644 --- a/src/arch/emulate.rs +++ b/src/arch/emulate.rs @@ -1,5 +1,4 @@ -use core::{marker::PhantomData, mem, ptr}; -use std::collections::BTreeMap; +use std::{collections::BTreeMap, marker::PhantomData, mem, ptr, sync::Mutex}; use crate::{ arch::x86_64::X8664Arch, page::PageFlags, Arch, MemoryArea, PageEntry, PhysicalAddress, @@ -64,7 +63,7 @@ impl Arch for EmulateArch { ); } - MACHINE = Some(machine); + *MACHINE.lock().unwrap() = Some(machine); // Set table to pml4 EmulateArch::set_table(TableKind::Kernel, PhysicalAddress::new(pml4)); @@ -75,43 +74,52 @@ impl Arch for EmulateArch { #[inline(always)] unsafe fn read(address: VirtualAddress) -> T { - unsafe { MACHINE.as_ref().unwrap().read(address) } + MACHINE.lock().unwrap().as_ref().unwrap().read(address) } #[inline(always)] unsafe fn write(address: VirtualAddress, value: T) { - unsafe { MACHINE.as_mut().unwrap().write(address, value) } + MACHINE + .lock() + .unwrap() + .as_mut() + .unwrap() + .write(address, value) } #[inline(always)] unsafe fn write_bytes(address: VirtualAddress, value: u8, count: usize) { - unsafe { MACHINE.as_mut().unwrap().write_bytes(address, value, count) } + MACHINE + .lock() + .unwrap() + .as_mut() + .unwrap() + .write_bytes(address, value, count) } #[inline(always)] unsafe fn invalidate(address: VirtualAddress) { - unsafe { - MACHINE.as_mut().unwrap().invalidate(address); - } + MACHINE + .lock() + .unwrap() + .as_mut() + .unwrap() + .invalidate(address); } #[inline(always)] unsafe fn invalidate_all() { - unsafe { - MACHINE.as_mut().unwrap().invalidate_all(); - } + MACHINE.lock().unwrap().as_mut().unwrap().invalidate_all(); } #[inline(always)] unsafe fn table(_table_kind: TableKind) -> PhysicalAddress { - unsafe { MACHINE.as_mut().unwrap().get_table() } + MACHINE.lock().unwrap().as_mut().unwrap().get_table() } #[inline(always)] unsafe fn set_table(_table_kind: TableKind, address: PhysicalAddress) { - unsafe { - MACHINE.as_mut().unwrap().set_table(address); - } + MACHINE.lock().unwrap().as_mut().unwrap().set_table(address); } fn virt_is_valid(_address: VirtualAddress) -> bool { // TODO: Don't see why an emulated arch would have any problems with canonicalness... @@ -132,7 +140,7 @@ static MEMORY_AREAS: [MemoryArea; 2] = [ }, ]; -static mut MACHINE: Option> = None; +static MACHINE: Mutex>> = Mutex::new(None); struct Machine { memory: Box<[u8]>, From 075d52f1534dbbdeed0bf49822b19d06deda4a74 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 26 Oct 2025 11:58:43 +0100 Subject: [PATCH 4/4] Fix example binary --- src/allocator/frame/bump.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/allocator/frame/bump.rs b/src/allocator/frame/bump.rs index 9985feff3a..9043b181ae 100644 --- a/src/allocator/frame/bump.rs +++ b/src/allocator/frame/bump.rs @@ -25,7 +25,7 @@ impl BumpAllocator { } } pub fn areas(&self) -> &'static [MemoryArea] { - todo!() + self.orig_areas.0 } /// Returns one semifree and the fully free areas. The offset is the number of bytes after /// which the first area is free.