1MPROTECT(3P) POSIX Programmer's Manual MPROTECT(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 mprotect — set protection of memory mapping
14
16 #include <sys/mman.h>
17
18 int mprotect(void *addr, size_t len, int prot);
19
21 The mprotect() function shall change the access protections to be that
22 specified by prot for those whole pages containing any part of the
23 address space of the process starting at address addr and continuing
24 for len bytes. The parameter prot determines whether read, write, exe‐
25 cute, or some combination of accesses are permitted to the data being
26 mapped. The prot argument should be either PROT_NONE or the bitwise-
27 inclusive OR of one or more of PROT_READ, PROT_WRITE, and PROT_EXEC.
28
29 If an implementation cannot support the combination of access types
30 specified by prot, the call to mprotect() shall fail.
31
32 An implementation may permit accesses other than those specified by
33 prot; however, no implementation shall permit a write to succeed where
34 PROT_WRITE has not been set or shall permit any access where PROT_NONE
35 alone has been set. Implementations shall support at least the follow‐
36 ing values of prot: PROT_NONE, PROT_READ, PROT_WRITE, and the bitwise-
37 inclusive OR of PROT_READ and PROT_WRITE. If PROT_WRITE is specified,
38 the application shall ensure that it has opened the mapped objects in
39 the specified address range with write permission, unless MAP_PRIVATE
40 was specified in the original mapping, regardless of whether the file
41 descriptors used to map the objects have since been closed.
42
43 The implementation may require that addr be a multiple of the page size
44 as returned by sysconf().
45
46 The behavior of this function is unspecified if the mapping was not
47 established by a call to mmap().
48
49 When mprotect() fails for reasons other than [EINVAL], the protections
50 on some of the pages in the range [addr,addr+len) may have been
51 changed.
52
54 Upon successful completion, mprotect() shall return 0; otherwise, it
55 shall return −1 and set errno to indicate the error.
56
58 The mprotect() function shall fail if:
59
60 EACCES The prot argument specifies a protection that violates the
61 access permission the process has to the underlying memory
62 object.
63
64 EAGAIN The prot argument specifies PROT_WRITE over a MAP_PRIVATE map‐
65 ping and there are insufficient memory resources to reserve for
66 locking the private page.
67
68 ENOMEM Addresses in the range [addr,addr+len) are invalid for the
69 address space of a process, or specify one or more pages which
70 are not mapped.
71
72 ENOMEM The prot argument specifies PROT_WRITE on a MAP_PRIVATE mapping,
73 and it would require more space than the system is able to sup‐
74 ply for locking the private pages, if required.
75
76 ENOTSUP
77 The implementation does not support the combination of accesses
78 requested in the prot argument.
79
80 The mprotect() function may fail if:
81
82 EINVAL The addr argument is not a multiple of the page size as returned
83 by sysconf().
84
85 The following sections are informative.
86
88 None.
89
91 Most implementations require that addr is a multiple of the page size
92 as returned by sysconf().
93
95 None.
96
98 None.
99
101 mmap(), sysconf()
102
103 The Base Definitions volume of POSIX.1‐2008, <sys_mman.h>
104
106 Portions of this text are reprinted and reproduced in electronic form
107 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
108 -- Portable Operating System Interface (POSIX), The Open Group Base
109 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
110 cal and Electronics Engineers, Inc and The Open Group. (This is
111 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
112 event of any discrepancy between this version and the original IEEE and
113 The Open Group Standard, the original IEEE and The Open Group Standard
114 is the referee document. The original Standard can be obtained online
115 at http://www.unix.org/online.html .
116
117 Any typographical or formatting errors that appear in this page are
118 most likely to have been introduced during the conversion of the source
119 files to man page format. To report such errors, see https://www.ker‐
120 nel.org/doc/man-pages/reporting_bugs.html .
121
122
123
124IEEE/The Open Group 2013 MPROTECT(3P)