Created
September 26, 2021 14:06
-
-
Save sgqy/e318921c04cab5c7f9ed57ba5613ab05 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 <string.h> | |
#include <stdio.h> | |
#include <errno.h> | |
#include <sys/mman.h> | |
int main() | |
{ | |
#if 0 | |
const size_t addr = 0x00000100f0000000; | |
const size_t sz = 1024 * 1024 * 1024; | |
printf("hint: 0x%lx, size: %ld\n", addr, sz); | |
void *p = mmap( (void *)addr, // addr | |
sz, // size | |
PROT_READ | PROT_WRITE, // | |
MAP_ANONYMOUS | MAP_PRIVATE, | |
-1, // fd | |
0 // fseek | |
); | |
printf("auto: %p: %s\n", p, strerror(errno)); | |
munmap(p, sz); | |
p = mmap( (void *)addr, // addr | |
sz, // size | |
PROT_READ | PROT_WRITE, // | |
MAP_ANONYMOUS | MAP_FIXED, | |
-1, // fd | |
0 // fseek | |
); | |
printf("fix : %p: %s\n", p, strerror(errno)); | |
munmap(p, sz); | |
return 0; | |
#endif | |
void *p = | |
mmap( (void *) 0x80c0000000, 1048576, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); | |
printf("auto: %p: %s\n", p, strerror(errno)); | |
p = | |
mmap( (void *) 0x80c0000000, 1048576, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); | |
printf("auto: %p: %s\n", p, strerror(errno)); | |
p = | |
mmap( (void *) 0x80c0100000, 1048576, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); | |
printf("auto: %p: %s\n", p, strerror(errno)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment