Skip to content

Instantly share code, notes, and snippets.

@GoldsteinE
Created March 11, 2020 09:52
Show Gist options
  • Save GoldsteinE/6d9bd7d5a0eab009c12009e5be1ce538 to your computer and use it in GitHub Desktop.
Save GoldsteinE/6d9bd7d5a0eab009c12009e5be1ce538 to your computer and use it in GitHub Desktop.
#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