Xenomai API
2.6.5
|
Shared memory services. More...
Functions | |
int | shm_open (const char *name, int oflags, mode_t mode) |
Open a shared memory object. More... | |
int | close (int fd) |
Close a file descriptor. More... | |
int | shm_unlink (const char *name) |
Unlink a shared memory object. More... | |
int | ftruncate (int fd, off_t len) |
Truncate a file or shared memory object to a specified length. More... | |
void * | mmap (void *addr, size_t len, int prot, int flags, int fd, off_t off) |
Map pages of memory. More... | |
int | munmap (void *addr, size_t len) |
Unmap pages of memory. More... | |
Shared memory services.
Shared memory objects are memory regions that can be mapped into processes address space, allowing them to share these regions as well as to share them with kernel-space modules.
Shared memory are also the only mean by which anonymous POSIX skin synchronization objects (mutexes, condition variables or semaphores) may be shared between kernel-space modules and user-space processes, or between several processes.
int close | ( | int | fd | ) |
Close a file descriptor.
This service closes the file descriptor fd. In kernel-space, this service only works for file descriptors opened with shm_open(), i.e. shared memory objects. A shared memory object is only destroyed once all file descriptors are closed with this service, it is unlinked with the shm_unlink() service, and all mappings are unmapped with the munmap() service.
fd | file descriptor. |
0 | on success; |
-1 | with errno set if:
|
Referenced by shm_open().
int ftruncate | ( | int | fd, |
off_t | len | ||
) |
Truncate a file or shared memory object to a specified length.
When used in kernel-space, this service set to len the size of a shared memory object opened with the shm_open() service. In user-space this service falls back to Linux regular ftruncate service for file descriptors not obtained with shm_open(). When this service is used to increase the size of a shared memory object, the added space is zero-filled.
Shared memory are suitable for direct memory access (allocated in physically contiguous memory) if O_DIRECT was passed to shm_open.
Shared memory objects may only be resized if they are not currently mapped.
fd | file descriptor; |
len | new length of the underlying file or shared memory object. |
0 | on success; |
-1 | with errno set if:
|
References xnheap_alloc(), xnheap_free(), and xnheap_set_label().
Referenced by shm_open().
void* mmap | ( | void * | addr, |
size_t | len, | ||
int | prot, | ||
int | flags, | ||
int | fd, | ||
off_t | off | ||
) |
Map pages of memory.
This service allow shared memory regions to be accessed by the caller.
When used in kernel-space, this service returns the address of the offset off of the shared memory object underlying fd. The protection flags prot, are only checked for consistency with fd open flags, but memory protection is unsupported. An existing shared memory region exists before it is mapped, this service only increments a reference counter.
The only supported value for flags is MAP_SHARED.
When used in user-space, this service maps the specified shared memory region into the caller address-space. If fd is not a shared memory object descriptor (i.e. not obtained with shm_open()), this service falls back to the regular Linux mmap service.
addr | ignored. |
len | size of the shared memory region to be mapped. |
prot | protection bits, checked in kernel-space, but only useful in user-space, are a bitwise or of the following values:
|
flags | only MAP_SHARED is accepted, meaning that the mapped memory region is shared. |
fd | file descriptor, obtained with shm_open(). |
off | offset in the shared memory region. |
0 | on success; |
MAP_FAILED | with errno set if:
|
int munmap | ( | void * | addr, |
size_t | len | ||
) |
Unmap pages of memory.
This service unmaps the shared memory region [addr;addr+len) from the caller address-space.
When called from kernel-space the memory region remain accessible as long as it exists, and this service only decrements a reference counter.
When called from user-space, if the region is not a shared memory region, this service falls back to the regular Linux munmap() service.
addr | start address of shared memory area; |
len | length of the shared memory area. |
0 | on success; |
-1 | with errno set if:
|
int shm_open | ( | const char * | name, |
int | oflags, | ||
mode_t | mode | ||
) |
Open a shared memory object.
This service establishes a connection between a shared memory object and a file descriptor. Further use of this descriptor will allow to dimension and map the shared memory into the calling context address space.
One of the following access mode should be set in oflags:
If no shared memory object named name exists, and oflags has the O_CREAT bit set, the shared memory object is created by this function.
If oflags has the two bits O_CREAT and O_EXCL set and the shared memory object alread exists, this service fails.
If oflags has the bit O_TRUNC set, the shared memory exists and is not currently mapped, its size is truncated to 0.
If oflags has the bit O_DIRECT set, the shared memory will be suitable for direct memory access (allocated in physically contiguous memory).
name may be any arbitrary string, in which slashes have no particular meaning. However, for portability, using a name which starts with a slash and contains no other slash is recommended.
name | name of the shared memory object to open; |
oflags | flags. |
mode | ignored. |
References close(), and ftruncate().
int shm_unlink | ( | const char * | name | ) |
Unlink a shared memory object.
This service unlinks the shared memory object named name. The shared memory object is not destroyed until every file descriptor obtained with the shm_open() service is closed with the close() service and all mappings done with mmap() are unmapped with munmap(). However, after a call to this service, the unlinked shared memory object may no longer be reached with the shm_open() service.
name | name of the shared memory obect to be unlinked. |
0 | on success; |
-1 | with errno set if:
|