mprotect() — set or check protection of memory mapping
int mprotect(void *addr, size_t len, int prot);
function changes the access protections on the mappings
specified by the range
up to the next multiple of the page size as returned by
to be that specified by
Legitimate values for
are the same as those permitted for
and are defined in
Page can be read.
Page can be written.
Page can be executed.
Page cannot be accessed.
Check page effective permissions
flag is specified,
checks the access protections on the mappings specified with the rest of
value to see if the requested permissions are set.
If the address range being modified
corresponds to a mapped file that was mapped with
grants write access permission
only if the file descriptor used to map the file
was opened for writing.
If the address range corresponds to a mapped file
that was mapped with the
grants all requested access permissions.
fails for reasons other than
the protections on some of the pages in the range
may have been changed.
For example, if an error occurs on some page at an
may have modified the protections of all whole pages in the range
Upon successful completion,
Otherwise, it returns
to indicate the error.
function will fail if:
argument specifies a protection that violates, or is different than
(in the case where flag
is present), the access permission the process has to the underlying memory
is invalid, or
is not a multiple of the page size as returned by
The range specified by
(from, and including,
to, but not including,
is invalid for the address space of a process,
or the range specifies one or more unmapped pages.
Addresses in the range
are invalid for the address space of a process, or specify one
or more pages which are not mapped.
mapping and there are insufficient memory resources to reserve
for locking the private page.
was developed by HP, AT&T, and OSF.
mprotect(): AES, SVID3