Go to the previous, next section.

mmap and munmap

SYNOPSIS

caddr_t mmap(caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset);

int munmap(caddr_t addr, size_t len);

PARAMETERS

addr: for mmap, [in] where to map the object. For munmap, [in] the region to unmap.

len: [in] length of the mapped region.

prot: [in] protection for the mapping space.

flags: [in] see description.

fd: [in] the object to map.

offset: [in] begining of the part of the object to map.

DESCRIPTION

Maps an file object in the virtual address space of the task. In the case where offset or len are not multiple of a page size, the mapping space may extend beyond the specified range. addr is only a clue to the system as where to place the mapping region. The system may choose to map the object elsewhere. A value of zero for addr tells the system to map the object where it sees fit. A sucessfull mmap on a previously mapped region cancel the previous mapping on that region. The prot parameter may be one or more or'ed values among the following:

PROT_EXEC
the mapped range is executable.

PROT_READ
the mapped range is readable.

PROT_WRITE
the mapped range is writable.

The flags parameter my be one or more or'ed values among the following:

MAP_ANON
the new region is not associated with any physical file. In this case, the fd parameter is used to name the region. If no name is needed, fd may be set to -1.

MAP_FILE
the new region is a mapping of a regular file or a character device.

MAP_FIXED
the system may not choose another memory region than addr for mapping. If this region cannot be used, the call fails.

MAP_HASSEMAPHORE
notifies the system that the mapped region may contain semaphores.

MAP_INHERIT
allow for mapped regions to be inherited through the exec system call.

MAP_PRIVATE
modifications to the mapped region are private.

MAP_SHARED
modifications to the mapped region are public.

munmap unmaps the region.

RETURN VALUE

On success mmap returns the address of the newly mapped region, munmap returns zero. On error, those calls return -1 and sets errno to one of the following:

Go to the previous, next section.