delorie.com/djgpp/doc/libc/libc_588.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

mprotect

Syntax

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

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

Description

This function modifies the access protection of a memory region. Protection occurs in 4Kbyte regions (pages) aligned on 4Kbyte boundaries. All pages in the region will be changed, so addr and len should be multiples of 4096.

The protection prot for each page is specified with the values: PROT_NONE Region can not be touched (if or'ed is ignored). PROT_READ Region can be read (can be or'ed with PROT_WRITE). PROT_WRITE Region can be written (implies read access). This function is only supported on DPMI hosts which provide some V1.0 extensions on V0.9 memory blocks.

Return Value

The function returns 0 if successful and the value -1 if all the pages could not be set.

Portability

ANSI/ISO C No
POSIX No

Example

 
mprotect(readonly_buffer,8192,PROT_READ);
mprotect(guard_area,4096,PROT_NONE);
mprotect(NULL,4096,PROT_WRITE); /* Let NULL pointers not generate
                                 * exceptions */


  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004