upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/pe_loader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/pe_loader.cpp')
-rw-r--r--runtime/src/pe_loader.cpp33
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
353void* bundled_load(void* ctx, const std::string& dll_lower, bool& handled) { 353void* 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
357void* bundled_get_proc(void* ctx, void* module, const std::string& sym, bool& owns_handle) { 357void* 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
439void* Loader::load_runtime_module(const std::string& dll_lower, bool& handled) { 439void* 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();