Is there a way to set the heap start address in GCC compiled C program in linux? In x86_64 system,my test program sets the heap address to 4 byte referenced address ( less than FFFFFFFF). I want to set this to 8 byte referenced address for some testing ( > FFFFFFFF). Does GCC provide any way to set the heap start address?
7
votes
1 Answers
6
votes
You can do this a bit 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 "allocating" 0xFFFFFFFF bytes at the very start, so that the next thing malloc()
can allocate is a higher address.
malloc
-s are usingmmap
(and that is subject to ASLR...) – Basile Starynkevitch