1MPROTECT(P)                POSIX Programmer's Manual               MPROTECT(P)
2
3
4

NAME

6       mprotect - set protection of memory mapping
7

SYNOPSIS

9       #include <sys/mman.h>
10
11       int mprotect(void *addr, size_t len, int prot);
12
13

DESCRIPTION

15       The  mprotect() function shall change the access protections to be that
16       specified by prot for those whole pages  containing  any  part  of  the
17       address  space  of  the process starting at address addr and continuing
18       for len bytes. The parameter prot determines whether read, write,  exe‐
19       cute,  or  some combination of accesses are permitted to the data being
20       mapped. The prot argument should be either PROT_NONE  or  the  bitwise-
21       inclusive OR of one or more of PROT_READ, PROT_WRITE, and PROT_EXEC.
22
23       If  an  implementation  cannot  support the combination of access types
24       specified by prot, the call to mprotect() shall fail.
25
26       An implementation may permit accesses other  than  those  specified  by
27       prot;  however, no implementation shall permit a write to succeed where
28       PROT_WRITE has not been set or shall permit any access where  PROT_NONE
29       alone  has been set. Implementations shall support at least the follow‐
30       ing values of prot: PROT_NONE, PROT_READ, PROT_WRITE, and the  bitwise-
31       inclusive  OR  of PROT_READ and PROT_WRITE. If PROT_WRITE is specified,
32       the application shall ensure that it has opened the mapped  objects  in
33       the  specified  address range with write permission, unless MAP_PRIVATE
34       was specified in the original mapping, regardless of whether  the  file
35       descriptors used to map the objects have since been closed.
36
37       The  implementation  shall  require that addr be a multiple of the page
38       size as returned by sysconf().
39
40       The behavior of this function is unspecified if  the  mapping  was  not
41       established by a call to mmap().
42
43       When  mprotect() fails for reasons other than [EINVAL], the protections
44       on some of the  pages  in  the  range  [addr,addr+len)  may  have  been
45       changed.
46

RETURN VALUE

48       Upon  successful  completion,  mprotect() shall return 0; otherwise, it
49       shall return -1 and set errno to indicate the error.
50

ERRORS

52       The mprotect() function shall fail if:
53
54       EACCES The prot argument  specifies  a  protection  that  violates  the
55              access  permission  the  process  has  to  the underlying memory
56              object.
57
58       EAGAIN The prot argument specifies PROT_WRITE over a  MAP_PRIVATE  map‐
59              ping  and there are insufficient memory resources to reserve for
60              locking the private page.
61
62       EINVAL The addr argument is not a multiple of the page size as returned
63              by sysconf().
64
65       ENOMEM Addresses  in  the  range  [addr,addr+len)  are  invalid for the
66              address space of a process, or specify one or more  pages  which
67              are not mapped.
68
69       ENOMEM The prot argument specifies PROT_WRITE on a MAP_PRIVATE mapping,
70              and it would require more space than the system is able to  sup‐
71              ply for locking the private pages, if required.
72
73       ENOTSUP
74              The  implementation does not support the combination of accesses
75              requested in the prot argument.
76
77
78       The following sections are informative.
79

EXAMPLES

81       None.
82

APPLICATION USAGE

84       The [EINVAL] error above is marked EX  because  it  is  defined  as  an
85       optional error in the POSIX Realtime Extension.
86

RATIONALE

88       None.
89

FUTURE DIRECTIONS

91       None.
92

SEE ALSO

94       mmap()    ,    sysconf()    ,    the   Base   Definitions   volume   of
95       IEEE Std 1003.1-2001, <sys/mman.h>
96
98       Portions of this text are reprinted and reproduced in  electronic  form
99       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
100       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
101       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
102       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
103       event of any discrepancy between this version and the original IEEE and
104       The Open Group Standard, the original IEEE and The Open Group  Standard
105       is  the  referee document. The original Standard can be obtained online
106       at http://www.opengroup.org/unix/online.html .
107
108
109
110IEEE/The Open Group                  2003                          MPROTECT(P)
Impressum