MCTL(2)

NAME
mctl - memory management control

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

int mctl(addr, len, function, arg)
caddr_t addr;
size_t len;
int function;
void *arg;

DESCRIPTION

mctl() applies a variety of control functions over pages identified by the mappings established for the address range [addr, addr + len). The function to be performed is identified by the argument function. Legitimate functions are defined in <sys/mman.h> as follows.

MC_LOCK
    Lock the pages in the range in memory. This function is used to support mlock(3). See the mlock(3) description for semantics and usage. arg is ignored, but must have the value 0.

MC_LOCKAS
    Lock the pages in the address space in memory. This function is used to support mlockall(3). See the mlockall(3) description for semantics and usage. addr and len are ignored but must be 0. arg is an integer built from the flags:
        #define MCL_CURRENT	0x1	/* lock current mappings */
        #define MCL_FUTURE	0x2	/* lock future mappings */

MC_SYNC
    Synchronize the pages in the range with their backing storage. Optionally invalidate cache copies. This function is used to support msync(3). See the msync(3) description for semantics and usage. arg is used to represent the flags argument to msync(3).

MC_UNLOCK
    Unlock the pages in the range. This function is used to support mlock(3). See the mlock(3) description for semantics and usage. arg is ignored and must have the value 0.

MC_UNLOCKAS
    Remove address space memory lock, and locks on all current mappings. This function is used to support mlockall(3). addr and len must have the value 0. arg is ignored and must have the value 0.

RETURN VALUES

mctl() returns:

0   on success.

-1  on failure and sets errno to indicate the error.

ERRORS

EAGAIN
    function was MC_LOCK or MC_LOCKAS and some or all of the memory identified by the operation could not be locked due to insufficient system resources.

EINVAL
    addr was not a multiple of the page size as returned by getpagesize(2).

    addr and/or len did not have the value 0 when MC_LOCKAS or MC_UNLOCKAS were specified.

    arg was not valid for the function specified.

ENOMEM
    Addresses in the range [addr, addr + len) are invalid for the address space of a process, or specify one or more pages which are not mapped.

EPERM
    The process's effective user ID was not super-user and one of MC_LOCK, MC_LOCKAS, MC_UNLOCK, or MC_UNLOCKAS was specified.

SEE ALSO
madvise(3), mlock(3), mlockall(3), mmap(2), msync(3)