1MLOCK(P) POSIX Programmer's Manual MLOCK(P)
2
3
4
6 mlock, munlock - lock or unlock a range of process address space (REAL‐
7 TIME)
8
10 #include <sys/mman.h>
11
12 int mlock(const void *addr, size_t len);
13 int munlock(const void *addr, size_t len);
14
15
17 The mlock() function shall cause those whole pages containing any part
18 of the address space of the process starting at address addr and con‐
19 tinuing for len bytes to be memory-resident until unlocked or until the
20 process exits or execs another process image. The implementation may
21 require that addr be a multiple of {PAGESIZE}.
22
23 The munlock() function shall unlock those whole pages containing any
24 part of the address space of the process starting at address addr and
25 continuing for len bytes, regardless of how many times mlock() has been
26 called by the process for any of the pages in the specified range. The
27 implementation may require that addr be a multiple of {PAGESIZE}.
28
29 If any of the pages in the range specified to a call to munlock() are
30 also mapped into the address spaces of other processes, any locks
31 established on those pages by another process are unaffected by the
32 call of this process to munlock(). If any of the pages in the range
33 specified by a call to munlock() are also mapped into other portions of
34 the address space of the calling process outside the range specified,
35 any locks established on those pages via the other mappings are also
36 unaffected by this call.
37
38 Upon successful return from mlock(), pages in the specified range shall
39 be locked and memory-resident. Upon successful return from munlock(),
40 pages in the specified range shall be unlocked with respect to the
41 address space of the process. Memory residency of unlocked pages is
42 unspecified.
43
44 The appropriate privilege is required to lock process memory with
45 mlock().
46
48 Upon successful completion, the mlock() and munlock() functions shall
49 return a value of zero. Otherwise, no change is made to any locks in
50 the address space of the process, and the function shall return a value
51 of -1 and set errno to indicate the error.
52
54 The mlock() and munlock() functions shall fail if:
55
56 ENOMEM Some or all of the address range specified by the addr and len
57 arguments does not correspond to valid mapped pages in the
58 address space of the process.
59
60
61 The mlock() function shall fail if:
62
63 EAGAIN Some or all of the memory identified by the operation could not
64 be locked when the call was made.
65
66
67 The mlock() and munlock() functions may fail if:
68
69 EINVAL The addr argument is not a multiple of {PAGESIZE}.
70
71
72 The mlock() function may fail if:
73
74 ENOMEM Locking the pages mapped by the specified range would exceed an
75 implementation-defined limit on the amount of memory that the
76 process may lock.
77
78 EPERM The calling process does not have the appropriate privilege to
79 perform the requested operation.
80
81
82 The following sections are informative.
83
85 None.
86
88 None.
89
91 None.
92
94 None.
95
97 exec() , exit() , fork() , mlockall() , munmap() , the Base Definitions
98 volume of IEEE Std 1003.1-2001, <sys/mman.h>
99
101 Portions of this text are reprinted and reproduced in electronic form
102 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
103 -- Portable Operating System Interface (POSIX), The Open Group Base
104 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
105 Electrical and Electronics Engineers, Inc and The Open Group. In the
106 event of any discrepancy between this version and the original IEEE and
107 The Open Group Standard, the original IEEE and The Open Group Standard
108 is the referee document. The original Standard can be obtained online
109 at http://www.opengroup.org/unix/online.html .
110
111
112
113IEEE/The Open Group 2003 MLOCK(P)