From 2fa60c719f9678d4507fc3d4a12a148af399de4e Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Mon, 15 Jul 2019 16:14:36 +0100 Subject: [PATCH] POISON only integer pointers 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. --- src/mem/metaslab.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/mem/metaslab.h b/src/mem/metaslab.h index 0f959cb..6a87c89 100644 --- a/src/mem/metaslab.h +++ b/src/mem/metaslab.h @@ -109,11 +109,12 @@ namespace snmalloc /// simple corruptions. static SNMALLOC_FAST_PATH void store_next(void* p, void* head) { -#ifndef CHECK_CLIENT *static_cast(p) = head; -#else - *static_cast(p) = head; - *(static_cast(p) + 1) = address_cast(head) ^ POISON; +#if defined(CHECK_CLIENT) + if constexpr (aal_supports) + { + *(static_cast(p) + 1) = address_cast(head) ^ POISON; + } #endif } @@ -121,11 +122,14 @@ namespace snmalloc /// In Debug checks for simple corruptions. static SNMALLOC_FAST_PATH void* follow_next(void* node) { -#ifdef CHECK_CLIENT - uintptr_t next = *static_cast(node); - uintptr_t chk = *(static_cast(node) + 1); - if ((next ^ chk) != POISON) - error("Detected memory corruption. Use-after-free."); +#if defined(CHECK_CLIENT) + if constexpr (aal_supports) + { + uintptr_t next = *static_cast(node); + uintptr_t chk = *(static_cast(node) + 1); + if ((next ^ chk) != POISON) + error("Detected memory corruption. Use-after-free."); + } #endif return *static_cast(node); }