summaryrefslogtreecommitdiff
path: root/Source/Core/Common/MemArena.cpp
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2020-07-16 18:42:15 +0200
committerJosJuice <josjuice@gmail.com>2020-07-16 20:06:58 +0200
commit00cde7cbbddbd5be5e104a72f259578b109d8bb7 (patch)
tree29d5474de997823e29c8f56da8cb6dd924d6b169 /Source/Core/Common/MemArena.cpp
parentb6ee3228be73284e91ad5514f3d38c0c71ef93d3 (diff)
Android: Don't access /dev/ashmem on newer Android versions
Fixes a critical regression where 95945a0 made us unable to start emulation on Android 10 and newer. Android is restricting direct access to /dev/ashmem starting with the new SDK version, but we can use the new (and simpler) ASharedMemory API instead. We have to keep using the /dev/ashmem approach on old versions of Android, though.
Diffstat (limited to 'Source/Core/Common/MemArena.cpp')
-rw-r--r--Source/Core/Common/MemArena.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/Source/Core/Common/MemArena.cpp b/Source/Core/Common/MemArena.cpp
index fcd18892ba..19085e3d8f 100644
--- a/Source/Core/Common/MemArena.cpp
+++ b/Source/Core/Common/MemArena.cpp
@@ -23,6 +23,7 @@
#include <sys/mman.h>
#include <unistd.h>
#ifdef ANDROID
+#include <dlfcn.h>
#include <linux/ashmem.h>
#include <sys/ioctl.h>
#endif
@@ -35,6 +36,18 @@ namespace Common
static int AshmemCreateFileMapping(const char* name, size_t size)
{
+ // ASharedMemory path - works on API >= 26 and falls through on API < 26:
+
+ // We can't call ASharedMemory_create the normal way without increasing the
+ // minimum version requirement to API 26, so we use dlopen/dlsym instead
+ static void* libandroid = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL);
+ static auto shared_memory_create =
+ reinterpret_cast<int (*)(const char*, size_t)>(dlsym(libandroid, "ASharedMemory_create"));
+ if (shared_memory_create)
+ return shared_memory_create(name, size);
+
+ // /dev/ashmem path - works on API < 29:
+
int fd, ret;
fd = open(ASHMEM_DEVICE, O_RDWR);
if (fd < 0)