NAME |LIBRARY |SYNOPSIS |DESCRIPTION |RETURN VALUE |ERRORS |VERSIONS |STANDARDS |HISTORY |SEE ALSO |COLOPHON | |
mmap2(2) System Calls Manualmmap2(2)mmap2 - map files or devices into memory
Standard C library (libc,-lc)
#include <sys/mman.h>/* Definition ofMAP_*andPROT_*constants */#include <sys/syscall.h>/* Definition ofSYS_*constants */#include <unistd.h>void *syscall(SYS_mmap2, unsigned longaddr, unsigned longlength,unsigned longprot, unsigned longflags,unsigned longfd, unsigned longpgoffset);
This is probably not the system call that you are interested in; instead, seemmap(2), which describes the glibc wrapper function that invokes this system call. Themmap2() system call provides the same interface asmmap(2), except that the final argument specifies the offset into the file in 4096-byte units (instead of bytes, as is done bymmap(2)). This enables applications that use a 32-bitoff_t to map large files (up to 2^44 bytes).
On success,mmap2() returns a pointer to the mapped area. On error, -1 is returned anderrno is set to indicate the error.
EFAULTProblem with getting the data from user space.EINVAL(Various platforms where the page size is not 4096 bytes.)offset * 4096 is not a multiple of the system page size.mmap2() can also return any of the errors described inmmap(2).
On architectures where this system call is present, the glibcmmap() wrapper function invokes this system call rather than themmap(2) system call. This system call does not exist on x86-64. On ia64, the unit foroffset is actually the system page size, rather than 4096 bytes.
Linux.
Linux 2.3.31.
getpagesize(2),mmap(2),mremap(2),msync(2),shm_open(3)
This page is part of theman-pages (Linux kernel and C library user-space interface documentation) project. Information about the project can be found at ⟨https://www.kernel.org/doc/man-pages/⟩. If you have a bug report for this manual page, see ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩. This page was obtained from the tarball man-pages-6.15.tar.gz fetched from ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on 2025-08-11. If you discover any rendering problems in this HTML version of the page, or you believe there is a better or more up- to-date source for the page, or you have corrections or improvements to the information in this COLOPHON (which isnot part of the original manual page), send a mail to man-pages@man7.orgLinux man-pages 6.15 2025-05-17mmap2(2)Pages that refer to this page:mmap(2), remap_file_pages(2), syscalls(2)
HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface. For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere. Hosting byjambit GmbH. | ![]() |