DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

mprotect(S-osr5)


mprotect -- set protection of memory mapping

Syntax

cc . . . -lc
#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 protection 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.

Diagnostics

Under the following conditions, the function mprotect fails and sets errno to:

[EACCES]
if prot specifies a protection, that violates the access permission the process has to the underlying memory object.

[EAGAIN]
if prot specifies PROT_WRITE over a MAP_PRIVATE mapping and there are insufficient memory resources to reserve for locking the private page.

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

[ENOMEM]
if 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.

Files


/lib/libc.a
linking library

See also

mmap(S-osr5), sysconf(S-osr5)

Standards conformance

mprotect is conformant with:

AT&T Issue 3;
IEEE POSIX Std 1003.4 1992 System Application Program Interface (API) Realtime Extension [C Language] (ISO/IEC 9945-1).


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005