Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ mmap(2) — Duplix 5.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

brk(2)

getpagesize(2)

phys(3C)

mem(4)

MMAP(2)  —  Unix Programmer’s Manual

NAME

mmap, munmap − maps or unmaps pages

SYNOPSIS

#include <sys/mman.h>
 mmap(addr, len, prot, share, fd, pos)
char ∗addr;
int len, prot, share, fd;
int pos;

munmap(addr, len)
char ∗addr;
int len;

DESCRIPTION

Mmap maps physical memory non-contiguous with the rest of memory (e.g., the I/O pages or a video frame buffer).  Users can share this memory through access to /dev/mem.  Mmap causes the pages (starting at addr and continuing for len bytes) to be mapped to the character special file represented by fd at the absolute position pos.  The parameter share must be MAP_SHARED. The addr, len, and pos parameters must be multiples of the page size;  see getpagesize(2).  Also, the region described by addr and len must be within the program’s data segment;  see brk(2). 

The parameter prot, which specifies the accessibility of the mapped pages, consists of bits selected from PROT_READ, PROT_WRITE, and PROT_EXEC ored together.  The file descriptor, fd, must represent a character special file capable of mapping pages.  Fd is opened with read/write permissions as needed for prot. When fd is closed, the pages are automatically unmapped. 

While accesses outside the data segment cause segmentation violations, accesses to non-existent memory (within a mapped region) cause bus errors.  If permitted by prot, it is possible to perform read(2) and write(2) calls on mapped regions.  Bad buffer addresses or transfers encountering non-existent memory yield an EFAULT error or cause a segmentation violation, depending on the size of the attempted transfer. 

Munmap removes a mapping starting at addr and continuing for len bytes; further references to these pages refer to private pages initialized to zero. 

RETURN VALUE

Upon successful completion, a value of 0 is returned.  Otherwise, a value of −1 is returned and errno is set to indicate the error. 

ERRORS

Mmap fails and no pages are mapped when one of the following occurs:

[EBADF] The descriptor fd is not valid. 

[EINVAL] The descriptor fd does not refer to a character special file capable of mapping pages. 

[EINVAL] The descriptor fd is not opened with a mode supporting prot. 

[EINVAL] Addr, len, or pos is not a multiple of the page size, or len is not greater than zero. 

[EINVAL] The address region (starting at addr and continuing for len bytes) is not totally within the program’s data segment. 

[EINVAL] The device region (starting at pos and continuing for len bytes) exceeds the device size. 

[EINVAL] Share is not MAP_SHARED.

Munmap fails when one of the following errors occurs:

[EINVAL] Addr or len is not a multiple of the page size, or len is not greater than zero. 

[EINVAL] The address region (starting at addr and continuing for len bytes) is not wholly within the program’s data segment. 

SEE ALSO

brk(2), getpagesize(2), phys(3C), mem(4)

BUGS

Mmap is only partially implemented and cannot map pages to an ordinary file.  It is Integrated Solutions machine-dependent. 

4th Berkeley Distribution  —  1 August 1985

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026