From f49c7d991ab9bf191e33dc610a811860f69c4a58 Mon Sep 17 00:00:00 2001 From: Speedy_Lex Date: Fri, 24 Apr 2026 20:04:23 +0200 Subject: [PATCH] RSDP validation and fixing a few clippy lints --- src/acpi/rsdp.rs | 24 +++++++++++++++++++++--- src/context/switch.rs | 2 +- src/memory/mod.rs | 2 +- src/profiling.rs | 3 ++- src/scheme/debug.rs | 1 + src/scheme/sys/context.rs | 2 +- 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/acpi/rsdp.rs b/src/acpi/rsdp.rs index f10c5ac989..67e6798ddf 100644 --- a/src/acpi/rsdp.rs +++ b/src/acpi/rsdp.rs @@ -9,7 +9,7 @@ pub struct Rsdp { _oemid: [u8; 6], revision: u8, rsdt_address: u32, - _length: u32, + length: u32, xsdt_address: u64, _extended_checksum: u8, _reserved: [u8; 3], @@ -18,8 +18,26 @@ pub struct Rsdp { impl Rsdp { pub unsafe fn get_rsdp(already_supplied_rsdp: Option<*const u8>) -> Option { already_supplied_rsdp.map(|rsdp_ptr| { - // TODO: Validate - unsafe { *(rsdp_ptr as *const Rsdp) } + let rsdp = unsafe { *(rsdp_ptr as *const Rsdp) }; + + assert_eq!(rsdp.signature, *b"RSD PTR ", "RSDP signature check failed"); + + let mut sum: u8 = 0; + for i in 0..20 { + sum = sum.wrapping_add(unsafe { rsdp_ptr.add(i).read() }); + } + assert_eq!(sum, 0, "RSDP checksum failed"); + + + if rsdp.revision >= 2 { + let mut sum: u8 = 0; + for i in 0..rsdp.length as usize { + sum = sum.wrapping_add(unsafe { rsdp_ptr.add(i).read() }); + } + assert_eq!(sum, 0, "XSDP checksum failed"); + } + + rsdp }) } diff --git a/src/context/switch.rs b/src/context/switch.rs index e2e323ca37..177e213fcd 100644 --- a/src/context/switch.rs +++ b/src/context/switch.rs @@ -513,7 +513,7 @@ fn select_next_context( if let Some((next_context_guard, addr_space)) = next_context_guard_opt { // We found a new process! - return Some((next_context_guard, addr_space)); + Some((next_context_guard, addr_space)) } else { if !was_idle && !Arc::ptr_eq(&prev_context_lock, &idle_context) { // We switch into the idle context diff --git a/src/memory/mod.rs b/src/memory/mod.rs index 393ae7ebd9..09de032f13 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -555,7 +555,7 @@ fn init_sections(mut allocator: BumpAllocator) { assert_ne!( memory_map_area.size, 0, - "RMM should enforce areas are not zeroed" + "RMM should enforce areas are not of length 0" ); // TODO: Should RMM do this? diff --git a/src/profiling.rs b/src/profiling.rs index 79ed7fe085..82da648b11 100644 --- a/src/profiling.rs +++ b/src/profiling.rs @@ -188,6 +188,7 @@ pub unsafe fn nmi_handler(stack: &InterruptStack) { let mut len = 2; + #[expect(clippy::needless_range_loop)] for i in 2..32 { if bp < CurrentRmmArch::PHYS_OFFSET || bp.saturating_add(16) >= CurrentRmmArch::PHYS_OFFSET + crate::PML4_SIZE @@ -303,7 +304,7 @@ pub fn maybe_run_profiling_helper_forever(cpu_id: LogicalCpuId) { let apic = &mut crate::arch::device::local_apic::the_local_apic(); apic.set_lvt_timer((0b01 << 17) | 32); apic.set_div_conf(0b1011); - apic.set_init_count(0xffff_f); + apic.set_init_count(0x000f_ffff); while ACK.load(Ordering::Relaxed) < NUM_ORDINARY_CPUS.load(Ordering::SeqCst) { core::hint::spin_loop(); diff --git a/src/scheme/debug.rs b/src/scheme/debug.rs index c70ac5792b..9b48605ca6 100644 --- a/src/scheme/debug.rs +++ b/src/scheme/debug.rs @@ -37,6 +37,7 @@ pub fn debug_notify(token: &mut CleanLockToken) { pub struct DebugScheme; +#[expect(clippy::enum_clike_unportable_variant)] #[repr(usize)] enum SpecialFds { Default = -1isize as usize, diff --git a/src/scheme/sys/context.rs b/src/scheme/sys/context.rs index 313927a08e..5f2ed0b946 100644 --- a/src/scheme/sys/context.rs +++ b/src/scheme/sys/context.rs @@ -19,7 +19,7 @@ pub fn resource(token: &mut CleanLockToken) -> Result> { let (contexts, mut token) = contexts.token_split(); for context_ref in contexts.iter() { let context = context_ref.read(token.token()); - let addr_space = context.addr_space().map(|a| a.clone()); + let addr_space = context.addr_space().cloned(); let affinity = context.sched_affinity.to_string(); let cpu_time_s = context.cpu_time / crate::time::NANOS_PER_SEC;