Home arrow BrainDump arrow Page 3 - Using mmap() for Advanced File I/O

Changing the Protection of a Mapping - BrainDump

In this fourth part of a seven-part series on Linux I/O file system calls, you will learn how to use mmap(). It is excerpted from chapter four of the book Linux System Programming: Talking Directly to the Kernel and C Library, written by Robert Love (O'Reilly, 2007; ISBN: 0596009585). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

TABLE OF CONTENTS:
  1. Using mmap() for Advanced File I/O
  2. Resizing a Mapping
  3. Changing the Protection of a Mapping
  4. Synchronizing a File with a Mapping
  5. Giving Advice on a Mapping
By: O'Reilly Media
Rating: starstarstarstarstar / 5
December 18, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

POSIX defines the mprotect() interface to allow programs to change the permissions of existing regions of memory:

  #include <sys/mman.h>

  int mprotect (const void *addr,
               
size_t len,
               
int prot);

A call to mprotect() will change the protection mode for the memory pages contained in [addr,addr+len), where addr is page-aligned. Theprotparameter accepts the same values as theprotgiven tommap():PROT_NONE,PROT_READ,PROT_WRITE, andPROT_EXEC. These values are not additive; if a region of memory is readable, andprot is set to onlyPROT_WRITE, the call will make the region only writable.

On some systems,mprotect()may operate only on memory mappings previously created viammap(). On Linux,mprotect()can operate on any region of memory.

On success, mprotect() returns 0. On failure, it returns -1, and setserrnoto one of the following:

EACCESS

The memory cannot be given the permissions requested byprot. This can happen, for example, if you attempt to set the mapping of a file opened read-only to writable.

EINVAL

The parameteraddr is invalid or not page-aligned.

ENOMEM

Insufficient kernel memory is available to satisfy the request, or one or more pages in the given memory region are not a valid part of the processí address space.



 
 
>>> More BrainDump Articles          >>> More By O'Reilly Media
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

BRAINDUMP ARTICLES

- Apple Founder Steve Jobs Dies
- Steve Jobs` Era at Apple Ends
- Google's Chrome Developer Tool Updated
- Google's Chrome 6 Browser Brings Speed to th...
- New Open Source Update Fedora 13 is Released...
- Install Linux with Knoppix
- iPad Developers Flock To SDK 3.2
- Managing a Linux Wireless Access Point
- Maintaining a Linux Wireless Access Point
- Securing a Linux Wireless Access Point
- Configuring a Linux Wireless Access Point
- Building a Linux Wireless Access Point
- Migrating Oracle to PostgreSQL with Enterpri...
- Demystifying SELinux on Kernel 2.6
- Yahoo and Microsoft Create Ad Partnership

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: