Controlling Memory-Mapped Regions

A memory-mapped region often requires its attributes to be queried or changed in some fashion. This section looks at four system calls designed for this purpose:

mprotect(2) Change the access of the indicated memory pages.
madvise(2) Advise the UNIX kernel how you intend to use your memory region.
mincore(2) Determine if pages of mapped memory are currently in memory.
msync(2) Where modifications exist, indicate what regions of memory should be updated to the mapped files.

Changing the Access Protection

A memory-mapped region, entirely or in part, may have its access protections changed by the mprotect(2) system call. Its function synopsis is as follows:

 #include <sys/types.h> #include <sys/mman.h> int mprotect(const ...

Get Advanced UNIX Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.