MPROTECT(2) BSD MPROTECT(2)
NAME
mprotect - assign protection to region mapped in virtual memory
SYNOPSIS
#include <sys/mman.h>
mprotect(addr, len, prot)
caddr_t addr;
int len, prot;
DESCRIPTION
mprotect modifies the access protection of a mapped file or shared memory
region. addr and len arguments specify the address and length of the
region to be modified. This region must reside within a mapping
established via an earlier call to MMAP. The specified region is
expanded to cover an integral number of system segments. That is, the
segment containing addr, the segment containing addr+len-1 and any
intervening segments are processed. The segment size is as follows: 32K
for Apollo M68K (M68010, M68020, M68030) workstations, 512K for Apollo
M88K (AT) workstations, and 256K for Apollo M68K (M68040) workstations.
<sys/mman.h> defines the possible settings for prot:
/* protections are chosen from these bits, ORed together */
#define PROT_READ 0x04 /* mapped region can be read */
#define PROT_WRITE 0x02 /* mapped region can be written */
#define PROT_EXEC 0x01 /* mapped region can be executed */
#define PROT_NONE 0x00 /* mapped region cannot be accessed */
The prot argument can be PROT_NONE, or any combination of PROT_READ,
PROT_WRITE, and PROT_EXEC ORed together. If PROT_NONE is not specified,
access permissions may be granted to the region in addition to those
explicitly requested, except that write access will not be granted unless
PROT_WRITE is specified.
If the region is a mapped file which was mapped with MAP_SHARED, the
mprotect function grants read or execute access permission only if the
file descriptor used to map the file is open for reading and grants write
access permission only if the file descriptor used to map the file is
open for writing.
If the region is a mapped file which was mapped with MAP_PRIVATE, the
behavior is dependent on the environment. In an AES environment, the
mprotect function grants read, write, or execute access permission only
if the file descriptor used to map the file is open for reading. In a
non-AES environment, the behavior is identical to that in the MAP_SHARED
case.
If the region is a shared memory region which was mapped with
MAP_ANONYMOUS, mprotect grants all requested access permissions.
NOTES
In Domain/OS, the unit of mapping and protection is the segment.
SEE ALSO
madvise(2), mmap(2), mset(2).
DIAGNOSTICS
A successful call returns 0. An unsuccessful call returns -1 and sets
errno as indicated below.
ERRORS
mprotect will fail if any of the following is true:
[EINVAL] An invalid protection mode was specified.
[ENOENT] No region is mapped at the specified address.
[EACCESS] Attempt to change the protection to a mode precluded by file
access proctections.
[ETXTBSY] The file is a pure-procedure (shared text) file that is being
executed and the protections request write access.
[EROFS] The mapped file resides on a read-only file system and the
protections request write access.