System: Remove redundant remap

This commit is contained in:
Stenzek 2024-08-04 20:57:50 +10:00
parent 02fbfae6a0
commit c3bf267936
No known key found for this signature in database
4 changed files with 19 additions and 19 deletions

View File

@ -154,7 +154,7 @@ static u8** s_fastmem_lut = nullptr;
static bool s_kernel_initialize_hook_run = false;
static bool AllocateMemoryMap(Error* error);
static bool AllocateMemoryMap(bool export_shared_memory, Error* error);
static void ReleaseMemoryMap();
static void SetRAMSize(bool enable_8mb_ram);
@ -197,11 +197,14 @@ static constexpr size_t TOTAL_SIZE = LUT_OFFSET + LUT_SIZE;
#define FIXUP_WORD_WRITE_VALUE(size, offset, value) \
((size == MemoryAccessSize::Word) ? (value) : ((value) << (((offset) & 3u) * 8)))
bool Bus::AllocateMemoryMap(Error* error)
bool Bus::AllocateMemoryMap(bool export_shared_memory, Error* error)
{
// This executes super early in process startup, therefore export_shared_memory will always be false.
if (g_settings.export_shared_memory)
INFO_LOG("Allocating{} shared memory map.", export_shared_memory ? " EXPORTED" : "");
if (export_shared_memory)
{
s_shmem_name = MemMap::GetFileMappingName("duckstation");
INFO_LOG("Shared memory object name is \"{}\".", s_shmem_name);
}
s_shmem_handle = MemMap::CreateSharedMemory(s_shmem_name.c_str(), MemoryMap::TOTAL_SIZE, error);
if (!s_shmem_handle)
{
@ -304,9 +307,9 @@ void Bus::ReleaseMemoryMap()
}
}
bool Bus::AllocateMemory(Error* error)
bool Bus::AllocateMemory(bool export_shared_memory, Error* error)
{
if (!AllocateMemoryMap(error))
if (!AllocateMemoryMap(export_shared_memory, error))
return false;
#ifdef ENABLE_MMAP_FASTMEM
@ -336,7 +339,7 @@ void Bus::ReleaseMemory()
ReleaseMemoryMap();
}
bool Bus::ReallocateMemoryMap(Error* error)
bool Bus::ReallocateMemoryMap(bool export_shared_memory, Error* error)
{
// Need to back up RAM+BIOS.
DynamicHeapArray<u8> ram_backup;
@ -354,7 +357,7 @@ bool Bus::ReallocateMemoryMap(Error* error)
}
ReleaseMemoryMap();
if (!AllocateMemoryMap(error)) [[unlikely]]
if (!AllocateMemoryMap(export_shared_memory, error)) [[unlikely]]
return false;
if (System::IsValid())

View File

@ -113,12 +113,12 @@ enum : u32
static constexpr size_t FASTMEM_ARENA_SIZE = UINT64_C(0x100000000);
#endif
bool AllocateMemory(Error* error);
bool AllocateMemory(bool export_shared_memory, Error* error);
void ReleaseMemory();
/// Frees and re-allocates the memory map for the process.
/// This should be called when shared memory exports are enabled.
bool ReallocateMemoryMap(Error* error);
bool ReallocateMemoryMap(bool export_shared_memory, Error* error);
/// Cleans up/deletes the shared memory object for this process.
/// Should be called when the process crashes, to avoid leaking.

View File

@ -712,6 +712,7 @@ void GameDatabase::Entry::ApplySettings(Settings& settings, bool display_osd_mes
Host::OSD_WARNING_DURATION);
}
#undef APPEND_MESSAGE_FMT
#undef APPEND_MESSAGE
#define BIT_FOR(ctype) (static_cast<u16>(1) << static_cast<u32>(ctype))

View File

@ -402,8 +402,11 @@ bool System::Internal::ProcessStartup(Error* error)
if (!CPU::CodeCache::ProcessStartup(error))
return false;
// g_settings is not valid at this point, query global config directly.
const bool export_shared_memory = Host::GetBoolSettingValue("Hacks", "ExportSharedMemory", false);
// Fastmem alloc *must* come after JIT alloc, otherwise it tends to eat the 4GB region after the executable on MacOS.
if (!Bus::AllocateMemory(error))
if (!Bus::AllocateMemory(export_shared_memory, error))
{
CPU::CodeCache::ProcessShutdown();
return false;
@ -439,13 +442,6 @@ bool System::Internal::CPUThreadInitialize(Error* error)
// This will call back to Host::LoadSettings() -> ReloadSources().
LoadSettings(false);
// Yuckity yuck. We have to test for memory export explicitly, because the allocation happens before config load.
if (g_settings.export_shared_memory && !Bus::ReallocateMemoryMap(error))
{
Error::AddPrefix(error, "Failed to reallocate memory map:\n");
return false;
}
#ifdef ENABLE_RAINTEGRATION
if (Host::GetBaseBoolSettingValue("Cheevos", "UseRAIntegration", false))
Achievements::SwitchToRAIntegration();
@ -4367,7 +4363,7 @@ void System::CheckForSettingsChanges(const Settings& old_settings)
if (g_settings.export_shared_memory != old_settings.export_shared_memory) [[unlikely]]
{
Error error;
if (!Bus::ReallocateMemoryMap(&error)) [[unlikely]]
if (!Bus::ReallocateMemoryMap(g_settings.export_shared_memory, &error)) [[unlikely]]
{
ERROR_LOG(error.GetDescription());
Panic("Failed to reallocate memory map. The log may contain more information.");