Skip to content

Commit

Permalink
reuse code for memory_map_mte
Browse files Browse the repository at this point in the history
This drops the separate error message since that doesn't seem useful.
  • Loading branch information
thestinger committed Oct 12, 2024
1 parent e86192e commit 81a9166
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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

Expand Down

0 comments on commit 81a9166

Please sign in to comment.