From aa950244f8af6844b597b587a5faf818981e92b9 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sat, 12 Oct 2024 02:19:48 -0400 Subject: [PATCH] reuse code for memory_map_mte This drops the separate error message since that doesn't seem useful. --- memory.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/memory.c b/memory.c index 5434060..e1bd2ef 100644 --- a/memory.c +++ b/memory.c @@ -17,8 +17,8 @@ #include "memory.h" #include "util.h" -void *memory_map(size_t size) { - void *p = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); +static void *memory_map_prot(size_t size, int prot) { + void *p = mmap(NULL, size, prot, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); if (unlikely(p == MAP_FAILED)) { if (errno != ENOMEM) { fatal_error("non-ENOMEM mmap failure"); @@ -28,17 +28,14 @@ void *memory_map(size_t size) { return p; } +void *memory_map(size_t size) { + return memory_map_prot(size, PROT_NONE); +} + #ifdef HAS_ARM_MTE // Note that PROT_MTE can't be cleared via mprotect void *memory_map_mte(size_t size) { - void *p = mmap(NULL, size, PROT_MTE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); - if (unlikely(p == MAP_FAILED)) { - if (errno != ENOMEM) { - fatal_error("non-ENOMEM MTE mmap failure"); - } - return NULL; - } - return p; + return memory_map_prot(size, PROT_MTE); } #endif