diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 11:41:02 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 11:41:02 -0500 |
| commit | 68733d6606b54ab93c77ccacaf694e38187c01ba (patch) | |
| tree | e96da6274e37d5bc5ac788c7b4080c0129218511 /runtime/src/pe_loader.cpp | |
| parent | be3a80efcebb5bf973c8987834bc592bee7bd472 (diff) | |
| parent | f4a3fe8d4a6dff718fa6ca9d2f5d5c5dcd8d6c41 (diff) | |
Merge pull request #2021 from jaybeebabageyus
Diffstat (limited to 'runtime/src/pe_loader.cpp')
| -rw-r--r-- | runtime/src/pe_loader.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp index bdb3df6f5..31f5cc0a5 100644 --- a/runtime/src/pe_loader.cpp +++ b/runtime/src/pe_loader.cpp | |||
| @@ -357,8 +357,8 @@ void* bundled_find_loaded(void* ctx, const std::string& dll_lower) { | |||
| 357 | return static_cast<Loader*>(ctx)->find_loaded_module(dll_lower); | 357 | return static_cast<Loader*>(ctx)->find_loaded_module(dll_lower); |
| 358 | } | 358 | } |
| 359 | 359 | ||
| 360 | void* bundled_load(void* ctx, const std::string& dll_lower, bool& handled) { | 360 | void* bundled_load(void* ctx, const std::string& dll_lower, uint32_t flags, bool& handled) { |
| 361 | return static_cast<Loader*>(ctx)->load_runtime_module(dll_lower, handled); | 361 | return static_cast<Loader*>(ctx)->load_runtime_module(dll_lower, flags, handled); |
| 362 | } | 362 | } |
| 363 | 363 | ||
| 364 | void* bundled_get_proc(void* ctx, void* module, const std::string& sym, bool& owns_handle) { | 364 | void* bundled_get_proc(void* ctx, void* module, const std::string& sym, bool& owns_handle) { |
| @@ -448,16 +448,32 @@ void* Loader::find_loaded_module(const std::string& dll_lower) const { | |||
| 448 | return it == by_name_.end() ? nullptr : static_cast<void*>(it->second->base); | 448 | return it == by_name_.end() ? nullptr : static_cast<void*>(it->second->base); |
| 449 | } | 449 | } |
| 450 | 450 | ||
| 451 | void* Loader::load_runtime_module(const std::string& dll_lower, bool& handled) { | 451 | void* Loader::load_runtime_module(const std::string& dll_lower, uint32_t flags, bool& handled) { |
| 452 | handled = false; | 452 | handled = false; |
| 453 | if (dll_lower.empty() || prefer_host_copy(dll_lower)) return nullptr; | 453 | if (dll_lower.empty() || prefer_host_copy(dll_lower)) return nullptr; |
| 454 | 454 | ||
| 455 | std::lock_guard lock(mutex_); | 455 | std::lock_guard lock(mutex_); |
| 456 | if (auto it = by_name_.find(dll_lower); it != by_name_.end()) { | 456 | const auto existing = by_name_.find(dll_lower); |
| 457 | handled = true; | 457 | const std::filesystem::path candidate = game_dir_ / dll_lower; |
| 458 | std::error_code ec; | ||
| 459 | const bool is_bundled = existing != by_name_.end() || std::filesystem::is_regular_file(candidate, ec); | ||
| 460 | if (!is_bundled) return nullptr; | ||
| 461 | |||
| 462 | handled = true; | ||
| 463 | // Win32 DONT_RESOLVE_DLL_REFERENCES (0x1) forbids resolving dependencies or running TLS/DllMain; refuse it | ||
| 464 | // explicitly instead of silently performing a normal resolving + initialising load. | ||
| 465 | if ((flags & DONT_RESOLVE_DLL_REFERENCES) != 0) { | ||
| 466 | std::fprintf(stderr, | ||
| 467 | "[rt] loader: LoadLibraryEx(%s, DONT_RESOLVE_DLL_REFERENCES) is not supported for bundled DLLs\n", | ||
| 468 | dll_lower.c_str()); | ||
| 469 | SetLastError(ERROR_NOT_SUPPORTED); | ||
| 470 | return nullptr; | ||
| 471 | } | ||
| 472 | |||
| 473 | if (existing != by_name_.end()) { | ||
| 458 | try { | 474 | try { |
| 459 | initialise(); | 475 | initialise(); |
| 460 | return static_cast<void*>(it->second->base); | 476 | return static_cast<void*>(existing->second->base); |
| 461 | } catch (const std::exception& e) { | 477 | } catch (const std::exception& e) { |
| 462 | std::fprintf(stderr, "[rt] loader: run-time initialise of %s failed: %s\n", dll_lower.c_str(), e.what()); | 478 | std::fprintf(stderr, "[rt] loader: run-time initialise of %s failed: %s\n", dll_lower.c_str(), e.what()); |
| 463 | SetLastError(ERROR_DLL_INIT_FAILED); | 479 | SetLastError(ERROR_DLL_INIT_FAILED); |
| @@ -465,11 +481,6 @@ void* Loader::load_runtime_module(const std::string& dll_lower, bool& handled) { | |||
| 465 | } | 481 | } |
| 466 | } | 482 | } |
| 467 | 483 | ||
| 468 | const std::filesystem::path candidate = game_dir_ / dll_lower; | ||
| 469 | std::error_code ec; | ||
| 470 | if (!std::filesystem::is_regular_file(candidate, ec)) return nullptr; | ||
| 471 | |||
| 472 | handled = true; | ||
| 473 | try { | 484 | try { |
| 474 | Module& m = load(candidate); | 485 | Module& m = load(candidate); |
| 475 | initialise(); | 486 | initialise(); |