Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

memcntl(2)

mmap(2)

getpagesize(2)

sysconf(2)



munmap(2)                         SDK R4.11                        munmap(2)


NAME
       munmap - unmap pages of memory

SYNOPSIS
       #include <sys/types.h>
       #include <sys/mman.h>

       int munmap(void * addr, size_t len);

   where:
       addr   Starting address of the memory region to unmap
       len    Length in bytes of the memory region to unmap

DESCRIPTION
       The munmap() function removes any mappings for pages in the range
       [addr, addr + len).  Such mappings in the address range will be
       removed regardless of how they were established.  References to
       unmapped pages will result in the delivery of a SIGSEGV signal to the
       process.  Note that the mmap(2) function performs an implicit
       munmap() operation when MAP_FIXED is specified in the flags
       parameter.

       The addr parameter must specify a page aligned address.  The system
       page size is available by calling either getpagesize(2) or sysconf(2)
       with the _SC_PAGESIZE parameter; both calls return identical values.

       The len parameter is rounded up to the next multiple of the page size
       before computing the ending address of the range to unmap.

       The addr and len parameters to munmap() operations do not have to
       match the similar parameters to mmap(2) calls which may have
       established the mapping.  Munmap() can release the address range of
       any part of a mapped region, at the beginning, ending, or middle of
       it.  Also, the [addr, addr + len) interval may span regions of
       multiple mmap(2) calls, possibly containing addresses not currently
       mapped in the caller's address space.  Further, not only mmap(2)
       regions can be unmapped by munmap().  Any part of a process's address
       space which overlaps the range [addr, addr + len) will be unmapped,
       even if the segment is part of the data segment, stack, or a shared
       memory segment.

       When the given address range spans a shared memory region, the
       attached shared memory segment will be unmapped.  However, such
       segments will still be considered attached by the system, which may
       cause unexpected results.  Processes should avoid the use of munmap()
       on ranges of shared memory addresses, and instead use shmdt(2) to
       cleanly detach the shared memory segment.

       Regions of the process's data segment (allocated via brk(2), sbrk(2),
       and malloc(3C)) can also be invalidated with munmap().  This practice
       is not recommended since it does not alter the caller's break value,
       and thus may lead to unexpected results.

       Since the [addr, addr + len) range may span unmapped portions of the
       caller's address space, the actual memory unmapped by munmap() may be
       smaller than len.  The size of the caller's virtual address space as
       accounted for by the system will decrease only by the sum of the
       ranges of newly unmapped pages.

       Note that any pages within the range which were locked into memory
       via memcntl(2) or any of its associated library routines will be
       unlocked when unmapped.

ACCESS CONTROL
       No access check is made.

RETURN VALUE
       Upon successful completion, munmap() returns a value of 0.
       Otherwise, it returns the value -1, and sets errno to indicate an
       error.

DIAGNOSTICS
       Under the following conditions, munmap() fails and sets errno to:

       EINVAL         if len is equal to zero.

       EINVAL         if addr is not a page aligned address.

       EINVAL         if addr+len exceeds the largest legal user address.

SEE ALSO
       memcntl(2), mmap(2), getpagesize(2), sysconf(2).


Licensed material--property of copyright holder(s)

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