mlock(3) — Subroutines
Digital
NAME
mlock, munlock − lock or unlock a specified region in memory (P1003.4/D10)
SYNOPSIS
#include <mlock.h>
int mlock (
void ∗addr,
size_t len) ; int munlock (
void ∗addr,
size_t len) ;
PARAMETERS
addr A pointer to the starting address of the region to lock or unlock. The addr argument must be a multiple of the page size returned by the sysconf system call.
len The size of the memory region to lock or unlock. The value of len is rounded up to a mulitple of the page size.
DESCRIPTION
The mlock function guarantees residency of a region of process address space. The in memory region is specified as an address and a length.
A lock is not inherited across a fork or an exec.
The munlock function unlocks a previously locked region. A memory lock is also unlocked by an exec call or process termination. All memory locks are removed if an address range associated with the lock is unmapped.
You must have superuser privileges to call the mlock or munlock functions.
RETURN VALUES
On a successful call to the mlock function, a value of 0 is returned. Upon a successful return from the mlock function, a region becomes locked and resident. On an unsuccessful call, a value of −1 is returned, and errno is set to indicate that an error occurred.
On a successful call to the munlock function, a value of 0 is returned. On an unsuccessful call, a value of −1 is returned, none of the memory is unlocked and errno is set to indicate that an error occurred.
ERRORS
The mlock and munlock functions fail under the following conditions:
[EINVAL] The addr argument is not a multiple of the page size returned by sysconf.
[ENOMEM] The address range specified by the addr and len arguments does not all correspond to valid mapped pages in the process’s address space. The calling process has exceeded an implementation-defined limit on the amount of memory that the process may lock.
[EAGAIN] Some or all of the memory identified by the operation could not be locked when the call was made.
[EPERM] The calling process does not have the appropriate privileges to perform the requested operation.
[ENOSYS] P1003.4/D10 memory locking is not configured in this implementation. Refer to the DEC OSF/1 Realtime Installation Guide for information on how to install the realtime software.
RELATED INFORMATION
exec(2), _exit(2), fork(2), mlockall(3), munmap(3), sysconf(3)