From 5c974bdf8209e79dedeab1a4d22286f0bbece8ff Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 12 May 2021 00:20:03 -0400 Subject: [PATCH] use region quarantine even if MAP_FIXED call fails This is a more sensible way of handling an out-of-memory failure in this edge case. It doesn't matter much in practice. --- README.md | 2 +- h_malloc.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2cc5db2..7cea6f6 100644 --- a/README.md +++ b/README.md @@ -1008,7 +1008,7 @@ System calls used by all build configurations: * `mremap(old, old_size, new_size, MREMAP_MAYMOVE|MREMAP_FIXED, new)` * `munmap` * `write(STDERR_FILENO, buf, len)` (before aborting due to memory corruption) -* `madvise(ptr, size, MADV_DONTNEED)` for `malloc_trim` with slab quarantines +* `madvise(ptr, size, MADV_DONTNEED)` The main distinction from a typical malloc implementation is the use of getrandom. A common compatibility issue is that existing system call whitelists diff --git a/h_malloc.c b/h_malloc.c index 904c461..8f1d721 100644 --- a/h_malloc.c +++ b/h_malloc.c @@ -839,10 +839,10 @@ static void regions_quarantine_deallocate_pages(void *p, size_t size, size_t gua } if (unlikely(memory_map_fixed(p, size))) { - deallocate_pages(p, size, guard_size); - return; + memory_purge(p, size); + } else { + memory_set_name(p, size, "malloc large quarantine"); } - memory_set_name(p, size, "malloc large quarantine"); struct quarantine_info target = (struct quarantine_info){(char *)p - guard_size, size + guard_size * 2};