Your Browser is not longer supported
Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...
{{viewport.spaceProperty.prod}}
mprotect - modify access protection for memory mapping
&pagelevel(4)&pagelevel
Syntax | #include <sys/mman.h> int mprotect(void *addr, size_t len, int prot); |
Syntax | #include <sys/mman.h> int mprotect(void *addr, size_t len, int prot); |
Description | The mprotect() function changes the access permissions for the mappings in the [addr, addr + len) area to the access permission specified in prot. The value specified in len is rounded to a multiple of the page size specified by sysconf() . All values that can also be specified in mmap() are permissible for prot. The values for prot are defined in sys/mman.h as follows: |
| PROT_READ
| Page can be read. |
| PROT_WRITE
| Page can be written. |
| PROT_EXEC
| Page can be executed. |
| PROT_NONE
| Page cannot be accessed. |
| If mprotect() fails but the reason is not EINVAL , it may be that the access permissions of some pages were already changed in the specified area [addr, addr + len). If the error is in the address addr2, the access permissions of all whole pages in the area [addr, addr2] will be changed. |
Return val. | 0 | if successful. |
| -1 | if an error occurs. errno is set to indicate the error. |
Errors | Under the conditions described below, the mprotect() function will fail and set errno to the following values: |
| EACCES
| prot contains a value that does not match the access permissions of the process for the underlying file. |
| EAGAIN
| prot contains the value PROT_WRITE for a mapping of type MAP_PRIVATE and a memory bottleneck occurs, i.e. the storage resources for reserving and locking the private page are not sufficient. |
| EINVAL
| addr is not a multiple of the page size specified by sysconf() , or the len argument contains a value less than or equal to 0. |
| ENOMEM
| Addresses in the area [addr, addr + len) are invalid for the address area of the process, or one or more pages have been specified which are not mapped. |
See also | mmap() , sysconf() , sys/mman.h .
|