Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

mmap(2)

sysconf(2)

mprotect(2)

NAME

mprotect − modify access protections of memory mapping

SYNOPSIS

#include <sys/mman.h>

int mprotect(

caddr_t addr,
size_t len,
int prot );

DESCRIPTION

mprotect() modifies the access protection of the memory mappings specified by the address range starting at addr and continuing for len bytes, rounded up to the next multiple of the page size, to be that specified by prot. If the address range does not correspond to one created by a successful call to mmap(), mprotect() returns an error.  prot determines whether read, write, execute, or some combination of accesses are permitted to the data being mapped.  Legitimate values for prot are the same as those permitted for mmap() (see mmap(2)).

If the address range being modified corresponds to a mapped file that was mapped with MAP_SHARED, mprotect() grants write access permission only if the file descriptor used to map the file was opened for writing.  If the address range corresponds to a mapped file that was mapped with the MAP_PRIVATE or the MAP_ANONYMOUS flag, mprotect() grants all requested access permissions. 

If mprotect() fails under a condition other than that specified by EINVAL, the access protection of some of the pages in the range [addr, addr+len)  (from, and including, addr to, but not including, addr+len) may have been changed. For example, suppose an error occurs on some page at an addr2; mprotect() may have modified the protections of all whole pages in the range [addr,addr2].

RETURN VALUE

mprotect() returns 0 upon success; otherwise, it returns −1 and sets errno to indicate the error. 

ERRORS

mprotect() fails if any of the following conditions are encountered:

[EACCES] prot specifies a protection that conflicts with the access permission set for the underlying file. 

[EINVAL] prot is invalid, or addr is not a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE). 

[ENOMEM] The range specified by [addr, addr+len)  (from, and including, addr to, but not including, addr+len) is invalid for a process’ address space, or the range specifies one or more unmapped pages.

AUTHOR

mprotect() was developed by HP, AT&T, and OSF. 

SEE ALSO

mmap(2), sysconf(2). 

STANDARDS CONFORMANCE

mprotect(): AES

Hewlett-Packard Company  —  HP-UX Release 9.0: August 1992

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026