source: rtems-docs/posix-users/memory_managment.rst @ 12dccfe

5
Last change on this file since 12dccfe was 12dccfe, checked in by Sebastian Huber <sebastian.huber@…>, on 01/09/19 at 15:14:05

Remove superfluous "All rights reserved."

  • Property mode set to 100644
File size: 11.2 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. Copyright (C) 1988, 2002 On-Line Applications Research Corporation (OAR)
4
5Memory Management Manager
6#########################
7
8Introduction
9============
10
11The
12memory management manager is ...
13
14The directives provided by the memory management manager are:
15
16- mlockall_ - Lock the Address Space of a Process
17
18- munlockall_ - Unlock the Address Space of a Process
19
20- mlock_ - Lock a Range of the Process Address Space
21
22- munlock_ - Unlock a Range of the Process Address Space
23
24- mmap_ - Map Process Addresses to a Memory Object
25
26- munmap_ - Unmap Previously Mapped Addresses
27
28- mprotect_ - Change Memory Protection
29
30- msync_ - Memory Object Synchronization
31
32- shm_open_ - Open a Shared Memory Object
33
34- shm_unlink_ - Remove a Shared Memory Object
35
36Background
37==========
38
39There is currently no text in this section.
40
41Operations
42==========
43
44There is currently no text in this section.
45
46Directives
47==========
48
49This section details the memory management manager's directives.  A subsection
50is dedicated to each of this manager's directives and describes the calling
51sequence, related constants, usage, and status codes.
52
53.. _mlockall:
54
55mlockall - Lock the Address Space of a Process
56----------------------------------------------
57.. index:: mlockall
58.. index:: lock the address space of a process
59
60**CALLING SEQUENCE:**
61
62.. code-block:: c
63
64    #include <sys/mman.h>
65    int mlockall(
66        int flags
67    );
68
69**STATUS CODES:**
70
71.. list-table::
72 :class: rtems-table
73
74 * - ``E``
75   - The
76
77**DESCRIPTION:**
78
79**NOTES:**
80
81.. _munlockall:
82
83munlockall - Unlock the Address Space of a Process
84--------------------------------------------------
85.. index:: munlockall
86.. index:: unlock the address space of a process
87
88**CALLING SEQUENCE:**
89
90.. code-block:: c
91
92    #include <sys/mman.h>
93    int munlockall(
94        void
95    );
96
97**STATUS CODES:**
98
99.. list-table::
100 :class: rtems-table
101
102 * - ``E``
103   - The
104
105**DESCRIPTION:**
106
107**NOTES:**
108
109.. _mlock:
110
111mlock - Lock a Range of the Process Address Space
112-------------------------------------------------
113.. index:: mlock
114.. index:: lock a range of the process address space
115
116**CALLING SEQUENCE:**
117
118.. code-block:: c
119
120    #include <sys/mman.h>
121    int mlock(
122        const void *addr,
123        size_t len
124    );
125
126**STATUS CODES:**
127
128.. list-table::
129 :class: rtems-table
130
131 * - ``E``
132   - The
133
134**DESCRIPTION:**
135
136**NOTES:**
137
138.. _munlock:
139
140munlock - Unlock a Range of the Process Address Space
141-----------------------------------------------------
142.. index:: munlock
143.. index:: unlock a range of the process address space
144
145**CALLING SEQUENCE:**
146
147.. code-block:: c
148
149    #include <sys/mman.h>
150    int munlock(
151        const void *addr,
152        size_t len
153    );
154
155**STATUS CODES:**
156
157.. list-table::
158 :class: rtems-table
159
160 * - ``E``
161   - The
162
163**DESCRIPTION:**
164
165**NOTES:**
166
167.. _mmap:
168
169mmap - Map Process Addresses to a Memory Object
170-----------------------------------------------
171.. index:: mmap
172.. index:: map process addresses to a memory object
173
174**CALLING SEQUENCE:**
175
176.. code-block:: c
177
178    #include <sys/mman.h>
179    void *mmap(
180        void *addr,
181        size_t len,
182        int prot,
183        int flags,
184        int fildes,
185        off_t off
186    );
187
188**STATUS CODES:**
189
190.. list-table::
191 :class: rtems-table
192
193 * - ``EBADF``
194   - The fildes argument is not a valid open file descriptor.
195 * - ``EINVAL``
196   - The value of len is zero.
197 * - ``EINVAL``
198   - The value of flags is invalid (neither MAP_PRIVATE nor MAP_SHARED is set).
199 * - ``EINVAL``
200   - The addr argument (if MAP_FIXED was specified) or off is not a multiple of
201     the page size as returned by sysconf(), or is considered invalid by the
202     implementation.
203 * - ``ENODEV``
204   - The fildes argument refers to a file whose type is not supported by mmap.
205 * - ``ENOMEM``
206   - MAP_FIXED was specified, and the range [addr,addr+len) exceeds that
207     allowed for the address space of a process; or, if MAP_FIXED was not
208     specified and there is insufficient room in the address space to effect
209     the mapping.
210 * - ``ENOTSUP``
211   - MAP_FIXED or MAP_PRIVATE was specified in the flags argument and the
212     implementation does not support this functionality.
213 * - ``ENOTSUP``
214   - The implementation does not support the combination of accesses requested
215     in the prot argument.
216 * - ``ENXIO``
217   - Addresses in the range [off,off+len) are invalid for the object specified
218     by fildes.
219 * - ``ENXIO``
220   - MAP_FIXED was specified in flags and the combination of addr, len, and off
221     is invalid for the object specified by fildes.
222 * - ``EOVERFLOW``
223   - The file is a regular file and the value of off plus len exceeds the
224     offset maximum established in the open file description associated with
225     fildes.
226
227**DESCRIPTION:**
228
229``mmap`` establishes a mapping between an address ``pa`` for ``len`` bytes to
230the memory object represented by the file descriptor ``fildes`` at offset
231``off`` for ``len`` bytes.  The value of ``pa`` is an implementation-defined
232function of the parameter addr and the values of ``flags``. A successful
233``mmap()`` call shall return ``pa`` as its result. An unsuccessful call returns
234``MAP_FAILED`` and sets ``errno`` accordingly.
235
236**NOTES:**
237
238RTEMS is a single address space operating system without privilege separation
239between the kernel and user space. Therefore, the implementation of ``mmap``
240has a number of implementation-specific issues to be aware of:
241 * Read, write and execute permissions are allowed because the memory in RTEMS
242   does not normally have protections but we cannot hide access to memory.
243   Thus, the use of ``PROT_NONE`` for the ``prot`` argument is not supported.
244   Similarly, there is no restriction of write access, so ``PROT_WRITE`` must
245   be in the ``prot`` argument.
246 * Anonymous mappings must have ``fildes`` set to -1 and ``off`` set to 0.
247   Shared mappings are not supported with Anonymous mappings.
248 * ``MAP_FIXED`` is not supported for shared memory objects with ``MAP_SHARED``.
249 * Support for shared mappings is dependent on the underlying object's
250   filesystem implementation of an ``mmap_h`` file operation handler.
251
252.. _munmap:
253
254munmap - Unmap Previously Mapped Addresses
255------------------------------------------
256.. index:: munmap
257.. index:: unmap previously mapped addresses
258
259**CALLING SEQUENCE:**
260
261.. code-block:: c
262
263    #include <sys/mman.h>
264    int munmap(
265        void *addr,
266        size_t len
267    );
268
269**STATUS CODES:**
270
271.. list-table::
272 :class: rtems-table
273
274 * - ``EINVAL``
275   - Addresses in the range [addr,addr+len) are outside the valid range for the
276     address space.
277 * - ``EINVAL``
278   - The len argument is 0.
279
280**DESCRIPTION:**
281
282The ``munmap()`` function shall remove any mappings for those entire pages
283containing any part of the address space of the process starting at ``addr``
284and continuing for ``len`` bytes.  If there are no mappings in the specified
285address range, then ``munmap()`` has no effect.
286
287Upon successful completion, ``munmap()`` shall return 0; otherwise, it shall
288return -1 and set ``errno`` to indicate the error.
289
290**NOTES:**
291
292.. _mprotect:
293
294mprotect - Change Memory Protection
295-----------------------------------
296.. index:: mprotect
297.. index:: change memory protection
298
299**CALLING SEQUENCE:**
300
301.. code-block:: c
302
303    #include <sys/mman.h>
304    int mprotect(
305        void *addr,
306        size_t len,
307        int prot
308    );
309
310**STATUS CODES:**
311
312.. list-table::
313 :class: rtems-table
314
315 * - ``E``
316   - The
317
318**DESCRIPTION:**
319
320**NOTES:**
321
322.. _msync:
323
324msync - Memory Object Synchronization
325-------------------------------------
326.. index:: msync
327.. index:: memory object synchronization
328
329**CALLING SEQUENCE:**
330
331.. code-block:: c
332
333    #include <sys/mman.h>
334    int msync(
335        void *addr,
336        size_t len,
337        int flags
338    );
339
340**STATUS CODES:**
341
342.. list-table::
343 :class: rtems-table
344
345 * - ``E``
346   - The
347
348**DESCRIPTION:**
349
350**NOTES:**
351
352.. _shm_open:
353
354shm_open - Open a Shared Memory Object
355--------------------------------------
356.. index:: shm_open
357.. index:: open a shared memory object
358
359**CALLING SEQUENCE:**
360
361.. code-block:: c
362
363    #include <sys/mman.h>
364    int shm_open(
365        const char *name,
366        int oflag,
367        mode_t mode
368    );
369
370**STATUS CODES:**
371
372.. list-table::
373 :class: rtems-table
374
375 * - ``EACCES``
376   - The shared memory object exists and the permissions specified by oflag are
377     denied, or the shared memory object does not exist and permission to
378     create the shared memory object is denied, or O_TRUNC is specified and
379     write permission is denied.
380 * - ``EEXIST``
381   - O_CREAT and O_EXCL are set and the named shared memory object already
382     exists.
383 * - ``EINVAL``
384   - The ``shm_open()`` operation is not supported for the given name.
385 * - ``EMFILE``
386   - All file descriptors available to the process are currently open.
387 * - ``ENFILE``
388   - Too many shared memory objects are currently open in the system.
389 * - ``ENOENT``
390   - O_CREAT is not set and the named shared memory object does not exist.
391 * - ``ENOSPC``
392   - There is insufficient space for the creation of the new shared memory
393     object.
394 * - ``ENAMETOOLONG``
395   - The length of the name argument exceeds ``_POSIX_PATH_MAX``.
396
397
398**DESCRIPTION:**
399
400The ``shm_open()`` function shall establish a connection between a shared
401memory object and a file descriptor. It shall create an open file description
402that refers to the shared memory object and a file descriptor that refers to
403that open file description. The ``name`` argument points to a string naming a
404shared memory object.
405
406If successful, ``shm_open()`` shall return a file descriptor for the shared
407memory object. Upon successful completion, the ``shm_open()`` function shall
408return a non-negative integer representing the file descriptor. Otherwise, it
409shall return -1 and set ``errno`` to indicate the error.
410
411**NOTES:**
412
413An application can set the ``_POSIX_Shm_Object_operations`` to control the
414behavior of shared memory objects when accessed via the file descriptor.
415
416The ``name`` must be valid for an RTEMS SuperCore Object.
417
418.. _shm_unlink:
419
420shm_unlink - Remove a Shared Memory Object
421------------------------------------------
422.. index:: shm_unlink
423.. index:: remove a shared memory object
424
425**CALLING SEQUENCE:**
426
427.. code-block:: c
428
429    #include <sys/mman.h>
430    int shm_unlink(
431        const char *name
432    );
433
434**STATUS CODES:**
435
436.. list-table::
437 :class: rtems-table
438
439 * - ``ENOENT``
440   - The named shared memory object does not exist.
441 * - ``ENAMETOOLONG``
442   - The length of the name argument exceeds ``_POSIX_PATH_MAX``.
443
444**DESCRIPTION:**
445
446The ``shm_unlink()`` function shall remove the name of the shared memory object
447named by the string pointed to by ``name``.
448
449If one or more references to the shared memory object exist when the object is
450unlinked, the name shall be removed before ``shm_unlink()`` returns, but the
451removal of the memory object contents shall be postponed until all open and map
452references to the shared memory object have been removed.
453
454Even if the object continues to exist after the last ``shm_unlink()``, reuse of
455the name shall subsequently cause ``shm_open()`` to behave as if no shared
456memory object of this name exists.
457
458Upon successful completion, a value of zero shall be returned. Otherwise, a
459value of -1 shall be returned and errno set to indicate the error. If -1 is
460returned, the named shared memory object shall not be changed by this function
461call.
462
463**NOTES:**
464
Note: See TracBrowser for help on using the repository browser.