Skip to content

Instantly share code, notes, and snippets.

@dsh0005
Created June 22, 2021 20:38
Show Gist options
  • Save dsh0005/3761286ab1b62df56997a308c3dd40f5 to your computer and use it in GitHub Desktop.
Save dsh0005/3761286ab1b62df56997a308c3dd40f5 to your computer and use it in GitHub Desktop.
Allocate high addresses with mmap
#include <stdio.h>
#include <stdint.h>
#include <sys/mman.h>
int main(void){
void * const hint = (void*)~(uintptr_t)0;
const void * const reserved = mmap(hint, 1, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
printf("hint:%p\nreserved: %p\n", hint, reserved);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment