This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] malloc: move out perturb_byte conditionals
- From: Joern Engel <joern at purestorage dot com>
- To: "GNU C. Library" <libc-alpha at sourceware dot org>
- Cc: Siddhesh Poyarekar <siddhesh dot poyarekar at gmail dot com>, Joern Engel <joern at purestorage dot com>
- Date: Mon, 25 Jan 2016 16:25:29 -0800
- Subject: [PATCH] malloc: move out perturb_byte conditionals
- Authentication-results: sourceware.org; auth=none
- References: <1453767942-19369-1-git-send-email-joern at purestorage dot com>
Lots of repetitive code. Probably not worth an inline function.
JIRA: PURE-27597
---
tpc/malloc2.13/malloc.c | 41 +++++++++++++++++++----------------------
tpc/malloc2.13/tcache.h | 9 +++------
2 files changed, 22 insertions(+), 28 deletions(-)
diff --git a/tpc/malloc2.13/malloc.c b/tpc/malloc2.13/malloc.c
index 74b35f6aa366..2427fae19b39 100644
--- a/tpc/malloc2.13/malloc.c
+++ b/tpc/malloc2.13/malloc.c
@@ -2264,8 +2264,14 @@ static int check_action = DEFAULT_CHECK_ACTION;
static int perturb_byte;
-#define alloc_perturb(p, n) memset (p, (perturb_byte ^ 0xff) & 0xff, n)
-#define free_perturb(p, n) memset (p, perturb_byte & 0xff, n)
+#define alloc_perturb(p, n) do { \
+ if (perturb_byte) \
+ memset(p, (perturb_byte ^ 0xff) & 0xff, n); \
+} while (0)
+#define free_perturb(p, n) do { \
+ if (perturb_byte) \
+ memset(p, perturb_byte & 0xff, n); \
+} while (0)
/* ------------------- Support for multiple arenas -------------------- */
@@ -3688,8 +3694,7 @@ _int_malloc(struct malloc_state * av, size_t bytes)
*fb = victim->fd;
check_remalloced_chunk(av, victim, nb);
void *p = chunk2mem(victim);
- if (perturb_byte)
- alloc_perturb (p, bytes);
+ alloc_perturb(p, bytes);
return p;
}
}
@@ -3724,8 +3729,7 @@ _int_malloc(struct malloc_state * av, size_t bytes)
victim->size |= NON_MAIN_ARENA;
check_malloced_chunk(av, victim, nb);
void *p = chunk2mem(victim);
- if (perturb_byte)
- alloc_perturb (p, bytes);
+ alloc_perturb(p, bytes);
return p;
}
}
@@ -3804,8 +3808,7 @@ _int_malloc(struct malloc_state * av, size_t bytes)
check_malloced_chunk(av, victim, nb);
void *p = chunk2mem(victim);
- if (perturb_byte)
- alloc_perturb (p, bytes);
+ alloc_perturb(p, bytes);
return p;
}
@@ -3821,8 +3824,7 @@ _int_malloc(struct malloc_state * av, size_t bytes)
victim->size |= NON_MAIN_ARENA;
check_malloced_chunk(av, victim, nb);
void *p = chunk2mem(victim);
- if (perturb_byte)
- alloc_perturb (p, bytes);
+ alloc_perturb(p, bytes);
return p;
}
@@ -3946,8 +3948,7 @@ _int_malloc(struct malloc_state * av, size_t bytes)
}
check_malloced_chunk(av, victim, nb);
void *p = chunk2mem(victim);
- if (perturb_byte)
- alloc_perturb (p, bytes);
+ alloc_perturb(p, bytes);
return p;
}
}
@@ -4050,8 +4051,7 @@ _int_malloc(struct malloc_state * av, size_t bytes)
}
check_malloced_chunk(av, victim, nb);
void *p = chunk2mem(victim);
- if (perturb_byte)
- alloc_perturb (p, bytes);
+ alloc_perturb(p, bytes);
return p;
}
}
@@ -4085,8 +4085,7 @@ _int_malloc(struct malloc_state * av, size_t bytes)
check_malloced_chunk(av, victim, nb);
void *p = chunk2mem(victim);
- if (perturb_byte)
- alloc_perturb (p, bytes);
+ alloc_perturb(p, bytes);
return p;
}
@@ -4107,8 +4106,8 @@ _int_malloc(struct malloc_state * av, size_t bytes)
*/
else {
void *p = sYSMALLOc(nb, av);
- if (p != NULL && perturb_byte)
- alloc_perturb (p, bytes);
+ if (p)
+ alloc_perturb(p, bytes);
return p;
}
}
@@ -4181,8 +4180,7 @@ _int_free(struct malloc_state * av, mchunkptr p)
}
}
- if (perturb_byte)
- free_perturb (chunk2mem(p), size - 2 * SIZE_SZ);
+ free_perturb(chunk2mem(p), size - 2 * SIZE_SZ);
set_fastchunks(av);
unsigned int idx = fastbin_index(size);
@@ -4244,8 +4242,7 @@ _int_free(struct malloc_state * av, mchunkptr p)
goto errout;
}
- if (perturb_byte)
- free_perturb (chunk2mem(p), size - 2 * SIZE_SZ);
+ free_perturb(chunk2mem(p), size - 2 * SIZE_SZ);
/* consolidate backward */
if (!prev_inuse(p)) {
diff --git a/tpc/malloc2.13/tcache.h b/tpc/malloc2.13/tcache.h
index 00fe24249d49..e267ce905ed0 100644
--- a/tpc/malloc2.13/tcache.h
+++ b/tpc/malloc2.13/tcache.h
@@ -287,8 +287,7 @@ static void *tcache_malloc(size_t size)
void *p = chunk2mem(victim);
cache->tc_size -= chunksize(victim);
cache->tc_count--;
- if (perturb_byte)
- alloc_perturb(p, size);
+ alloc_perturb(p, size);
return p;
}
@@ -335,8 +334,7 @@ static void *tcache_malloc(size_t size)
}
arena_unlock(arena);
assert(!victim || arena == arena_for_chunk(mem2chunk(victim)));
- if (perturb_byte)
- alloc_perturb(victim, size);
+ alloc_perturb(victim, size);
return victim;
}
@@ -368,8 +366,7 @@ static void tcache_free(mchunkptr p)
malloc_printerr(check_action, "invalid tcache entry", chunk2mem(p));
return;
}
- if (perturb_byte)
- free_perturb(p, size - 2 * SIZE_SZ);
+ free_perturb(p, size - 2 * SIZE_SZ);
add_to_bin(bin, p);
if (cache->tc_size > CACHE_SIZE)
tcache_gc(cache);
--
2.7.0.rc3