Disable named mmap usage for host/ndk Android If ANDROID_HOST_BUILD or ANDROID_NDK_BUILD is set, PR_SET_VMA_ANON_NAME may not be available. Disable it on such builds. Bug: b/171498948 Bug: b/174801963 Change-Id: Ia9d9ddbe29a812d678263e5f217f3e5037fa14f9 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/53648 Presubmit-Ready: Alistair Delva <adelva@google.com> Reviewed-by: Nicolas Capens <nicolascapens@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: Jason Macnak <natsu@google.com> Commit-Queue: Jason Macnak <natsu@google.com>
diff --git a/src/Reactor/ExecutableMemory.cpp b/src/Reactor/ExecutableMemory.cpp index 7174cb3..2ffb904 100644 --- a/src/Reactor/ExecutableMemory.cpp +++ b/src/Reactor/ExecutableMemory.cpp
@@ -33,7 +33,7 @@ # include <unistd.h> #endif -#if defined(__ANDROID__) +#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD) # include <sys/prctl.h> #endif @@ -136,7 +136,7 @@ #endif // !defined(_WIN32) && !defined(__Fuchsia__) #if defined(__linux__) && defined(REACTOR_ANONYMOUS_MMAP_NAME) -# if !defined(__ANDROID__) +# if !defined(__ANDROID__) || defined(ANDROID_HOST_BUILD) || defined(ANDROID_NDK_BUILD) // Create a file descriptor for anonymous memory with the given // name. Returns -1 on failure. // TODO: remove once libc wrapper exists. @@ -170,12 +170,12 @@ static int fd = memfd_create(MACRO_STRINGIFY(REACTOR_ANONYMOUS_MMAP_NAME), 0); return fd; } -# else // defined(__ANDROID__) +# else // __ANDROID__ && !ANDROID_HOST_BUILD && !ANDROID_NDK_BUILD int anonymousFd() { return -1; } -# endif // defined(__ANDROID__) +# endif // __ANDROID__ && !ANDROID_HOST_BUILD && !ANDROID_NDK_BUILD // Ensure there is enough space in the "anonymous" fd for length. void ensureAnonFileSize(int anonFd, size_t length) @@ -289,7 +289,7 @@ { mapping = nullptr; } -# if defined(__ANDROID__) +# if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD) else { // On Android, prefer to use a non-standard prctl called @@ -299,7 +299,7 @@ prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, mapping, length, MACRO_STRINGIFY(REACTOR_ANONYMOUS_MMAP_NAME)); } -# endif // __ANDROID__ +# endif // __ANDROID__ && !ANDROID_HOST_BUILD && !ANDROID_NDK_BUILD #elif defined(__Fuchsia__) zx_handle_t vmo; if(zx_vmo_create(length, 0, &vmo) != ZX_OK)