X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmalloc%2Fmalloc.c;h=96982596b94d8c638eb716f1b0000081288e7e8c;hb=63a4c9adf227a6f6a5f7f70f6dc3f8863f846927;hp=c8bc9227c6a5bbc5f88920d9abfd4d6bc186f1ce;hpb=23389b1988b061e8487c316893a8a8eb77770a2f;p=musl diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index c8bc9227..96982596 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -20,6 +20,8 @@ static struct { volatile int free_lock[2]; } mal; +int __malloc_replaced; + /* Synchronization tools */ static inline void lock(volatile int *lk) @@ -121,8 +123,6 @@ void __dump_heap(int x) } #endif -void *__expand_heap(size_t *); - static struct chunk *expand_heap(size_t n) { static int heap_lock[2]; @@ -263,8 +263,6 @@ static int pretrim(struct chunk *self, size_t n, int i, int j) return 1; } -static void bin_chunk(struct chunk *); - static void trim(struct chunk *self, size_t n) { size_t n1 = CHUNK_SIZE(self); @@ -280,7 +278,7 @@ static void trim(struct chunk *self, size_t n) next->psize = n1-n | C_INUSE; self->csize = n | C_INUSE; - bin_chunk(split); + __bin_chunk(split); } void *malloc(size_t n) @@ -358,10 +356,13 @@ void *calloc(size_t m, size_t n) } n *= m; void *p = malloc(n); - if (!p || IS_MMAPPED(MEM_TO_CHUNK(p))) - return p; - if (n >= PAGE_SIZE) - n = mal0_clear(p, PAGE_SIZE, n); + if (!p) return p; + if (!__malloc_replaced) { + if (IS_MMAPPED(MEM_TO_CHUNK(p))) + return p; + if (n >= PAGE_SIZE) + n = mal0_clear(p, PAGE_SIZE, n); + } return memset(p, 0, n); } @@ -436,7 +437,7 @@ copy_free_ret: return new; } -static void bin_chunk(struct chunk *self) +void __bin_chunk(struct chunk *self) { struct chunk *next = NEXT_CHUNK(self); size_t final_size, new_size, size; @@ -524,7 +525,7 @@ void free(void *p) if (IS_MMAPPED(self)) unmap_chunk(self); else - bin_chunk(self); + __bin_chunk(self); } void __malloc_donate(char *start, char *end) @@ -543,5 +544,5 @@ void __malloc_donate(char *start, char *end) struct chunk *c = MEM_TO_CHUNK(start), *n = MEM_TO_CHUNK(end); c->psize = n->csize = C_INUSE; c->csize = n->psize = C_INUSE | (end-start); - bin_chunk(c); + __bin_chunk(c); }