Using mmap

Using mmap - Using mmap The mmap() function establishes a...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Using mmap The mmap() function establishes a mapping between a process's address space and a file or shared memory object. #include <sys/mman.h> void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off); Mmap returns the address of the memory mapping and it will be always aligned to a page size (addr %PageSize==0). The data in the file can be read/written as if it were memory.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Using mmap Memory 0x00000000 0xFFFFFFFF Disk File mmap ptr= 0x00020000 ptr = mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)
Background image of page 2
Mmap parameters void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off); addr – Suggested address. If NULL is passed the OS will choose the address of the mapping. len – Length of the memory mapping. The mmaped file should have this length of larger or the program gets SEGV on access. prot – Protections of the mapping: PROT_READ, PROT_WRITE, PROT_EXEC, PROT_NONE.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Mmap parameters flags: - Semantics of the mapping: MAP_SHARED – Changes in memory will be done in the file
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/30/2012 for the course CS 354 taught by Professor Staff during the Fall '08 term at Purdue.

Page1 / 5

Using mmap - Using mmap The mmap() function establishes a...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online