munmap Subroutine

Purpose

Unmaps pages of memory.

Library

Standard C Library (libc.a)

Syntax

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

int munmap ( addr len)
void *addr;
size_t len;

Description

The munmap subroutine unmaps a mapped file or shared memory region or anonymous memory region. The munmap subroutine unmaps regions created from calls to the mmap subroutine only.

If an address lies in a region that is unmapped by the munmap subroutine and that region is not subsequently mapped again, any reference to that address will result in the delivery of a SIGSEGV signal to the process.

Parameters

Item Description
addr Specifies the address of the region to be unmapped. Must be a multiple of the page size returned by the sysconf subroutine using the _SC_PAGE_SIZE value for the Name parameter.
len Specifies the length, in bytes, of the region to be unmapped. If the len parameter is not a multiple of the page size returned by the sysconf subroutine using the _SC_PAGE_SIZE value for the Name parameter, the length of the region is rounded up to the next multiple of the page size.

Return Values

When successful, the munmap subroutine returns 0. Otherwise, it returns -1 and sets the errno global variable to indicate the error.

Error Codes

If the munmap subroutine is unsuccessful, the errno global variable is set to the following value:

Item Description
EINVAL The addr parameter is not a multiple of the page size as returned by the sysconf subroutine using the _SC_PAGE_SIZE value for the Name parameter.
EINVAL The application has requested Single UNIX Specification, Version 2 compliant behavior and the len arguement is 0.