What is the heap start address in program C?

Is there a way to set the heap start address in a GCC compiled C program in linux? On x86_64, my test program sets the heap address to 4 bytes of the reference address (less than FFFFFFFF). I want to set an 8-byte reference address for this for some testing (> FFFFFFFF). Does GCC provide any way to set the starting address of the heap?

+4
source share
1 answer

You can do this a little indirectly using sbrk():

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(void)
{
  sbrk(0xFFFFFFFF);
  printf("%p\n", malloc(1));
  return 0;
}

This works by "highlighting" the 0xFFFFFFFF bytes at the very beginning, so the next thing malloc()can allocate a higher address.

+3

All Articles