mprotect()

NAME

mprotect() - change access protections on memory mappings

SYNOPSIS

#include <sys/mman.h>

int mprotect(void *addr, size_t len, int prot)

DESCRIPTION

The mprotect(2) call sets or changes the permissions on memory mappings in the address range [addr addr + len], rounded up to the next multiple of the page size.

The prot argument specifies the protections on the page, which are layered over the permissions. The protections are the same as for mmap(2). As defined in <sys/mman.h>:

PROT_READ
Read page.
PROT_WRITE
Write page.
PROT_EXEC
Execute page.
PROT_NONE
No permission to access page.

If the call fails for a reason other than [EINVAL], it may mean that the permissions have been changed on the pages in the specified range.

RETURN VALUES

The mprotect(2) call returns 0 for success, and -1 if an error occurred. If it returns -1, it sets errno to indicate the error.

ERRORS

[EACCES]
The value for prot conflicts with the permissions on the underlying memory object.
[EAGAIN]
When specifying PROT_WRITE on a section of memory mapped MAP_PRIVATE, there is not enough memory to lock the private page.
[EINVAL]
The addr argument is not a multiple of the page size.
[ENOMEM]
The addresses in the range are not valid for the process' address space, or those pages aren't mapped.

SEE ALSO

mmap(2)

sysconf(2)