mirror of
https://github.com/fluencelabs/musl
synced 2025-04-25 07:12:15 +00:00
return chunks split off by memalign using __bin_chunk instead of free
this change serves multiple purposes: 1. it ensures that static linking of memalign-family functions will pull in the system malloc implementation, thereby causing link errors if an attempt is made to link the system memalign functions with a replacement malloc (incomplete allocator replacement). 2. it eliminates calls to free that are unpaired with allocations, which are confusing when setting breakpoints or tracing execution. as a bonus, making __bin_chunk external may discourage aggressive and unnecessary inlining of it.
This commit is contained in:
parent
3c2cbbe7ba
commit
72141795d4
@ -36,4 +36,7 @@ struct bin {
|
|||||||
|
|
||||||
#define IS_MMAPPED(c) !((c)->csize & (C_INUSE))
|
#define IS_MMAPPED(c) !((c)->csize & (C_INUSE))
|
||||||
|
|
||||||
|
__attribute__((__visibility__("hidden")))
|
||||||
|
void __bin_chunk(struct chunk *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -263,8 +263,6 @@ static int pretrim(struct chunk *self, size_t n, int i, int j)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bin_chunk(struct chunk *);
|
|
||||||
|
|
||||||
static void trim(struct chunk *self, size_t n)
|
static void trim(struct chunk *self, size_t n)
|
||||||
{
|
{
|
||||||
size_t n1 = CHUNK_SIZE(self);
|
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;
|
next->psize = n1-n | C_INUSE;
|
||||||
self->csize = n | C_INUSE;
|
self->csize = n | C_INUSE;
|
||||||
|
|
||||||
bin_chunk(split);
|
__bin_chunk(split);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *malloc(size_t n)
|
void *malloc(size_t n)
|
||||||
@ -436,7 +434,7 @@ copy_free_ret:
|
|||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bin_chunk(struct chunk *self)
|
void __bin_chunk(struct chunk *self)
|
||||||
{
|
{
|
||||||
struct chunk *next = NEXT_CHUNK(self);
|
struct chunk *next = NEXT_CHUNK(self);
|
||||||
size_t final_size, new_size, size;
|
size_t final_size, new_size, size;
|
||||||
@ -524,7 +522,7 @@ void free(void *p)
|
|||||||
if (IS_MMAPPED(self))
|
if (IS_MMAPPED(self))
|
||||||
unmap_chunk(self);
|
unmap_chunk(self);
|
||||||
else
|
else
|
||||||
bin_chunk(self);
|
__bin_chunk(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __malloc_donate(char *start, char *end)
|
void __malloc_donate(char *start, char *end)
|
||||||
@ -543,5 +541,5 @@ void __malloc_donate(char *start, char *end)
|
|||||||
struct chunk *c = MEM_TO_CHUNK(start), *n = MEM_TO_CHUNK(end);
|
struct chunk *c = MEM_TO_CHUNK(start), *n = MEM_TO_CHUNK(end);
|
||||||
c->psize = n->csize = C_INUSE;
|
c->psize = n->csize = C_INUSE;
|
||||||
c->csize = n->psize = C_INUSE | (end-start);
|
c->csize = n->psize = C_INUSE | (end-start);
|
||||||
bin_chunk(c);
|
__bin_chunk(c);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ void *__memalign(size_t align, size_t len)
|
|||||||
n->psize = c->csize = C_INUSE | (new-mem);
|
n->psize = c->csize = C_INUSE | (new-mem);
|
||||||
n->csize = t->psize -= new-mem;
|
n->csize = t->psize -= new-mem;
|
||||||
|
|
||||||
free(mem);
|
__bin_chunk(c);
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user