mmap_address_hint_valid(9)
π mmap_address_hint_valid(9) β a page from the Kernel API Manual, bestie
okay so picture this: you're deep in kernel-land, somebody hands you an address hint, and you need to know if it's actually valid. that's the whole gig. this is mmap_address_hint_valid, and honestly it's giving "small function, big drama" energy π
β¨ SYNOPSIS β¨
bool mmap_address_hint_valid (unsigned long addr , unsigned long len );
like, it returns a bool. yes or no. valid or not. periodt π
πΈ ARGUMENTS πΈ
addrβ the address hint. the suggestion. the "hey maybe put it here?" of it all π«Άlenβ the mapping length. how much space we're talking about.
π DESCRIPTION π
so what it does is check whether addr and addr + len result in a valid mapping. simple enough, right? bestie, it gets so much juicier π
on 32bit β it's chill. this only checks whether addr + len is <= TASK_SIZE. that's it. that's the whole vibe check.
on 64bit with 5-level page tables β okay so HERE'S where it gets unhinged. another sanity check is required, because mappings requested by mmap(addr, 0) which cross the 47-bit virtual address boundary can cause the following theoretical issue:
An application calls mmap(addr, 0), i.e. without MAP_FIXED, where addr is below the border of the 47-bit address space and addr + len is above the border.
With 4-level paging this request succeeds, but the resulting mapping address will always be within the 47-bit virtual address space, because the hint address does not result in a valid mapping and is ignored. Hence applications which are not prepared to handle virtual addresses above 47-bit work correctly. slay for backwards compat honestly π₯
With 5-level paging this request would be granted and result in a mapping which crosses the border of the 47-bit virtual address space. and if the application cannot handle addresses above 47-bit this will lead to misbehaviour and hard to diagnose failures. hard to diagnose failures ππ like the worst kind. the "why is this crashing, nothing is wrong" kind.
Therefore ignore address hints which would result in a mapping crossing the 47-bit virtual address boundary. we simply do not engage β
β οΈ note, that in the same scenario withMAP_FIXEDthe behaviour is different. the request withaddr< 47-bit andaddr + len> 47-bit fails on a 4-level paging machine but succeeds on a 5-level paging machine. It is reasonable to expect that an application does not rely on the failure of such a fixed mapping request, so the restriction is not applied. iykyk π§
π¦ SEE ALSO π¦
- Kernel file
./arch/x86/mm/mmap.cβ go read it, it's literally right there, you're gonna love her π
and that's the whole page, bestie! this lil gem lives in the ./arch/x86/mm directory, dated October 2026, and it's page mmap_address_hint_valid(9) of the Kernel API Manual. go be iconic with your address hints πβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms