Commit 1a094f18 by Nicolas Capens Committed by Nicolas Capens

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: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com>
parent 945f1448
......@@ -58,7 +58,7 @@ void *allocateRaw(size_t bytes, size_t alignment)
{
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 @@ int permissionsToMmapProt(int permissions)
}
#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 @@ void ensureAnonFileSize(int anonFd, size_t length)
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 *allocate(size_t bytes, size_t alignment)
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 @@ void *allocateMemoryPages(size_t bytes, int permissions, bool need_exec)
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 @@ void deallocateMemoryPages(void *memory, size_t bytes)
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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment