memctl(2) DG/UX R4.11MU05 memctl(2)
NAME
memctl - set memory access for mapping
SYNOPSIS
#include <sys/m88kbcs.h>
int memctl(addr, len, state)
caddrt *addr;
int len;
int state;
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) as explained below. Otherwise, use
mprotect(2).
The memctl(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.
state is the access attribute: MCT_RONLY for read access, MCT_DATA
for read-write access, MCT_TEXT for read-execute access, or
MCT_RWX for read-write-execute access.
Note: MCT_RWX is supported on the DG/UX system but not on all
BCS-compliant platforms. Use sysconf(2) with the
_SC_RWX_SUPPORT parameter to find out whether it is supported.
The addr and len must be integer multiples of the memory control
unit. Use sysconf(2) with the _SC_MEMCTL_UNIT parameter to find out
the size of this unit. Also, the memory region specified by addr and
len must all be mapped within the caller's address space.
Programs that modify and execute a memory region, and which will run
on a BCS-compliant platform that supports simultaneous read-write-
execute access, should do the following:
· Set the access state of the region to MCT_RWX.
· After the modification and prior to execution, notify the
system to allow for synchronization of hardware cache and memory
contents. Use a trap to vector 502 for the notification, as
explained in the 88open Binary Compatibility Standard (BCS),
revision 1.1A, chapter 9. (When several processes share a memory
region, at least one of them performs notification for the
others, following all modifications and preceding execution by
any of them.)
Programs that modify and execute a memory region, and which will run
on a platform that does not support MCT_RWX, should use memctl(2) to
flip between read-write and read-execute access. Namely:
· After a write operation, before attempting an execute operation,
set the access state of the region to read-execute (MCT_TEXT).
· After an execute operation, before attempting a write operation,
set the region's access state to read-write (MCT_DATA).
ACCESS CONTROL
In the following two cases, the state must be either read-only
(MCTRONLY) or read-write (MCTTEXT):
· 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. (If your program maps with mmap(2), it
should, for consistency, use the ABI-compliant mprotect and/or
csync calls instead of the BCS-compliant memctl call.)
RETURN VALUE
Upon successful completion, memctl(2) returns 0. Otherwise, it
returns -1 and sets errno to indicate the error.
DIAGNOSTICS
If memctl(2) fails, it sets errno to one of the following:
EACCES A mapping within the memory region lacks the required
permission to change its memory to the requested
state.
EAGAIN The access state is MCT_DATA or MCT_RWX; the memory
needed to lock one or more private pages in the region
is unavailable.
EAGAIN The access state is MCT_DATA or MCT_RWX; the swap
space needed to modify one or more private pages in
the region is unavailable.
EFAULT The memory region is not fully mapped in the caller's
address space.
EINVAL The state parameter is invalid.
EINVAL The addr address parameter is not aligned on a memory
control unit boundary.
EINVAL The len parameter is not an integral multiple of the
memory control unit for the system.
SEE ALSO
mmap(2), mprotect(2), shmat(2), stkexec(2), sysconf(2).
Licensed material--property of copyright holder(s)