Skip to content

Instantly share code, notes, and snippets.

@dryman
Created October 7, 2016 03:33
Show Gist options
  • Save dryman/6eae4c79f267d1cc0f72353261d63780 to your computer and use it in GitHub Desktop.
Save dryman/6eae4c79f267d1cc0f72353261d63780 to your computer and use it in GitHub Desktop.
#include <sys/mman.h>
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
int main()
{
ptrdiff_t offset = 1L << 36;
void* addr = NULL + offset;
void* map_addr;
for (int i = 0; i < 64; i++)
{
map_addr = mmap(addr, 1UL << 36,
PROT_READ | PROT_WRITE,
MAP_ANON | MAP_PRIVATE | MAP_FIXED,
-1, 0);
if (map_addr == MAP_FAILED)
{
printf("map failed on %p\n", addr);
addr += offset;
}
else
{
printf("successfully mmap on %p\n", map_addr);
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment