MPROTECT(2)

NAME
mprotect - set protection of memory mapping

SYNOPSIS
#include <sys/mman.h>

mprotect(addr, len, prot)
caddr_t addr;
int len, prot;

DESCRIPTION

mprotect() changes the access protections on the mappings specified by the range [addr, addr + len) to be that specified by prot. Legitimate values for prot are the same as those permitted for mmap(2).

RETURN VALUES

mprotect() returns:

0   on success.

-1  on failure and sets errno to indicate the error.

ERRORS

EACCES
    prot specifies a protection which violates the access permission the process has to the underlying memory object.

EINVAL
    addr is not a multiple of the page size as returned by getpagesize(2).

ENOMEM
    Addresses in the range [addr, addr + len) are invalid for the address space of a process, or specify one or more pages which are not mapped.

When mprotect() fails for reasons other than EINVAL, the protections on some of the pages in the range [addr, addr + len) will have been changed. If the error occurs on some page at address addr2, then the protections of all whole pages in the range [addr, addr2) have been modified.

SEE ALSO
getpagesize(2), mmap(2)