Login or Register to Ask a Question and Join Our Community

Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

mmap(2) [opendarwin man page]

MMAP(2) 						      BSD System Calls Manual							   MMAP(2)

NAME
mmap -- map files or devices into memory SYNOPSIS
#include <sys/types.h> #include <sys/mman.h> void * mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset); DESCRIPTION
The mmap function causes the pages starting at addr and continuing for at most len bytes to be mapped from the object described by fd, start- ing at byte offset offset. If offset or len is not a multiple of the pagesize, the mapped region may extend past the specified range. If addr is non-zero, it is used as a hint to the system. (As a convenience to the system, the actual address of the region may differ from the address supplied.) If addr is zero, an address will be selected by the system. The actual starting address of the region is returned. A successful mmap deletes any previous mapping in the allocated address range. The protections (region accessibility) are specified in the prot argument by or'ing the following values: PROT_EXEC Pages may be executed. PROT_READ Pages may be read. PROT_WRITE Pages may be written. The flags parameter specifies the type of the mapped object, mapping options and whether modifications made to the mapped copy of the page are private to the process or are to be shared with other references. Sharing, mapping type and options are specified in the flags argument by or'ing the following values: MAP_ANON Map anonymous memory not associated with any specific file. The file descriptor used for creating MAP_ANON regions is used only for naming, and may be specified as -1 if no name is associated with the region. MAP_FILE Mapped from a regular file or character-special device memory. (This is the default mapping type, and need not be specified.) MAP_FIXED Do not permit the system to select a different address than the one specified. If the specified address cannot be used, mmap will fail. If MAP_FIXED is specified, addr must be a multiple of the pagesize. Use of this option is discouraged. MAP_HASSEMAPHORE Notify the kernel that the region may contain semaphores and that special handling may be necessary. MAP_PRIVATE Modifications are private. MAP_SHARED Modifications are shared. The close(2) function does not unmap pages, see munmap(2) for further information. The current design does not allow a process to specify the location of swap space. In the future we may define an additional mapping type, MAP_SWAP, in which the file descriptor argument specifies a file or device to which swapping should be done. RETURN VALUES
Upon successful completion, mmap returns a pointer to the mapped region. Otherwise, a value of -1 is returned and errno is set to indicate the error. ERRORS
Mmap() will fail if: [EACCES] The flag PROT_READ was specified as part of the prot parameter and fd was not open for reading. The flags PROT_WRITE and MAP_SHARED were specified as part of the flags and prot parameters and fd was not open for writing. [EBADF] fd is not a valid open file descriptor. [EINVAL] MAP_FIXED was specified and the parameter was not page aligned. fd did not reference a regular or character special file. [ENOMEM] MAP_FIXED was specified and the addr parameter wasn't available. MAP_ANON was specified and insufficient memory was available. SEE ALSO
getpagesize(2), msync(2), munmap(2), mprotect(2), madvise(2), mincore(2), mlock(2) 4th Berkeley Distribution June 4, 1993 4th Berkeley Distribution

Check Out this Related Man Page

mprotect(2)							   System Calls 						       mprotect(2)

NAME
mprotect - set protection of memory mapping SYNOPSIS
#include <sys/mman.h> int mprotect(void *addr, size_t len, int prot); DESCRIPTION
The mprotect() function changes the access protections on the mappings specified by the range [addr, addr + len), rounding len up to the next multiple of the page size as returned by sysconf(3C), to be that specified by prot. Legitimate values for prot are the same as those permitted for mmap(2) and are defined in <sys/mman.h> as: PROT_READ /* page can be read */ PROT_WRITE /* page can be written */ PROT_EXEC /* page can be executed */ PROT_NONE /* page can not be accessed */ When mprotect() fails for reasons other than EINVAL, the protections on some of the pages in the range [addr, addr + len) may have been changed. If the error occurs on some page at addr2, then the protections of all whole pages in the range [addr, addr2] will have been modi- fied. RETURN VALUES
Upon successful completion, mprotect() returns 0. Otherwise, it returns -1 and sets errno to indicate the error. ERRORS
The mprotect() function will fail if: EACCES The prot argument specifies a protection that violates the access permission the process has to the underlying memory object. EINVAL The len argument has a value equal to 0, or addr is not a multiple of the page size as returned by sysconf(3C). ENOMEM Addresses in the range [addr, addr + len) are invalid for the address space of a process, or specify one or more pages which are not mapped. The mprotect() function may fail if: EAGAIN The address range [addr, addr + len) includes one or more pages that have been locked in memory and that were mapped MAP_PRIVATE; prot includes PROT_WRITE; and the system has insufficient resources to reserve memory for the private pages that may be created. These private pages may be created by store operations in the now-writable address range. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
mmap(2), plock(3C), mlock(3C), mlockall(3C), sysconf(3C), attributes(5), standards(5) SunOS 5.11 12 Jan 1998 mprotect(2)
Man Page

Featured Tech Videos