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