mprotect()

change access protections for memory pages 

Function


SYNOPSIS

#include <sys/mman.h>

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


DESCRIPTION

The mprotect() function changes the access protections to be that specified by prot for those whole pages containing any part of the address space of the process starting at address addr and continuing for len bytes. The parameter prot specifies whether read, write, execute, or some combination of accesses are permitted to the data being mapped. The prot argument should be the bitwise inclusive OR of one or more of PROT_NONE, PROT_READ, PROT_WRITE and PROT_EXEC.

The system does not permit a write to succeed where PROT_WRITE has not been set or permit any access where PROT_NONE alone has been set. If PROT_WRITE is specified, the application must have opened the mapped objects in the specified address range with write permission, unless MAP_PRIVATE was specified in the original mapping. It is irrelevant whether the file descriptors used to map the objects have since been closed.

addr must be a multiple of the page size as returned by sysconf().


PARAMETERS

addr 

Is the starting address of the region for which the protection has to be changed.

len 

Is the length of the region, in bytes, whose protection has to be changed.

prot 

Is the desired protection of the memory mapped region.


RETURN VALUES

On success, the mprotect() function returns 0. Otherwise, it returns -1 and sets errno one of the following values.

EACCES 

The prot argument specifies a protection that violates the access permission the process has to the underlying memory object.

EAGAIN 

The prot argument specifies PROT_WRITE over a MAP_PRIVATE mapping and there are insufficient memory resources to reserve for locking the private page.

EINVAL 

The addr argument is not a multiple of the page size as returned by sysconf().

EINVAL 

The len argument is has a value less than 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.

ENOMEM 

The prot argument specifies PROT_WRITE on a MAP_PRIVATE mapping, and it would require more space than the system is able to supply for locking the private pages, if required.

ENOTSUP 

The implementation does not support the combination of accesses requested in the prot argument.


CONFORMANCE

UNIX 98, with exceptions.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

Windows 9x does not support the PROT_EXEC flag, nor does it support mprotect() on regions created with the MAP_SHARED flag.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
mmap(), sysconf()


PTC MKS Toolkit 10.4 Documentation Build 39.