1mprotect(2)                      System Calls                      mprotect(2)
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 changes the access protections on the mappings
16       specified by the range [addr, addr + len), rounding len up to the  next
17       multiple of the page size as returned by sysconf(3C), to be that speci‐
18       fied by prot. Legitimate values for prot are the same as those  permit‐
19       ted for mmap(2) and are defined in <sys/mman.h> as:
20
21       PROT_READ     /* page can be read */
22
23
24       PROT_WRITE    /* page can be written */
25
26
27       PROT_EXEC     /* page can be executed */
28
29
30       PROT_NONE     /* page can not be accessed */
31
32
33
34       When mprotect() fails for reasons other than EINVAL, the protections on
35       some of the pages in the  range  [addr,  addr  +  len)  may  have  been
36       changed.  If  the  error occurs on some page at addr2, then the protec‐
37       tions of all whole pages in the range [addr, addr2] will have been mod‐
38       ified.
39

RETURN VALUES

41       Upon successful completion, mprotect() returns 0. Otherwise, it returns
42       −1 and sets errno to indicate the error.
43

ERRORS

45       The mprotect() function will fail if:
46
47       EACCES    The prot argument specifies a protection  that  violates  the
48                 access  permission  the  process has to the underlying memory
49                 object.
50
51
52       EINVAL    The len argument has a value equal to 0, or  addr  is  not  a
53                 multiple of the page size as returned by sysconf(3C).
54
55
56       ENOMEM    Addresses in the range [addr, addr + len) are invalid for the
57                 address space of a process, or  specify  one  or  more  pages
58                 which are not mapped.
59
60
61
62       The mprotect() function may fail if:
63
64       EAGAIN    The  address  range  [addr,  addr + len) includes one or more
65                 pages that have been locked in memory and  that  were  mapped
66                 MAP_PRIVATE;  prot  includes  PROT_WRITE;  and the system has
67                 insufficient resources to  reserve  memory  for  the  private
68                 pages that may be created. These private pages may be created
69                 by store operations in the now-writable address range.
70
71

ATTRIBUTES

73       See attributes(5) for descriptions of the following attributes:
74
75
76
77
78       ┌─────────────────────────────┬─────────────────────────────┐
79ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
80       ├─────────────────────────────┼─────────────────────────────┤
81       │Interface Stability          │Standard                     │
82       └─────────────────────────────┴─────────────────────────────┘
83

SEE ALSO

85       mmap(2),    plock(3C),    mlock(3C),     mlockall(3C),     sysconf(3C),
86       attributes(5), standards(5)
87
88
89
90SunOS 5.11                        12 Jan 1998                      mprotect(2)
Impressum