mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-26 07:39:56 -06:00
Assorted portability enhancements (#1800)
* Introduce some Platform calls for managing dynamic libraries * Add Platform::WriteFATSectors * Introduce some Platform calls for managing dynamic libraries * Add Platform::WriteFATSectors * Change includes of "../types.h" to "types.h" - Makes it easier to directly include these headers in downstream projects * Change an include of "../Wifi.h" to "Wifi.h" * Allow CommonFuncs.cpp to compile on Android * Tidy up some logging calls - Use Platform::Log in LAN_Socket.cpp - Soften some warnings to Debug logs (since they don't necessarily represent problems) * Add Platform::EnterGBAMode - Gracefully stop the emulator if trying to enter GBA mode * Soften some logs that most players won't care about * Soften some more logs * Introduce Platform wrappers for file operations * Fix pointer spacing * Fix more style nits * Log the errno when ftruncate fails * Fix FileSeek offset argument - With an s32 offset, we couldn't access files larger than 2GB * Revise Platform::StopEmu to address feedback - Remove Platform::EnterGBAMode in favor of adding a reason to Platform::StopEmu - Also rename Platform::StopEmu to Platform::SignalStop - Add an optional argument to NDS::Stop - Use the new argument everywhere that the console stops itself * Rename FileGetString to FileReadLine - It conveys the meaning better * Rename FileSeekOrigin::Set to Start - It conveys the meaning better * Change definition of FileGetString to FileReadLine - Oops, almost forgot it * Rename FlushFile to FileFlush - To remain consistent with the other File functions * Add a FileType usage * Fix line break in FileSeekOrigin * Document Platform::DeInit * Clarify that StopReason::Unknown doesn't always mean an error * Move and document FileType::HostFile * Remove Platform::OpenDataFile - Nothing currently uses it * Refactor Platform::OpenFile and Platform::OpenLocalFile to accept a FileMode enum instead of a string - The enum is converted to fopen flags under the hood - The file type is used to decide whether to add the "b" flag - Some helper functions are exposed for the benefit of consistent behavior among frontends - Equivalent behavior is maintained * Fix a tab that should be spaces * Use Windows' 64-bit implementations of fseek/ftell * Move Platform::IsBinaryFile to Platform.cpp - It could vary by frontend * Remove an unused FileType * Rename an enum constant * Document various Platform items * Use Platform::DynamicLibrary to load libandroid - And clean it up at the end * Fix a typo * Pass the correct filetype to FATStorage - Since it can be used for DSI NAND images or for SD cards * Remove Platform::FileType
This commit is contained in:

committed by
GitHub

parent
f454eba3c3
commit
ee55677086
@ -112,6 +112,7 @@ bool FaultHandler(FaultDescription& faultDesc);
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#define ASHMEM_DEVICE "/dev/ashmem"
|
||||
Platform::DynamicLibrary* Libandroid = nullptr;
|
||||
#endif
|
||||
|
||||
#if defined(__SWITCH__)
|
||||
@ -753,14 +754,13 @@ void Init()
|
||||
MemoryBase = MemoryBase + AddrSpaceSize*2;
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
static void* libandroid = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL);
|
||||
Libandroid = Platform::DynamicLibrary_Load("libandroid.so");
|
||||
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);
|
||||
auto ASharedMemory_create = reinterpret_cast<type_ASharedMemory_create>(Platform::DynamicLibrary_LoadFunction(Libandroid, "ASharedMemory_create"));
|
||||
|
||||
if (shared_memory_create)
|
||||
if (ASharedMemory_create)
|
||||
{
|
||||
MemoryFile = shared_memory_create("melondsfastmem", MemoryTotalSize);
|
||||
MemoryFile = ASharedMemory_create("melondsfastmem", MemoryTotalSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -775,13 +775,13 @@ void Init()
|
||||
MemoryFile = shm_open(fastmemPidName, O_RDWR | O_CREAT | O_EXCL, 0600);
|
||||
if (MemoryFile == -1)
|
||||
{
|
||||
Log(LogLevel::Error, "Failed to open memory using shm_open!");
|
||||
Log(LogLevel::Error, "Failed to open memory using shm_open! (%s)", strerror(errno));
|
||||
}
|
||||
shm_unlink(fastmemPidName);
|
||||
#endif
|
||||
if (ftruncate(MemoryFile, MemoryTotalSize) < 0)
|
||||
{
|
||||
Log(LogLevel::Error, "Failed to allocate memory using ftruncate!");
|
||||
Log(LogLevel::Error, "Failed to allocate memory using ftruncate! (%s)", strerror(errno));
|
||||
}
|
||||
|
||||
struct sigaction sa;
|
||||
@ -830,6 +830,15 @@ void DeInit()
|
||||
|
||||
munmap(MemoryBase, MemoryTotalSize);
|
||||
close(MemoryFile);
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
if (Libandroid)
|
||||
{
|
||||
Platform::DynamicLibrary_Unload(Libandroid);
|
||||
Libandroid = nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user