1mmap(2)                       System Calls Manual                      mmap(2)
2
3
4

NAME

6       mmap, munmap - map or unmap files or devices into memory
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <sys/mman.h>
13
14       void *mmap(void addr[.length], size_t length, int prot, int flags,
15                  int fd, off_t offset);
16       int munmap(void addr[.length], size_t length);
17
18       See NOTES for information on feature test macro requirements.
19

DESCRIPTION

21       mmap()  creates a new mapping in the virtual address space of the call‐
22       ing process.  The starting address for the new mapping is specified  in
23       addr.   The  length argument specifies the length of the mapping (which
24       must be greater than 0).
25
26       If addr is NULL, then the kernel chooses the (page-aligned) address  at
27       which to create the mapping; this is the most portable method of creat‐
28       ing a new mapping.  If addr is not NULL, then the kernel takes it as  a
29       hint about where to place the mapping; on Linux, the kernel will pick a
30       nearby page boundary (but always above or equal to the value  specified
31       by /proc/sys/vm/mmap_min_addr) and attempt to create the mapping there.
32       If another mapping already exists there, the kernel picks a new address
33       that may or may not depend on the hint.  The address of the new mapping
34       is returned as the result of the call.
35
36       The contents of a file mapping (as opposed to an anonymous mapping; see
37       MAP_ANONYMOUS  below),  are  initialized using length bytes starting at
38       offset offset in the file (or other object) referred to by the file de‐
39       scriptor fd.  offset must be a multiple of the page size as returned by
40       sysconf(_SC_PAGE_SIZE).
41
42       After the mmap() call has returned, the file  descriptor,  fd,  can  be
43       closed immediately without invalidating the mapping.
44
45       The  prot  argument describes the desired memory protection of the map‐
46       ping (and must not conflict with the open mode of the file).  It is ei‐
47       ther PROT_NONE or the bitwise OR of one or more of the following flags:
48
49       PROT_EXEC  Pages may be executed.
50
51       PROT_READ  Pages may be read.
52
53       PROT_WRITE Pages may be written.
54
55       PROT_NONE  Pages may not be accessed.
56
57   The flags argument
58       The  flags argument determines whether updates to the mapping are visi‐
59       ble to other processes mapping the same region, and whether updates are
60       carried through to the underlying file.  This behavior is determined by
61       including exactly one of the following values in flags:
62
63       MAP_SHARED
64              Share this mapping.  Updates to the mapping are visible to other
65              processes  mapping  the  same  region, and (in the case of file-
66              backed m