|
|
077c9d |
commit 1ecba1fafc160ca70f81211b23f688df8676e612
|
|
|
077c9d |
Author: Florian Weimer <fweimer@redhat.com>
|
|
|
077c9d |
Date: Mon Nov 12 14:15:14 2018 +0100
|
|
|
077c9d |
|
|
|
077c9d |
malloc: Convert the unlink macro to the unlink_chunk function
|
|
|
077c9d |
|
|
|
077c9d |
This commit is in preparation of turning the macro into a proper
|
|
|
077c9d |
function. The output arguments of the macro were in fact unused.
|
|
|
077c9d |
|
|
|
077c9d |
Also clean up uses of __builtin_expect.
|
|
|
077c9d |
|
|
|
077c9d |
diff --git a/malloc/arena.c b/malloc/arena.c
|
|
|
077c9d |
index 497ae475e7a85902..ff8fd5d2a7e51ac8 100644
|
|
|
077c9d |
--- a/malloc/arena.c
|
|
|
077c9d |
+++ b/malloc/arena.c
|
|
|
077c9d |
@@ -596,7 +596,7 @@ heap_trim (heap_info *heap, size_t pad)
|
|
|
077c9d |
{
|
|
|
077c9d |
mstate ar_ptr = heap->ar_ptr;
|
|
|
077c9d |
unsigned long pagesz = GLRO (dl_pagesize);
|
|
|
077c9d |
- mchunkptr top_chunk = top (ar_ptr), p, bck, fwd;
|
|
|
077c9d |
+ mchunkptr top_chunk = top (ar_ptr), p;
|
|
|
077c9d |
heap_info *prev_heap;
|
|
|
077c9d |
long new_size, top_size, top_area, extra, prev_size, misalign;
|
|
|
077c9d |
|
|
|
077c9d |
@@ -625,7 +625,7 @@ heap_trim (heap_info *heap, size_t pad)
|
|
|
077c9d |
if (!prev_inuse (p)) /* consolidate backward */
|
|
|
077c9d |
{
|
|
|
077c9d |
p = prev_chunk (p);
|
|
|
077c9d |
- unlink (ar_ptr, p, bck, fwd);
|
|
|
077c9d |
+ unlink_chunk (ar_ptr, p);
|
|
|
077c9d |
}
|
|
|
077c9d |
assert (((unsigned long) ((char *) p + new_size) & (pagesz - 1)) == 0);
|
|
|
077c9d |
assert (((char *) p + new_size) == ((char *) heap + heap->size));
|
|
|
077c9d |
diff --git a/malloc/malloc.c b/malloc/malloc.c
|
|
|
077c9d |
index e450597e2e527fb7..7bfa66a56786d110 100644
|
|
|
077c9d |
--- a/malloc/malloc.c
|
|
|
077c9d |
+++ b/malloc/malloc.c
|
|
|
077c9d |
@@ -1384,39 +1384,6 @@ typedef struct malloc_chunk *mbinptr;
|
|
|
077c9d |
#define first(b) ((b)->fd)
|
|
|
077c9d |
#define last(b) ((b)->bk)
|
|
|
077c9d |
|
|
|
077c9d |
-/* Take a chunk off a bin list */
|
|
|
077c9d |
-#define unlink(AV, P, BK, FD) { \
|
|
|
077c9d |
- if (__builtin_expect (chunksize(P) != prev_size (next_chunk(P)), 0)) \
|
|
|
077c9d |
- malloc_printerr ("corrupted size vs. prev_size"); \
|
|
|
077c9d |
- FD = P->fd; \
|
|
|
077c9d |
- BK = P->bk; \
|
|
|
077c9d |
- if (__builtin_expect (FD->bk != P || BK->fd != P, 0)) \
|
|
|
077c9d |
- malloc_printerr ("corrupted double-linked list"); \
|
|
|
077c9d |
- else { \
|
|
|
077c9d |
- FD->bk = BK; \
|
|
|
077c9d |
- BK->fd = FD; \
|
|
|
077c9d |
- if (!in_smallbin_range (chunksize_nomask (P)) \
|
|
|
077c9d |
- && __builtin_expect (P->fd_nextsize != NULL, 0)) { \
|
|
|
077c9d |
- if (__builtin_expect (P->fd_nextsize->bk_nextsize != P, 0) \
|
|
|
077c9d |
- || __builtin_expect (P->bk_nextsize->fd_nextsize != P, 0)) \
|
|
|
077c9d |
- malloc_printerr ("corrupted double-linked list (not small)"); \
|
|
|
077c9d |
- if (FD->fd_nextsize == NULL) { \
|
|
|
077c9d |
- if (P->fd_nextsize == P) \
|
|
|
077c9d |
- FD->fd_nextsize = FD->bk_nextsize = FD; \
|
|
|
077c9d |
- else { \
|
|
|
077c9d |
- FD->fd_nextsize = P->fd_nextsize; \
|
|
|
077c9d |
- FD->bk_nextsize = P->bk_nextsize; \
|
|
|
077c9d |
- P->fd_nextsize->bk_nextsize = FD; \
|
|
|
077c9d |
- P->bk_nextsize->fd_nextsize = FD; \
|
|
|
077c9d |
- } \
|
|
|
077c9d |
- } else { \
|
|
|
077c9d |
- P->fd_nextsize->bk_nextsize = P->bk_nextsize; \
|
|
|
077c9d |
- P->bk_nextsize->fd_nextsize = P->fd_nextsize; \
|
|
|
077c9d |
- } \
|
|
|
077c9d |
- } \
|
|
|
077c9d |
- } \
|
|
|
077c9d |
-}
|
|
|
077c9d |
-
|
|
|
077c9d |
/*
|
|
|
077c9d |
Indexing
|
|
|
077c9d |
|
|
|
077c9d |
@@ -1489,6 +1456,46 @@ typedef struct malloc_chunk *mbinptr;
|
|
|
077c9d |
#define bin_index(sz) \
|
|
|
077c9d |
((in_smallbin_range (sz)) ? smallbin_index (sz) : largebin_index (sz))
|
|
|
077c9d |
|
|
|
077c9d |
+/* Take a chunk off a bin list. */
|
|
|
077c9d |
+static void
|
|
|
077c9d |
+unlink_chunk (mstate av, mchunkptr p)
|
|
|
077c9d |
+{
|
|
|
077c9d |
+ if (chunksize (p) != prev_size (next_chunk (p)))
|
|
|
077c9d |
+ malloc_printerr ("corrupted size vs. prev_size");
|
|
|
077c9d |
+
|
|
|
077c9d |
+ mchunkptr fd = p->fd;
|
|
|
077c9d |
+ mchunkptr bk = p->bk;
|
|
|
077c9d |
+
|
|
|
077c9d |
+ if (__builtin_expect (fd->bk != p || bk->fd != p, 0))
|
|
|
077c9d |
+ malloc_printerr ("corrupted double-linked list");
|
|
|
077c9d |
+
|
|
|
077c9d |
+ fd->bk = bk;
|
|
|
077c9d |
+ bk->fd = fd;
|
|
|
077c9d |
+ if (!in_smallbin_range (chunksize_nomask (p)) && p->fd_nextsize != NULL)
|
|
|
077c9d |
+ {
|
|
|
077c9d |
+ if (p->fd_nextsize->bk_nextsize != p
|
|
|
077c9d |
+ || p->bk_nextsize->fd_nextsize != p)
|
|
|
077c9d |
+ malloc_printerr ("corrupted double-linked list (not small)");
|
|
|
077c9d |
+
|
|
|
077c9d |
+ if (fd->fd_nextsize == NULL)
|
|
|
077c9d |
+ {
|
|
|
077c9d |
+ if (p->fd_nextsize == p)
|
|
|
077c9d |
+ fd->fd_nextsize = fd->bk_nextsize = fd;
|
|
|
077c9d |
+ else
|
|
|
077c9d |
+ {
|
|
|
077c9d |
+ fd->fd_nextsize = p->fd_nextsize;
|
|
|
077c9d |
+ fd->bk_nextsize = p->bk_nextsize;
|
|
|
077c9d |
+ p->fd_nextsize->bk_nextsize = fd;
|
|
|
077c9d |
+ p->bk_nextsize->fd_nextsize = fd;
|
|
|
077c9d |
+ }
|
|
|
077c9d |
+ }
|
|
|
077c9d |
+ else
|
|
|
077c9d |
+ {
|
|
|
077c9d |
+ p->fd_nextsize->bk_nextsize = p->bk_nextsize;
|
|
|
077c9d |
+ p->bk_nextsize->fd_nextsize = p->fd_nextsize;
|
|
|
077c9d |
+ }
|
|
|
077c9d |
+ }
|
|
|
077c9d |
+}
|
|
|
077c9d |
|
|
|
077c9d |
/*
|
|
|
077c9d |
Unsorted chunks
|
|
|
077c9d |
@@ -3917,7 +3924,7 @@ _int_malloc (mstate av, size_t bytes)
|
|
|
077c9d |
victim = victim->fd;
|
|
|
077c9d |
|
|
|
077c9d |
remainder_size = size - nb;
|
|
|
077c9d |
- unlink (av, victim, bck, fwd);
|
|
|
077c9d |
+ unlink_chunk (av, victim);
|
|
|
077c9d |
|
|
|
077c9d |
/* Exhaust */
|
|
|
077c9d |
if (remainder_size < MINSIZE)
|
|
|
077c9d |
@@ -4019,7 +4026,7 @@ _int_malloc (mstate av, size_t bytes)
|
|
|
077c9d |
remainder_size = size - nb;
|
|
|
077c9d |
|
|
|
077c9d |
/* unlink */
|
|
|
077c9d |
- unlink (av, victim, bck, fwd);
|
|
|
077c9d |
+ unlink_chunk (av, victim);
|
|
|
077c9d |
|
|
|
077c9d |
/* Exhaust */
|
|
|
077c9d |
if (remainder_size < MINSIZE)
|
|
|
077c9d |
@@ -4308,7 +4315,7 @@ _int_free (mstate av, mchunkptr p, int have_lock)
|
|
|
077c9d |
p = chunk_at_offset(p, -((long) prevsize));
|
|
|
077c9d |
if (__glibc_unlikely (chunksize(p) != prevsize))
|
|
|
077c9d |
malloc_printerr ("corrupted size vs. prev_size while consolidating");
|
|
|
077c9d |
- unlink(av, p, bck, fwd);
|
|
|
077c9d |
+ unlink_chunk (av, p);
|
|
|
077c9d |
}
|
|
|
077c9d |
|
|
|
077c9d |
if (nextchunk != av->top) {
|
|
|
077c9d |
@@ -4317,7 +4324,7 @@ _int_free (mstate av, mchunkptr p, int have_lock)
|
|
|
077c9d |
|
|
|
077c9d |
/* consolidate forward */
|
|
|
077c9d |
if (!nextinuse) {
|
|
|
077c9d |
- unlink(av, nextchunk, bck, fwd);
|
|
|
077c9d |
+ unlink_chunk (av, nextchunk);
|
|
|
077c9d |
size += nextsize;
|
|
|
077c9d |
} else
|
|
|
077c9d |
clear_inuse_bit_at_offset(nextchunk, 0);
|
|
|
077c9d |
@@ -4430,8 +4437,6 @@ static void malloc_consolidate(mstate av)
|
|
|
077c9d |
INTERNAL_SIZE_T nextsize;
|
|
|
077c9d |
INTERNAL_SIZE_T prevsize;
|
|
|
077c9d |
int nextinuse;
|
|
|
077c9d |
- mchunkptr bck;
|
|
|
077c9d |
- mchunkptr fwd;
|
|
|
077c9d |
|
|
|
077c9d |
atomic_store_relaxed (&av->have_fastchunks, false);
|
|
|
077c9d |
|
|
|
077c9d |
@@ -4471,7 +4476,7 @@ static void malloc_consolidate(mstate av)
|
|
|
077c9d |
p = chunk_at_offset(p, -((long) prevsize));
|
|
|
077c9d |
if (__glibc_unlikely (chunksize(p) != prevsize))
|
|
|
077c9d |
malloc_printerr ("corrupted size vs. prev_size in fastbins");
|
|
|
077c9d |
- unlink(av, p, bck, fwd);
|
|
|
077c9d |
+ unlink_chunk (av, p);
|
|
|
077c9d |
}
|
|
|
077c9d |
|
|
|
077c9d |
if (nextchunk != av->top) {
|
|
|
077c9d |
@@ -4479,7 +4484,7 @@ static void malloc_consolidate(mstate av)
|
|
|
077c9d |
|
|
|
077c9d |
if (!nextinuse) {
|
|
|
077c9d |
size += nextsize;
|
|
|
077c9d |
- unlink(av, nextchunk, bck, fwd);
|
|
|
077c9d |
+ unlink_chunk (av, nextchunk);
|
|
|
077c9d |
} else
|
|
|
077c9d |
clear_inuse_bit_at_offset(nextchunk, 0);
|
|
|
077c9d |
|
|
|
077c9d |
@@ -4527,9 +4532,6 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize,
|
|
|
077c9d |
mchunkptr remainder; /* extra space at end of newp */
|
|
|
077c9d |
unsigned long remainder_size; /* its size */
|
|
|
077c9d |
|
|
|
077c9d |
- mchunkptr bck; /* misc temp for linking */
|
|
|
077c9d |
- mchunkptr fwd; /* misc temp for linking */
|
|
|
077c9d |
-
|
|
|
077c9d |
unsigned long copysize; /* bytes to copy */
|
|
|
077c9d |
unsigned int ncopies; /* INTERNAL_SIZE_T words to copy */
|
|
|
077c9d |
INTERNAL_SIZE_T* s; /* copy source */
|
|
|
077c9d |
@@ -4579,7 +4581,7 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize,
|
|
|
077c9d |
(unsigned long) (nb))
|
|
|
077c9d |
{
|
|
|
077c9d |
newp = oldp;
|
|
|
077c9d |
- unlink (av, next, bck, fwd);
|
|
|
077c9d |
+ unlink_chunk (av, next);
|
|
|
077c9d |
}
|
|
|
077c9d |
|
|
|
077c9d |
/* allocate, copy, free */
|