Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ mprotect(2) — Ultrix-32 3.1D RISC

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

getpagesize(2)

sbrk(2)

sigvec(2)

malloc(3)

signal(3)

mprotect(2)

NAME

mprotect − memory protection control

SYNTAX

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

int mprotect (addr, len, prot)
caddr_t addr;
int len, prot;

DESCRIPTION

The mprotect system call changes the protection of portions of an application program’s data memory. Protection is performed on page cluster boundaries. The default protection for data memory on process invocation is user READ/WRITE. The addr argument is the beginning address of the data block, and must fall on a page cluster boundary. 

The len argument is the length of the data block, in bytes.  The length of the block is rounded up to a cluster boundary, and the size of the block to be protected is returned. 

The prot argument is the requested protection for the block of memory.  Protection values affect only the user process.  Protection values are defined in <mman.h> as:

/* protections are chosen from these bits, ORed together */
#define PROT_READ       0x1     /* pages can be read */
#define PROT_WRITE      0x2     /* pages can be written */
#define PROT_EXEC       0x4     /* pages can be executed */

Setting the prot argument to zero (0) indicates that the process cannot reference the memory block, without causing a fault. 

A protected page will fault if the protection is violated, and a SIGBUS signal will be issued.  If the process has a handler defined for the SIGBUS signal, the code parameter, described in sigvec() and signal(,), will be used to pass in the virtual address that faulted.

RESTRICTIONS

The page cluster size may change in future versions of ULTRIX.  As a result, getpagesize() should be used to determine the correct len argument, and sbrk() or malloc() should be used to determine the correct addr argument. 

If the user handles a SIGBUS signal, the signal handler must either abort the process or correct the condition that caused the protection fault (SIGBUS).  If some corrective action is not taken, an infinite loop will result as the faulting instruction will be restarted.  If the user permits the default SIGBUS handler to be used, the process will abort if a referenced page causes a fault. 

The VAX architecture makes the following implications; PROT_WRITE implies (PROT_WRITE | PROT_READ | PROT_EXEC), and PROT_READ implies (PROT_READ | PROT_EXEC). 

This system call will only permit the application to change its private data space.  This means that attempts to change text, shared memory or stack space will cause a EACCES failure. 

RETURN VALUE

Upon successful completion, the size of the protected memory block, in bytes, is returned.  Otherwise, a value of -1 is returned and errno is set to indicate the error. 

DIAGNOSTICS

The mprotect call will fail if one or more of the following are true:

[EALIGN] The addr argument is not on a cluster boundary. 

[EINVAL] The prot argument is not a valid protection mask. 

[EACCES] Memory block is not fully contained within private data space. 

SEE ALSO

getpagesize(2), sbrk(2), sigvec(2), malloc(3), signal(3)

System Calls

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