Util: Disable mmap allocator when running under address sanitizer

This commit is contained in:
Vicki Pfau 2020-07-22 00:13:02 -07:00
parent 0902dbdd39
commit 9eb0c374b3
1 changed files with 21 additions and 0 deletions

View File

@ -5,6 +5,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <mgba-util/memory.h>
#ifndef DISABLE_ANON_MMAP
#ifdef __SANITIZE_ADDRESS__
#define DISABLE_ANON_MMAP
#elif defined(__has_feature)
#if __has_feature(address_sanitizer)
#define DISABLE_ANON_MMAP
#endif
#endif
#endif
#ifndef DISABLE_ANON_MMAP
#include <sys/mman.h>
void* anonymousMemoryMap(size_t size) {
@ -14,3 +25,13 @@ void* anonymousMemoryMap(size_t size) {
void mappedMemoryFree(void* memory, size_t size) {
munmap(memory, size);
}
#else
void* anonymousMemoryMap(size_t size) {
return calloc(1, size);
}
void mappedMemoryFree(void* memory, size_t size) {
UNUSED(size);
free(memory);
}
#endif