mmap2(2)
π mmap2 β map files or devices into memory π
okay bestie, settle in, because we're reading the mmap2(2) page from the System Calls Manual. yes, section 2, the syscalls section, we're being β¨feralβ¨ today.
π LIBRARY
Standard C library (libc, -lc) β the usual queen.
π SYNOPSIS
#include <sys/mman.h> /* Definition of MAP_* and PROT_* constants */
#include <sys/syscall.h> /* Definition of SYS_* constants */
#include <unistd.h>
void *syscall(SYS_mmap2, unsigned long addr, unsigned long length,
unsigned long prot, unsigned long flags,
unsigned long fd, unsigned long pgoffset);
π«Ά DESCRIPTION
okay so real talk before anything else: this is probably not the system call that you are interested in π go look at mmap(2) instead, because that's where the glibc wrapper function lives, and that wrapper is the one actually calling this system call. iykyk.
so what does mmap2() even DO. it gives you the exact same interface as mmap(2), no cap, except the final argument doesn't count the offset into the file in bytes like mmap(2) does β it counts it in 4096-byte units. slay. and why do we care? because this is what lets applications that are stuck using a 32-bit off_t still map large files, up to 2^44 bytes. iconic behavior honestly.
β RETURN VALUE
- on success,
mmap2()hands you back a pointer to the mapped area π - on error, it returns
-1anderrnogets set to tell you what went wrong. rude but informative.
π ERRORS
EFAULTβ there was a problem with getting the data from user space. not me, not you, just the data. πEINVALβ (various platforms where the page size is not 4096 bytes.)offset * 4096is not a multiple of the system page size. the math just did NOT math on those platforms bestie.- and honestly?
mmap2()can also return any of the errors described inmmap(2). so go read that too.
π¦ VERSIONS
- on architectures where this system call is present, the glibc
mmap()wrapper function invokes this system call rather than themmap(2)system call. she's the understudy that's actually on stage every night. - this system call does not exist on x86-64. periodt. it's simply not invited to that party.
- on
ia64, the unit foroffsetis actually the system page size, rather than 4096 bytes. plot twist π different unit, same energy.
π STANDARDS
Linux. that's it, that's the whole vibe.
π HISTORY
Linux 2.3.31. a legend from the archives.
πΈ SEE ALSO
getpagesize(2), mmap(2), mremap(2), msync(2), shm_open(3)
and that's the whole page bestie π«Ά this little masterpiece came to you from Linux man-pages 6.20, dated 2026-02-08, starring mmap2(2) in the leading role πβ¨ go read mmap(2) now fr fr π
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 2002, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms