aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFilippo Scognamiglio <flscogna@gmail.com>2020-11-30 15:33:43 +0100
committerGitHub <noreply@github.com>2020-11-30 15:33:43 +0100
commitacb272ed782d7682deb39901ce9ea1ea86269af3 (patch)
tree968271ea65e3888c0614c2ab50600dc598252401 /src
parent7da4550eea43a5ec83d1afc88022aaa62827febc (diff)
Use ashmem instead of memfd_create on Android. (#816)
* Use ashmem instead of memfd_create on Android. * Fix code styling issues. * fix small mistake in merge commit Co-authored-by: RSDuck <RSDuck@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r--src/ARMJIT_Memory.cpp43
1 files changed, 35 insertions, 8 deletions
diff --git a/src/ARMJIT_Memory.cpp b/src/ARMJIT_Memory.cpp
index cc0f149..f9f82aa 100644
--- a/src/ARMJIT_Memory.cpp
+++ b/src/ARMJIT_Memory.cpp
@@ -10,6 +10,12 @@
#include <signal.h>
#endif
+#if defined(__ANDROID__)
+#include <dlfcn.h>
+#include <linux/ashmem.h>
+#include <sys/ioctl.h>
+#endif
+
#include "ARMJIT_Memory.h"
#include "ARMJIT_Internal.h"
@@ -58,6 +64,10 @@ struct FaultDescription
bool FaultHandler(FaultDescription& faultDesc);
}
+#if defined(__ANDROID__)
+#define ASHMEM_DEVICE "/dev/ashmem"
+#endif
+
#if defined(__SWITCH__)
// with LTO the symbols seem to be not properly overriden
// if they're somewhere else
@@ -712,14 +722,31 @@ void Init()
FastMem7Start = MemoryBase + AddrSpaceSize;
MemoryBase = MemoryBase + AddrSpaceSize*2;
- #ifdef __APPLE__
- char* fastmemPidName = new char[snprintf(NULL, 0, "melondsfastmem%d", getpid()) + 1];
- sprintf(fastmemPidName, "melondsfastmem%d", getpid());
- MemoryFile = shm_open(fastmemPidName, O_RDWR|O_CREAT, 0600);
- delete[] fastmemPidName;
- #else
- MemoryFile = memfd_create("melondsfastmem", 0);
- #endif
+#if defined(__ANDROID__)
+ static void* libandroid = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL);
+ using type_ASharedMemory_create = int(*)(const char* name, size_t size);
+ static void* symbol = dlsym(libandroid, "ASharedMemory_create");
+ static auto shared_memory_create = reinterpret_cast<type_ASharedMemory_create>(symbol);
+
+ if (shared_memory_create)
+ {
+ MemoryFile = shared_memory_create("melondsfastmem", MemoryTotalSize);
+ }
+ else
+ {
+ int fd = open(ASHMEM_DEVICE, O_RDWR);
+ ioctl(fd, ASHMEM_SET_NAME, "melondsfastmem");
+ ioctl(fd, ASHMEM_SET_SIZE, MemoryTotalSize);
+ MemoryFile = fd;
+ }
+#elif defined(__APPLE__)
+ char* fastmemPidName = new char[snprintf(NULL, 0, "melondsfastmem%d", getpid()) + 1];
+ sprintf(fastmemPidName, "melondsfastmem%d", getpid());
+ MemoryFile = shm_open(fastmemPidName, O_RDWR|O_CREAT, 0600);
+ delete[] fastmemPidName;
+#else
+ MemoryFile = memfd_create("melondsfastmem", 0);
+#endif
ftruncate(MemoryFile, MemoryTotalSize);
struct sigaction sa;