mmap_address_hint_valid(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 with MAP_FIXED the behaviour is different. the request with addr < 47-bit and addr + 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