Only enable naming anonymous mmap on Linux
This change restricts the effect of REACTOR_ANONYMOUS_MMAP_NAME to
platforms which define the __linux__ macro, since this feature makes
use of mmap(), syscall(), and posix_memalign().
Note Android is considered Linux.
Bug: b/174801963
Change-Id: Id194aca837b2c9c23f5c7419c926bc2872b77d1b
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/52209
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/Reactor/ExecutableMemory.cpp b/src/Reactor/ExecutableMemory.cpp
index 504dceb..38b73b7 100644
--- a/src/Reactor/ExecutableMemory.cpp
+++ b/src/Reactor/ExecutableMemory.cpp
@@ -58,7 +58,7 @@
{
ASSERT((alignment & (alignment - 1)) == 0); // Power of 2 alignment.
-#if defined(REACTOR_ANONYMOUS_MMAP_NAME)
+#if defined(__linux__) && defined(REACTOR_ANONYMOUS_MMAP_NAME)
if(alignment < sizeof(void *))
{
return malloc(bytes);
@@ -131,7 +131,7 @@
}
#endif // !defined(_WIN32) && !defined(__Fuchsia__)
-#if defined(REACTOR_ANONYMOUS_MMAP_NAME)
+#if defined(__linux__) && defined(REACTOR_ANONYMOUS_MMAP_NAME)
// Create a file descriptor for anonymous memory with the given
// name. Returns -1 on failure.
// TODO: remove once libc wrapper exists.
@@ -176,7 +176,7 @@
fileSize = length;
}
}
-#endif // defined(REACTOR_ANONYMOUS_MMAP_NAME)
+#endif // defined(__linux__) && defined(REACTOR_ANONYMOUS_MMAP_NAME)
#if defined(__Fuchsia__)
zx_vm_option_t permissionsToZxVmOptions(int permissions)
@@ -229,7 +229,7 @@
void deallocate(void *memory)
{
-#if defined(REACTOR_ANONYMOUS_MMAP_NAME)
+#if defined(__linux__) && defined(REACTOR_ANONYMOUS_MMAP_NAME)
free(memory);
#else
if(memory)
@@ -255,7 +255,7 @@
size_t length = roundUp(bytes, pageSize);
void *mapping = nullptr;
-#if defined(REACTOR_ANONYMOUS_MMAP_NAME)
+#if defined(__linux__) && defined(REACTOR_ANONYMOUS_MMAP_NAME)
int flags = MAP_PRIVATE;
// Try to name the memory region for the executable code,
@@ -364,7 +364,7 @@
VirtualProtect(memory, bytes, PAGE_READWRITE, &oldProtection);
ASSERT(result);
deallocate(memory);
-#elif defined(__APPLE__) || defined(REACTOR_ANONYMOUS_MMAP_NAME)
+#elif defined(__APPLE__) || (defined(__linux__) && defined(REACTOR_ANONYMOUS_MMAP_NAME))
size_t pageSize = memoryPageSize();
size_t length = (bytes + pageSize - 1) & ~(pageSize - 1);
int result = munmap(memory, length);