remap_pfn_range(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… remap_pfn_range β€” like, the kernel-memory-to-userspace glow-up

Okay bestie, welcome to the Kernel API Manual ✨ β€” this one's called remap_pfn_range(9) and it's literally the function that hands kernel memory over to userspace. Main character energy fr fr 🫢


🌸 NAME

remap_pfn_range β€” remap kernel memory to userspace πŸ’«


✨ SYNOPSIS

int remap_pfn_range (struct vm_area_struct *vma , unsigned long addr ,
       unsigned long pfn , unsigned long size , pgprot_t prot );

That's the whole vibe check right there πŸ‘† five args, no notes.


πŸŽ€ ARGUMENTS

  • vma β€” the user vma you're mapping into, i.e. the userspace side of the situationship πŸ¦‹
  • addr β€” the target, page-aligned user address where the mapping starts. Page-aligned, bestie, don't play with me πŸ™ˆ
  • pfn β€” page frame number of the kernel physical memory address πŸ‘‘
  • size β€” how big the mapping area is 🌈
  • prot β€” page protection flags for this mapping, aka the outfit it wears πŸ’…

πŸ’€ NOTE

This is only safe if the mm semaphore is held when it's called. Not "probably fine", not "we'll see" β€” held. Do not come for me if you skip this, I warned you 😭

⭐ RETURN

  • 0 on success πŸŽ‰
  • a negative error code otherwise πŸ’”

πŸ”₯ SEE ALSO

Kernel file ./mm/memory.c β€” and honestly the whole extended friend group:


okayyy that's the whole page, you ate that πŸ’– This one ships out of ./mm and is dated October 2026 β€” so go forth, remap responsibly, and keep that mm semaphore held, iykyk πŸ§šπŸ“

πŸ“¦ where this page comes from