sanity-check mmap errno on failure too

pull/50/head
Daniel Micay 2018-08-28 22:41:18 -04:00
parent 705b6a4f8d
commit 66aa98dbd9
1 changed files with 6 additions and 3 deletions

View File

@ -30,7 +30,10 @@ static_assert(sizeof(void *) == 8, "64-bit only");
static void *memory_map(size_t size) { static void *memory_map(size_t size) {
void *p = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); void *p = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
if (p == MAP_FAILED) { if (unlikely(p == MAP_FAILED)) {
if (errno != ENOMEM) {
fatal_error("non-ENOMEM mmap failure");
}
return NULL; return NULL;
} }
return p; return p;
@ -38,7 +41,7 @@ static void *memory_map(size_t size) {
static int memory_unmap(void *ptr, size_t size) { static int memory_unmap(void *ptr, size_t size) {
int ret = munmap(ptr, size); int ret = munmap(ptr, size);
if (ret && errno != ENOMEM) { if (unlikely(ret) && errno != ENOMEM) {
fatal_error("non-ENOMEM munmap failure"); fatal_error("non-ENOMEM munmap failure");
} }
return ret; return ret;
@ -46,7 +49,7 @@ static int memory_unmap(void *ptr, size_t size) {
static int memory_protect(void *ptr, size_t size, int prot) { static int memory_protect(void *ptr, size_t size, int prot) {
int ret = mprotect(ptr, size, prot); int ret = mprotect(ptr, size, prot);
if (ret && errno != ENOMEM) { if (unlikely(ret) && errno != ENOMEM) {
fatal_error("non-ENOMEM mprotect failure"); fatal_error("non-ENOMEM mprotect failure");
} }
return ret; return ret;