Skip to content

Commit

Permalink
POISON only integer pointers
Browse files Browse the repository at this point in the history
For architectures that can't manipulate pointers like integers, don't
try XORing them like this.  It's not ideal -- perhaps we should have
"else" branches to these tests.
  • Loading branch information
nwf committed Dec 5, 2019
1 parent 0d6f708 commit 2fa60c7
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/mem/metaslab.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,27 @@ namespace snmalloc
/// simple corruptions.
static SNMALLOC_FAST_PATH void store_next(void* p, void* head)
{
#ifndef CHECK_CLIENT
*static_cast<void**>(p) = head;
#else
*static_cast<void**>(p) = head;
*(static_cast<uintptr_t*>(p) + 1) = address_cast(head) ^ POISON;
#if defined(CHECK_CLIENT)
if constexpr (aal_supports<IntegerPointers>)
{
*(static_cast<uintptr_t*>(p) + 1) = address_cast(head) ^ POISON;
}
#endif
}

/// Accessor function for the next pointer in a block.
/// In Debug checks for simple corruptions.
static SNMALLOC_FAST_PATH void* follow_next(void* node)
{
#ifdef CHECK_CLIENT
uintptr_t next = *static_cast<uintptr_t*>(node);
uintptr_t chk = *(static_cast<uintptr_t*>(node) + 1);
if ((next ^ chk) != POISON)
error("Detected memory corruption. Use-after-free.");
#if defined(CHECK_CLIENT)
if constexpr (aal_supports<IntegerPointers>)
{
uintptr_t next = *static_cast<uintptr_t*>(node);
uintptr_t chk = *(static_cast<uintptr_t*>(node) + 1);
if ((next ^ chk) != POISON)
error("Detected memory corruption. Use-after-free.");
}
#endif
return *static_cast<void**>(node);
}
Expand Down

0 comments on commit 2fa60c7

Please sign in to comment.