Repository navigation
Conversation
…and safe user copy
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9944810a2f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let mut rollback = start; | ||
| while rollback < mapped_until { | ||
| let _ = self.arch.unmap_4k(VirtAddr::new(rollback)); | ||
| rollback += PAGE_SIZE as u64; | ||
| } |
There was a problem hiding this comment.
Reclaim newly allocated page tables during OOM rollback
When frame allocation fails while mapping a region, this rollback frees only leaf frames: unmap_4k leaves intermediate tables allocated, and map_4k_in_root also retains tables created before the failing allocation. For example, with three free frames and an unused PML4 slot, the first page consumes a data frame and two table frames before failing to allocate the final table; the data frame is returned, but both table frames remain despite map_region returning ENOMEM without adding a VMA. This violates the advertised strong rollback guarantee and retains scarce physical memory until the entire address space is dropped. Track and reclaim newly created empty tables, including those on the page whose mapping failed.
Useful? React with 👍 / 👎.
Summary
Rebuilds kernel physical & virtual memory management into a clean three-layer Rust OS architecture, removing
OffsetPageTable,x86_64::FrameAllocator,'staticpage-table lifetime hacks, memory leaks on address-space teardown, and unchecked user pointers:1. RAII Physical Frames (
src/memory/frame.rs,bitmap.rs,mod.rs)src/memorycompletely fromx86_64traits (removing#[cfg(target_arch = "x86_64")]onpub mod memoryinmain.rs).OwnedFrame(alloc,alloc_zeroed,as_slice,as_mut_slice,into_raw,from_raw) that automatically returns physical pages toFRAME_ALLOCATORonDropunless transferred into a hardware PTE.2. Thin Hardware Page Table (
src/arch/x86_64/paging.rs,allocator.rs,start.rs)OffsetPageTable/Mapper/Translate/MapperFlushwithArchPageTableoperating directly overPAGE_OFFSET_BASEwithout forging&'static mut PageTablereferences.PML4[384..480]slots at boot (paging::init()) and marks kernel leaf PTEsGLOBAL, ensuring dynamic kernel heap, stack, and MMIO mappings are permanently synchronized across all processes.ArchPageTable::Dropover userPML4[0..256](freeing all leaf data frames andL1..=L4page-table frames in one pass).arch/x86_64/allocator.rs(init_heap) andKernelStack::allocto a singlepaging::map_kernel_range(...)call.3. VMA-Backed
AddressSpace, W^Xexec, & Safe User Memory Copy (address_space.rs,process.rs,syscall/)MapPerm(R | W | X | U),VmArea/VmAreaKind, andBTreeMap-backedAddressSpacewithO(log N)overlap checks, unmapped null-page guard (USER_SPACE_MIN = 0x1000), and strong OOM rollback guarantees inmap_region.Process::exec(.rodata->R,.text->R | X,.data/.bss& stack ->R | W) with atomicself.vm = new_vmswap-and-drop semantics.slice::from_raw_parts/from_raw_parts_mutinsrc/syscall.rsandsrc/syscall/fs.rswithvalidate_user_range,copy_from_user, andcopy_to_user(enforcingMapPerm::U | R/Wand returningEFAULT/ENAMETOOLONGinstead of panicking or exposing kernel memory).Verification
make build(dev&release)AddressSpacecreation, multi-VMA mapping, cross-pagecopy_to_user/copy_from_user,EEXISToverlap checks, W^X read-onlyEFAULTrejection, null/kernel-pointerEFAULTrejection, andDropteardown (free_framesbefore == after)debug&release) and verified Ring 3/initinteractive shell execution