diff options
Diffstat (limited to 'runtime/src/pe_loader.cpp')
| -rw-r--r-- | runtime/src/pe_loader.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp index 5e55ac1f9..ff0693a15 100644 --- a/runtime/src/pe_loader.cpp +++ b/runtime/src/pe_loader.cpp | |||
| @@ -1721,10 +1721,17 @@ bool Loader::resolve_compat(const std::string& key, const std::string& dll, cons | |||
| 1721 | if (!std::filesystem::is_regular_file(candidate, ec)) return false; | 1721 | if (!std::filesystem::is_regular_file(candidate, ec)) return false; |
| 1722 | // The full path, with the compat folder on the DLL's own search path for its dependencies; never the game | 1722 | // The full path, with the compat folder on the DLL's own search path for its dependencies; never the game |
| 1723 | // folder. Windows maps it, so its CRT, TLS and SEH work as for any host DLL. | 1723 | // folder. Windows maps it, so its CRT, TLS and SEH work as for any host DLL. |
| 1724 | // A file Windows cannot map (truncated, wrong machine, not a PE image) otherwise raises a modal "Bad Image" | ||
| 1725 | // box and LoadLibraryExW does not return until someone clicks it: a headless run would hang on a failure | ||
| 1726 | // that is reported right below anyway. The mode is this thread's, and goes back as it was. | ||
| 1727 | DWORD previous_mode = 0; | ||
| 1728 | const bool mode_set = SetThreadErrorMode(GetThreadErrorMode() | SEM_FAILCRITICALERRORS, &previous_mode) != 0; | ||
| 1724 | h = LoadLibraryExW(candidate.c_str(), nullptr, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32); | 1729 | h = LoadLibraryExW(candidate.c_str(), nullptr, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32); |
| 1730 | const DWORD load_error = h ? ERROR_SUCCESS : GetLastError(); | ||
| 1731 | if (mode_set) SetThreadErrorMode(previous_mode, nullptr); | ||
| 1725 | if (!h) | 1732 | if (!h) |
| 1726 | throw std::runtime_error("LEONIDA_COMPAT_DIR: " + path_utf8(candidate) + " exists but Windows could not " + | 1733 | throw std::runtime_error("LEONIDA_COMPAT_DIR: " + path_utf8(candidate) + " exists but Windows could not " + |
| 1727 | "load it (error " + std::to_string(GetLastError()) + ")"); | 1734 | "load it (error " + std::to_string(load_error) + ")"); |
| 1728 | compat_modules_.emplace(key, h); | 1735 | compat_modules_.emplace(key, h); |
| 1729 | std::fprintf(stderr, "[rt] compat: %s -> %s\n", dll.c_str(), path_utf8(candidate).c_str()); | 1736 | std::fprintf(stderr, "[rt] compat: %s -> %s\n", dll.c_str(), path_utf8(candidate).c_str()); |
| 1730 | } | 1737 | } |