Name
munmap - unmap files or devices into memory
Library
libc.lib
Synopsis
|
int
munmap (void *addr, size_t len);
|
Return values
Upon successful completion, munmap() shall return 0; otherwise, it shall return -1 and set
errno
to indicate the error.
Detailed description
The
munmap
system call
deletes the mappings for the specified address range,
and causes further references to addresses within the range
to generate invalid memory references. The current implementation does not
support partial deletion of mapped memory, i.e if
offset
to
offset+len
section of memory was mapped using
mmap,
then the entire section of memory
offset+len
will be deleted.
Examples
/*
* Detailed description: Example to create a mapped memory to a file region.
* Precondition: None
*
*/
#include <unistd.h>
#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
int main(void)
{
int fd = -1;
char* mapaddr;
int len = getpagesize();
int prot = PROT_WRITE | PROT_READ;
if((fd = open("C:\est.txt", O_RDWR | O_CREAT, 0666) ) < 0){
printf("File open failed\n");
}
mapaddr = (char*)mmap((void*)0, len, prot, MAP_SHARED, fd, 0);
if(mapaddr == MAP_FAILED){
printf("mmap on file failed\n");
}
printf("mmap on file succeeded\n");
}
Errors
The
munmap
system call
will fail if:
[EINVAL]
|
|
The
addr
argument was not page aligned, the
len
argument was zero or negative, or
some part of the region being unmapped is outside the
valid address range for a process.
|
See also
mmap,
mprotect,
msync,
getpagesize
Feedback
For additional information or queries on this page send feedback
© 2005-2007 Nokia
|
|