diff --git a/src/snmalloc/backend_helpers/pagemap.h b/src/snmalloc/backend_helpers/pagemap.h index dd0b313..531196c 100644 --- a/src/snmalloc/backend_helpers/pagemap.h +++ b/src/snmalloc/backend_helpers/pagemap.h @@ -58,6 +58,8 @@ namespace snmalloc */ void register_range(address_t p, size_t length) { + SNMALLOC_ASSERT(is_initialised()); + // Calculate range in pagemap that is associated to this space. auto first = &body[p >> SHIFT]; auto last = &body[(p + length + bits::one_at_bit(SHIFT) - 1) >> SHIFT]; @@ -96,6 +98,8 @@ namespace snmalloc template std::enable_if_t init(T* address) { + SNMALLOC_ASSERT(!is_initialised()); + static_assert( has_bounds_ == has_bounds, "Don't set SFINAE template parameter!"); body = address; @@ -111,6 +115,8 @@ namespace snmalloc std::enable_if_t> init(void* b, size_t s) { + SNMALLOC_ASSERT(!is_initialised()); + static_assert( has_bounds_ == has_bounds, "Don't set SFINAE template parameter!"); #ifdef SNMALLOC_TRACING @@ -167,6 +173,8 @@ namespace snmalloc template std::enable_if_t init() { + SNMALLOC_ASSERT(!is_initialised()); + static_assert( has_bounds_ == has_bounds, "Don't set SFINAE template parameter!"); static constexpr size_t REQUIRED_SIZE = required_size(); @@ -222,6 +230,8 @@ namespace snmalloc template std::enable_if_t> get_bounds() { + SNMALLOC_ASSERT(is_initialised()); + static_assert( has_bounds_ == has_bounds, "Don't set SFINAE template parameter!"); @@ -233,6 +243,8 @@ namespace snmalloc */ [[nodiscard]] constexpr size_t num_entries() const { + SNMALLOC_ASSERT(is_initialised()); + if constexpr (has_bounds) { return size >> GRANULARITY_BITS; @@ -258,6 +270,8 @@ namespace snmalloc return const_cast(default_value); } + SNMALLOC_ASSERT(is_initialised() || p == 0); + if constexpr (has_bounds) { if (p - base > size) @@ -318,6 +332,7 @@ namespace snmalloc */ [[nodiscard]] address_t get_address(const T& t) const { + SNMALLOC_ASSERT(is_initialised()); address_t entry_offset = address_cast(&t) - address_cast(body); address_t entry_index = entry_offset / sizeof(T); SNMALLOC_ASSERT( @@ -327,6 +342,7 @@ namespace snmalloc void set(address_t p, const T& t) { + SNMALLOC_ASSERT(is_initialised()); #ifdef SNMALLOC_TRACING message<1024>("Pagemap.Set {}", p); #endif diff --git a/src/snmalloc/override/malloc.cc b/src/snmalloc/override/malloc.cc index 5830f94..14e770b 100644 --- a/src/snmalloc/override/malloc.cc +++ b/src/snmalloc/override/malloc.cc @@ -154,6 +154,8 @@ extern "C" } sz = bits::min(sz, a.alloc_size(*ptr)); + + SNMALLOC_ASSUME(*ptr != nullptr || sz == 0); // Guard memcpy as GCC is assuming not nullptr for ptr after the memcpy // otherwise. if (sz != 0)