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 Manual						       mprotect(2)

NAME
mprotect - Modifies access protections of memory mapping SYNOPSIS
#include <sys/mman.h> int mprotect ( void *addr, size_t len, int prot ); The following definitions of the addr parameter do not conform to current standards and are supported only for backward compatibility: caddr_t addr const void addr STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: mprotect(): XSH4.2 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Points to the address of the region to be modified. Specifies the length in bytes of the region to be modified. Specifies access permis- sions as PROT_NONE or any combination of PROT_READ, PROT_WRITE, and PROT_EXEC ORed together. DESCRIPTION
The mprotect() function modifies the access protection of a mapped file or shared memory region. The addr and len parameters specify the address and length in bytes of the region to be modified. The len parameter must be a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE). If len is not a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE), the length of the region will be rounded up to the next multiple of the page size. The prot parameter specifies the new access protection for the region. The sys/mman.h header file defines the following access options: The mapped region can be read. The mapped region can be written. The mapped region can be executed. The mapped region cannot be accessed. The prot parameter can be PROT_NONE or any combination of PROT_READ, PROT_WRITE, and PROT_EXEC ORed together. If PROT_NONE is not speci- fied, access permissions may be granted to the region in addition to those explicitly requested, except that write access will not be granted unless PROT_WRITE is specified. If the region is a mapped file which was mapped with MAP_SHARED, the mprotect() function grants read or execute access permission only if the file descriptor used to map the file is open for reading, and grants write access permission only if the file descriptor used to map the file is open for writing. If the region is a mapped file which was mapped with MAP_PRIVATE, the mprotect() function grants read, write, or execute access permission only if the file descriptor used to map the file is open for reading. If the region is a shared memory region which was mapped with MAP_ANONYMOUS, the mprotect() function grants all requested access permissions. The mprotect() function does not modify the access permission of any region which lies outside of the specified region, except that the effect on addresses between the end of the region and the end of the page containing the end of the region is unspecified. If the mprotect() function fails under a condition other than that specified by [EINVAL], the access protection of some of the pages in the range [addr, addr + len) may have been changed. For example, if the error occurs on some page at an addr2, mprotect() may have modified the protections of all whole pages in the range [addr, addr2). RETURN VALUES
Upon successful completion, the mprotect() function returns 0 (zero). Otherwise, mprotect() returns -1 and sets errno to indicate the error. ERRORS
The mprotect() function sets errno to the specified values for the following conditions: The prot parameter specifies a protection that conflicts with the access permission set for the underlying file. The prot parameter speci- fies PROT_WRITE over a MAP_PRIVATE mapping and there are insufficient memory resources to reserve for locking the private page. [Tru64 UNIX] Some or all of the addresses in the range starting at addr and continuing for len bytes are locked. [Tru64 UNIX] The range [addr, addr + len) includes an invalid address. The prot parameter is invalid, or the addr parameter is not a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE). [Tru64 UNIX] Addresses in the range [addr, addr + len) are invalid for the address space of a process, or specify one or more unmapped pages. [Tru64 UNIX] A system resource was exhausted or a system limit was exceeded. The most common case occurs when the calling process exceeds the kernel configuration parameter VPAGEMAX. This limit specifies the maximum number of pages per process that can reside in regions of contiguous virtual address space which have mixed page protections. The system administrator can override the default VPAGEMAX value by setting the vpagemax nnn option in the system configuration file, then reconfiguring the kernel, and finally rebooting the system. RELATED INFORMATION
Functions: getpagesize(2), mmap(2), msync(2), sysconf(3) Standards: standards(5) delim off mprotect(2)
Man Page