summaryrefslogtreecommitdiffstats
path: root/posix-users/memory_managment.rst
blob: ec3e60ce860ccdb1ecaea698c69d12877c97163e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
.. comment SPDX-License-Identifier: CC-BY-SA-4.0

.. COMMENT: COPYRIGHT (c) 1988-2002.
.. COMMENT: On-Line Applications Research Corporation (OAR).
.. COMMENT: All rights reserved.

Memory Management Manager
#########################

Introduction
============

The
memory management manager is ...

The directives provided by the memory management manager are:

- mlockall_ - Lock the Address Space of a Process

- munlockall_ - Unlock the Address Space of a Process

- mlock_ - Lock a Range of the Process Address Space

- munlock_ - Unlock a Range of the Process Address Space

- mmap_ - Map Process Addresses to a Memory Object

- munmap_ - Unmap Previously Mapped Addresses

- mprotect_ - Change Memory Protection

- msync_ - Memory Object Synchronization

- shm_open_ - Open a Shared Memory Object

- shm_unlink_ - Remove a Shared Memory Object

Background
==========

There is currently no text in this section.

Operations
==========

There is currently no text in this section.

Directives
==========

This section details the memory management manager's directives.  A subsection
is dedicated to each of this manager's directives and describes the calling
sequence, related constants, usage, and status codes.

.. _mlockall:

mlockall - Lock the Address Space of a Process
----------------------------------------------
.. index:: mlockall
.. index:: lock the address space of a process

**CALLING SEQUENCE:**

.. code-block:: c

    int mlockall(
    );

**STATUS CODES:**

.. list-table::
 :class: rtems-table

 * - ``E``
   - The

**DESCRIPTION:**

**NOTES:**

.. _munlockall:

munlockall - Unlock the Address Space of a Process
--------------------------------------------------
.. index:: munlockall
.. index:: unlock the address space of a process

**CALLING SEQUENCE:**

.. code-block:: c

    int munlockall(
    );

**STATUS CODES:**

.. list-table::
 :class: rtems-table

 * - ``E``
   - The

**DESCRIPTION:**

**NOTES:**

.. _mlock:

mlock - Lock a Range of the Process Address Space
-------------------------------------------------
.. index:: mlock
.. index:: lock a range of the process address space

**CALLING SEQUENCE:**

.. code-block:: c

    int mlock(
    );

**STATUS CODES:**

.. list-table::
 :class: rtems-table

 * - ``E``
   - The

**DESCRIPTION:**

**NOTES:**

.. _munlock:

munlock - Unlock a Range of the Process Address Space
-----------------------------------------------------
.. index:: munlock
.. index:: unlock a range of the process address space

**CALLING SEQUENCE:**

.. code-block:: c

    int munlock(
    );

**STATUS CODES:**

.. list-table::
 :class: rtems-table

 * - ``E``
   - The

**DESCRIPTION:**

**NOTES:**

.. _mmap:

mmap - Map Process Addresses to a Memory Object
-----------------------------------------------
.. index:: mmap
.. index:: map process addresses to a memory object

**CALLING SEQUENCE:**

.. code-block:: c

    void *mmap(
        void *addr,
        size_t len,
        int prot,
        int flags,
        int fildes,
        off_t off
    );

**STATUS CODES:**

.. list-table::
 :class: rtems-table

 * - ``EBADF``
   - The fildes argument is not a valid open file descriptor.
 * - ``EINVAL``
   - The value of len is zero.
 * - ``EINVAL``
   - The value of flags is invalid (neither MAP_PRIVATE nor MAP_SHARED is set).
 * - ``EINVAL``
   - The addr argument (if MAP_FIXED was specified) or off is not a multiple of
     the page size as returned by sysconf(), or is considered invalid by the
     implementation.
 * - ``ENODEV``
   - The fildes argument refers to a file whose type is not supported by mmap. 
 * - ``ENOMEM``
   - MAP_FIXED was specified, and the range [addr,addr+len) exceeds that
     allowed for the address space of a process; or, if MAP_FIXED was not
     specified and there is insufficient room in the address space to effect
     the mapping.
 * - ``ENOTSUP``
   - MAP_FIXED or MAP_PRIVATE was specified in the flags argument and the
     implementation does not support this functionality.
 * - ``ENOTSUP``
   - The implementation does not support the combination of accesses requested
     in the prot argument.
 * - ``ENXIO``
   - Addresses in the range [off,off+len) are invalid for the object specified
     by fildes.
 * - ``ENXIO``
   - MAP_FIXED was specified in flags and the combination of addr, len, and off
     is invalid for the object specified by fildes.
 * - ``EOVERFLOW``
   - The file is a regular file and the value of off plus len exceeds the
     offset maximum established in the open file description associated with
     fildes.

**DESCRIPTION:**

``mmap`` establishes a mapping between an address ``pa`` for ``len`` bytes to
the memory object represented by the file descriptor ``fildes`` at offset
``off`` for ``len`` bytes.  The value of ``pa`` is an implementation-defined
function of the parameter addr and the values of ``flags``. A successful
``mmap()`` call shall return ``pa`` as its result. An unsuccessful call returns
``MAP_FAILED`` and sets ``errno`` accordingly. 

**NOTES:**

RTEMS is a single address space operating system without privilege separation
between the kernel and user space. Therefore, the implementation of ``mmap``
has a number of implementation-specific issues to be aware of:
 * Read, write and execute permissions are allowed because the memory in RTEMS
   does not normally have protections but we cannot hide access to memory.
   Thus, the use of ``PROT_NONE`` for the ``prot`` argument is not supported.
   Similarly, there is no restriction of write access, so ``PROT_WRITE`` must
   be in the ``prot`` argument.
 * Anonymous mappings must have ``fildes`` set to -1 and ``off`` set to 0.
   Shared mappings are not supported with Anonymous mappings.
 * ``MAP_FIXED`` is not supported for shared memory objects with ``MAP_SHARED``.
 * Support for shared mappings is dependent on the underlying object's
   filesystem implementation of an ``mmap_h`` file operation handler.

.. _munmap:

munmap - Unmap Previously Mapped Addresses
------------------------------------------
.. index:: munmap
.. index:: unmap previously mapped addresses

**CALLING SEQUENCE:**

.. code-block:: c

    int munmap(
        void *addr,
        size_t len
    );

**STATUS CODES:**

.. list-table::
 :class: rtems-table

 * - ``EINVAL``
   - Addresses in the range [addr,addr+len) are outside the valid range for the
     address space.
 * - ``EINVAL``
   - The len argument is 0.

**DESCRIPTION:**

The ``munmap()`` function shall remove any mappings for those entire pages
containing any part of the address space of the process starting at ``addr``
and continuing for ``len`` bytes.  If there are no mappings in the specified
address range, then ``munmap()`` has no effect.

Upon successful completion, ``munmap()`` shall return 0; otherwise, it shall
return -1 and set ``errno`` to indicate the error.

**NOTES:**

.. _mprotect:

mprotect - Change Memory Protection
-----------------------------------
.. index:: mprotect
.. index:: change memory protection

**CALLING SEQUENCE:**

.. code-block:: c

    int mprotect(
    );

**STATUS CODES:**

.. list-table::
 :class: rtems-table

 * - ``E``
   - The

**DESCRIPTION:**

**NOTES:**

.. _msync:

msync - Memory Object Synchronization
-------------------------------------
.. index:: msync
.. index:: memory object synchronization

**CALLING SEQUENCE:**

.. code-block:: c

    int msync(
    );

**STATUS CODES:**

.. list-table::
 :class: rtems-table

 * - ``E``
   - The

**DESCRIPTION:**

**NOTES:**

.. _shm_open:

shm_open - Open a Shared Memory Object
--------------------------------------
.. index:: shm_open
.. index:: open a shared memory object

**CALLING SEQUENCE:**

.. code-block:: c

    int shm_open(
        const char *name,
        int oflag,
        mode_t mode
    );

**STATUS CODES:**

.. list-table::
 :class: rtems-table

 * - ``EACCES``
   - The shared memory object exists and the permissions specified by oflag are
     denied, or the shared memory object does not exist and permission to
     create the shared memory object is denied, or O_TRUNC is specified and
     write permission is denied.
 * - ``EEXIST``
   - O_CREAT and O_EXCL are set and the named shared memory object already
     exists.
 * - ``EINVAL``
   - The ``shm_open()`` operation is not supported for the given name.
 * - ``EMFILE``
   - All file descriptors available to the process are currently open.
 * - ``ENFILE``
   - Too many shared memory objects are currently open in the system.
 * - ``ENOENT``
   - O_CREAT is not set and the named shared memory object does not exist.
 * - ``ENOSPC``
   - There is insufficient space for the creation of the new shared memory
     object.
 * - ``ENAMETOOLONG``
   - The length of the name argument exceeds ``_POSIX_PATH_MAX``.


**DESCRIPTION:**

The ``shm_open()`` function shall establish a connection between a shared
memory object and a file descriptor. It shall create an open file description
that refers to the shared memory object and a file descriptor that refers to
that open file description. The ``name`` argument points to a string naming a
shared memory object. 

If successful, ``shm_open()`` shall return a file descriptor for the shared
memory object. Upon successful completion, the ``shm_open()`` function shall
return a non-negative integer representing the file descriptor. Otherwise, it
shall return -1 and set ``errno`` to indicate the error.

**NOTES:**

An application can set the ``_POSIX_Shm_Object_operations`` to control the
behavior of shared memory objects when accessed via the file descriptor.

The ``name`` must be valid for an RTEMS SuperCore Object.

.. _shm_unlink:

shm_unlink - Remove a Shared Memory Object
------------------------------------------
.. index:: shm_unlink
.. index:: remove a shared memory object

**CALLING SEQUENCE:**

.. code-block:: c

    int shm_unlink(
        const char *name
    );

**STATUS CODES:**

.. list-table::
 :class: rtems-table

 * - ``ENOENT``
   - The named shared memory object does not exist.
 * - ``ENAMETOOLONG``
   - The length of the name argument exceeds ``_POSIX_PATH_MAX``.

**DESCRIPTION:**

The ``shm_unlink()`` function shall remove the name of the shared memory object
named by the string pointed to by ``name``.

If one or more references to the shared memory object exist when the object is
unlinked, the name shall be removed before ``shm_unlink()`` returns, but the
removal of the memory object contents shall be postponed until all open and map
references to the shared memory object have been removed.

Even if the object continues to exist after the last ``shm_unlink()``, reuse of
the name shall subsequently cause ``shm_open()`` to behave as if no shared
memory object of this name exists.

Upon successful completion, a value of zero shall be returned. Otherwise, a
value of -1 shall be returned and errno set to indicate the error. If -1 is
returned, the named shared memory object shall not be changed by this function
call.

**NOTES:**