Last active
June 27, 2024 18:25
-
-
Save chrislattman/205eb38ae5f8c07151266208f6f2e1a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE // needed for MAP_ANONYMOUS | |
#include <stdio.h> | |
#include <sys/mman.h> | |
int main(void) | |
{ | |
void *ptr = mmap(NULL, 24, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | |
if (ptr == MAP_FAILED) { | |
perror("mmap"); | |
return 1; | |
} | |
int status = mprotect(ptr, 24, PROT_READ); | |
if (status != 0) { | |
perror("mprotect"); | |
return 1; | |
} | |
status = munmap(ptr, 24); | |
if (status != 0) { | |
perror("munmap"); | |
return 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment