diff options
| author | jaybeebabageyus <jaybeebabageyus@users.noreply.github.com> | 2026-11-22 17:14:23 +0100 |
|---|---|---|
| committer | jaybeebabageyus <jaybeebabageyus@users.noreply.github.com> | 2026-11-22 17:14:23 +0100 |
| commit | f4a3fe8d4a6dff718fa6ca9d2f5d5c5dcd8d6c41 (patch) | |
| tree | 67f24736e8471674d58fe0fb4851e35a5bf3cb1d /runtime/src/pe_loader.cpp | |
| parent | 47f4cdc643f3fca3f87a34d9a4718f250d7cd905 (diff) | |
runtime: propagate LoadLibraryEx flags and reject DONT_RESOLVE_DLL_REFERENCES for bundled DLLs
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 558ed2799..ce43936b7 100644 --- a/runtime/src/pe_loader.cpp +++ b/runtime/src/pe_loader.cpp | |||
| @@ -350,8 +350,8 @@ void* bundled_find_loaded(void* ctx, const std::string& dll_lower) { | |||
| 350 | return static_cast<Loader*>(ctx)->find_loaded_module(dll_lower); | 350 | return static_cast<Loader*>(ctx)->find_loaded_module(dll_lower); |
| 351 | } | 351 | } |
| 352 | 352 | ||
| 353 | void* bundled_load(void* ctx, const std::string& dll_lower, bool& handled) { | 353 | void* bundled_load(void* ctx, const std::string& dll_lower, uint32_t flags, bool& handled) { |
| 354 | return static_cast<Loader*>(ctx)->load_runtime_module(dll_lower, handled); | 354 | return static_cast<Loader*>(ctx)->load_runtime_module(dll_lower, flags, handled); |
| 355 | } | 355 | } |
| 356 | 356 | ||
| 357 | void* bundled_get_proc(void* ctx, void* module, const std::string& sym, bool& owns_handle) { | 357 | void* bundled_get_proc(void* ctx, void* module, const std::string& sym, bool& owns_handle) { |
| @@ -436,16 +436,32 @@ void* Loader::find_loaded_module(const std::string& dll_lower) const { | |||
| 436 | return it == by_name_.end() ? nullptr : static_cast<void*>(it->second->base); | 436 | return it == by_name_.end() ? nullptr : static_cast<void*>(it->second->base); |
| 437 | } | 437 | } |
| 438 | 438 | ||
| 439 | void* Loader::load_runtime_module(const std::string& dll_lower, bool& handled) { | 439 | void* Loader::load_runtime_module(const std::string& dll_lower, uint32_t flags, bool& handled) { |
| 440 | handled = false; | 440 | handled = false; |
| 441 | if (dll_lower.empty() || prefer_host_copy(dll_lower)) return nullptr; | 441 | if (dll_lower.empty() || prefer_host_copy(dll_lower)) return nullptr; |
| 442 | 442 | ||
| 443 | std::lock_guard lock(mutex_); | 443 | std::lock_guard lock(mutex_); |
| 444 | if (auto it = by_name_.find(dll_lower); it != by_name_.end()) { | 444 | const auto existing = by_name_.find(dll_lower); |
| 445 | handled = true; | 445 | const std::filesystem::path candidate = game_dir_ / dll_lower; |
| 446 | std::error_code ec; | ||
| 447 | const bool is_bundled = existing != by_name_.end() || std::filesystem::is_regular_file(candidate, ec); | ||
| 448 | if (!is_bundled) return nullptr; | ||
| 449 | |||
| 450 | handled = true; | ||
| 451 | // Win32 DONT_RESOLVE_DLL_REFERENCES (0x1) forbids resolving dependencies or running TLS/DllMain; refuse it | ||
| 452 | // explicitly instead of silently performing a normal resolving + initialising load. | ||
| 453 | if ((flags & DONT_RESOLVE_DLL_REFERENCES) != 0) { | ||
| 454 | std::fprintf(stderr, | ||
| 455 | "[rt] loader: LoadLibraryEx(%s, DONT_RESOLVE_DLL_REFERENCES) is not supported for bundled DLLs\n", | ||
| 456 | dll_lower.c_str()); | ||
| 457 | SetLastError(ERROR_NOT_SUPPORTED); | ||
| 458 | return nullptr; | ||
| 459 | } | ||
| 460 | |||
| 461 | if (existing != by_name_.end()) { | ||
| 446 | try { | 462 | try { |
| 447 | initialise(); | 463 | initialise(); |
| 448 | return static_cast<void*>(it->second->base); | 464 | return static_cast<void*>(existing->second->base); |
| 449 | } catch (const std::exception& e) { | 465 | } catch (const std::exception& e) { |
| 450 | std::fprintf(stderr, "[rt] loader: run-time initialise of %s failed: %s\n", dll_lower.c_str(), e.what()); | 466 | std::fprintf(stderr, "[rt] loader: run-time initialise of %s failed: %s\n", dll_lower.c_str(), e.what()); |
| 451 | SetLastError(ERROR_DLL_INIT_FAILED); | 467 | SetLastError(ERROR_DLL_INIT_FAILED); |
| @@ -453,11 +469,6 @@ void* Loader::load_runtime_module(const std::string& dll_lower, bool& handled) { | |||
| 453 | } | 469 | } |
| 454 | } | 470 | } |
| 455 | 471 | ||
| 456 | const std::filesystem::path candidate = game_dir_ / dll_lower; | ||
| 457 | std::error_code ec; | ||
| 458 | if (!std::filesystem::is_regular_file(candidate, ec)) return nullptr; | ||
| 459 | |||
| 460 | handled = true; | ||
| 461 | try { | 472 | try { |
| 462 | Module& m = load(candidate); | 473 | Module& m = load(candidate); |
| 463 | initialise(); | 474 | initialise(); |