Bug 1365460 - Remove the possibility to disable free() poisoning at runtime. r?njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 18 May 2017 10:03:43 +0900
changeset 580749 f9fb0357a5970311decd7bb45a7eccc716bda2a3
parent 580748 b0a67155ceb4baaf1d51ffe88a50bae05e672313
child 580750 b6f40047fb381fd48c17853096039becb7830a49
push id59654
push userbmo:mh+mozilla@glandium.org
push dateThu, 18 May 2017 22:44:22 +0000
reviewersnjn
bugs1365460
milestone55.0a1
Bug 1365460 - Remove the possibility to disable free() poisoning at runtime. r?njn
memory/mozjemalloc/mozjemalloc.cpp
memory/mozjemalloc/mozjemalloc_types.h
--- a/memory/mozjemalloc/mozjemalloc.cpp
+++ b/memory/mozjemalloc/mozjemalloc.cpp
@@ -1078,22 +1078,20 @@ static __thread arena_t	*arenas_map;
 const char	*_malloc_options = MOZ_MALLOC_OPTIONS;
 
 const uint8_t kAllocJunk = 0xe4;
 const uint8_t kAllocPoison = 0xe5;
 
 #ifndef MALLOC_PRODUCTION
 static bool	opt_abort = true;
 static bool	opt_junk = true;
-static bool	opt_poison = true;
 static bool	opt_zero = false;
 #else
 static bool	opt_abort = false;
 static const bool	opt_junk = false;
-static const bool	opt_poison = true;
 static const bool	opt_zero = false;
 #endif
 
 static size_t	opt_dirty_max = DIRTY_MAX_DEFAULT;
 static bool	opt_print_stats = false;
 #ifdef MALLOC_STATIC_SIZES
 #define opt_quantum_2pow	QUANTUM_2POW_MIN
 #define opt_small_max_2pow	SMALL_MAX_2POW_DEFAULT
@@ -3911,18 +3909,17 @@ arena_dalloc_small(arena_t *arena, arena
 	arena_bin_t *bin;
 	size_t size;
 
 	run = (arena_run_t *)(mapelm->bits & ~pagesize_mask);
 	RELEASE_ASSERT(run->magic == ARENA_RUN_MAGIC);
 	bin = run->bin;
 	size = bin->reg_size;
 
-	if (opt_poison)
-		memset(ptr, kAllocPoison, size);
+	memset(ptr, kAllocPoison, size);
 
 	arena_run_reg_dalloc(run, bin, ptr, size);
 	run->nfree++;
 
 	if (run->nfree == bin->nregs) {
 		/* Deallocate run. */
 		if (run == bin->runcur)
 			bin->runcur = NULL;
@@ -3987,18 +3984,17 @@ arena_dalloc_small(arena_t *arena, arena
 
 static void
 arena_dalloc_large(arena_t *arena, arena_chunk_t *chunk, void *ptr)
 {
 	size_t pageind = ((uintptr_t)ptr - (uintptr_t)chunk) >>
 	    pagesize_2pow;
 	size_t size = chunk->map[pageind].bits & ~pagesize_mask;
 
-	if (opt_poison)
-		memset(ptr, kAllocPoison, size);
+	memset(ptr, kAllocPoison, size);
 	arena->stats.allocated_large -= size;
 	arena->stats.ndalloc_large++;
 
 	arena_run_dalloc(arena, (arena_run_t *)ptr, true);
 }
 
 static inline void
 arena_dalloc(void *ptr, size_t offset)
@@ -4108,35 +4104,33 @@ arena_ralloc_large_grow(arena_t *arena, 
 static bool
 arena_ralloc_large(void *ptr, size_t size, size_t oldsize)
 {
 	size_t psize;
 
 	psize = PAGE_CEILING(size);
 	if (psize == oldsize) {
 		/* Same size class. */
-		if (opt_poison && size < oldsize) {
+		if (size < oldsize) {
 			memset((void *)((uintptr_t)ptr + size), kAllocPoison, oldsize -
 			    size);
 		}
 		return (false);
 	} else {
 		arena_chunk_t *chunk;
 		arena_t *arena;
 
 		chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
 		arena = chunk->arena;
 		RELEASE_ASSERT(arena->magic == ARENA_MAGIC);
 
 		if (psize < oldsize) {
 			/* Fill before shrinking in order avoid a race. */
-			if (opt_poison) {
-				memset((void *)((uintptr_t)ptr + size), kAllocPoison,
-				    oldsize - size);
-			}
+			memset((void *)((uintptr_t)ptr + size), kAllocPoison,
+			    oldsize - size);
 			arena_ralloc_large_shrink(arena, chunk, ptr, psize,
 			    oldsize);
 			return (false);
 		} else {
 			bool ret = arena_ralloc_large_grow(arena, chunk, ptr,
 			    psize, oldsize);
 			if (ret == false && opt_zero) {
 				memset((void *)((uintptr_t)ptr + oldsize), 0,
@@ -4189,17 +4183,17 @@ arena_ralloc(void *ptr, size_t size, siz
 	if (copysize >= VM_COPY_MIN)
 		pages_copy(ret, ptr, copysize);
 	else
 #endif
 		memcpy(ret, ptr, copysize);
 	idalloc(ptr);
 	return (ret);
 IN_PLACE:
-	if (opt_poison && size < oldsize)
+	if (size < oldsize)
 		memset((void *)((uintptr_t)ptr + size), kAllocPoison, oldsize - size);
 	else if (opt_zero && size > oldsize)
 		memset((void *)((uintptr_t)ptr + oldsize), 0, size - oldsize);
 	return (ptr);
 }
 
 static inline void *
 iralloc(void *ptr, size_t size)
@@ -4459,17 +4453,17 @@ huge_ralloc(void *ptr, size_t size, size
 	void *ret;
 	size_t copysize;
 
 	/* Avoid moving the allocation if the size class would not change. */
 
 	if (oldsize > arena_maxclass &&
 	    CHUNK_CEILING(size) == CHUNK_CEILING(oldsize)) {
 		size_t psize = PAGE_CEILING(size);
-		if (opt_poison && size < oldsize) {
+		if (size < oldsize) {
 			memset((void *)((uintptr_t)ptr + size), kAllocPoison, oldsize
 			    - size);
 		}
 #ifdef MALLOC_DECOMMIT
 		if (psize < oldsize) {
 			extent_node_t *node, key;
 
 			pages_decommit((void *)((uintptr_t)ptr + psize),
@@ -4578,17 +4572,16 @@ malloc_print_stats(void)
 #ifdef NDEBUG
 		    "disabled",
 #else
 		    "enabled",
 #endif
 		    "\n", "");
 		_malloc_message("Boolean MALLOC_OPTIONS: ",
 		    opt_abort ? "A" : "a", "", "");
-		_malloc_message(opt_poison ? "C" : "c", "", "", "");
 		_malloc_message(opt_junk ? "J" : "j", "", "", "");
 		_malloc_message("P", "", "", "");
 #ifdef MALLOC_SYSV
 		_malloc_message(opt_sysv ? "V" : "v", "", "", "");
 #endif
 #ifdef MALLOC_XMALLOC
 		_malloc_message(opt_xmalloc ? "X" : "x", "", "", "");
 #endif
@@ -4847,24 +4840,16 @@ MALLOC_OUT:
 			for (k = 0; k < nreps; k++) {
 				switch (opts[j]) {
 				case 'a':
 					opt_abort = false;
 					break;
 				case 'A':
 					opt_abort = true;
 					break;
-#ifndef MALLOC_PRODUCTION
-				case 'c':
-					opt_poison = false;
-					break;
-				case 'C':
-					opt_poison = true;
-					break;
-#endif
 				case 'f':
 					opt_dirty_max >>= 1;
 					break;
 				case 'F':
 					if (opt_dirty_max == 0)
 						opt_dirty_max = 1;
 					else if ((opt_dirty_max << 1) != 0)
 						opt_dirty_max <<= 1;
@@ -5457,17 +5442,16 @@ jemalloc_stats_impl(jemalloc_stats_t *st
 
 	assert(stats != NULL);
 
 	/*
 	 * Gather runtime settings.
 	 */
 	stats->opt_abort = opt_abort;
 	stats->opt_junk = opt_junk;
-	stats->opt_poison = opt_poison;
 	stats->opt_sysv =
 #ifdef MALLOC_SYSV
 	    opt_sysv ? true :
 #endif
 	    false;
 	stats->opt_xmalloc =
 #ifdef MALLOC_XMALLOC
 	    opt_xmalloc ? true :
--- a/memory/mozjemalloc/mozjemalloc_types.h
+++ b/memory/mozjemalloc/mozjemalloc_types.h
@@ -51,17 +51,16 @@ typedef unsigned char jemalloc_bool;
  * file.
  */
 typedef struct {
 	/*
 	 * Run-time configuration settings.
 	 */
 	jemalloc_bool	opt_abort;	/* abort(3) on error? */
 	jemalloc_bool	opt_junk;	/* Fill allocated memory with kAllocJunk? */
-	jemalloc_bool	opt_poison;	/* Fill free memory with kAllocPoison? */
 	jemalloc_bool	opt_sysv;	/* SysV semantics? */
 	jemalloc_bool	opt_xmalloc;	/* abort(3) on OOM? */
 	jemalloc_bool	opt_zero;	/* Fill allocated memory with 0x0? */
 	size_t	narenas;	/* Number of arenas. */
 	size_t	quantum;	/* Allocation quantum. */
 	size_t	small_max;	/* Max quantum-spaced allocation size. */
 	size_t	large_max;	/* Max sub-chunksize allocation size. */
 	size_t	chunksize;	/* Size of each virtual memory mapping. */