mlock(), mlock_r()
Lock a range of process address space in physical memory
Synopsis:
#include <sys/mman.h>
int mlock(const void * addr,
size_t len);
int mlock_r(const void * addr,
size_t len);
Arguments:
- addr
- The starting address for the range of process address space.
- len
- The amount of the memory to lock, in bytes. There's no limit on the amount of memory that a process may lock, other than the amount of physical memory in the system.
Library:
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
These kernel calls cause all pages containing any part of the calling process's address space starting at address addr and continuing for len bytes to be memory-resident until unlocked or until the process exits or is replaced by an exec*() call.
Memory-resident is a term used to indicate that the addresses always reside in physical memory.
For more information, see
Memory management
in the Process Manager chapter of the System Architecture guide.
The mlock() and mlock_r() functions are identical, except in the way they indicate errors. See the Returns section for details.
Returns:
The only difference between these functions is the way they indicate errors:
- mlock()
- If successful this function returns 0. If an error occurs, it returns -1 and sets errno.
- mlock_r()
- If successful, this function returns EOK. This function does NOT set errno, even on success. If an error occurs, it may return any value from the Errors section.
Errors:
- ENOMEM
- The provided range is not fully mapped and backed.
Classification:
| Safety: | |
|---|---|
| Cancellation point | No |
| Signal handler | Yes |
| Thread | Yes |
