#include #include #include #include void die(const char *what) { perror(what); exit(1); } int main(int arg, char **argv) { void *p = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (p == MAP_FAILED) die("mmap"); /* Tickle the page. */ ((char *) p)[0] = 0; if (mprotect(p, 4096, PROT_NONE) != 0) die("mprotect"); if (mprotect(p, 4096, PROT_READ) != 0) die("mprotect"); if (munmap(p, 4096) != 0) die("munmap"); return 0; }