Created
March 11, 2020 09:52
-
-
Save GoldsteinE/6d9bd7d5a0eab009c12009e5be1ce538 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
#include <stdio.h> | |
#include <sys/mman.h> | |
int main() { | |
printf("mmaping zero\n"); | |
int* pa = mmap(0, sizeof(int), PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0); | |
if (pa == MAP_FAILED) { | |
perror("mmap failed: "); | |
return 1; | |
} | |
printf("pointer = %p\n", pa); | |
printf("assigning value\n"); | |
*pa = 5; | |
printf("value = %d\n", *pa); | |
printf("our pointer is %s!", (pa == NULL ? "null" : "not null")); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment