diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 8f1cc658..0322513d 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -26,8 +26,6 @@ add_library(common cd_subchannel_replacement.h cd_xa.cpp cd_xa.h - crash_handler.cpp - crash_handler.h cue_parser.cpp cue_parser.h dimensional_array.h diff --git a/src/common/crash_handler.cpp b/src/common/crash_handler.cpp deleted file mode 100644 index 6c75a70b..00000000 --- a/src/common/crash_handler.cpp +++ /dev/null @@ -1,212 +0,0 @@ -#include "crash_handler.h" -#include "string_util.h" -#include -#include - -#if defined(_WIN32) && !defined(_UWP) -#include "windows_headers.h" - -#include "thirdparty/StackWalker.h" -#include - -namespace CrashHandler { - -class CrashHandlerStackWalker : public StackWalker -{ -public: - CrashHandlerStackWalker(HANDLE out_file); - ~CrashHandlerStackWalker(); - -protected: - void OnOutput(LPCSTR szText) override; - -private: - HANDLE m_out_file; -}; - -CrashHandlerStackWalker::CrashHandlerStackWalker(HANDLE out_file) - : StackWalker(RetrieveVerbose, nullptr, GetCurrentProcessId(), GetCurrentProcess()), m_out_file(out_file) -{ -} - -CrashHandlerStackWalker::~CrashHandlerStackWalker() -{ - if (m_out_file) - CloseHandle(m_out_file); -} - -void CrashHandlerStackWalker::OnOutput(LPCSTR szText) -{ - if (m_out_file) - { - DWORD written; - WriteFile(m_out_file, szText, static_cast(std::strlen(szText)), &written, nullptr); - } - - OutputDebugStringA(szText); -} - -static bool WriteMinidump(HMODULE hDbgHelp, HANDLE hFile, HANDLE hProcess, DWORD process_id, DWORD thread_id, - PEXCEPTION_POINTERS exception, MINIDUMP_TYPE type) -{ - using PFNMINIDUMPWRITEDUMP = - BOOL(WINAPI*)(HANDLE hProcess, DWORD ProcessId, HANDLE hFile, MINIDUMP_TYPE DumpType, - PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, - PMINIDUMP_CALLBACK_INFORMATION CallbackParam); - - PFNMINIDUMPWRITEDUMP minidump_write_dump = - reinterpret_cast(GetProcAddress(hDbgHelp, "MiniDumpWriteDump")); - if (!minidump_write_dump) - return false; - - MINIDUMP_EXCEPTION_INFORMATION mei; - PMINIDUMP_EXCEPTION_INFORMATION mei_ptr = nullptr; - if (exception) - { - mei.ThreadId = thread_id; - mei.ExceptionPointers = exception; - mei.ClientPointers = FALSE; - mei_ptr = &mei; - } - - return minidump_write_dump(hProcess, process_id, hFile, type, mei_ptr, nullptr, nullptr); -} - -static std::wstring s_write_directory; -static PVOID s_veh_handle = nullptr; -static bool s_in_crash_handler = false; - -static LONG NTAPI ExceptionHandler(PEXCEPTION_POINTERS exi) -{ - if (s_in_crash_handler) - return EXCEPTION_CONTINUE_SEARCH; - - switch (exi->ExceptionRecord->ExceptionCode) - { - case EXCEPTION_ACCESS_VIOLATION: - case EXCEPTION_BREAKPOINT: - case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: - case EXCEPTION_INT_DIVIDE_BY_ZERO: - case EXCEPTION_INT_OVERFLOW: - case EXCEPTION_PRIV_INSTRUCTION: - case EXCEPTION_ILLEGAL_INSTRUCTION: - case EXCEPTION_NONCONTINUABLE_EXCEPTION: - case EXCEPTION_STACK_OVERFLOW: - case EXCEPTION_GUARD_PAGE: - break; - - default: - return EXCEPTION_CONTINUE_SEARCH; - } - - // if the debugger is attached, let it take care of it. - if (IsDebuggerPresent()) - return EXCEPTION_CONTINUE_SEARCH; - - s_in_crash_handler = true; - - // we definitely need dbg helper - maintain an extra reference here - HMODULE hDbgHelp = StackWalker::LoadDbgHelpLibrary(); - - wchar_t filename[1024] = {}; - if (!s_write_directory.empty()) - { - wcsncpy_s(filename, countof(filename), s_write_directory.c_str(), _TRUNCATE); - wcsncat_s(filename, countof(filename), L"\\crash.txt", _TRUNCATE); - } - else - { - wcsncat_s(filename, countof(filename), L"crash.txt", _TRUNCATE); - } - - // might fail - HANDLE hFile = CreateFileW(filename, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, 0, nullptr); - if (hFile) - { - char line[1024]; - DWORD written; - std::snprintf(line, countof(line), "Exception 0x%08X at 0x%p\n", exi->ExceptionRecord->ExceptionCode, - exi->ExceptionRecord->ExceptionAddress); - WriteFile(hFile, line, static_cast(std::strlen(line)), &written, nullptr); - } - - if (!s_write_directory.empty()) - { - wcsncpy_s(filename, countof(filename), s_write_directory.c_str(), _TRUNCATE); - wcsncat_s(filename, countof(filename), L"\\crash.dmp", _TRUNCATE); - } - else - { - wcsncat_s(filename, countof(filename), L"crash.dmp", _TRUNCATE); - } - - const MINIDUMP_TYPE minidump_type = - static_cast(MiniDumpNormal | MiniDumpWithHandleData | MiniDumpWithProcessThreadData | - MiniDumpWithThreadInfo | MiniDumpWithIndirectlyReferencedMemory); - HANDLE hMinidumpFile = CreateFileW(filename, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, 0, nullptr); - if (!hMinidumpFile || !WriteMinidump(hDbgHelp, hMinidumpFile, GetCurrentProcess(), GetCurrentProcessId(), - GetCurrentThreadId(), exi, minidump_type)) - { - static const char error_message[] = "Failed to write minidump file.\n"; - if (hFile) - { - DWORD written; - WriteFile(hFile, error_message, sizeof(error_message) - 1, &written, nullptr); - } - } - if (hMinidumpFile) - CloseHandle(hMinidumpFile); - - CrashHandlerStackWalker sw(hFile); - sw.ShowCallstack(GetCurrentThread(), exi->ContextRecord); - - if (hFile) - CloseHandle(hFile); - - if (hDbgHelp) - FreeLibrary(hDbgHelp); - - return EXCEPTION_CONTINUE_SEARCH; -} - -bool Install() -{ - s_veh_handle = AddVectoredExceptionHandler(0, ExceptionHandler); - return (s_veh_handle != nullptr); -} - -void SetWriteDirectory(const std::string_view& dump_directory) -{ - if (!s_veh_handle) - return; - - s_write_directory = StringUtil::UTF8StringToWideString(dump_directory); -} - -void Uninstall() -{ - if (s_veh_handle) - { - RemoveVectoredExceptionHandler(s_veh_handle); - s_veh_handle = nullptr; - } -} - -} // namespace CrashHandler - -#else - -namespace CrashHandler { - -bool Install() -{ - return false; -} - -void SetWriteDirectory(const std::string_view& dump_directory) {} - -void Uninstall() {} - -} // namespace CrashHandler - -#endif diff --git a/src/common/crash_handler.h b/src/common/crash_handler.h deleted file mode 100644 index a5fdad3c..00000000 --- a/src/common/crash_handler.h +++ /dev/null @@ -1,8 +0,0 @@ -#include "types.h" -#include - -namespace CrashHandler { -bool Install(); -void SetWriteDirectory(const std::string_view& dump_directory); -void Uninstall(); -} // namespace CrashHandler diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index c53be0f3..9f9a6fe4 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -246,9 +246,7 @@ std::optional> HostInterface::GetBIOSImage(ConsoleRegion region) std::optional image = BIOS::LoadImageFromFile( StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "%s", bios_dir.c_str(), bios_name.c_str()).c_str()); if (!image.has_value()) - { return FindBIOSImageInDirectory(region, bios_dir.c_str()); - } BIOS::Hash found_hash = BIOS::GetHash(*image); Log_DevPrintf("Hash for BIOS '%s': %s", bios_name.c_str(), found_hash.ToString().c_str()); @@ -323,41 +321,6 @@ std::optional> HostInterface::FindBIOSImageInDirectory(ConsoleRe return fallback_image; } -std::vector> -HostInterface::FindBIOSImagesInDirectory(const char* directory) -{ - std::vector> results; - - FileSystem::FindResultsArray files; - FileSystem::FindFiles(directory, "*", - FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_HIDDEN_FILES | FILESYSTEM_FIND_RELATIVE_PATHS, &files); - - for (FILESYSTEM_FIND_DATA& fd : files) - { - if (fd.Size != BIOS::BIOS_SIZE && fd.Size != BIOS::BIOS_SIZE_PS2 && fd.Size != BIOS::BIOS_SIZE_PS3) - continue; - - std::string full_path( - StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "%s", directory, fd.FileName.c_str())); - - std::optional found_image = BIOS::LoadImageFromFile(full_path.c_str()); - if (!found_image) - continue; - - BIOS::Hash found_hash = BIOS::GetHash(*found_image); - const BIOS::ImageInfo* ii = BIOS::GetImageInfoForHash(found_hash); - results.emplace_back(std::move(fd.FileName), ii); - } - - return results; -} - -bool HostInterface::HasAnyBIOSImages() -{ - const std::string dir = GetBIOSDirectory(); - return (FindBIOSImageInDirectory(ConsoleRegion::Auto, dir.c_str()).has_value()); -} - std::string HostInterface::GetShaderCacheBasePath() const { return GetUserDirectoryRelativePath("cache/"); @@ -781,24 +744,6 @@ void HostInterface::ToggleSoftwareRendering() System::RecreateGPU(new_renderer); } -void HostInterface::ModifyResolutionScale(s32 increment) -{ - const u32 new_resolution_scale = std::clamp( - static_cast(static_cast(g_settings.gpu_resolution_scale) + increment), 1, GPU::MAX_RESOLUTION_SCALE); - if (new_resolution_scale == g_settings.gpu_resolution_scale) - return; - - g_settings.gpu_resolution_scale = new_resolution_scale; - - if (!System::IsShutdown()) - { - g_gpu->RestoreGraphicsAPIState(); - g_gpu->UpdateSettings(); - g_gpu->ResetGraphicsAPIState(); - System::ClearMemorySaveStates(); - } -} - void HostInterface::UpdateSoftwareCursor() { if (System::IsShutdown()) diff --git a/src/core/host_interface.h b/src/core/host_interface.h index fe778f6a..409ff3cb 100644 --- a/src/core/host_interface.h +++ b/src/core/host_interface.h @@ -136,12 +136,6 @@ public: /// BIOS image within 512KB and 4MB will be used. std::optional> FindBIOSImageInDirectory(ConsoleRegion region, const char* directory); - /// Returns a list of filenames and descriptions for BIOS images in a directory. - std::vector> FindBIOSImagesInDirectory(const char* directory); - - /// Returns true if any BIOS images are found in the configured BIOS directory. - bool HasAnyBIOSImages(); - virtual void OnRunningGameChanged(const std::string& path, CDImage* image, const std::string& game_code, const std::string& game_title) = 0; protected: @@ -175,9 +169,6 @@ protected: /// Quick switch between software and hardware rendering. void ToggleSoftwareRendering(); - /// Adjusts the internal (render) resolution of the hardware backends. - void ModifyResolutionScale(s32 increment); - /// Updates software cursor state, based on controllers. void UpdateSoftwareCursor();