mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2024-10-01 01:36:01 -04:00
sanity-check mmap errno on failure too
This commit is contained in:
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) {
|
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;
|
||||||
|
Loading…
Reference in New Issue
Block a user