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>
This commit is contained in:
parent
7da4550eea
commit
acb272ed78
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue