Remove magic.
Remove structure magic, because 1) it is no longer conditional, and 2) it stopped being very effective at detecting memory corruption several years ago.
This commit is contained in:
parent
7372b15a31
commit
fd56043c53
@ -211,9 +211,6 @@ struct arena_chunk_s {
|
|||||||
typedef rb_tree(arena_chunk_t) arena_chunk_tree_t;
|
typedef rb_tree(arena_chunk_t) arena_chunk_tree_t;
|
||||||
|
|
||||||
struct arena_run_s {
|
struct arena_run_s {
|
||||||
uint32_t magic;
|
|
||||||
# define ARENA_RUN_MAGIC 0x384adf93
|
|
||||||
|
|
||||||
/* Bin this run is associated with. */
|
/* Bin this run is associated with. */
|
||||||
arena_bin_t *bin;
|
arena_bin_t *bin;
|
||||||
|
|
||||||
@ -290,9 +287,6 @@ struct arena_bin_s {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct arena_s {
|
struct arena_s {
|
||||||
uint32_t magic;
|
|
||||||
# define ARENA_MAGIC 0x947d3d24
|
|
||||||
|
|
||||||
/* This arena's index within the arenas array. */
|
/* This arena's index within the arenas array. */
|
||||||
unsigned ind;
|
unsigned ind;
|
||||||
|
|
||||||
@ -499,7 +493,6 @@ arena_run_regind(arena_run_t *run, arena_bin_info_t *bin_info, const void *ptr)
|
|||||||
unsigned shift, diff, regind;
|
unsigned shift, diff, regind;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
assert(run->magic == ARENA_RUN_MAGIC);
|
|
||||||
/*
|
/*
|
||||||
* Freeing a pointer lower than region zero can cause assertion
|
* Freeing a pointer lower than region zero can cause assertion
|
||||||
* failure.
|
* failure.
|
||||||
@ -590,7 +583,6 @@ arena_prof_ctx_get(const void *ptr)
|
|||||||
arena_bin_info_t *bin_info = &arena_bin_info[binind];
|
arena_bin_info_t *bin_info = &arena_bin_info[binind];
|
||||||
unsigned regind;
|
unsigned regind;
|
||||||
|
|
||||||
assert(run->magic == ARENA_RUN_MAGIC);
|
|
||||||
regind = arena_run_regind(run, bin_info, ptr);
|
regind = arena_run_regind(run, bin_info, ptr);
|
||||||
ret = *(prof_ctx_t **)((uintptr_t)run +
|
ret = *(prof_ctx_t **)((uintptr_t)run +
|
||||||
bin_info->ctx0_offset + (regind *
|
bin_info->ctx0_offset + (regind *
|
||||||
@ -626,7 +618,6 @@ arena_prof_ctx_set(const void *ptr, prof_ctx_t *ctx)
|
|||||||
arena_bin_info_t *bin_info;
|
arena_bin_info_t *bin_info;
|
||||||
unsigned regind;
|
unsigned regind;
|
||||||
|
|
||||||
assert(run->magic == ARENA_RUN_MAGIC);
|
|
||||||
binind = arena_bin_index(chunk->arena, bin);
|
binind = arena_bin_index(chunk->arena, bin);
|
||||||
bin_info = &arena_bin_info[binind];
|
bin_info = &arena_bin_info[binind];
|
||||||
regind = arena_run_regind(run, bin_info, ptr);
|
regind = arena_run_regind(run, bin_info, ptr);
|
||||||
@ -646,7 +637,6 @@ arena_dalloc(arena_t *arena, arena_chunk_t *chunk, void *ptr)
|
|||||||
arena_chunk_map_t *mapelm;
|
arena_chunk_map_t *mapelm;
|
||||||
|
|
||||||
assert(arena != NULL);
|
assert(arena != NULL);
|
||||||
assert(arena->magic == ARENA_MAGIC);
|
|
||||||
assert(chunk->arena == arena);
|
assert(chunk->arena == arena);
|
||||||
assert(ptr != NULL);
|
assert(ptr != NULL);
|
||||||
assert(CHUNK_ADDR2BASE(ptr) != ptr);
|
assert(CHUNK_ADDR2BASE(ptr) != ptr);
|
||||||
@ -667,7 +657,6 @@ arena_dalloc(arena_t *arena, arena_chunk_t *chunk, void *ptr)
|
|||||||
run = (arena_run_t *)((uintptr_t)chunk +
|
run = (arena_run_t *)((uintptr_t)chunk +
|
||||||
(uintptr_t)((pageind - (mapelm->bits >>
|
(uintptr_t)((pageind - (mapelm->bits >>
|
||||||
PAGE_SHIFT)) << PAGE_SHIFT));
|
PAGE_SHIFT)) << PAGE_SHIFT));
|
||||||
assert(run->magic == ARENA_RUN_MAGIC);
|
|
||||||
bin = run->bin;
|
bin = run->bin;
|
||||||
if (config_debug) {
|
if (config_debug) {
|
||||||
size_t binind = arena_bin_index(arena, bin);
|
size_t binind = arena_bin_index(arena, bin);
|
||||||
|
@ -30,9 +30,6 @@ struct ckhc_s {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ckh_s {
|
struct ckh_s {
|
||||||
#define CKH_MAGIC 0x3af2489d
|
|
||||||
uint32_t magic;
|
|
||||||
|
|
||||||
#ifdef CKH_COUNT
|
#ifdef CKH_COUNT
|
||||||
/* Counters used to get an idea of performance. */
|
/* Counters used to get an idea of performance. */
|
||||||
uint64_t ngrows;
|
uint64_t ngrows;
|
||||||
|
@ -774,8 +774,6 @@ isalloc(const void *ptr)
|
|||||||
chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
|
chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
|
||||||
if (chunk != ptr) {
|
if (chunk != ptr) {
|
||||||
/* Region. */
|
/* Region. */
|
||||||
assert(chunk->arena->magic == ARENA_MAGIC);
|
|
||||||
|
|
||||||
if (config_prof)
|
if (config_prof)
|
||||||
ret = arena_salloc_demote(ptr);
|
ret = arena_salloc_demote(ptr);
|
||||||
else
|
else
|
||||||
|
@ -336,8 +336,6 @@ prof_ctx_get(const void *ptr)
|
|||||||
chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
|
chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
|
||||||
if (chunk != ptr) {
|
if (chunk != ptr) {
|
||||||
/* Region. */
|
/* Region. */
|
||||||
assert(chunk->arena->magic == ARENA_MAGIC);
|
|
||||||
|
|
||||||
ret = arena_prof_ctx_get(ptr);
|
ret = arena_prof_ctx_get(ptr);
|
||||||
} else
|
} else
|
||||||
ret = huge_prof_ctx_get(ptr);
|
ret = huge_prof_ctx_get(ptr);
|
||||||
@ -356,8 +354,6 @@ prof_ctx_set(const void *ptr, prof_ctx_t *ctx)
|
|||||||
chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
|
chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
|
||||||
if (chunk != ptr) {
|
if (chunk != ptr) {
|
||||||
/* Region. */
|
/* Region. */
|
||||||
assert(chunk->arena->magic == ARENA_MAGIC);
|
|
||||||
|
|
||||||
arena_prof_ctx_set(ptr, ctx);
|
arena_prof_ctx_set(ptr, ctx);
|
||||||
} else
|
} else
|
||||||
huge_prof_ctx_set(ptr, ctx);
|
huge_prof_ctx_set(ptr, ctx);
|
||||||
|
@ -333,7 +333,6 @@ tcache_dalloc_small(tcache_t *tcache, void *ptr)
|
|||||||
mapelm = &chunk->map[pageind-map_bias];
|
mapelm = &chunk->map[pageind-map_bias];
|
||||||
run = (arena_run_t *)((uintptr_t)chunk + (uintptr_t)((pageind -
|
run = (arena_run_t *)((uintptr_t)chunk + (uintptr_t)((pageind -
|
||||||
(mapelm->bits >> PAGE_SHIFT)) << PAGE_SHIFT));
|
(mapelm->bits >> PAGE_SHIFT)) << PAGE_SHIFT));
|
||||||
assert(run->magic == ARENA_RUN_MAGIC);
|
|
||||||
bin = run->bin;
|
bin = run->bin;
|
||||||
binind = ((uintptr_t)bin - (uintptr_t)&arena->bins) /
|
binind = ((uintptr_t)bin - (uintptr_t)&arena->bins) /
|
||||||
sizeof(arena_bin_t);
|
sizeof(arena_bin_t);
|
||||||
|
15
src/arena.c
15
src/arena.c
@ -255,7 +255,6 @@ arena_run_reg_alloc(arena_run_t *run, arena_bin_info_t *bin_info)
|
|||||||
bitmap_t *bitmap = (bitmap_t *)((uintptr_t)run +
|
bitmap_t *bitmap = (bitmap_t *)((uintptr_t)run +
|
||||||
(uintptr_t)bin_info->bitmap_offset);
|
(uintptr_t)bin_info->bitmap_offset);
|
||||||
|
|
||||||
assert(run->magic == ARENA_RUN_MAGIC);
|
|
||||||
assert(run->nfree > 0);
|
assert(run->nfree > 0);
|
||||||
assert(bitmap_full(bitmap, &bin_info->bitmap_info) == false);
|
assert(bitmap_full(bitmap, &bin_info->bitmap_info) == false);
|
||||||
|
|
||||||
@ -758,7 +757,6 @@ arena_chunk_purge(arena_t *arena, arena_chunk_t *chunk)
|
|||||||
chunk + (uintptr_t)(pageind << PAGE_SHIFT));
|
chunk + (uintptr_t)(pageind << PAGE_SHIFT));
|
||||||
|
|
||||||
assert((mapelm->bits >> PAGE_SHIFT) == 0);
|
assert((mapelm->bits >> PAGE_SHIFT) == 0);
|
||||||
assert(run->magic == ARENA_RUN_MAGIC);
|
|
||||||
size_t binind = arena_bin_index(arena,
|
size_t binind = arena_bin_index(arena,
|
||||||
run->bin);
|
run->bin);
|
||||||
arena_bin_info_t *bin_info =
|
arena_bin_info_t *bin_info =
|
||||||
@ -1220,8 +1218,6 @@ arena_bin_nonfull_run_get(arena_t *arena, arena_bin_t *bin)
|
|||||||
run->nextind = 0;
|
run->nextind = 0;
|
||||||
run->nfree = bin_info->nregs;
|
run->nfree = bin_info->nregs;
|
||||||
bitmap_init(bitmap, &bin_info->bitmap_info);
|
bitmap_init(bitmap, &bin_info->bitmap_info);
|
||||||
if (config_debug)
|
|
||||||
run->magic = ARENA_RUN_MAGIC;
|
|
||||||
}
|
}
|
||||||
malloc_mutex_unlock(&arena->lock);
|
malloc_mutex_unlock(&arena->lock);
|
||||||
/********************************/
|
/********************************/
|
||||||
@ -1281,7 +1277,6 @@ arena_bin_malloc_hard(arena_t *arena, arena_bin_t *bin)
|
|||||||
* Another thread updated runcur while this one ran without the
|
* Another thread updated runcur while this one ran without the
|
||||||
* bin lock in arena_bin_nonfull_run_get().
|
* bin lock in arena_bin_nonfull_run_get().
|
||||||
*/
|
*/
|
||||||
assert(bin->runcur->magic == ARENA_RUN_MAGIC);
|
|
||||||
assert(bin->runcur->nfree > 0);
|
assert(bin->runcur->nfree > 0);
|
||||||
ret = arena_run_reg_alloc(bin->runcur, bin_info);
|
ret = arena_run_reg_alloc(bin->runcur, bin_info);
|
||||||
if (run != NULL) {
|
if (run != NULL) {
|
||||||
@ -1309,7 +1304,6 @@ arena_bin_malloc_hard(arena_t *arena, arena_bin_t *bin)
|
|||||||
|
|
||||||
bin->runcur = run;
|
bin->runcur = run;
|
||||||
|
|
||||||
assert(bin->runcur->magic == ARENA_RUN_MAGIC);
|
|
||||||
assert(bin->runcur->nfree > 0);
|
assert(bin->runcur->nfree > 0);
|
||||||
|
|
||||||
return (arena_run_reg_alloc(bin->runcur, bin_info));
|
return (arena_run_reg_alloc(bin->runcur, bin_info));
|
||||||
@ -1579,7 +1573,6 @@ arena_salloc(const void *ptr)
|
|||||||
arena_run_t *run = (arena_run_t *)((uintptr_t)chunk +
|
arena_run_t *run = (arena_run_t *)((uintptr_t)chunk +
|
||||||
(uintptr_t)((pageind - (mapbits >> PAGE_SHIFT)) <<
|
(uintptr_t)((pageind - (mapbits >> PAGE_SHIFT)) <<
|
||||||
PAGE_SHIFT));
|
PAGE_SHIFT));
|
||||||
assert(run->magic == ARENA_RUN_MAGIC);
|
|
||||||
size_t binind = arena_bin_index(chunk->arena, run->bin);
|
size_t binind = arena_bin_index(chunk->arena, run->bin);
|
||||||
arena_bin_info_t *bin_info = &arena_bin_info[binind];
|
arena_bin_info_t *bin_info = &arena_bin_info[binind];
|
||||||
assert(((uintptr_t)ptr - ((uintptr_t)run +
|
assert(((uintptr_t)ptr - ((uintptr_t)run +
|
||||||
@ -1632,7 +1625,6 @@ arena_salloc_demote(const void *ptr)
|
|||||||
arena_run_t *run = (arena_run_t *)((uintptr_t)chunk +
|
arena_run_t *run = (arena_run_t *)((uintptr_t)chunk +
|
||||||
(uintptr_t)((pageind - (mapbits >> PAGE_SHIFT)) <<
|
(uintptr_t)((pageind - (mapbits >> PAGE_SHIFT)) <<
|
||||||
PAGE_SHIFT));
|
PAGE_SHIFT));
|
||||||
assert(run->magic == ARENA_RUN_MAGIC);
|
|
||||||
size_t binind = arena_bin_index(chunk->arena, run->bin);
|
size_t binind = arena_bin_index(chunk->arena, run->bin);
|
||||||
arena_bin_info_t *bin_info = &arena_bin_info[binind];
|
arena_bin_info_t *bin_info = &arena_bin_info[binind];
|
||||||
assert(((uintptr_t)ptr - ((uintptr_t)run +
|
assert(((uintptr_t)ptr - ((uintptr_t)run +
|
||||||
@ -1727,8 +1719,6 @@ arena_dalloc_bin_run(arena_t *arena, arena_chunk_t *chunk, arena_run_t *run,
|
|||||||
((past - run_ind) << PAGE_SHIFT), false);
|
((past - run_ind) << PAGE_SHIFT), false);
|
||||||
/* npages = past - run_ind; */
|
/* npages = past - run_ind; */
|
||||||
}
|
}
|
||||||
if (config_debug)
|
|
||||||
run->magic = 0;
|
|
||||||
arena_run_dalloc(arena, run, true);
|
arena_run_dalloc(arena, run, true);
|
||||||
malloc_mutex_unlock(&arena->lock);
|
malloc_mutex_unlock(&arena->lock);
|
||||||
/****************************/
|
/****************************/
|
||||||
@ -1785,7 +1775,6 @@ arena_dalloc_bin(arena_t *arena, arena_chunk_t *chunk, void *ptr,
|
|||||||
pageind = ((uintptr_t)ptr - (uintptr_t)chunk) >> PAGE_SHIFT;
|
pageind = ((uintptr_t)ptr - (uintptr_t)chunk) >> PAGE_SHIFT;
|
||||||
run = (arena_run_t *)((uintptr_t)chunk + (uintptr_t)((pageind -
|
run = (arena_run_t *)((uintptr_t)chunk + (uintptr_t)((pageind -
|
||||||
(mapelm->bits >> PAGE_SHIFT)) << PAGE_SHIFT));
|
(mapelm->bits >> PAGE_SHIFT)) << PAGE_SHIFT));
|
||||||
assert(run->magic == ARENA_RUN_MAGIC);
|
|
||||||
bin = run->bin;
|
bin = run->bin;
|
||||||
size_t binind = arena_bin_index(arena, bin);
|
size_t binind = arena_bin_index(arena, bin);
|
||||||
arena_bin_info_t *bin_info = &arena_bin_info[binind];
|
arena_bin_info_t *bin_info = &arena_bin_info[binind];
|
||||||
@ -2019,7 +2008,6 @@ arena_ralloc_large(void *ptr, size_t oldsize, size_t size, size_t extra,
|
|||||||
|
|
||||||
chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
|
chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
|
||||||
arena = chunk->arena;
|
arena = chunk->arena;
|
||||||
assert(arena->magic == ARENA_MAGIC);
|
|
||||||
|
|
||||||
if (psize < oldsize) {
|
if (psize < oldsize) {
|
||||||
/* Fill before shrinking in order avoid a race. */
|
/* Fill before shrinking in order avoid a race. */
|
||||||
@ -2183,9 +2171,6 @@ arena_new(arena_t *arena, unsigned ind)
|
|||||||
memset(&bin->stats, 0, sizeof(malloc_bin_stats_t));
|
memset(&bin->stats, 0, sizeof(malloc_bin_stats_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_debug)
|
|
||||||
arena->magic = ARENA_MAGIC;
|
|
||||||
|
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,6 @@ ckh_isearch(ckh_t *ckh, const void *key)
|
|||||||
size_t hash1, hash2, bucket, cell;
|
size_t hash1, hash2, bucket, cell;
|
||||||
|
|
||||||
assert(ckh != NULL);
|
assert(ckh != NULL);
|
||||||
assert(ckh->magic == CKH_MAGIC);
|
|
||||||
|
|
||||||
ckh->hash(key, ckh->lg_curbuckets, &hash1, &hash2);
|
ckh->hash(key, ckh->lg_curbuckets, &hash1, &hash2);
|
||||||
|
|
||||||
@ -394,9 +393,6 @@ ckh_new(ckh_t *ckh, size_t minitems, ckh_hash_t *hash, ckh_keycomp_t *keycomp)
|
|||||||
goto RETURN;
|
goto RETURN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_debug)
|
|
||||||
ckh->magic = CKH_MAGIC;
|
|
||||||
|
|
||||||
ret = false;
|
ret = false;
|
||||||
RETURN:
|
RETURN:
|
||||||
return (ret);
|
return (ret);
|
||||||
@ -407,7 +403,6 @@ ckh_delete(ckh_t *ckh)
|
|||||||
{
|
{
|
||||||
|
|
||||||
assert(ckh != NULL);
|
assert(ckh != NULL);
|
||||||
assert(ckh->magic == CKH_MAGIC);
|
|
||||||
|
|
||||||
#ifdef CKH_VERBOSE
|
#ifdef CKH_VERBOSE
|
||||||
malloc_printf(
|
malloc_printf(
|
||||||
@ -432,7 +427,6 @@ ckh_count(ckh_t *ckh)
|
|||||||
{
|
{
|
||||||
|
|
||||||
assert(ckh != NULL);
|
assert(ckh != NULL);
|
||||||
assert(ckh->magic == CKH_MAGIC);
|
|
||||||
|
|
||||||
return (ckh->count);
|
return (ckh->count);
|
||||||
}
|
}
|
||||||
@ -463,7 +457,6 @@ ckh_insert(ckh_t *ckh, const void *key, const void *data)
|
|||||||
bool ret;
|
bool ret;
|
||||||
|
|
||||||
assert(ckh != NULL);
|
assert(ckh != NULL);
|
||||||
assert(ckh->magic == CKH_MAGIC);
|
|
||||||
assert(ckh_search(ckh, key, NULL, NULL));
|
assert(ckh_search(ckh, key, NULL, NULL));
|
||||||
|
|
||||||
#ifdef CKH_COUNT
|
#ifdef CKH_COUNT
|
||||||
@ -488,7 +481,6 @@ ckh_remove(ckh_t *ckh, const void *searchkey, void **key, void **data)
|
|||||||
size_t cell;
|
size_t cell;
|
||||||
|
|
||||||
assert(ckh != NULL);
|
assert(ckh != NULL);
|
||||||
assert(ckh->magic == CKH_MAGIC);
|
|
||||||
|
|
||||||
cell = ckh_isearch(ckh, searchkey);
|
cell = ckh_isearch(ckh, searchkey);
|
||||||
if (cell != SIZE_T_MAX) {
|
if (cell != SIZE_T_MAX) {
|
||||||
@ -520,7 +512,6 @@ ckh_search(ckh_t *ckh, const void *searchkey, void **key, void **data)
|
|||||||
size_t cell;
|
size_t cell;
|
||||||
|
|
||||||
assert(ckh != NULL);
|
assert(ckh != NULL);
|
||||||
assert(ckh->magic == CKH_MAGIC);
|
|
||||||
|
|
||||||
cell = ckh_isearch(ckh, searchkey);
|
cell = ckh_isearch(ckh, searchkey);
|
||||||
if (cell != SIZE_T_MAX) {
|
if (cell != SIZE_T_MAX) {
|
||||||
|
Loading…
Reference in New Issue
Block a user