From c3bf26793664a6ff696990ca03954c8524337e51 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 4 Aug 2024 20:57:50 +1000 Subject: [PATCH] System: Remove redundant remap --- src/core/bus.cpp | 19 +++++++++++-------- src/core/bus.h | 4 ++-- src/core/game_database.cpp | 1 + src/core/system.cpp | 14 +++++--------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/core/bus.cpp b/src/core/bus.cpp index f470b44cd..54129375a 100644 --- a/src/core/bus.cpp +++ b/src/core/bus.cpp @@ -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 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()) diff --git a/src/core/bus.h b/src/core/bus.h index 4c7aa98c1..e6f3e7d0d 100644 --- a/src/core/bus.h +++ b/src/core/bus.h @@ -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. diff --git a/src/core/game_database.cpp b/src/core/game_database.cpp index 7b4aecd94..db4c6a095 100644 --- a/src/core/game_database.cpp +++ b/src/core/game_database.cpp @@ -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(1) << static_cast(ctype)) diff --git a/src/core/system.cpp b/src/core/system.cpp index e824be28d..abd33893e 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -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.");