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
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 shall require that addr be a multiple of the page
44 size 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 EINVAL The addr argument is not a multiple of the page size as returned
69 by sysconf().
70
71 ENOMEM Addresses in the range [addr,addr+len) are invalid for the
72 address space of a process, or specify one or more pages which
73 are not mapped.
74
75 ENOMEM The prot argument specifies PROT_WRITE on a MAP_PRIVATE mapping,
76 and it would require more space than the system is able to sup‐
77 ply for locking the private pages, if required.
78
79 ENOTSUP
80 The implementation does not support the combination of accesses
81 requested in the prot argument.
82
83
84 The following sections are informative.
85
87 None.
88
90 The [EINVAL] error above is marked EX because it is defined as an
91 optional error in the POSIX Realtime Extension.
92
94 None.
95
97 None.
98
100 mmap(), sysconf(), the Base Definitions volume of IEEE Std 1003.1-2001,
101 <sys/mman.h>
102
104 Portions of this text are reprinted and reproduced in electronic form
105 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
106 -- Portable Operating System Interface (POSIX), The Open Group Base
107 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
108 Electrical and Electronics Engineers, Inc and The Open Group. In the
109 event of any discrepancy between this version and the original IEEE and
110 The Open Group Standard, the original IEEE and The Open Group Standard
111 is the referee document. The original Standard can be obtained online
112 at http://www.opengroup.org/unix/online.html .
113
114
115
116IEEE/The Open Group 2003 MPROTECT(3P)