Repository navigation
protos/limine: read the memory map count after the snapshot alloc - #688
Merged
Merged
Conversation
…cation Assisted-by: Antigravity:gemini-4-argon Signed-off-by: hotline1337 <denuvo@tuta.io>
Member
|
LGTM, thanks! |
|
Thanks! |
nil0ft
pushed a commit
to SlopLabs/slopos
that referenced
this pull request
Oct 6, 2026
PR #688 asks memmap_entries + 2 where the tested patch asks + 1. +2 is the bound: a usable entry across 4 GiB splits in three. On the laptop both ask for one page at one address, so the tested boot stands for #688. With the split forced under QEMU, 12.9.1 drops the top entry and both diffs keep it. Refs Limine-Bootloader/Limine#687, Limine-Bootloader/Limine#688
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
build_pagemap()andbuild_identity_map()incommon/protos/limine.creadmemmap_entriesafter the snapshot allocation instead of before it.Background & Problem
Both pagemap builders take a private copy of the memory map before mapping it into the higher half direct map:
ext_mem_alloc()serves allocations from the top of a usable entry (common/mm/pmm.s2.c, trying below 4 GiB first on x86). Reserving that range appends a newMEMMAP_BOOTLOADER_RECLAIMABLEentry to the map (pmm_new_entry()), andpmm_sanitise_entries()then sorts and merges. When the new entry cannot merge with a same-type neighbour,memmap_entriesgrows by 1 - but the copy loop is still bounded by the count read before the allocation. The entries at the end of the freshly sorted map are silently dropped, and whatever they describe is never mapped into the HHDM (nor seen by the framebuffer mapping loop, which walks the same copy inbuild_pagemap()).As reported in #687: on a Lenovo V15 G4 IRU (UEFI, GOP framebuffer 1920x1080 at
0x4000000000, the highest memory map entry) the dropped entry is the framebuffer: the kernel's first write to the screen through the HHDM faults before it has installed an IDT, and the machine hangs on a black screen. Opening the entry in the menu editor first works around it - the editor keeps a 4 KiB buffer around, shifting later allocations down by a page so that this one merges and the map does not grow.The reporter verified the same code in 12.3.1, 12.5.2, 12.7.0, 12.8.0, 12.9.1, and trunk (
bc8b9536). QEMU does not reproduce it (with 1 to 8 GiB of RAM the allocation always merged): it takes both a splitting allocation and a highest entry the HHDM has to map, and on most machines the top of the map is reserved MMIO, which the HHDM leaves out.Changes
common/protos/limine.c, in both builders: allocatememmap_entries + 2entries and read_memmap_entriesafter the allocation, so the copy reflects the map as it exists after its own allocation.ext_mem_alloc()boils down to onepmm_new_entry()call, which appends the allocation entry itself, plus at most one split remainder - the latter only in the x86 case where the chosen usable entry spans the 4 GiB boundary and the allocation is clipped to the below-4-GiB limit (the "nested" case inpmm_new_entry()). Merging can only shrink the count, so +2 covers the provable worst case.AI assistance disclosure
The fix itself was created with material AI help (gemini-4-argon), and the commit carries the corresponding
Assisted-by:trailer.Fixes #687