Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libc/sys/mmap.2
Show All 22 Lines | |||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
.\" SUCH DAMAGE. | .\" SUCH DAMAGE. | ||||
.\" | .\" | ||||
.\" @(#)mmap.2 8.4 (Berkeley) 5/11/95 | .\" @(#)mmap.2 8.4 (Berkeley) 5/11/95 | ||||
.\" $FreeBSD$ | .\" $FreeBSD$ | ||||
.\" | .\" | ||||
.Dd October 21, 2020 | .Dd October 27, 2020 | ||||
.Dt MMAP 2 | .Dt MMAP 2 | ||||
.Os | .Os | ||||
.Sh NAME | .Sh NAME | ||||
.Nm mmap | .Nm mmap | ||||
.Nd allocate memory, or map files or devices into memory | .Nd allocate memory, or map files or devices into memory | ||||
.Sh LIBRARY | .Sh LIBRARY | ||||
.Lb libc | .Lb libc | ||||
.Sh SYNOPSIS | .Sh SYNOPSIS | ||||
▲ Show 20 Lines • Show All 274 Lines • ▼ Show 20 Lines | |||||
.Dv PROT_WRITE , | .Dv PROT_WRITE , | ||||
it does not eliminate soft faults on the initial write accesses to the | it does not eliminate soft faults on the initial write accesses to the | ||||
region. | region. | ||||
.It Dv MAP_PRIVATE | .It Dv MAP_PRIVATE | ||||
Modifications are private. | Modifications are private. | ||||
.It Dv MAP_SHARED | .It Dv MAP_SHARED | ||||
Modifications are shared. | Modifications are shared. | ||||
.It Dv MAP_STACK | .It Dv MAP_STACK | ||||
Creates both a mapped region that grows downward on demand and an | |||||
adjoining guard that both reserves address space for the mapped region | |||||
to grow into and limits the mapped region's growth. | |||||
Together, the mapped region and the guard occupy | |||||
.Fa len | |||||
bytes of the address space. | |||||
The guard starts at the returned address, and the mapped region ends at | |||||
the returned address plus | |||||
.Fa len | |||||
bytes. | |||||
Upon access to the guard, the mapped region automatically grows in size, | |||||
and the guard shrinks by an equal amount. | |||||
Essentially, the boundary between the guard and the mapped region moves | |||||
downward so that the access falls within the enlarged mapped region. | |||||
However, the guard will never shrink to less than the number of pages | |||||
specified by the sysctl | |||||
.Dv security.bsd.stack_guard_page , | |||||
thereby ensuring that a gap for detecting stack overflow always exists | |||||
between the downward growing mapped region and the closest mapped region | |||||
beneath it. | |||||
.Pp | |||||
.Dv MAP_STACK | .Dv MAP_STACK | ||||
implies | implies | ||||
.Dv MAP_ANON , | .Dv MAP_ANON | ||||
and | and | ||||
.Fa offset | .Fa offset | ||||
of 0. | of 0. | ||||
The | The | ||||
.Fa fd | .Fa fd | ||||
argument | argument | ||||
must be -1 and | must be -1 and | ||||
.Fa prot | .Fa prot | ||||
must include at least | must include at least | ||||
.Dv PROT_READ | .Dv PROT_READ | ||||
and | and | ||||
.Dv PROT_WRITE . | .Dv PROT_WRITE . | ||||
.Pp | |||||
This option creates | |||||
a memory region that grows to at most | |||||
.Fa len | |||||
bytes in size, starting from the stack top and growing down. | |||||
The | |||||
stack top is the starting address returned by the call, plus | |||||
.Fa len | |||||
bytes. | |||||
The bottom of the stack at maximum growth is the starting | |||||
address returned by the call. | |||||
.Pp | |||||
Stacks created with | |||||
.Dv MAP_STACK | |||||
automatically grow. | |||||
Guards prevent inadvertent use of the regions into which those | |||||
stacks can grow without requiring mapping the whole stack in advance. | |||||
The size of the guard, in pages, is specified by sysctl | The size of the guard, in pages, is specified by sysctl | ||||
.Dv security.bsd.stack_guard_page . | .Dv security.bsd.stack_guard_page . | ||||
.El | .El | ||||
.Pp | .Pp | ||||
The | The | ||||
.Xr close 2 | .Xr close 2 | ||||
system call does not unmap pages, see | system call does not unmap pages, see | ||||
.Xr munmap 2 | .Xr munmap 2 | ||||
▲ Show 20 Lines • Show All 203 Lines • Show Last 20 Lines |