mprotect

change memory protection

Synopsis:

#include <sys/mman.h>
int mprotect( void *addr, size_t len, int prot );

Description:

The mprotect() function changes the access protections on any mappings residing in the range starting at addr, and continuing for len bytes.

The prot parameter specifies the new access capabilities to the mapped memory region(s). The bits that can be combined in this field are defined in sys/mman.h, and are described in “Header Files in /usr/include/sys” in the C Library Overview chapter.

Returns:

On success the mprotect() function returns a value of zero. On error, a (-1) is returned and errno is set.

If the mprotect() function fails for reasons other than EINVAL, the protections on some of the pages in the address range starting at addr and continuing for len bytes may have been changed.

Errors:

EACCES
The memory object was not opened for read, regardless of the protection specified.

The memory object was not opened for write, and PROT_WRITE was specified for a MAP_SHARED type mapping.

EAGAIN
The prot argument specifies PROT_WRITE on a MAP_PRIVATE mapping and there are insufficient memory resources to reserve for locking the private pages (if required).
EINVAL
The value of addr is not a multiple of the page size as returned by the sysconf() function for _SC_PAGESIZE.
ENOMEM
The addresses in the range starting at addr and continuing for len bytes are outside the range allowed for the address space of a process, or specify one or more pages that are not mapped.

The prot argument specifies PROT_WRITE on a MAP_PRIVATE mapping, and locking the private pages (if required) would need more space than the system can supply to reserve for doing so.

ENOSYS
The function mprotect() is not supported by this implementation.

See also:

errno, mmap(), munmap(), shm_open(), shm_unlink()

Classification:

POSIX 1003.4

Systems:

QNX/32