NAME | SYNOPSIS | API RESTRICTIONS | FEATURES | DESCRIPTION | RETURN VALUES | ERRORS | ATTRIBUTES | SEE ALSO
#include <posix/unistd.h> #include <sys/mman.h>int shm_open(const char *name, int oflag [, mode_t mode]);
The function or functions documented here may not be used safely in all application contexts with all APIs provided in the ChorusOS 5.0 product.
See API(5FEA) for details.
POSIX_SHM
The shm_open system call establishes a connection between a shared memory object and a file descriptor. It creates a shared memory object description that refers to the shared memory object, and a file descriptor that refers to that shared memory object description. The file descriptor is used by other functions to refer to that shared memory object. The name argument points to a string naming a shared memory object. The name does not appear in the file system. The name argument points to a posix object name. The shared memory object name cannot exceed SHM_PATHMAX characters as returned by aconf(2K) or sysconf(3POSIX).
If successful, shm_open returns a file descriptor for the shared memory object that is the lowest numbered file descriptor not currently open for that process.
The new file descriptor is set to remain open across afexec(2K) system calls. See fcntl(2POSIX).
The file status flags and file access modes of the open file description are set according to the value of oflag. The oflag argument is the bitwise inclusive OR of the following flags defined in header <fcntl.h>. Applications should specify one of the following values (access modes) in oflag:
Open for read access only.
Open for read or write access.
Any combination of the remaining flags may be specified in the value of oflag:
If the shared memory object exists, this flag will have no effect, except as noted under O_EXCL below. Otherwise, the shared memory object is created. The owner ID of the shared memory object is set to the user ID of the process, the group ID of the shared memory object is set to the group ID of the process. The shared memory object's permission bits will be set to the value of the mode argument. When bits in mode other than the file permission bits are set, further access to the shared memory object may result in an access error. The mode argument does not affect whether the shared memory object is opened for reading, writing, or both. The shared memory object will have a size of 0.
If O_EXCL and O_CREAT are set, shm_open will fail if the shared memory object exists. The check for the existence of the shared memory object (and the creation of the object if it does not exist) is atomic with respect to other threads executing shm_open naming the same shared memory object with O_EXCL and O_CREAT set. If O_EXCL is set and O_CREAT is not set this flag is ignored.
When a shared memory object is created, the state of the shared memory object, including all data associated with the shared memory object, persists until the shared memory object is unlinked and all other references are gone. The name and shared memory object state are invalid after a system reboot.
Upon successful completion, shm_open returns a non-negative integer representing the lowest numbered unused file descriptor; otherwise, it returns -1 and sets errno to indicate the error condition.
The function shm_open is not supported.
The SHM feature [_POSIX_SHARED_MEMORY_OBJECTS] option (see aconf(2K), sysconf(3POSIX)) is not configured.
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.
O_CREAT and O_EXCL are set and the named shared memory object already exists.
The name string exceeds SHM_PATHMAX.
The access modes specified by oflag are incompatible.
Too many shared file descriptors are currently in use by this process.
The system file table is full.
There is insufficient space for the creation of the new shared memory object.
O_CREAT is not set and the named shared memory object does not exist.
name points outside the allocated address space of the process.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
Interface Stability | Evolving |
close(2POSIX), dup(2POSIX), afexec(2K), fcntl(2POSIX), shm_unlink(2POSIX), mmap(2POSIX), ftruncate(2POSIX), open(2POSIX)
NAME | SYNOPSIS | API RESTRICTIONS | FEATURES | DESCRIPTION | RETURN VALUES | ERRORS | ATTRIBUTES | SEE ALSO