#include <sys/mman.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>

#define HP_SIZE  (2 * 1024 * 1024) // <-- Adjust with size of the supported HP size on your system


static void handler(int sig)
{
  printf("Signal %d\n", sig);
}

int main(void)
{
  char *addr, *addr1;

  signal(SIGINT, handler);

  // Map a Huge page
  addr = mmap(NULL, HP_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED| MAP_HUGETLB, -1, 0);
  if (addr == MAP_FAILED) {
    perror("mmap()");
    return 1;
  }

  printf("Mapping located at address: %p\n", addr);

  pause();

  printf("Writing into the memory area...\n");

  memset(addr, 0xff, HP_SIZE);

  pause();

  printf("Exiting...\n");

  return 0;
}
