DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

mprotect(S)


mprotect -- set protection of memory mapping

Synopsis

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

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

Description

mprotect changes the access protections on the mappings specified by the range [addr, addr + len) to be that specified by prot. The access protections will apply to the entire page or pages containing [addr, addr + len). (The notation [start, end) denotes the interval from start to end, including start but excluding end.)

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

On success, mprotect returns 0. On failure, mprotect returns -1 and sets errno to identify the error.

Errors

In the following conditions, 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
prot specifies PROT_WRITE over a MAP_PRIVATE mapping and there are insufficient memory resources to reserve for locking the private page.

EINVAL
addr is not a multiple of the page size as returned by sysconf.

ENOMEM
The argument len 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.

References

mlock(S), mlockall(S), memcntl(S), mmap(S), plock(S), sysconf(S)

Notices

Considerations for threads programming

Sibling threads share (by definition) the same address space; modifications to the address space by one can be perceived by the others.
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005