Modifying sbrk allocators

Custom allocators are written to obtain their memory directly from the operating system using brk, sbrk, mmap, or some other method. Usually such allocators also supply a definition of malloc and free because many libc functions call malloc and the default malloc does not work when other functions are calling sbrk.

To use Purify with sbrk allocators, you need to write an alternate implementation of your allocator calling malloc instead of sbrk. For example, if you have an external function GetPages that calls sbrk, and your own malloc implementation on top of GetPages, you could use:

char* GetPages(int n) {
    if (purify_is_running()) {
        return malloc(n * PAGESIZE);
    } else {
        return sbrk(n * PAGESIZE); /* original code */
    }
}
    
/* for Purify, don't define malloc, free: use default from libc */
#ifndef PURIFY     /* original case */
char* malloc(int n) {
    ... original code for malloc on top of GetPages ...
}
void free(char* x) {
    ...
}
#endif /* PURIFY */