Skip to content

Instantly share code, notes, and snippets.

@sgqy
Created September 26, 2021 14:06
Show Gist options
  • Save sgqy/e318921c04cab5c7f9ed57ba5613ab05 to your computer and use it in GitHub Desktop.
Save sgqy/e318921c04cab5c7f9ed57ba5613ab05 to your computer and use it in GitHub Desktop.
#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