mprotect(2) DG/UX 5.4.2 mprotect(2)
NAME
mprotect - set memory access for mapping
SYNOPSIS
#include <sys/types.h>
#include <sys/mman.h>
int mprotect(addr, len, prot)
caddrt addr;
sizet len;
int prot;
DESCRIPTION
The DG/UX system provides alternative calls for setting memory
access: memctl(2), defined by the 88open Binary Compatibility
Standard (BCS), revision 1.1A; and mprotect(2), defined by the System
V Interface Definition, Issue 3 (SVID3). If your program must be BCS-
compliant, use memctl(2). Otherwise, use mprotect(2) as explained
below.
The mprotect(2) call sets access attributes for a designated region
of memory:
addr is the starting address of the memory region.
len is the length in bytes of the region.
prot is the access attribute, which may be any one or an ORed
combination of: PROT_READ for read access, PROT_WRITE for
write access, PROT_EXEC for execute access, or PROT_NONE for
no access.
The addr must be a page-aligned address; len is rounded up to the
next page multiple. To find out the system page size, use sysconf(2)
with the _SC_PAGESIZE argument. The memory region specified by addr
and len must all be mapped within the caller's address space.
Read and execute access are not guaranteed to be enforced exactly as
specified in prot. For example, write access is often implemented as
read-write (PROTREAD | PROTWRITE), rather than as simply write
(PROTWRITE). However, write access is always denied unless prot
includes PROTWRITE. Also, no access is allowed if prot is PROTNONE.
On M88000 systems such as the AViiON, programs that modify and
execute memory need to invoke csync(2) just after the modification
and prior to the execution. Doing so notifies the system, and
synchronizes the contents of memory with that of the caches.
When several processes share a memory region, note:
⊕ Executable mappings of the shared region should include write
access, to insure that reading is always safe.
⊕ At least one of the processes must invoke csync(2), following
Licensed material--property of copyright holder(s) 1
mprotect(2) DG/UX 5.4.2 mprotect(2)
any modifications by the processes, and preceding execution by
any of them.
If mprotect(2) fails, the access attributes for portions of the
specified memory region may change, while the attributes for other
portions may not.
ACCESS CONTROL
In the following two cases, the prot argument must not include write
(PROTWRITE) access:
⊕ One or more pages in the region lie in a shared memory segment
that was attached using the SHMRDONLY option.
⊕ One or more pages in the region have been mapped using mmap(2)
with the MAPSHARED option, and the file passed to mmap(2) was
not open for writing.
RETURN VALUE
Upon successful completion, mprotect() returns a value of 0.
Otherwise, it returns the value -1, and sets errno to indicate an
error.
DIAGNOSTICS
Under the following conditions, mprotect() fails and sets errno to:
EINVAL if addr is not a page aligned address.
EACCES if prot specifies a protection that violates the
access permissions some mapping in the region has to
its underlying memory object.
EAGAIN if prot specifies PROTWRITE over a locked MAPPRIVATE
mapping and there are insufficient memory resources to
reserve for locking the private page.
EAGAIN if prot specifies PROTWRITE over a MAPPRIVATE
mapping and there are insufficient swap space
resources to be reserved for possible page
modification.
ENOMEM if len is equal to zero.
ENOMEM if some page in the memory region is not mapped within
the caller's address space.
SEE ALSO
csync(2), memctl(2), mmap(2), shmat(2), sysconf(2).
Licensed material--property of copyright holder(s) 2