mprotect(2)mprotect(2)Namemprotect - 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 system call changes the protection of portions of an application
program's data memory. Protection is performed on page cluster bound‐
aries. 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 faults if the protection is violated, and a SIGBUS
signal is issued. If the process has a handler defined for the SIGBUS
signal, the code parameter, described in and is used to pass in the
virtual address that faulted.
Restrictions
The page cluster size may change in future versions of ULTRIX. As a
result, should be used to determine the correct len argument, and or
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 results because the faulting instruction is restarted. If the
user permits the default SIGBUS handler to be used, the process aborts
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).
Only the application can change the call's private data space. This
means that attempts to change text, shared memory, or stack space
causes a EACCES failure.
Return Values
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 call fails under the following conditions:
[EALIGN] The addr argument is not on a cluster boundary.
[EINVAL] The prot argument is not a valid protection mask.
[EACCES] The memory block is not fully contained within private
data space.
See Alsogetpagesize(2), sbrk(2), sigvec(2), malloc(3), signal(3)mprotect(2)