[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    mprotect(2) manual page Table of Contents

Name

mprotect - set protection of memory mapping

Synopsis


#include <sys/types.h>
#include <sys/mman.h>

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

Description

The function 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 and are defined in <sys/mman.h> as:


PROT_READ    /* page can be read */
PROT_WRITE    /* page can be written */
PROT_EXEC    /* page can be executed */
PROT_NONE    /* page can not be accessed */

Return Values

Upon successful completion, the function mprotect() returns a value of 0; otherwise, it returns a value of -1 and sets errno to indicate an error.

Errors

Under the following conditions, the function mprotect() fails and sets errno to:
EACCES
prot specifies a protection that violates the access permission the process has to the underlying memory object.
EAGAIN
the address range [addr, addr + len) includes one or more pages that have been locked in memory and that were mapped MAP_PRIVATE; prot includes PROT_WRITE; and the system has insufficient resources to reserve memory for the private pages that may be created. These private pages may be created by store operations into the now-writable address range.
EINVAL
addr is not a multiple of the page size as returned by sysconf.
EINVAL
the len argument has a value less than or equal to 0.
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) may have been changed. If the error occurs on some page at addr2, then the protections of all whole pages in the range [addr, addr2] will have been modified.

See Also

mmap(2) , plock(3C) , mlock(3C) , mlockall(3C) , sysconf(3C)


Table of Contents