|
|||||||
|
|
MPROTECTSection: Linux Programmer's Manual (2)Updated: 1997-05-31 Index Return to Main Contents ̾Á°mprotect - ¥¢¥¯¥»¥¹²Äǽ¤Ê¥á¥â¥ê¶è²è¤òÀ©¸æ¤¹¤ë½ñ¼°#include <sys/mman.h> int mprotect(const void *addr, size_t len, int prot); ÀâÌÀmprotect ¤Ï¥á¥â¥ê¶è²è¤¬¤É¤Î¤è¤¦¤Ë¥¢¥¯¥»¥¹¤Ç¤¤ë¤«¤òÀ©¸æ¤¹¤ë¡£ÊݸͿ¤¨¤é¤ì¤Æ ¤¤¤Æ¥¢¥¯¥»¥¹¤Ç¤¤Ê¤¤¾ì¹ç¡¢¥×¥í¥°¥é¥à¤Ï SIGSEGV ¤ò¼õ¤±¤È¤ë¡£prot ¤Ï°Ê²¼¤ÎÃÍ¤Î¥Ó¥Ã¥È OR ¤Ç¤¢¤ë:
¿·¤·¤¤Êݸî¤Ïº£¤Þ¤Ç¤ÎÊݸî¤òÃÖ¤´¹¤¨¤ë¡£Î㤨¤Ð¡¢¥á¥â¥ê¤¬°ÊÁ°¤Ë¤Ï PROT_READ ¤È¥Þ¡¼¥¯¤µ¤ì¤Æ¤¤¤Æ¡¢mprotect ¤¬ prot PROT_WRITE ¤Ç¸Æ¤Ó½Ð¤µ¤ì¤¿¾ì¹ç¤Ï¡¢¤â¤¦¤½¤ì¤ÏÆÉ¤ß¹þ¤ß²Äǽ ¤Ç¤Ï¤Ê¤¤¡£ ÊÖ¤êÃÍÀ®¸ù¤·¤¿¾ì¹ç¤Ï¡¢ mprotect ¤Ï¥¼¥í¤òÊÖ¤¹¡£¥¨¥é¡¼¤Î¾ì¹ç¤Ï -1 ¤¬ÊÖ¤µ¤ì¡¢ errno ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤ë¡£¥¨¥é¡¼
Îã#include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/mman.h> #include <limits.h> /* for PAGESIZE */ #ifndef PAGESIZE #define PAGESIZE 4096 #endif int main(void) { char *p; char c; /* Allocate a buffer; it will have the default protection of PROT_READ|PROT_WRITE. */ p = malloc(1024+PAGESIZE-1); if (!p) { perror("Couldn't malloc(1024)"); exit(errno); } /* Align to a multiple of PAGESIZE, assumed to be a power of two */ p = (char *)(((int) p + PAGESIZE-1) & ~(PAGESIZE-1)); c = p[666]; /* Read; ok */ p[666] = 42; /* Write; ok */ /* Mark the buffer read-only. */ if (mprotect(p, 1024, PROT_READ)) { perror("Couldn't mprotect"); exit(errno); } c = p[666]; /* Read; ok */ p[666] = 42; /* Write; program dies on SIGSEGV */ exit(0); } ½àµòSVr4, POSIX.1b (°ÊÁ°¤Î POSIX.4). SVr4 ¤Ï¾¤Ë EAGAIN ¥¨¥é¡¼¤òÄêµÁ¤·¤Æ¤¤¤ë¡£ SVr4 ¤Î¥¨¥é¡¼¾õÂÖ¤ò Linux ¤Î¤â¤Î¤ËÂбþ¤·¤Ê¤¤¡£ POSIX.1b ¤Ç¤Ï mprotect ¤Ï mmap(2) ¤ÇÆÀ¤¿¥á¥â¥êÎΰè¤Î¤ß¤¬»ÈÍѤǤ¤ë¤È¤µ¤ì¤Æ¤¤¤ë¡£´ØÏ¢¹àÌÜmmap(2)
Index | ||||||
|
|
|
Home :: Copyright :: Privacy :: Credits :: Get a free Linuxinfor Email Account Document on this page is part of "Linuxinfor Man Pages in HTML Format: man2". See Index Page for more info about Authorship and Copyright. 1999-2008 Linuxinfor.com. No rights reserved. |