summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Evans <je@facebook.com>2010-03-15 23:38:27 (GMT)
committerJason Evans <je@facebook.com>2010-03-15 23:44:12 (GMT)
commitf00bb7f132e3b74cb36c34223217df0c4394ada4 (patch)
treea4eb3841c33ab95c53a7b9ee3134397d6ee09643
parent6b5974403b673bc8dd9993b67a1403481089d439 (diff)
downloadjemalloc-f00bb7f132e3b74cb36c34223217df0c4394ada4.zip
jemalloc-f00bb7f132e3b74cb36c34223217df0c4394ada4.tar.gz
jemalloc-f00bb7f132e3b74cb36c34223217df0c4394ada4.tar.bz2
Add assertions.
Check for interior pointers in arena_[ds]alloc(). Check for corrupt pointers in tcache_alloc().
-rw-r--r--jemalloc/include/jemalloc/internal/arena.h7
-rw-r--r--jemalloc/include/jemalloc/internal/tcache.h1
-rw-r--r--jemalloc/src/arena.c4
3 files changed, 11 insertions, 1 deletions
diff --git a/jemalloc/include/jemalloc/internal/arena.h b/jemalloc/include/jemalloc/internal/arena.h
index f4186a3..c58f536 100644
--- a/jemalloc/include/jemalloc/internal/arena.h
+++ b/jemalloc/include/jemalloc/internal/arena.h
@@ -495,6 +495,9 @@ arena_dalloc(arena_t *arena, arena_chunk_t *chunk, void *ptr)
CHUNK_MAP_PG_MASK) >> CHUNK_MAP_PG_SHIFT)) <<
PAGE_SHIFT));
assert(run->magic == ARENA_RUN_MAGIC);
+ assert(((uintptr_t)ptr - ((uintptr_t)run +
+ (uintptr_t)run->bin->reg0_offset)) %
+ run->bin->reg_size == 0);
bin = run->bin;
malloc_mutex_lock(&bin->lock);
arena_dalloc_bin(arena, chunk, ptr, mapelm);
@@ -502,8 +505,10 @@ arena_dalloc(arena_t *arena, arena_chunk_t *chunk, void *ptr)
#ifdef JEMALLOC_TCACHE
}
#endif
- } else
+ } else {
+ assert(((uintptr_t)ptr & PAGE_MASK) == 0);
arena_dalloc_large(arena, chunk, ptr);
+ }
}
#endif
diff --git a/jemalloc/include/jemalloc/internal/tcache.h b/jemalloc/include/jemalloc/internal/tcache.h
index ad30b7c..afad709 100644
--- a/jemalloc/include/jemalloc/internal/tcache.h
+++ b/jemalloc/include/jemalloc/internal/tcache.h
@@ -181,6 +181,7 @@ tcache_alloc(tcache_t *tcache, size_t size, bool zero)
if (ret == NULL)
return (NULL);
}
+ assert(arena_salloc(ret) == tcache->arena->bins[binind].reg_size);
if (zero == false) {
#ifdef JEMALLOC_FILL
diff --git a/jemalloc/src/arena.c b/jemalloc/src/arena.c
index 289fac1..971e4f9 100644
--- a/jemalloc/src/arena.c
+++ b/jemalloc/src/arena.c
@@ -1492,8 +1492,12 @@ arena_salloc(const void *ptr)
(uintptr_t)((pageind - ((mapbits & CHUNK_MAP_PG_MASK) >>
CHUNK_MAP_PG_SHIFT)) << PAGE_SHIFT));
assert(run->magic == ARENA_RUN_MAGIC);
+ assert(((uintptr_t)ptr - ((uintptr_t)run +
+ (uintptr_t)run->bin->reg0_offset)) % run->bin->reg_size ==
+ 0);
ret = run->bin->reg_size;
} else {
+ assert(((uintptr_t)ptr & PAGE_MASK) == 0);
ret = mapbits & ~PAGE_MASK;
assert(ret != 0);
}