Files
oldlinux-files/Ref-docs/syscalls/syscalls_39.html
2024-02-19 00:21:47 -05:00

104 lines
4.1 KiB
HTML

<html><!-- This HTML file has been created by texi2html 1.29
from syscalls.texi on 4 June 1994 -->
<TITLE>Syscall specifications of Linux - mmap</TITLE>
<P>Go to the <A HREF="syscalls_38.html" tppabs="http://www.infran.ru/TechInfo/syscalls/syscalls_38.html">previous</A>, <A HREF="syscalls_40.html" tppabs="http://www.infran.ru/TechInfo/syscalls/syscalls_40.html">next</A> section.<P>
<H2><A NAME="SEC39" HREF="syscalls_toc.html#SEC39" tppabs="http://www.infran.ru/TechInfo/syscalls/syscalls_toc.html#SEC39">mmap and munmap</A></H2>
<P>
<H3>SYNOPSIS</H3>
<P>
<CODE>caddr_t mmap(caddr_t <VAR>addr</VAR>, size_t <VAR>len</VAR>, int <VAR>prot</VAR>, int
<VAR>flags</VAR>, int <VAR>fd</VAR>, off_t <VAR>offset</VAR>);</CODE>
<P>
<CODE>int munmap(caddr_t <VAR>addr</VAR>, size_t <VAR>len</VAR>);</CODE>
<P>
<H3>PARAMETERS</H3>
<P>
<VAR>addr</VAR>: for <CODE>mmap</CODE>, [in] where to map the object. For
<CODE>munmap</CODE>, [in] the region to unmap.
<P>
<VAR>len</VAR>: [in] length of the mapped region.
<P>
<VAR>prot</VAR>: [in] protection for the mapping space.
<P>
<VAR>flags</VAR>: [in] see description.
<P>
<VAR>fd</VAR>: [in] the object to map.
<P>
<VAR>offset</VAR>: [in] begining of the part of the object to map.
<P>
<H3>DESCRIPTION</H3>
<P>
Maps an file object in the virtual address space of the task. In the
case where <VAR>offset</VAR> or <VAR>len</VAR> are not multiple of a page size,
the mapping space may extend beyond the specified range. <VAR>addr</VAR> 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
<VAR>addr</VAR> tells the system to map the object where it sees fit. A
sucessfull <CODE>mmap</CODE> on a previously mapped region cancel the previous
mapping on that region. The <CODE>prot</CODE> parameter may be one or more
or'ed values among the following:
<P>
<DL COMPACT>
<DT><CODE>PROT_EXEC</CODE>
<DD>the mapped range is executable.
<P>
<DT><CODE>PROT_READ</CODE>
<DD>the mapped range is readable.
<P>
<DT><CODE>PROT_WRITE</CODE>
<DD>the mapped range is writable.
</DL>
<P>
The <CODE>flags</CODE> parameter my be one or more or'ed values among the
following:
<P>
<DL COMPACT>
<DT><CODE>MAP_ANON</CODE>
<DD>the new region is not associated with any physical file. In this case,
the <VAR>fd</VAR> parameter is used to name the region. If no name is
needed, <VAR>fd</VAR> may be set to -1.
<P>
<DT><CODE>MAP_FILE</CODE>
<DD>the new region is a mapping of a regular file or a character device.
<P>
<DT><CODE>MAP_FIXED</CODE>
<DD>the system may not choose another memory region than <VAR>addr</VAR> for
mapping. If this region cannot be used, the call fails.
<P>
<DT><CODE>MAP_HASSEMAPHORE</CODE>
<DD>notifies the system that the mapped region may contain semaphores.
<P>
<DT><CODE>MAP_INHERIT</CODE>
<DD>allow for mapped regions to be inherited through the <CODE>exec</CODE> system
call.
<P>
<DT><CODE>MAP_PRIVATE</CODE>
<DD>modifications to the mapped region are private.
<P>
<DT><CODE>MAP_SHARED</CODE>
<DD>modifications to the mapped region are public.
</DL>
<P>
<CODE>munmap</CODE> unmaps the region.
<P>
<H3>RETURN VALUE</H3>
<P>
On success <CODE>mmap</CODE> returns the address of the newly mapped region,
<VAR>munmap</VAR> returns zero. On error, those calls return -1 and sets
<CODE>errno</CODE> to one of the following:
<P>
<UL>
<LI><CODE>EACCESS</CODE>: the protection requested for the mapped region is
not consistent with the mode of <VAR>fd</VAR>.
<LI><CODE>EINVAL</CODE>: the <CODE>flags</CODE> value is incorrect or
<CODE>MAP_FIXED</CODE> was requested but the address range is not a multiple
of a page size.
<LI><CODE>ENOMEM</CODE>: <CODE>MAP_FIXED</CODE> was requested but the memory range
can not be used for mapping or there is insufficient memory to complete
the call.
<LI><CODE>ENODEV</CODE>: the file descriptor cannot be mapped.
<LI><CODE>EBADF</CODE>, <CODE>EFAULT</CODE>.
</UL>
<P>Go to the <A HREF="syscalls_38.html" tppabs="http://www.infran.ru/TechInfo/syscalls/syscalls_38.html">previous</A>, <A HREF="syscalls_40.html" tppabs="http://www.infran.ru/TechInfo/syscalls/syscalls_40.html">next</A> section.<P>