From fa17f70a731247eb2e27003988aae01e37be2823 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sun, 6 Jan 2019 00:52:25 -0500 Subject: [PATCH] add more configuration sanity checks --- h_malloc.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/h_malloc.c b/h_malloc.c index 536e4ce..b3cc4a2 100644 --- a/h_malloc.c +++ b/h_malloc.c @@ -30,10 +30,28 @@ extern int __register_atfork(void (*)(void), void (*)(void), void (*)(void), voi #define SLAB_QUARANTINE (SLAB_QUARANTINE_RANDOM_LENGTH > 0 || SLAB_QUARANTINE_QUEUE_LENGTH > 0) +#define MREMAP_MOVE_THRESHOLD (32 * 1024 * 1024) + static_assert(sizeof(void *) == 8, "64-bit only"); static_assert(!WRITE_AFTER_FREE_CHECK || ZERO_ON_FREE, "WRITE_AFTER_FREE_CHECK depends on ZERO_ON_FREE"); +static_assert(SLAB_QUARANTINE_RANDOM_LENGTH >= 0 && SLAB_QUARANTINE_RANDOM_LENGTH <= 65536, + "invalid slab quarantine random length"); +static_assert(SLAB_QUARANTINE_QUEUE_LENGTH >= 0 && SLAB_QUARANTINE_QUEUE_LENGTH <= 65536, + "invalid slab quarantine queue length"); +static_assert(REGION_QUARANTINE_RANDOM_LENGTH >= 0 && REGION_QUARANTINE_RANDOM_LENGTH <= 65536, + "invalid region quarantine random length"); +static_assert(REGION_QUARANTINE_QUEUE_LENGTH >= 0 && REGION_QUARANTINE_QUEUE_LENGTH <= 65536, + "invalid region quarantine queue length"); +static_assert(FREE_SLABS_QUARANTINE_RANDOM_LENGTH >= 0 && FREE_SLABS_QUARANTINE_RANDOM_LENGTH <= 65536, + "invalid free slabs quarantine random length"); + +static_assert(REGION_QUARANTINE_SKIP_THRESHOLD >= 0, + "invalid region quarantine skip threshold"); +static_assert(MREMAP_MOVE_THRESHOLD >= REGION_QUARANTINE_SKIP_THRESHOLD, + "mremap move threshold must be above region quarantine limit"); + // either sizeof(u64) or 0 static const size_t canary_size = SLAB_CANARY ? sizeof(u64) : 0; @@ -1101,11 +1119,6 @@ EXPORT void *h_calloc(size_t nmemb, size_t size) { return p; } -#define MREMAP_MOVE_THRESHOLD (32 * 1024 * 1024) - -static_assert(MREMAP_MOVE_THRESHOLD >= REGION_QUARANTINE_SKIP_THRESHOLD, - "mremap move threshold must be above region quarantine limit"); - EXPORT void *h_realloc(void *old, size_t size) { if (old == NULL) { init();