sanity-check mmap errno on failure too
parent
705b6a4f8d
commit
66aa98dbd9
9
malloc.c
9
malloc.c
|
@ -30,7 +30,10 @@ static_assert(sizeof(void *) == 8, "64-bit only");
|
|||
|
||||
static void *memory_map(size_t size) {
|
||||
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 p;
|
||||
|
@ -38,7 +41,7 @@ static void *memory_map(size_t size) {
|
|||
|
||||
static int memory_unmap(void *ptr, size_t size) {
|
||||
int ret = munmap(ptr, size);
|
||||
if (ret && errno != ENOMEM) {
|
||||
if (unlikely(ret) && errno != ENOMEM) {
|
||||
fatal_error("non-ENOMEM munmap failure");
|
||||
}
|
||||
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) {
|
||||
int ret = mprotect(ptr, size, prot);
|
||||
if (ret && errno != ENOMEM) {
|
||||
if (unlikely(ret) && errno != ENOMEM) {
|
||||
fatal_error("non-ENOMEM mprotect failure");
|
||||
}
|
||||
return ret;
|
||||
|
|
Loading…
Reference in New Issue