mmap
mmap — implements the C mmap function
call.
Syntax
mmap (size, prot_flags, share_flags, shm_file, offset)
Arguments
- size
- The size (in bytes) of the shared memory segment to map.
- prot_flags
- Access capability flags.
- share_flags
- Sharing flags.
- shm_file
- A file descriptor as returned by shm_open.
- offset
- An offset from the beginning of the shared memory area.
Returns
A buffer which is mapped to the shared memory region, or nil on failure with
errno set.
Description
This function is currently only available in QNX 4. It
implements the C mmap function call,
returning a buffer which maps to the shared memory region. The
shm_open function needs to be called before
using this function.
The prot_flags specifies the access capability. Valid prot_flags are bitwise OR-ed combinations of:
- PROT_EXEC The region can be executed.
- PROT_NOCACHE Disable caching of the region (use for dual port RAM).
- PROT_NONE The region cannot be accessed.
- PROT_READ The region can be read.
- PROT_WRITE The region can be written.
The share_flags specify the handling of the memory region. Valid share_flags are bitwise OR-ed combinations of:
- MAP_PRIVATE Changes are private.
- MAP_SHARED Share changes.
Remember to require the "const/mman.lsp" file before using these constants.
Possible errors when using this function are:
- EACCES The shm_file is not open for the correct mode
- EAGAIN The mapping could not be locked in memory due to a lack of resources
- EBADF The passed shm_file is bad.
- EINVAL The
prot_flags of
share_flags argument is
invalid
- ENODEV The shm_file
arg refers to an argument for which mmap is
meaningless
- ENOMEM The mapping
could not be locked because it would require more
space than the system is able to supply
- ENOSYS The function
mmap is not supported by this
implementation
- ENOTSUP MAP_PRIVATE
was specified but the implementation does not
support this functionality
- ENXIO The offset or size arguments are invalid.
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);