From 38bc47c5f55f0055ec5705a770cba418e254441d Mon Sep 17 00:00:00 2001 From: Matthew Leach Date: Sat, 10 Oct 2026 13:00:37 +0100 Subject: [PATCH 1/4] libkernel: add address_space feature Add a new feature, `address_space` which pulls out non-`proc_vm` types and traits from that feature. This permits the usage of address_space types without the need for compiling FS drivers. --- .github/workflows/ci.yml | 33 +++++++++++++++++-- libkernel/Cargo.toml | 5 +-- libkernel/README.md | 21 ++++++------ libkernel/src/fs/blk/mod.rs | 2 +- libkernel/src/fs/blk/ramdisk.rs | 2 +- libkernel/src/lib.rs | 21 ++++++------ libkernel/src/memory/address.rs | 25 ++++++++++++++ .../src/memory/{proc_vm => }/address_space.rs | 14 ++++++++ libkernel/src/memory/mod.rs | 2 ++ libkernel/src/memory/paging/permissions.rs | 16 --------- .../src/memory/proc_vm/memory_map/mod.rs | 9 ++--- libkernel/src/memory/proc_vm/mod.rs | 11 +++---- libkernel/src/memory/proc_vm/pg_offset.rs | 27 --------------- libkernel/src/memory/proc_vm/vmarea.rs | 19 +++++------ src/arch/arm64/boot/secondary.rs | 2 +- src/arch/arm64/exceptions/mod.rs | 2 +- src/arch/arm64/memory/address_space.rs | 2 +- src/arch/arm64/memory/fault.rs | 2 +- src/arch/arm64/memory/mmu.rs | 2 +- src/arch/arm64/mod.rs | 2 +- src/arch/arm64/proc/idle.rs | 6 ++-- src/arch/arm64/proc/vdso.rs | 2 +- src/arch/mod.rs | 2 +- src/drivers/display/virtio.rs | 2 +- src/drivers/interrupts/arm_gic_v2.rs | 2 +- src/drivers/interrupts/arm_gic_v3.rs | 2 +- src/drivers/rng/virtio.rs | 2 +- src/drivers/rtc/pl031.rs | 2 +- src/drivers/uart/imx_lp.rs | 2 +- src/drivers/uart/pl011.rs | 2 +- src/main.rs | 2 +- src/memory/fault.rs | 5 +-- src/memory/mincore.rs | 2 +- src/memory/mod.rs | 2 +- src/memory/process_vm.rs | 2 +- src/process/exec.rs | 2 +- src/process/mod.rs | 4 +-- src/process/owned.rs | 3 +- src/process/threading/futex/key.rs | 2 +- 39 files changed, 144 insertions(+), 123 deletions(-) rename libkernel/src/memory/{proc_vm => }/address_space.rs (94%) delete mode 100644 libkernel/src/memory/proc_vm/pg_offset.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b1ec2a09..d9d73e7f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,5 +31,34 @@ jobs: - name: Run clippy run: cargo clippy -- -D warnings - - name: Run unit tests for libkernel - run: cargo test -p libkernel --target x86_64-unknown-linux-gnu --all-features + - name: Run clippy for libkernel (all features, including tests) + run: > + cargo clippy -p libkernel + --target x86_64-unknown-linux-gnu + --all-features --all-targets -- -D warnings + + libkernel-features: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v6 + + # Use the toolchain from rust-toolchain.toml + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + + - name: Install cargo-hack + uses: taiki-e/install-action@cargo-hack + + - name: Check libkernel for every feature combination + run: > + cargo hack check -p libkernel + --target x86_64-unknown-linux-gnu + --feature-powerset --no-dev-deps --keep-going + + - name: Test libkernel for every feature combination + run: > + cargo hack test -p libkernel + --target x86_64-unknown-linux-gnu + --feature-powerset --keep-going diff --git a/libkernel/Cargo.toml b/libkernel/Cargo.toml index 361cb450..95811619 100644 --- a/libkernel/Cargo.toml +++ b/libkernel/Cargo.toml @@ -15,10 +15,11 @@ sync = [] alloc = ["sync", "dep:intrusive-collections"] paging = ["alloc", "dep:tock-registers", "dep:paste"] proc = [] +address_space = ["paging"] fs = ["proc", "sync", "dep:async-trait", "dep:ext4plus"] -proc_vm = ["paging", "fs", "dep:object"] +proc_vm = ["address_space", "fs", "dep:object"] kbuf = ["sync", "dep:ringbuf"] -all = ["paging", "fs", "proc_vm", "kbuf"] +all = ["paging", "address_space", "fs", "proc_vm", "kbuf"] [dependencies] # Always-on dependencies diff --git a/libkernel/README.md b/libkernel/README.md index 2e83b5ed..cbdf5950 100644 --- a/libkernel/README.md +++ b/libkernel/README.md @@ -9,16 +9,17 @@ gates to keep the dependency footprint minimal. ## Feature gates -| Feature | Enables | Implies | -|-----------|-------------------------------------------------------|------------------| -| `sync` | Synchronisation primitives (spinlock, mutex, rwlock…) | — | -| `alloc` | Memory allocators (buddy, slab) and collection types | `sync` | -| `paging` | Page tables, PTE helpers | `alloc` | -| `proc` | Process identity types (UID/GID, capabilities) | — | -| `fs` | VFS traits, path manipulation, block I/O | `proc`, `sync` | -| `proc_vm` | Process virtual-memory management (mmap, brk, CoW) | `paging`, `fs` | -| `kbuf` | Async-aware circular kernel buffers | `sync` | -| `all` | Everything above | all of the above | +| Feature | Enables | Implies | +|-----------------|-------------------------------------------------------|-----------------------| +| `sync` | Synchronisation primitives (spinlock, mutex, rwlock…) | — | +| `alloc` | Memory allocators (buddy, slab) and collection types | `sync` | +| `paging` | Page tables, PTE helpers | `alloc` | +| `address_space` | Kernel/user address-space traits and access kinds | `paging` | +| `proc` | Process identity types (UID/GID, capabilities) | — | +| `fs` | VFS traits, path manipulation, block I/O | `proc`, `sync` | +| `proc_vm` | Process virtual-memory management (mmap, brk, CoW) | `address_space`, `fs` | +| `kbuf` | Async-aware circular kernel buffers | `sync` | +| `all` | Everything above | all of the above | ## Quick start diff --git a/libkernel/src/fs/blk/mod.rs b/libkernel/src/fs/blk/mod.rs index 501839d5..14c81da0 100644 --- a/libkernel/src/fs/blk/mod.rs +++ b/libkernel/src/fs/blk/mod.rs @@ -1,5 +1,5 @@ //! Block device layer. pub mod buffer; -#[cfg(feature = "paging")] +#[cfg(feature = "address_space")] pub mod ramdisk; diff --git a/libkernel/src/fs/blk/ramdisk.rs b/libkernel/src/fs/blk/ramdisk.rs index dc5f3ea4..5c4957c7 100644 --- a/libkernel/src/fs/blk/ramdisk.rs +++ b/libkernel/src/fs/blk/ramdisk.rs @@ -6,8 +6,8 @@ use crate::{ memory::{ PAGE_SIZE, address::{TVA, VA}, + address_space::KernAddressSpace, paging::permissions::PtePermissions, - proc_vm::address_space::KernAddressSpace, region::{PhysMemoryRegion, VirtMemoryRegion}, }, }; diff --git a/libkernel/src/lib.rs b/libkernel/src/lib.rs index 9979254d..f0482112 100644 --- a/libkernel/src/lib.rs +++ b/libkernel/src/lib.rs @@ -14,16 +14,17 @@ //! Most of the crate is hidden behind Cargo features so that consumers only pay //! for the subsystems they need: //! -//! | Feature | Enables | Implies | -//! |-----------|-------------------------------------------------------|------------------| -//! | `sync` | Synchronisation primitives (spinlock, mutex, rwlock…) | — | -//! | `alloc` | Memory allocators (buddy, slab) and collection types | `sync` | -//! | `paging` | Page tables, PTE helpers | `alloc` | -//! | `proc` | Process identity types (UID/GID, capabilities) | — | -//! | `fs` | VFS traits, path manipulation, block I/O | `proc`, `sync` | -//! | `proc_vm` | Process virtual-memory management (mmap, brk, CoW) | `paging`, `fs` | -//! | `kbuf` | Async-aware circular kernel buffers | `sync` | -//! | `all` | Everything above | all of the above | +//! | Feature | Enables | Implies | +//! |-----------------|-------------------------------------------------------|-----------------------| +//! | `sync` | Synchronisation primitives (spinlock, mutex, rwlock…) | — | +//! | `alloc` | Memory allocators (buddy, slab) and collection types | `sync` | +//! | `paging` | Page tables, PTE helpers | `alloc` | +//! | `address_space` | Kernel/user address-space traits and access kinds | `paging` | +//! | `proc` | Process identity types (UID/GID, capabilities) | — | +//! | `fs` | VFS traits, path manipulation, block I/O | `proc`, `sync` | +//! | `proc_vm` | Process virtual-memory management (mmap, brk, CoW) | `address_space`, `fs` | +//! | `kbuf` | Async-aware circular kernel buffers | `sync` | +//! | `all` | Everything above | all of the above | //! //! ## The `CpuOps` trait //! diff --git a/libkernel/src/memory/address.rs b/libkernel/src/memory/address.rs index b2ed0575..bdf2ac91 100644 --- a/libkernel/src/memory/address.rs +++ b/libkernel/src/memory/address.rs @@ -371,6 +371,20 @@ impl AddressTranslator for IdentityTranslator { } } +/// Translates between physical and virtual addresses using a fixed page-offset +/// mapping. +pub struct PageOffsetTranslator; + +impl AddressTranslator for PageOffsetTranslator { + fn virt_to_phys(va: TVA) -> TPA { + TPA::from_value(va.value() - OFFSET) + } + + fn phys_to_virt(pa: TPA) -> TVA { + TVA::from_value(pa.value() + OFFSET) + } +} + #[cfg(test)] mod tests { use super::*; @@ -435,6 +449,17 @@ mod tests { assert_eq!(va.value(), TEST_ADDR); } + #[test] + fn test_page_offset_translation() { + const OFFSET: usize = usize::MAX & !0xffff; + for value in [0, NON_ALIGNED_ADDR, 0xffff] { + let pa = TPA::::from_value(value); + let va: TVA = pa.to_va::>(); + assert_eq!(va.value(), OFFSET + value); + assert_eq!(va.to_pa::>(), pa); + } + } + #[test] fn test_va_pointer_conversion() { let va = VA::from_value(0x1000); diff --git a/libkernel/src/memory/proc_vm/address_space.rs b/libkernel/src/memory/address_space.rs similarity index 94% rename from libkernel/src/memory/proc_vm/address_space.rs rename to libkernel/src/memory/address_space.rs index 813d2d23..862f268c 100644 --- a/libkernel/src/memory/proc_vm/address_space.rs +++ b/libkernel/src/memory/address_space.rs @@ -1,4 +1,7 @@ //! Kernel and user address-space management. +//! +//! Available with the `address_space` feature, independently of process VMAs +//! and filesystems. use alloc::vec::Vec; @@ -14,6 +17,17 @@ use crate::{ sync::spinlock::SpinLockIrq, }; +/// Describes the kind of access that occurred during a page fault. +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum AccessKind { + /// The CPU attempted to read the faulting address. + Read, + /// The CPU attempted to write to the faulting address. + Write, + /// The CPU attempted to execute the instruction at the faulting address. + Execute, +} + /// An architecture-independent representation of a page table entry (PTE). pub struct PageInfo { /// The page frame number identifying the physical page. diff --git a/libkernel/src/memory/mod.rs b/libkernel/src/memory/mod.rs index 3fc8051f..62769a96 100644 --- a/libkernel/src/memory/mod.rs +++ b/libkernel/src/memory/mod.rs @@ -9,6 +9,8 @@ //! feature flags. pub mod address; +#[cfg(feature = "address_space")] +pub mod address_space; #[cfg(feature = "alloc")] pub mod allocators; #[cfg(feature = "alloc")] diff --git a/libkernel/src/memory/paging/permissions.rs b/libkernel/src/memory/paging/permissions.rs index b6af717e..f1f2baf6 100644 --- a/libkernel/src/memory/paging/permissions.rs +++ b/libkernel/src/memory/paging/permissions.rs @@ -2,9 +2,6 @@ use core::fmt; -#[cfg(feature = "proc_vm")] -use crate::memory::proc_vm::vmarea::VMAPermissions; - /// Represents the memory permissions for a virtual memory mapping. #[derive(Clone, Copy, PartialEq, Eq, Default)] pub struct PtePermissions { @@ -15,19 +12,6 @@ pub struct PtePermissions { cow: bool, } -#[cfg(feature = "proc_vm")] -impl From for PtePermissions { - fn from(value: VMAPermissions) -> Self { - Self { - read: value.read, - write: value.write, - execute: value.execute, - user: true, // VMAs only represent user address spaces. - cow: false, // a VMA will only be COW when it's cloned. - } - } -} - impl PtePermissions { /// Creates a new `PtePermissions` from its raw boolean components. /// diff --git a/libkernel/src/memory/proc_vm/memory_map/mod.rs b/libkernel/src/memory/proc_vm/memory_map/mod.rs index a80c5828..880528bd 100644 --- a/libkernel/src/memory/proc_vm/memory_map/mod.rs +++ b/libkernel/src/memory/proc_vm/memory_map/mod.rs @@ -1,14 +1,11 @@ //! Memory map management for a process address space. -use super::{ - address_space::UserAddressSpace, - vmarea::{VMAPermissions, VMArea, VMAreaKind}, -}; +use super::vmarea::{VMAPermissions, VMArea, VMAreaKind}; use crate::{ error::{KernelError, Result}, memory::{ - PAGE_MASK, PAGE_SIZE, address::VA, page::PageFrame, paging::permissions::PtePermissions, - region::VirtMemoryRegion, + PAGE_MASK, PAGE_SIZE, address::VA, address_space::UserAddressSpace, page::PageFrame, + paging::permissions::PtePermissions, region::VirtMemoryRegion, }, }; use alloc::{collections::BTreeMap, string::String, vec::Vec}; diff --git a/libkernel/src/memory/proc_vm/mod.rs b/libkernel/src/memory/proc_vm/mod.rs index 8e0c08d7..20fc8a3e 100644 --- a/libkernel/src/memory/proc_vm/mod.rs +++ b/libkernel/src/memory/proc_vm/mod.rs @@ -1,16 +1,15 @@ //! Manages the virtual memory address space of a process. -use super::{ - PAGE_SIZE, address::VA, proc_vm::address_space::UserAddressSpace, region::VirtMemoryRegion, +use super::{PAGE_SIZE, address::VA, address_space::UserAddressSpace, region::VirtMemoryRegion}; +use crate::{ + error::{KernelError, Result}, + memory::address_space::AccessKind, }; -use crate::error::{KernelError, Result}; use alloc::string::ToString; use memory_map::{AddressRequest, MemoryMap}; -use vmarea::{AccessKind, FaultValidation, VMAPermissions, VMArea, VMAreaKind}; +use vmarea::{FaultValidation, VMAPermissions, VMArea, VMAreaKind}; -pub mod address_space; pub mod memory_map; -pub mod pg_offset; pub mod vmarea; const BRK_PERMISSIONS: VMAPermissions = VMAPermissions::rw(); diff --git a/libkernel/src/memory/proc_vm/pg_offset.rs b/libkernel/src/memory/proc_vm/pg_offset.rs deleted file mode 100644 index ba876ee8..00000000 --- a/libkernel/src/memory/proc_vm/pg_offset.rs +++ /dev/null @@ -1,27 +0,0 @@ -//! Page-offset arithmetic helpers. - -pub(crate) use crate::memory::address::{AddressTranslator, TPA, TVA}; - -/// Translates between physical and virtual addresses using a fixed page-offset mapping. -pub struct PageOffsetTranslator; - -unsafe impl Send for PageOffsetTranslator {} -unsafe impl Sync for PageOffsetTranslator {} - -impl AddressTranslator for PageOffsetTranslator { - fn virt_to_phys(va: TVA) -> TPA { - let mut v = va.value(); - - v -= OFFSET; - - TPA::from_value(v) - } - - fn phys_to_virt(pa: TPA) -> TVA { - let mut v = pa.value(); - - v += OFFSET; - - TVA::from_value(v) - } -} diff --git a/libkernel/src/memory/proc_vm/vmarea.rs b/libkernel/src/memory/proc_vm/vmarea.rs index 322cd723..adbfa811 100644 --- a/libkernel/src/memory/proc_vm/vmarea.rs +++ b/libkernel/src/memory/proc_vm/vmarea.rs @@ -13,7 +13,10 @@ use core::cmp; use crate::{ fs::{Inode, InodeId}, - memory::{PAGE_MASK, PAGE_SIZE, address::VA, region::VirtMemoryRegion}, + memory::{ + PAGE_MASK, PAGE_SIZE, address::VA, address_space::AccessKind, + paging::permissions::PtePermissions, region::VirtMemoryRegion, + }, }; use alloc::string::{String, ToString}; use alloc::sync::Arc; @@ -63,15 +66,11 @@ impl VMAPermissions { } } -/// Describes the kind of access that occurred during a page fault. -#[derive(Clone, Copy, PartialEq, Eq)] -pub enum AccessKind { - /// The CPU attempted to read the faulting address. - Read, - /// The CPU attempted to write to the faulting address. - Write, - /// The CPU attempted to execute the instruction at the faulting address. - Execute, +impl From for PtePermissions { + fn from(value: VMAPermissions) -> Self { + // VMAs describe user mappings; CoW is applied separately when cloning. + Self::from_raw_bits(value.read, value.write, value.execute, true, false) + } } /// The result of checking a memory access against a `VMArea`. diff --git a/src/arch/arm64/boot/secondary.rs b/src/arch/arm64/boot/secondary.rs index 2940f1e8..9b0f50f9 100644 --- a/src/arch/arm64/boot/secondary.rs +++ b/src/arch/arm64/boot/secondary.rs @@ -29,8 +29,8 @@ use libkernel::{ error::{KernelError, Result}, memory::{ address::{PA, VA}, + address_space::{KernAddressSpace, VirtualMemory}, paging::permissions::PtePermissions, - proc_vm::address_space::{KernAddressSpace, VirtualMemory}, }, }; use log::{info, warn}; diff --git a/src/arch/arm64/exceptions/mod.rs b/src/arch/arm64/exceptions/mod.rs index 5d618319..bb333440 100644 --- a/src/arch/arm64/exceptions/mod.rs +++ b/src/arch/arm64/exceptions/mod.rs @@ -20,8 +20,8 @@ use libkernel::{ error::Result, memory::{ address::VA, + address_space::{KernAddressSpace, VirtualMemory}, paging::permissions::PtePermissions, - proc_vm::address_space::{KernAddressSpace, VirtualMemory}, region::{PhysMemoryRegion, VirtMemoryRegion}, }, }; diff --git a/src/arch/arm64/memory/address_space.rs b/src/arch/arm64/memory/address_space.rs index 74848bb5..c054e68e 100644 --- a/src/arch/arm64/memory/address_space.rs +++ b/src/arch/arm64/memory/address_space.rs @@ -20,12 +20,12 @@ use libkernel::{ memory::{ PAGE_SIZE, address::{TPA, VA}, + address_space::{PageInfo, UserAddressSpace}, page::PageFrame, paging::{ PaMapper, PageAllocator, PageTableEntry, PgTableArray, permissions::PtePermissions, tear_down::TeardownAction, walk::WalkContext, }, - proc_vm::address_space::{PageInfo, UserAddressSpace}, region::{PhysMemoryRegion, VirtMemoryRegion}, }, }; diff --git a/src/arch/arm64/memory/fault.rs b/src/arch/arm64/memory/fault.rs index 01f3a7a7..5726faa8 100644 --- a/src/arch/arm64/memory/fault.rs +++ b/src/arch/arm64/memory/fault.rs @@ -19,7 +19,7 @@ use libkernel::{ error::Result, memory::{ address::VA, - proc_vm::{address_space::UserAddressSpace, vmarea::AccessKind}, + address_space::{AccessKind, UserAddressSpace}, region::VirtMemoryRegion, }, }; diff --git a/src/arch/arm64/memory/mmu.rs b/src/arch/arm64/memory/mmu.rs index 9b841139..4a6341f8 100644 --- a/src/arch/arm64/memory/mmu.rs +++ b/src/arch/arm64/memory/mmu.rs @@ -9,8 +9,8 @@ use libkernel::{ error::Result, memory::{ address::{PA, TPA, VA}, + address_space::KernAddressSpace, paging::{PaMapper, PgTableArray, permissions::PtePermissions}, - proc_vm::address_space::KernAddressSpace, region::{PhysMemoryRegion, VirtMemoryRegion}, }, }; diff --git a/src/arch/arm64/mod.rs b/src/arch/arm64/mod.rs index ad3fa4d2..ca80f5d2 100644 --- a/src/arch/arm64/mod.rs +++ b/src/arch/arm64/mod.rs @@ -12,8 +12,8 @@ use libkernel::{ error::Result, memory::{ address::{UA, VA}, + address_space::VirtualMemory, paging::PgTableArray, - proc_vm::address_space::VirtualMemory, }, }; use memory::{ diff --git a/src/arch/arm64/proc/idle.rs b/src/arch/arm64/proc/idle.rs index 7c8eb690..71f59e57 100644 --- a/src/arch/arm64/proc/idle.rs +++ b/src/arch/arm64/proc/idle.rs @@ -6,11 +6,9 @@ use crate::{ use core::arch::global_asm; use libkernel::memory::{ address::VA, + address_space::{UserAddressSpace, VirtualMemory}, paging::permissions::PtePermissions, - proc_vm::{ - address_space::{UserAddressSpace, VirtualMemory}, - vmarea::{VMAPermissions, VMArea, VMAreaKind}, - }, + proc_vm::vmarea::{VMAPermissions, VMArea, VMAreaKind}, region::VirtMemoryRegion, }; diff --git a/src/arch/arm64/proc/vdso.rs b/src/arch/arm64/proc/vdso.rs index 4946a3a5..6027053c 100644 --- a/src/arch/arm64/proc/vdso.rs +++ b/src/arch/arm64/proc/vdso.rs @@ -3,8 +3,8 @@ use libkernel::{ error::Result, memory::{ address::VA, + address_space::{KernAddressSpace, VirtualMemory}, paging::permissions::PtePermissions, - proc_vm::address_space::{KernAddressSpace, VirtualMemory}, region::{PhysMemoryRegion, VirtMemoryRegion}, }, }; diff --git a/src/arch/mod.rs b/src/arch/mod.rs index 750e3df6..14347d8d 100644 --- a/src/arch/mod.rs +++ b/src/arch/mod.rs @@ -24,7 +24,7 @@ use libkernel::{ error::Result, memory::{ address::{UA, VA}, - proc_vm::address_space::VirtualMemory, + address_space::VirtualMemory, }, }; diff --git a/src/drivers/display/virtio.rs b/src/drivers/display/virtio.rs index 25fd4520..787eb11c 100644 --- a/src/drivers/display/virtio.rs +++ b/src/drivers/display/virtio.rs @@ -12,7 +12,7 @@ use crate::{ }; use alloc::{boxed::Box, sync::Arc}; use core::ptr::NonNull; -use libkernel::memory::proc_vm::address_space::{KernAddressSpace, VirtualMemory}; +use libkernel::memory::address_space::{KernAddressSpace, VirtualMemory}; use libkernel::{ error::{KernelError, ProbeError, Result}, memory::{ diff --git a/src/drivers/interrupts/arm_gic_v2.rs b/src/drivers/interrupts/arm_gic_v2.rs index 83645ab8..9cee60eb 100644 --- a/src/drivers/interrupts/arm_gic_v2.rs +++ b/src/drivers/interrupts/arm_gic_v2.rs @@ -6,7 +6,7 @@ use libkernel::{ error::{KernelError, Result}, memory::{ address::PA, - proc_vm::address_space::{KernAddressSpace, VirtualMemory}, + address_space::{KernAddressSpace, VirtualMemory}, region::PhysMemoryRegion, }, }; diff --git a/src/drivers/interrupts/arm_gic_v3.rs b/src/drivers/interrupts/arm_gic_v3.rs index efce5a9b..6b084b19 100644 --- a/src/drivers/interrupts/arm_gic_v3.rs +++ b/src/drivers/interrupts/arm_gic_v3.rs @@ -19,7 +19,7 @@ use libkernel::{ error::{KernelError, Result}, memory::{ address::{PA, VA}, - proc_vm::address_space::{KernAddressSpace, VirtualMemory}, + address_space::{KernAddressSpace, VirtualMemory}, region::PhysMemoryRegion, }, }; diff --git a/src/drivers/rng/virtio.rs b/src/drivers/rng/virtio.rs index 5b563752..a0263fb1 100644 --- a/src/drivers/rng/virtio.rs +++ b/src/drivers/rng/virtio.rs @@ -12,7 +12,7 @@ use crate::{ }; use alloc::{boxed::Box, sync::Arc}; use core::ptr::NonNull; -use libkernel::memory::proc_vm::address_space::{KernAddressSpace, VirtualMemory}; +use libkernel::memory::address_space::{KernAddressSpace, VirtualMemory}; use libkernel::{ error::{KernelError, ProbeError, Result}, memory::{ diff --git a/src/drivers/rtc/pl031.rs b/src/drivers/rtc/pl031.rs index 53010daa..9f5cdd81 100644 --- a/src/drivers/rtc/pl031.rs +++ b/src/drivers/rtc/pl031.rs @@ -9,7 +9,7 @@ use alloc::sync::Arc; use core::time::Duration; use libkernel::error::{ProbeError, Result}; use libkernel::memory::address::{PA, VA}; -use libkernel::memory::proc_vm::address_space::{KernAddressSpace, VirtualMemory}; +use libkernel::memory::address_space::{KernAddressSpace, VirtualMemory}; use libkernel::memory::region::PhysMemoryRegion; /// Driver for a PL031 real-time clock. diff --git a/src/drivers/uart/imx_lp.rs b/src/drivers/uart/imx_lp.rs index 89f68a60..aaa84026 100644 --- a/src/drivers/uart/imx_lp.rs +++ b/src/drivers/uart/imx_lp.rs @@ -15,7 +15,7 @@ use libkernel::{ error::Result, memory::{ address::{PA, VA}, - proc_vm::address_space::{KernAddressSpace, VirtualMemory}, + address_space::{KernAddressSpace, VirtualMemory}, region::PhysMemoryRegion, }, }; diff --git a/src/drivers/uart/pl011.rs b/src/drivers/uart/pl011.rs index 01ad7e8b..5590d830 100644 --- a/src/drivers/uart/pl011.rs +++ b/src/drivers/uart/pl011.rs @@ -16,7 +16,7 @@ use libkernel::{ error::{ProbeError, Result}, memory::{ address::{PA, VA}, - proc_vm::address_space::{KernAddressSpace, VirtualMemory}, + address_space::{KernAddressSpace, VirtualMemory}, region::PhysMemoryRegion, }, }; diff --git a/src/main.rs b/src/main.rs index 36422704..f7bf608a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ use libkernel::{ }, memory::{ address::{PA, VA}, - proc_vm::address_space::VirtualMemory, + address_space::VirtualMemory, region::PhysMemoryRegion, }, }; diff --git a/src/memory/fault.rs b/src/memory/fault.rs index a09a31b9..f27f6c79 100644 --- a/src/memory/fault.rs +++ b/src/memory/fault.rs @@ -5,11 +5,8 @@ use libkernel::{ error::{KernelError, MapError, Result}, memory::{ address::VA, + address_space::{AccessKind, PageInfo, UserAddressSpace}, paging::permissions::PtePermissions, - proc_vm::{ - address_space::{PageInfo, UserAddressSpace}, - vmarea::AccessKind, - }, }, }; diff --git a/src/memory/mincore.rs b/src/memory/mincore.rs index ff87a846..1bdd6d89 100644 --- a/src/memory/mincore.rs +++ b/src/memory/mincore.rs @@ -1,6 +1,6 @@ use alloc::vec; use alloc::vec::Vec; -use libkernel::memory::proc_vm::address_space::UserAddressSpace; +use libkernel::memory::address_space::UserAddressSpace; use crate::memory::uaccess::copy_to_user_slice; use crate::sched::syscall_ctx::ProcessCtx; diff --git a/src/memory/mod.rs b/src/memory/mod.rs index 4d5fb024..44aca297 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -19,7 +19,7 @@ pub mod process_vm; pub mod uaccess; pub type PageOffsetTranslator = - libkernel::memory::proc_vm::pg_offset::PageOffsetTranslator<{ ArchImpl::PAGE_OFFSET }>; + libkernel::memory::address::PageOffsetTranslator<{ ArchImpl::PAGE_OFFSET }>; // Initial memory allocator. Used for initial memory setup. const STATIC_REGION_COUNT: usize = 128; diff --git a/src/memory/process_vm.rs b/src/memory/process_vm.rs index 7e9def4e..b10d9ca5 100644 --- a/src/memory/process_vm.rs +++ b/src/memory/process_vm.rs @@ -8,7 +8,7 @@ use crate::process::{Tid, find_task_by_tid}; use crate::{fs::syscalls::iov::IoVec, process::thread_group::pid::PidT}; use libkernel::{ error::{KernelError, Result}, - memory::{PAGE_SIZE, address::TUA, proc_vm::vmarea::AccessKind}, + memory::{PAGE_SIZE, address::TUA, address_space::AccessKind}, }; pub async fn sys_process_vm_readv( diff --git a/src/process/exec.rs b/src/process/exec.rs index 61a1028a..0e87503d 100644 --- a/src/process/exec.rs +++ b/src/process/exec.rs @@ -16,7 +16,7 @@ use alloc::{string::String, vec}; use alloc::{string::ToString, sync::Arc, vec::Vec}; use auxv::{AT_BASE, AT_ENTRY, AT_NULL, AT_PAGESZ, AT_PHDR, AT_PHENT, AT_PHNUM, AT_RANDOM}; use core::{ffi::c_char, mem, slice}; -use libkernel::memory::proc_vm::address_space::{UserAddressSpace, VirtualMemory}; +use libkernel::memory::address_space::{UserAddressSpace, VirtualMemory}; use libkernel::{ error::{ExecError, KernelError, Result}, fs::{Inode, path::Path}, diff --git a/src/process/mod.rs b/src/process/mod.rs index ad671c7a..7b154140 100644 --- a/src/process/mod.rs +++ b/src/process/mod.rs @@ -19,14 +19,14 @@ use core::sync::atomic::{AtomicU32, AtomicUsize, Ordering}; use core::time::Duration; use creds::Credentials; use fd_table::FileDescriptorTable; -use libkernel::memory::proc_vm::address_space::{UserAddressSpace, VirtualMemory}; +use libkernel::memory::address_space::{AccessKind, UserAddressSpace, VirtualMemory}; use libkernel::{ error::{KernelError, Result}, fs::{Inode, pathbuf::PathBuf}, memory::{ address::{UA, VA}, allocators::phys::PageAllocation, - proc_vm::{ProcessVM, vmarea::AccessKind}, + proc_vm::ProcessVM, }, sync::waker_set::WakerSet, }; diff --git a/src/process/owned.rs b/src/process/owned.rs index 0508cd9e..c500c497 100644 --- a/src/process/owned.rs +++ b/src/process/owned.rs @@ -23,7 +23,8 @@ use libkernel::{ fs::pathbuf::PathBuf, memory::{ address::{TUA, VA}, - proc_vm::{ProcessVM, address_space::VirtualMemory, vmarea::VMArea}, + address_space::VirtualMemory, + proc_vm::{ProcessVM, vmarea::VMArea}, }, sync::waker_set::WakerSet, }; diff --git a/src/process/threading/futex/key.rs b/src/process/threading/futex/key.rs index 6e9bb7bd..aa96a708 100644 --- a/src/process/threading/futex/key.rs +++ b/src/process/threading/futex/key.rs @@ -1,7 +1,7 @@ use crate::sched::syscall_ctx::ProcessCtx; use libkernel::error::{KernelError, Result}; use libkernel::memory::address::{TUA, VA}; -use libkernel::memory::proc_vm::address_space::UserAddressSpace; +use libkernel::memory::address_space::UserAddressSpace; #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug)] pub enum FutexKey { From a7d031e7cdd6f734ed9d21fd661de56b1dc1b91f Mon Sep 17 00:00:00 2001 From: Matthew Leach Date: Sat, 10 Oct 2026 13:02:15 +0100 Subject: [PATCH 2/4] libkernel: cargo: fix unused import warnings Some dependencies are not needed for all imports. Make those imports optional and import them when needed to supress warnings. --- libkernel/Cargo.toml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libkernel/Cargo.toml b/libkernel/Cargo.toml index 95811619..a4bc775f 100644 --- a/libkernel/Cargo.toml +++ b/libkernel/Cargo.toml @@ -11,10 +11,10 @@ categories = ["no-std", "os", "embedded"] [features] default = [] -sync = [] +sync = ["dep:log"] alloc = ["sync", "dep:intrusive-collections"] paging = ["alloc", "dep:tock-registers", "dep:paste"] -proc = [] +proc = ["dep:bitflags"] address_space = ["paging"] fs = ["proc", "sync", "dep:async-trait", "dep:ext4plus"] proc_vm = ["address_space", "fs", "dep:object"] @@ -23,10 +23,14 @@ all = ["paging", "address_space", "fs", "proc_vm", "kbuf"] [dependencies] # Always-on dependencies -bitflags = { workspace = true } -log = { workspace = true } thiserror = { version = "2.0.12", default-features = false } +# sync +log = { workspace = true, optional = true } + +# proc +bitflags = { workspace = true, optional = true } + # alloc intrusive-collections = { version = "0.10.0", default-features = false, optional = true } From 1c43636bb354f8b89e0fb0069ef3baae2e23fa4f Mon Sep 17 00:00:00 2001 From: Matthew Leach Date: Sat, 10 Oct 2026 16:43:09 +0100 Subject: [PATCH 3/4] libkernel: fix clippy lint errors in tests Since we are now running clippy over the test code in CI, fix all issues identified. --- .../src/arch/arm64/memory/pg_tear_down.rs | 8 ++------ .../src/arch/x86_64/memory/pg_descriptors.rs | 3 +-- .../src/arch/x86_64/memory/pg_tear_down.rs | 16 ++++++---------- libkernel/src/fs/filesystems/fat32/bpb.rs | 4 ++-- libkernel/src/fs/filesystems/fat32/dir.rs | 4 ++-- libkernel/src/fs/filesystems/fat32/file.rs | 3 +-- libkernel/src/fs/filesystems/tmpfs.rs | 13 ++++++++----- libkernel/src/memory/allocators/phys.rs | 19 ++++++++----------- libkernel/src/memory/allocators/slab/heap.rs | 13 ++++++------- libkernel/src/memory/allocators/slab/slab.rs | 4 ++-- libkernel/src/memory/paging/permissions.rs | 4 ++-- .../src/memory/proc_vm/memory_map/tests.rs | 16 +++++++--------- libkernel/src/sync/condvar.rs | 2 +- libkernel/src/sync/per_cpu.rs | 7 +++---- 14 files changed, 51 insertions(+), 65 deletions(-) diff --git a/libkernel/src/arch/arm64/memory/pg_tear_down.rs b/libkernel/src/arch/arm64/memory/pg_tear_down.rs index 997973da..faa8df3d 100644 --- a/libkernel/src/arch/arm64/memory/pg_tear_down.rs +++ b/libkernel/src/arch/arm64/memory/pg_tear_down.rs @@ -216,10 +216,7 @@ mod tests { .insert(region.start_address().value(), region.size()) .is_some() { - panic!( - "Double free detected! Physical Address {:?} was freed twice.", - region - ); + panic!("Double free detected! Physical Address {region:?} was freed twice."); } }) .expect("Teardown failed"); @@ -479,8 +476,7 @@ mod tests { let slot = unsafe { (table_pa as *const u64).add(idx).read_volatile() }; assert_eq!( slot, 0, - "table frame {:#x} slot {idx} should be zeroed after FreeAndClear", - table_pa + "table frame {table_pa:#x} slot {idx} should be zeroed after FreeAndClear" ); } } diff --git a/libkernel/src/arch/x86_64/memory/pg_descriptors.rs b/libkernel/src/arch/x86_64/memory/pg_descriptors.rs index 659df8b3..4db2034c 100644 --- a/libkernel/src/arch/x86_64/memory/pg_descriptors.rs +++ b/libkernel/src/arch/x86_64/memory/pg_descriptors.rs @@ -535,8 +535,7 @@ mod tests { assert_eq!( d.as_raw() & (1 << 7), 0, - "PAT bit (7) must be clear on PTE for {:?}", - mt + "PAT bit (7) must be clear on PTE for {mt:?}" ); } } diff --git a/libkernel/src/arch/x86_64/memory/pg_tear_down.rs b/libkernel/src/arch/x86_64/memory/pg_tear_down.rs index 43f75387..292dd9f0 100644 --- a/libkernel/src/arch/x86_64/memory/pg_tear_down.rs +++ b/libkernel/src/arch/x86_64/memory/pg_tear_down.rs @@ -225,10 +225,7 @@ mod tests { .insert(region.start_address().value(), region.size()) .is_some() { - panic!( - "Double free detected! Physical Address {:?} was freed twice.", - region - ); + panic!("Double free detected! Physical Address {region:?} was freed twice."); } }) .expect("Teardown failed"); @@ -392,10 +389,10 @@ mod tests { harness.inner.root_table, &mut harness.inner.create_walk_ctx(), |entry| { - if let EntryKind::Mapping(virt) = &entry.kind { - if virt.start_address().value() >= (1usize << 47) { - return TeardownAction::Skip; - } + if let EntryKind::Mapping(virt) = &entry.kind + && virt.start_address().value() >= (1usize << 47) + { + return TeardownAction::Skip; } TeardownAction::Free }, @@ -534,8 +531,7 @@ mod tests { let slot = unsafe { (table_pa as *const u64).add(idx).read_volatile() }; assert_eq!( slot, 0, - "table frame {:#x} slot {idx} should be zeroed after FreeAndClear", - table_pa + "table frame {table_pa:#x} slot {idx} should be zeroed after FreeAndClear" ); } } diff --git a/libkernel/src/fs/filesystems/fat32/bpb.rs b/libkernel/src/fs/filesystems/fat32/bpb.rs index 71b409ad..53c86c34 100644 --- a/libkernel/src/fs/filesystems/fat32/bpb.rs +++ b/libkernel/src/fs/filesystems/fat32/bpb.rs @@ -250,7 +250,7 @@ pub mod test { let bpb = create_test_bpb(); // Clusters 0 and 1 are reserved and should not be converted to sectors. - assert!(matches!(bpb.cluster_to_sectors(Cluster(0)), Err(_))); - assert!(matches!(bpb.cluster_to_sectors(Cluster(1)), Err(_))); + assert!(bpb.cluster_to_sectors(Cluster(0)).is_err()); + assert!(bpb.cluster_to_sectors(Cluster(1)).is_err()); } } diff --git a/libkernel/src/fs/filesystems/fat32/dir.rs b/libkernel/src/fs/filesystems/fat32/dir.rs index dfb17f6d..0a140c27 100644 --- a/libkernel/src/fs/filesystems/fat32/dir.rs +++ b/libkernel/src/fs/filesystems/fat32/dir.rs @@ -493,7 +493,7 @@ mod test { utf16_chars.push(0x0000); // Null terminator // Pad to a multiple of 13 characters - while utf16_chars.len() % 13 != 0 { + while !utf16_chars.len().is_multiple_of(13) { utf16_chars.push(0xFFFF); } @@ -526,7 +526,7 @@ mod test { ptr::write_unaligned(&raw mut lfn.name3, chunk[11..13].try_into().unwrap()); } - lfn_entries.push(unsafe { core::mem::transmute(lfn) }); + lfn_entries.push(unsafe { core::mem::transmute::(lfn) }); } lfn_entries } diff --git a/libkernel/src/fs/filesystems/fat32/file.rs b/libkernel/src/fs/filesystems/fat32/file.rs index 079eeb1f..acfae426 100644 --- a/libkernel/src/fs/filesystems/fat32/file.rs +++ b/libkernel/src/fs/filesystems/fat32/file.rs @@ -116,8 +116,7 @@ pub mod test { fn iter_clusters(&self, root: Cluster) -> impl Iterator> { // Assume a simple contiguous chain for testing. - let num_clusters = - (self.file_data.len() + self.sectors_per_cluster - 1) / self.sectors_per_cluster; + let num_clusters = self.file_data.len().div_ceil(self.sectors_per_cluster); (0..num_clusters).map(move |i| Ok(Cluster((root.value() + i) as u32))) } } diff --git a/libkernel/src/fs/filesystems/tmpfs.rs b/libkernel/src/fs/filesystems/tmpfs.rs index 5a48787e..789595c4 100644 --- a/libkernel/src/fs/filesystems/tmpfs.rs +++ b/libkernel/src/fs/filesystems/tmpfs.rs @@ -869,6 +869,12 @@ mod tests { } } + /// The `TmpFs` instantiation used throughout these tests. + type TestTmpFs = TmpFs; + + /// The regular-file inode type matching [`TestTmpFs`]. + type TestTmpFsReg = TmpFsReg; + /// Initializes the global allocator for the test suite. fn init_allocator() { PG_ALLOC.get_or_init(|| { @@ -878,10 +884,7 @@ mod tests { } /// Creates a fresh Filesystem and a detached regular file for isolated file testing. - fn setup_env() -> ( - Arc>, - TmpFsReg, - ) { + fn setup_env() -> (Arc, TestTmpFsReg) { init_allocator(); let fs = TmpFs::new(0); let reg = TmpFsReg::new( @@ -893,7 +896,7 @@ mod tests { } /// Creates just the Filesystem to test directory hierarchies. - fn setup_fs() -> Arc> { + fn setup_fs() -> Arc { init_allocator(); TmpFs::new(1) } diff --git a/libkernel/src/memory/allocators/phys.rs b/libkernel/src/memory/allocators/phys.rs index e4a70416..9a61bd6a 100644 --- a/libkernel/src/memory/allocators/phys.rs +++ b/libkernel/src/memory/allocators/phys.rs @@ -615,14 +615,13 @@ pub mod tests { /// Checks that the number of blocks in each free list matches the expected counts. fn assert_free_list_counts(&self, expected_counts: &[usize; MAX_ORDER + 1]) { - for order in 0..=MAX_ORDER { + for (order, expected) in expected_counts.iter().enumerate() { let count = self.allocator.inner.lock_save_irq().free_lists[order] .iter() .count(); assert_eq!( - count, expected_counts[order], - "Mismatch in free list count for order {}", - order + count, *expected, + "Mismatch in free list count for order {order}" ); } } @@ -828,9 +827,7 @@ pub mod tests { // Splitting a MAX_ORDER block to get an order 0 page should leave // one free block at each intermediate order. let mut expected_counts = [0; MAX_ORDER + 1]; - for i in 0..MAX_ORDER { - expected_counts[i] = 1; - } + expected_counts[..MAX_ORDER].fill(1); fixture.assert_free_list_counts(&expected_counts); } @@ -845,7 +842,7 @@ pub mod tests { // Check head page match fixture.frame_state(head_region.region.iter_pfns().next().unwrap()) { - FrameState::AllocatedHead(info) => assert_eq!(info.order, order as u8), + FrameState::AllocatedHead(info) => assert_eq!(info.order, order), _ => panic!("Head page has incorrect state"), } @@ -853,9 +850,9 @@ pub mod tests { for (i, pfn) in head_region.region.iter_pfns().skip(1).enumerate() { match fixture.frame_state(pfn) { FrameState::AllocatedTail(info) => { - assert_eq!(info.head, head_region.region.start_address().to_pfn()) + assert_eq!(info.head, head_region.region.start_address().to_pfn()); } - _ => panic!("Tail page {} has incorrect state", i), + _ => panic!("Tail page {i} has incorrect state"), } } } @@ -888,7 +885,7 @@ pub mod tests { for _ in 0..total_pages { match fixture.allocator.alloc_frames(0) { Ok(pfn) => allocs.push(pfn), - Err(e) => panic!("Allocation failed prematurely: {:?}", e), + Err(e) => panic!("Allocation failed prematurely: {e:?}"), } } diff --git a/libkernel/src/memory/allocators/slab/heap.rs b/libkernel/src/memory/allocators/slab/heap.rs index 451b101a..62452380 100644 --- a/libkernel/src/memory/allocators/slab/heap.rs +++ b/libkernel/src/memory/allocators/slab/heap.rs @@ -225,7 +225,7 @@ mod tests { } thread_local! { - static TLS_CACHE: RefCell> = RefCell::new(None); + static TLS_CACHE: RefCell> = const { RefCell::new(None) }; } struct ThreadLocalCacheStorage; @@ -254,7 +254,7 @@ mod tests { }); } - fn get() -> impl Deref + DerefMut { + fn get() -> impl DerefMut { let ptr = TLS_CACHE.with(|c| { c.borrow() .expect("Thread cache not initialized for this thread") @@ -283,7 +283,7 @@ mod tests { // Track allocated memory usage to verify leak detection later let initial_free_pages = get_fixture().allocator.free_pages(); - println!("Initial Free Pages: {}", initial_free_pages); + println!("Initial Free Pages: {initial_free_pages}"); let mut handles = vec![]; @@ -338,8 +338,7 @@ mod tests { for (i, &byte) in slice.iter().enumerate() { assert_eq!( byte, pattern, - "Memory Corruption detected in thread {} at byte {}", - t_idx, i + "Memory Corruption detected in thread {t_idx} at byte {i}" ); } @@ -361,7 +360,7 @@ mod tests { // Purge the per-cpu caches. let slab = SLAB_ALLOCATOR.get().unwrap(); - ThreadLocalCacheStorage::get().purge_into(&slab); + ThreadLocalCacheStorage::get().purge_into(slab); let addr = ThreadLocalCacheStorage::get().deref() as *const SlabCache; @@ -376,7 +375,7 @@ mod tests { PAGE_SIZE, )); } - })) + })); } // Wait for all threads diff --git a/libkernel/src/memory/allocators/slab/slab.rs b/libkernel/src/memory/allocators/slab/slab.rs index 76d33434..6b36a673 100644 --- a/libkernel/src/memory/allocators/slab/slab.rs +++ b/libkernel/src/memory/allocators/slab/slab.rs @@ -310,9 +310,9 @@ mod tests { ptrs.retain(|(i, ptr)| { if i % 2 == 0 { slab.put_object(*ptr); - return false; + false } else { - return true; + true } }); diff --git a/libkernel/src/memory/paging/permissions.rs b/libkernel/src/memory/paging/permissions.rs index f1f2baf6..f59b670b 100644 --- a/libkernel/src/memory/paging/permissions.rs +++ b/libkernel/src/memory/paging/permissions.rs @@ -266,9 +266,9 @@ mod tests { assert_eq!(format!("{}", PtePermissions::rx(false)), "r-x k"); let cow_perms = PtePermissions::rw(true).into_cow(); - assert_eq!(format!("{}", cow_perms), "rc- u"); + assert_eq!(format!("{cow_perms}"), "rc- u"); let cow_exec_perms = PtePermissions::rwx(false).into_cow(); - assert_eq!(format!("{}", cow_exec_perms), "rcx k"); + assert_eq!(format!("{cow_exec_perms}"), "rcx k"); } } diff --git a/libkernel/src/memory/proc_vm/memory_map/tests.rs b/libkernel/src/memory/proc_vm/memory_map/tests.rs index 52e493ac..bad609e3 100644 --- a/libkernel/src/memory/proc_vm/memory_map/tests.rs +++ b/libkernel/src/memory/proc_vm/memory_map/tests.rs @@ -5,10 +5,10 @@ use crate::{ memory::{ PAGE_SIZE, address::VA, + address_space::{PageInfo, UserAddressSpace}, page::PageFrame, paging::permissions::PtePermissions, proc_vm::{ - address_space::{PageInfo, UserAddressSpace}, memory_map::{AddressRequest, MMAP_BASE}, vmarea::{VMAPermissions, VMArea, VMAreaKind, VMFileMapping, tests::DummyTestInode}, }, @@ -160,8 +160,7 @@ fn assert_vma_perms(pvm: &MemoryMap, start: usize, perms: VMAP assert_eq!( vma.permissions(), perms, - "VMA permissions mismatch at {:#x}", - start + "VMA permissions mismatch at {start:#x}" ); } @@ -179,8 +178,7 @@ fn assert_ops_log_protect( }); assert!( found, - "Did not find ProtectRange op for {:?} with {:?}", - expected_region, expected_perms + "Did not find ProtectRange op for {expected_region:?} with {expected_perms:?}" ); } @@ -613,7 +611,7 @@ fn test_munmap_full_vma() { assert!(pvm.vmas.is_empty()); assert_eq!( *pvm.address_space.ops_log.lock().unwrap(), - &[MockPageTableOp::UnmapRange { region: region }] + &[MockPageTableOp::UnmapRange { region }] ); } @@ -635,7 +633,7 @@ fn test_munmap_truncate_start() { assert_vma_exists(&pvm, new_start, new_size); assert_eq!( *pvm.address_space.ops_log.lock().unwrap(), - &[MockPageTableOp::UnmapRange { region: region }] + &[MockPageTableOp::UnmapRange { region }] ); } @@ -656,7 +654,7 @@ fn test_munmap_truncate_end() { assert_vma_exists(&pvm, addr, new_size); assert_eq!( *pvm.address_space.ops_log.lock().unwrap(), - &[MockPageTableOp::UnmapRange { region: region }] + &[MockPageTableOp::UnmapRange { region }] ); } @@ -682,7 +680,7 @@ fn test_munmap_punch_hole() { assert_vma_exists(&pvm, right_start, right_size); assert_eq!( *pvm.address_space.ops_log.lock().unwrap(), - &[MockPageTableOp::UnmapRange { region: region }] + &[MockPageTableOp::UnmapRange { region }] ); } diff --git a/libkernel/src/sync/condvar.rs b/libkernel/src/sync/condvar.rs index b3cc3604..6c92806f 100644 --- a/libkernel/src/sync/condvar.rs +++ b/libkernel/src/sync/condvar.rs @@ -207,7 +207,7 @@ mod condvar_tests { tokio::spawn(async move { condvar .wait_until(|state| if state.counter == 1 { Some(()) } else { None }) - .await + .await; }) }; diff --git a/libkernel/src/sync/per_cpu.rs b/libkernel/src/sync/per_cpu.rs index 70f8496b..c11130de 100644 --- a/libkernel/src/sync/per_cpu.rs +++ b/libkernel/src/sync/per_cpu.rs @@ -310,7 +310,7 @@ mod tests { use std::thread; thread_local! { - static MOCK_CPU_ID: Cell = Cell::new(0); + static MOCK_CPU_ID: Cell = const { Cell::new(0) }; } struct MockArch; @@ -446,8 +446,7 @@ mod tests { let expected_final_val = initial_val + ITERATIONS_PER_THREAD; assert_eq!( final_val, expected_final_val, - "Incorrect final value on CPU {}", - i + "Incorrect final value on CPU {i}" ); }); handles.push(handle); @@ -461,7 +460,7 @@ mod tests { // Optional: Final sanity check from the main thread (acting as CPU 0) // to ensure its value was not corrupted by the other threads. MOCK_CPU_ID.with(|id| id.set(0)); - let expected_val_for_cpu0 = 0 * 100_000 + ITERATIONS_PER_THREAD; + let expected_val_for_cpu0 = ITERATIONS_PER_THREAD; assert_eq!(*per_cpu_data.borrow(), expected_val_for_cpu0); } } From 241a61ef3ede4754ffbc47a0048edb4e4f7af88f Mon Sep 17 00:00:00 2001 From: Matthew Leach Date: Sat, 10 Oct 2026 16:46:48 +0100 Subject: [PATCH 4/4] usertests: cargo: fix lint inherit warning Fix a warning related to inheriting the `lint.workspace` option in usertests. --- Cargo.toml | 1 - usertest/Cargo.toml | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a2645316..4d9e820c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,4 +62,3 @@ codegen-units = 1 [lints] workspace = true - diff --git a/usertest/Cargo.toml b/usertest/Cargo.toml index 21a7f478..a0daf5c0 100644 --- a/usertest/Cargo.toml +++ b/usertest/Cargo.toml @@ -8,3 +8,6 @@ colored = "3" inventory = "0.3" libc = "0.2" parking_lot = "0.12" + +[lints] +workspace = true