diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ARMJIT_Memory.cpp | 43 |
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; |