inline void* calloc(size_t nmemb, size_t size) { void* ptr = __calloc(nmemb, size, __malloc_pool); #if DEBUG malloced(((void**)read_rbp())[1], nmemb * size, ptr); #endif /* DEBUG */ return ptr; }
char *DMrealloc(char *ptr, int size, char *fname, int line) { char *saveptr; saveptr = ptr; ptr = DMmemcheck(ptr, fname, line); if ((ptr = (char *) realloc(ptr, size + HDRSIZE + 1)) == NULL) { fprintf(stderr, "%s[%d]: realloc(0x%x,%d) OUT OF MEMORY\n", fname, line, saveptr, size); abort(); } ptr = guardit(ptr, size); if (DMverbose || (DMtriggeraddr == ptr) || (DMtriggeraddr == saveptr)) { fprintf(stderr, "%s[%d]: realloc(0x%x,%d) = 0x%x\n", fname, line, saveptr, size, ptr); TRIGGER(saveptr); TRIGGER(ptr); } freed(saveptr, fname, line); malloced(ptr); return(ptr); }
char *DMcalloc(int size, int nitems, char *fname, int line) { char *ptr; int totalsize; int i; char *tempptr; DMmemcheck(NULL, fname, line); totalsize = size * nitems; if ((ptr = (char *) malloc(totalsize + HDRSIZE + 1)) == NULL) { fprintf(stderr, "%s[%d]: calloc(%d,%d) OUT OF MEMORY\n", fname, line, size, nitems); abort(); } ptr = guardit(ptr, totalsize); /* initialize to zeros */ tempptr = ptr; for (i = 0; i < totalsize; i++) { *tempptr++ = 0; } if (DMverbose || (ptr == DMtriggeraddr)) { fprintf(stderr, "%s[%d]: calloc(%d,%d) = 0x%x\n", fname, line, size, nitems, ptr); TRIGGER(ptr); } malloced(ptr); return(ptr); }
inline void* realloc(void* ptr, size_t size) { void* ptr2 = __realloc(ptr, size, __malloc_pool); #if DEBUG freed(ptr); malloced(((void**)read_rbp())[1], size, ptr2); #endif /* DEBUG */ return ptr2; }
inline void* malloc(size_t size) { void* ptr = __malloc(size, __malloc_pool); if(!ptr) { // TODO: print to stderr printf("Not enough local memory!!!\n"); printf("Requested size: %ld from %p\n", size, ((void**)read_rbp())[1]); #if DEBUG malloc_statistics(); #endif /* DEBUG */ while(1) asm("hlt"); } #if DEBUG malloced(((void**)read_rbp())[1], size, ptr); #endif /* DEBUG */ return ptr; }
char *DMmalloc(int size, char *fname, int line) { char *ptr; DMmemcheck(NULL, fname, line); if ((ptr = (char *) malloc(size + HDRSIZE + 1)) == NULL) { fprintf(stderr, "%s[%d]: malloc(%d) OUT OF MEMORY\n", fname, line, size); abort(); } ptr = guardit(ptr, size); if (DMverbose || (DMtriggeraddr == ptr)) { fprintf(stderr, "%s[%d]: malloc(%d) = 0x%x\n", fname, line, size, ptr); TRIGGER(ptr); } malloced(ptr); return(ptr); }