#include #include static void *addr = (void *)0x2000000; /** * Tries to allocate a block of memory including address 0x2000000. * On success, returns a pointer to the beginning of that block. * On failure, returns NULL. */ void *allocateToAddr() { void *heapBase = sbrk(0); if (heapBase > addr) { fprintf(stderr, "Heap started at %p > %p\n", heapBase, addr); return NULL; } void *block = sbrk((addr-heapBase)+8); return block; } int main(int argc, char *argv[]) { void *p = allocateToAddr(); if (!p) return 1; char *c = addr; *c = 0; for(int i=0; i<10; i+=1) { *c += 1; printf("Address %p, value = %hhd\n", c, *c); sleep(2); } return 0; }