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: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarJason Macnak <natsu@google.com> Commit-Queue: Jason Macnak <natsu@google.com>
parent 5cdf55ff
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
# include <unistd.h> # include <unistd.h>
#endif #endif
#if defined(__ANDROID__) #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD)
# include <sys/prctl.h> # include <sys/prctl.h>
#endif #endif
...@@ -136,7 +136,7 @@ int permissionsToMmapProt(int permissions) ...@@ -136,7 +136,7 @@ int permissionsToMmapProt(int permissions)
#endif // !defined(_WIN32) && !defined(__Fuchsia__) #endif // !defined(_WIN32) && !defined(__Fuchsia__)
#if defined(__linux__) && defined(REACTOR_ANONYMOUS_MMAP_NAME) #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 // Create a file descriptor for anonymous memory with the given
// name. Returns -1 on failure. // name. Returns -1 on failure.
// TODO: remove once libc wrapper exists. // TODO: remove once libc wrapper exists.
...@@ -170,12 +170,12 @@ int anonymousFd() ...@@ -170,12 +170,12 @@ int anonymousFd()
static int fd = memfd_create(MACRO_STRINGIFY(REACTOR_ANONYMOUS_MMAP_NAME), 0); static int fd = memfd_create(MACRO_STRINGIFY(REACTOR_ANONYMOUS_MMAP_NAME), 0);
return fd; return fd;
} }
# else // defined(__ANDROID__) # else // __ANDROID__ && !ANDROID_HOST_BUILD && !ANDROID_NDK_BUILD
int anonymousFd() int anonymousFd()
{ {
return -1; return -1;
} }
# endif // defined(__ANDROID__) # endif // __ANDROID__ && !ANDROID_HOST_BUILD && !ANDROID_NDK_BUILD
// Ensure there is enough space in the "anonymous" fd for length. // Ensure there is enough space in the "anonymous" fd for length.
void ensureAnonFileSize(int anonFd, size_t length) void ensureAnonFileSize(int anonFd, size_t length)
...@@ -289,7 +289,7 @@ void *allocateMemoryPages(size_t bytes, int permissions, bool need_exec) ...@@ -289,7 +289,7 @@ void *allocateMemoryPages(size_t bytes, int permissions, bool need_exec)
{ {
mapping = nullptr; mapping = nullptr;
} }
# if defined(__ANDROID__) # if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD)
else else
{ {
// On Android, prefer to use a non-standard prctl called // On Android, prefer to use a non-standard prctl called
...@@ -299,7 +299,7 @@ void *allocateMemoryPages(size_t bytes, int permissions, bool need_exec) ...@@ -299,7 +299,7 @@ void *allocateMemoryPages(size_t bytes, int permissions, bool need_exec)
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, mapping, length, prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, mapping, length,
MACRO_STRINGIFY(REACTOR_ANONYMOUS_MMAP_NAME)); MACRO_STRINGIFY(REACTOR_ANONYMOUS_MMAP_NAME));
} }
# endif // __ANDROID__ # endif // __ANDROID__ && !ANDROID_HOST_BUILD && !ANDROID_NDK_BUILD
#elif defined(__Fuchsia__) #elif defined(__Fuchsia__)
zx_handle_t vmo; zx_handle_t vmo;
if(zx_vmo_create(length, 0, &vmo) != ZX_OK) if(zx_vmo_create(length, 0, &vmo) != ZX_OK)
......
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