7
8 SYNOPSIS
9 #include <sys/mman.h>
10
11 void *mmap(void *addr, size_t len, int prot, int flags,
12 int fildes, off_t off);
13
14
15 DESCRIPTION
16 The mmap() function establishes a mapping between a process's address
17 space and a file or shared memory object. The format of the call is as
18 follows:
19
20
21 pa = mmap(addr, len, prot, flags, fildes, off);
22
23
24 The mmap() function establishes a mapping between the address space of
25 the process at an address pa for len bytes to the memory object
26 represented by the file descriptor fildes at offset off for len bytes.
27 The value of pa is a function of the addr argument and values of
28 flags, further described below. A successful mmap() call returns pa as
29 its result. The address range starting at pa and continuing for len
30 bytes will be legitimate for the possible (not necessarily current)
31 address space of the process. The range of bytes starting at off and
32 continuing for len bytes will be legitimate for the possible (not
33 necessarily current) offsets in the file or shared memory object
34 represented by fildes.
35
36
37 The mmap() function allows [pa, pa + len) to extend beyond the end of
38 the object both at the time of the mmap() and while the mapping
39 persists, such as when the file is created prior to the mmap() call and
40 has no contents, or when the file is truncated. Any reference to
41 addresses beyond the end of the object, however, will result in the
42 delivery of a SIGBUS or SIGSEGV signal. The mmap() function cannot be
43 used to implicitly extend the length of files.
44
45
46 The mapping established by mmap() replaces any previous mappings for
47 those whole pages containing any part of the address space of the
48 process starting at pa and continuing for len bytes.
49
50
51 If the size of the mapped file changes after the call to mmap() as a
52 result of some other operation on the mapped file, the effect of
53 references to portions of the mapped region that correspond to added or
54 removed portions of the file is unspecified.
81
82
83
84 If an implementation of mmap() for a specific platform cannot support
85 the combination of access types specified by prot, the call to mmap()
86 fails. An implementation may permit accesses other than those specified
87 by prot; however, the implementation will not permit a write to succeed
88 where PROT_WRITE has not been set or permit any access where PROT_NONE
89 alone has been set. Each platform-specific implementation of mmap()
90 supports the following values of prot: PROT_NONE, PROT_READ,
91 PROT_WRITE, and the inclusive OR of PROT_READ and PROT_WRITE. On some
92 platforms, the PROT_WRITE protection option is implemented as
93 PROT_READ|PROT_WRITE and PROT_EXEC as PROT_READ|PROT_EXEC. The file
94 descriptor fildes is opened with read permission, regardless of the
95 protection options specified. If PROT_WRITE is specified, the
96 application must have opened the file descriptor fildes with write
97 permission unless MAP_PRIVATE is specified in the flags argument as
98 described below.
99
100
101 The flags argument provides other information about the handling of
102 the mapped data. The value of flags is the bitwise inclusive OR of
103 these options, defined in <sys/mman.h>:
104
105 MAP_SHARED
106 Changes are shared.
107
108
109 MAP_PRIVATE
110 Changes are private.
111
112
113 MAP_FIXED
114 Interpret addr exactly.
115
116
117 MAP_NORESERVE
118 Do not reserve swap space.
119
120
121 MAP_ANON
122 Map anonymous memory.
123
601
602
603
604
605 +--------------------+-------------------+
606 | ATTRIBUTE TYPE | ATTRIBUTE VALUE |
607 +--------------------+-------------------+
608 |Interface Stability | Standard |
609 +--------------------+-------------------+
610 |MT-Level | Async-Signal-Safe |
611 +--------------------+-------------------+
612
613 SEE ALSO
614 close(2), exec(2), fcntl(2), fork(2), getrlimit(2), memcntl(2),
615 mmapobj(2), mprotect(2), munmap(2), shmat(2), lockf(3C), mlockall(3C),
616 msync(3C), plock(3C), sysconf(3C), attributes(5), lf64(5),
617 standards(5), null(7D), zero(7D)
618
619
620
621 August 29, 2016 MMAP(2)
|
7
8 SYNOPSIS
9 #include <sys/mman.h>
10
11 void *mmap(void *addr, size_t len, int prot, int flags,
12 int fildes, off_t off);
13
14
15 DESCRIPTION
16 The mmap() function establishes a mapping between a process's address
17 space and a file or shared memory object. The format of the call is as
18 follows:
19
20
21 pa = mmap(addr, len, prot, flags, fildes, off);
22
23
24 The mmap() function establishes a mapping between the address space of
25 the process at an address pa for len bytes to the memory object
26 represented by the file descriptor fildes at offset off for len bytes.
27 The value of pa is a function of the addr argument and values of flags,
28 further described below. A successful mmap() call returns pa as its
29 result. The address range starting at pa and continuing for len bytes
30 will be legitimate for the possible (not necessarily current) address
31 space of the process. The range of bytes starting at off and continuing
32 for len bytes will be legitimate for the possible (not necessarily
33 current) offsets in the file or shared memory object represented by
34 fildes.
35
36
37 The mmap() function allows [pa, pa + len) to extend beyond the end of
38 the object both at the time of the mmap() and while the mapping
39 persists, such as when the file is created prior to the mmap() call and
40 has no contents, or when the file is truncated. Any reference to
41 addresses beyond the end of the object, however, will result in the
42 delivery of a SIGBUS or SIGSEGV signal. The mmap() function cannot be
43 used to implicitly extend the length of files.
44
45
46 The mapping established by mmap() replaces any previous mappings for
47 those whole pages containing any part of the address space of the
48 process starting at pa and continuing for len bytes.
49
50
51 If the size of the mapped file changes after the call to mmap() as a
52 result of some other operation on the mapped file, the effect of
53 references to portions of the mapped region that correspond to added or
54 removed portions of the file is unspecified.
81
82
83
84 If an implementation of mmap() for a specific platform cannot support
85 the combination of access types specified by prot, the call to mmap()
86 fails. An implementation may permit accesses other than those specified
87 by prot; however, the implementation will not permit a write to succeed
88 where PROT_WRITE has not been set or permit any access where PROT_NONE
89 alone has been set. Each platform-specific implementation of mmap()
90 supports the following values of prot: PROT_NONE, PROT_READ,
91 PROT_WRITE, and the inclusive OR of PROT_READ and PROT_WRITE. On some
92 platforms, the PROT_WRITE protection option is implemented as
93 PROT_READ|PROT_WRITE and PROT_EXEC as PROT_READ|PROT_EXEC. The file
94 descriptor fildes is opened with read permission, regardless of the
95 protection options specified. If PROT_WRITE is specified, the
96 application must have opened the file descriptor fildes with write
97 permission unless MAP_PRIVATE is specified in the flags argument as
98 described below.
99
100
101 The flags argument provides other information about the handling of the
102 mapped data. The value of flags is the bitwise inclusive OR of these
103 options, defined in <sys/mman.h>:
104
105 MAP_SHARED
106 Changes are shared.
107
108
109 MAP_PRIVATE
110 Changes are private.
111
112
113 MAP_FIXED
114 Interpret addr exactly.
115
116
117 MAP_NORESERVE
118 Do not reserve swap space.
119
120
121 MAP_ANON
122 Map anonymous memory.
123
601
602
603
604
605 +--------------------+-------------------+
606 | ATTRIBUTE TYPE | ATTRIBUTE VALUE |
607 +--------------------+-------------------+
608 |Interface Stability | Standard |
609 +--------------------+-------------------+
610 |MT-Level | Async-Signal-Safe |
611 +--------------------+-------------------+
612
613 SEE ALSO
614 close(2), exec(2), fcntl(2), fork(2), getrlimit(2), memcntl(2),
615 mmapobj(2), mprotect(2), munmap(2), shmat(2), lockf(3C), mlockall(3C),
616 msync(3C), plock(3C), sysconf(3C), attributes(5), lf64(5),
617 standards(5), null(7D), zero(7D)
618
619
620
621 November 19, 2019 MMAP(2)
|