Modifies access protections of memory mapping.
#include <mman.h> int mprotect (void *addr, size_t len, int prot);
The addr and len arguments specify the address and length in bytes of the region that you want to modify. The len argument must be a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE). If len is not a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE), the length of the region is rounded up to the next multiple of the page size.
The prot argument specifies access permissions for the mapped region. Specify one of the following:
PROT_NONE | No access |
PROT_READ | Read-only |
PROT_WRITE | Read/Write access |
The mprotect function does not modify the access permission of any region that lies outside of the specified region, except that the effect on addresses between the end of the region, and the end of the page containing the end of the region, is unspecified.
If the mprotect function fails under a condition other than that specified by EINVAL, the access protection of some of the pages in the range [addr, addr + len] can change. Suppose the error occurs on some page at an addr2; mprotect can modify protections of all whole pages in the range [addr, addr2].
See also sysconf in this section.
0 | Indicates success. |
-1 | Indicates an error; errno is set to one
of the following values:
|