shm_open

shm_open — opens shared memory objects.

Syntax

shm_open (share_name, open_flags, create_mode, size?)

		

Arguments

share_name
The name of the shared memory object.
open_flags
Open control flags.
create_mode
Creation mode.
size
The size of the shared object in bytes.

Returns

A handle to the shared memory object, or nil on failure.

Description

This function is a wrapper for the C function shm_open. It is currently only available in QNX 4.

The name of the shared memory object is usually a name found under the /dev/shmem directory. Direct shared memory access to devices is acheived through a shm_open call to the existing Physical shared memory.

[Important]

If you are accessing the existing Physical shared memory region (/dev/shmem/Physical) DO NOT use the size argument, as you may inadvertantly resize this shared memory. The size argument is added as a convenience, and can be used to specify the size of a newly created object.

Valid open-flags are OR-ed combinations of:

  • O_RDONLY open for read-only
  • O_RDWR open for read and write access
  • O_CREAT create a new shared memory segment with access privledges governed by the create_mode parameter
  • O_EXCL Exclusive mode. If O_EXCL and O_CREAT are set then shm_open will fail if the shared memory segment exists.
  • O_TRUNC If the shared memory object exists, and it is successfully opened O_RDWR, the object is truncated to zero length and the mode and owner are unchanged.

The creation mode is usually an octal number in the range 0o000 - 0o777 defining the access privledges for the shared memory object. Require the 'const/filesys' file to load constants to make this arg easier

Possible errno values are:

  • EACCESS permission to create the shared memory object denied
  • EEXIST O_CREAT and O_EXCL are set and the named shared memory object already exists
  • EINTR The function call was interrupted by a signal
  • EMFILE Too many file descriptors in use by this process
  • ENAMETOOLONG The lengthof the name arg is too long
  • ENFILE To 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, or O_CREAT is set and either the name prefix does not exist or the name arg is an empty string
  • ENOSPC Not enough space for the creation of the new shared memory object
  • ENOSYS This function is not supported by this implementation.

Example

//This code maps the first 1000 bytes from video
//memory (0xA0000) into a buffer named buf.

require_lisp("const/filesys");
require_lisp("const/mman");
fd = shm_open("Physical",O_RDONLY, 0o777);
buf = mmap(1000, PROT_READ , MAP_SHARED, fd, 0xA0000);


		

See Also

mmap, shm_unlink