Made checks on client have own macro.
This commit is contained in:
@@ -469,7 +469,7 @@ namespace snmalloc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# ifndef NDEBUG
|
# ifdef CHECK_CLIENT
|
||||||
if (size > 64 || address_cast(super) != address_cast(p))
|
if (size > 64 || address_cast(super) != address_cast(p))
|
||||||
{
|
{
|
||||||
error("Not deallocating start of an object");
|
error("Not deallocating start of an object");
|
||||||
@@ -817,7 +817,7 @@ namespace snmalloc
|
|||||||
{
|
{
|
||||||
Superslab* super = Superslab::get(p);
|
Superslab* super = Superslab::get(p);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifdef CHECK_CLIENT
|
||||||
if (p->target_id() != super->get_allocator()->id())
|
if (p->target_id() != super->get_allocator()->id())
|
||||||
error("Detected memory corruption. Potential use-after-free");
|
error("Detected memory corruption. Potential use-after-free");
|
||||||
#endif
|
#endif
|
||||||
@@ -1013,7 +1013,7 @@ namespace snmalloc
|
|||||||
|
|
||||||
void small_dealloc(Superslab* super, void* p, uint8_t sizeclass)
|
void small_dealloc(Superslab* super, void* p, uint8_t sizeclass)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
#ifdef CHECK_CLIENT
|
||||||
Slab* slab = Slab::get(p);
|
Slab* slab = Slab::get(p);
|
||||||
if (!slab->is_start_of_object(super, p))
|
if (!slab->is_start_of_object(super, p))
|
||||||
{
|
{
|
||||||
@@ -1150,7 +1150,7 @@ namespace snmalloc
|
|||||||
stats().sizeclass_dealloc(sizeclass);
|
stats().sizeclass_dealloc(sizeclass);
|
||||||
bool was_full = slab->dealloc(p, large_allocator.memory_provider);
|
bool was_full = slab->dealloc(p, large_allocator.memory_provider);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifdef CHECK_CLIENT
|
||||||
if (!is_multiple_of_sizeclass(
|
if (!is_multiple_of_sizeclass(
|
||||||
sizeclass_to_size(sizeclass),
|
sizeclass_to_size(sizeclass),
|
||||||
address_cast(slab) + SUPERSLAB_SIZE - address_cast(p)))
|
address_cast(slab) + SUPERSLAB_SIZE - address_cast(p)))
|
||||||
|
|||||||
@@ -4,6 +4,12 @@
|
|||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
{
|
{
|
||||||
|
// The CHECK_CLIENT macro is used to turn on minimal checking of the client
|
||||||
|
// calling the API correctly.
|
||||||
|
#if !defined(NDEBUG) && !defined(CHECK_CLIENT)
|
||||||
|
# define CHECK_CLIENT
|
||||||
|
#endif
|
||||||
|
|
||||||
// 0 intermediate bits results in power of 2 small allocs. 1 intermediate
|
// 0 intermediate bits results in power of 2 small allocs. 1 intermediate
|
||||||
// bit gives additional sizeclasses at the midpoint between each power of 2.
|
// bit gives additional sizeclasses at the midpoint between each power of 2.
|
||||||
// 2 intermediate bits gives 3 intermediate sizeclasses, etc.
|
// 2 intermediate bits gives 3 intermediate sizeclasses, etc.
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ namespace snmalloc
|
|||||||
/// simple corruptions.
|
/// simple corruptions.
|
||||||
static void store_next(void* p, uint16_t head)
|
static void store_next(void* p, uint16_t head)
|
||||||
{
|
{
|
||||||
#ifdef NDEBUG
|
#ifndef CHECK_CLIENT
|
||||||
*static_cast<size_t*>(p) = head;
|
*static_cast<size_t*>(p) = head;
|
||||||
#else
|
#else
|
||||||
*static_cast<size_t*>(p) =
|
*static_cast<size_t*>(p) =
|
||||||
@@ -112,7 +112,7 @@ namespace snmalloc
|
|||||||
static uint16_t follow_next(void* node)
|
static uint16_t follow_next(void* node)
|
||||||
{
|
{
|
||||||
size_t next = *static_cast<size_t*>(node);
|
size_t next = *static_cast<size_t*>(node);
|
||||||
#ifndef NDEBUG
|
#ifdef CHECK_CLIENT
|
||||||
if (((next ^ POISON) ^ (next << (bits::BITS - 16))) > 0xFFFF)
|
if (((next ^ POISON) ^ (next << (bits::BITS - 16))) > 0xFFFF)
|
||||||
error("Detected memory corruption. Use-after-free.");
|
error("Detected memory corruption. Use-after-free.");
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ namespace snmalloc
|
|||||||
|
|
||||||
bool was_full = meta.is_full();
|
bool was_full = meta.is_full();
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifdef CHECK_CLIENT
|
||||||
if (meta.is_unused())
|
if (meta.is_unused())
|
||||||
error("Detected potential double free.");
|
error("Detected potential double free.");
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user