all repos — mgba @ faceb902c823411f8199705a02e196e8cf969337

mGBA Game Boy Advance Emulator

src/platform/posix/memory.c (view raw)

 1/* Copyright (c) 2013-2014 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include <mgba-util/memory.h>
 7
 8#ifndef DISABLE_ANON_MMAP
 9#ifdef __SANITIZE_ADDRESS__
10#define DISABLE_ANON_MMAP
11#elif defined(__has_feature)
12#if __has_feature(address_sanitizer)
13#define DISABLE_ANON_MMAP
14#endif
15#endif
16#endif
17
18#ifndef DISABLE_ANON_MMAP
19#include <sys/mman.h>
20
21void* anonymousMemoryMap(size_t size) {
22	return mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
23}
24
25void mappedMemoryFree(void* memory, size_t size) {
26	munmap(memory, size);
27}
28#else
29void* anonymousMemoryMap(size_t size) {
30	return calloc(1, size);
31}
32
33void mappedMemoryFree(void* memory, size_t size) {
34	UNUSED(size);
35	free(memory);
36}
37#endif