Issue #1307 - Part 1: Remove MALLOC_VALIDATE

This basic validation is hard-set to always-on, so no point in keeping
it conditional since we basically always want this rudimentary pointer
validation to be done.
This commit is contained in:
wolfbeast 2019-11-30 14:57:44 +01:00 committed by Roy Tam
commit 2224bed064

View file

@ -2,7 +2,7 @@
/* vim:set softtabstop=8 shiftwidth=8 noet: */
/*-
* Copyright (C) 2006-2008 Jason Evans <jasone@FreeBSD.org>.
* Copyright (C) 2015-2018 Mark Straver <moonchild@palemoon.org>
* Copyright (C) 2015-2019 Mark Straver <moonchild@palemoon.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -179,13 +179,6 @@
# define MALLOC_SYSV
#endif
/*
* MALLOC_VALIDATE causes malloc_usable_size() to perform some pointer
* validation. There are many possible errors that validation does not even
* attempt to detect.
*/
#define MALLOC_VALIDATE
#if defined(MOZ_MEMORY_LINUX) && !defined(MOZ_MEMORY_ANDROID)
#define _GNU_SOURCE /* For mremap(2). */
#if 0 /* Enable in order to test decommit code on Linux. */
@ -729,16 +722,15 @@ typedef rb_tree(extent_node_t) extent_tree_t;
* Radix tree data structures.
*/
#ifdef MALLOC_VALIDATE
/*
* Size of each radix tree node (must be a power of 2). This impacts tree
* depth.
*/
# if (SIZEOF_PTR == 4)
# define MALLOC_RTREE_NODESIZE (1U << 14)
# else
# define MALLOC_RTREE_NODESIZE CACHELINE
# endif
/*
* Size of each radix tree node (must be a power of 2). This impacts tree
* depth.
*/
#if (SIZEOF_PTR == 4)
#define MALLOC_RTREE_NODESIZE (1U << 14)
#else
#define MALLOC_RTREE_NODESIZE CACHELINE
#endif
typedef struct malloc_rtree_s malloc_rtree_t;
struct malloc_rtree_s {
@ -747,7 +739,6 @@ struct malloc_rtree_s {
unsigned height;
unsigned level2bits[1]; /* Dynamically sized. */
};
#endif
/******************************************************************************/
/*
@ -1152,9 +1143,7 @@ static size_t recycled_size;
* Chunks.
*/
#ifdef MALLOC_VALIDATE
static malloc_rtree_t *chunk_rtree;
#endif
/* Protects chunk-related data structures. */
static malloc_mutex_t chunks_mtx;
@ -2374,7 +2363,6 @@ pages_copy(void *dest, const void *src, size_t n)
}
#endif
#ifdef MALLOC_VALIDATE
static inline malloc_rtree_t *
malloc_rtree_new(unsigned bits)
{
@ -2515,7 +2503,6 @@ malloc_rtree_set(malloc_rtree_t *rtree, uintptr_t key, void *val)
return (false);
}
#endif
/* pages_trim, chunk_alloc_mmap_slow and chunk_alloc_mmap were cherry-picked
* from upstream jemalloc 3.4.1 to fix Mozilla bug 956501. */
@ -2804,14 +2791,12 @@ chunk_alloc(size_t size, size_t alignment, bool base, bool zero)
ret = NULL;
RETURN:
#ifdef MALLOC_VALIDATE
if (ret != NULL && base == false) {
if (malloc_rtree_set(chunk_rtree, (uintptr_t)ret, ret)) {
chunk_dealloc(ret, size);
return (NULL);
}
}
#endif
assert(CHUNK_ADDR2BASE(ret) == ret);
return (ret);
@ -2929,9 +2914,7 @@ chunk_dealloc(void *chunk, size_t size)
assert(size != 0);
assert((size & chunksize_mask) == 0);
#ifdef MALLOC_VALIDATE
malloc_rtree_set(chunk_rtree, (uintptr_t)chunk, NULL);
#endif
if (chunk_dalloc_mmap(chunk, size))
chunk_record(&chunks_szad_mmap, &chunks_ad_mmap, chunk, size);
@ -4289,7 +4272,6 @@ arena_salloc(const void *ptr)
return (ret);
}
#if (defined(MALLOC_VALIDATE) || defined(MOZ_MEMORY_DARWIN))
/*
* Validate ptr before assuming that it points to an allocation. Currently,
* the following validation is performed:
@ -4330,7 +4312,6 @@ isalloc_validate(const void *ptr)
return (ret);
}
}
#endif
static inline size_t
isalloc(const void *ptr)
@ -5780,11 +5761,9 @@ MALLOC_OUT:
malloc_spin_init(&arenas_lock);
#ifdef MALLOC_VALIDATE
chunk_rtree = malloc_rtree_new((SIZEOF_PTR << 3) - opt_chunk_2pow);
if (chunk_rtree == NULL)
return (true);
#endif
malloc_initialized = true;
@ -6263,13 +6242,7 @@ malloc_usable_size_impl(MALLOC_USABLE_SIZE_CONST_PTR void *ptr)
{
DARWIN_ONLY(return (szone->size)(szone, ptr));
#ifdef MALLOC_VALIDATE
return (isalloc_validate(ptr));
#else
assert(ptr != NULL);
return (isalloc(ptr));
#endif
}
MOZ_JEMALLOC_API void