upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/shims
diff options
context:
space:
mode:
authorjaybeebabageyus <jaybeebabageyus@users.noreply.github.com>2026-11-22 17:14:23 +0100
committerjaybeebabageyus <jaybeebabageyus@users.noreply.github.com>2026-11-22 17:14:23 +0100
commitf4a3fe8d4a6dff718fa6ca9d2f5d5c5dcd8d6c41 (patch)
tree67f24736e8471674d58fe0fb4851e35a5bf3cb1d /runtime/shims
parent47f4cdc643f3fca3f87a34d9a4718f250d7cd905 (diff)
runtime: propagate LoadLibraryEx flags and reject DONT_RESOLVE_DLL_REFERENCES for bundled DLLs
Diffstat (limited to 'runtime/shims')
-rw-r--r--runtime/shims/library_loader.cpp13
-rw-r--r--runtime/shims/registry.cpp4
-rw-r--r--runtime/shims/shims.h4
3 files changed, 11 insertions, 10 deletions
diff --git a/runtime/shims/library_loader.cpp b/runtime/shims/library_loader.cpp
index b67a38660..0093e6050 100644
--- a/runtime/shims/library_loader.cpp
+++ b/runtime/shims/library_loader.cpp
@@ -95,7 +95,7 @@ namespace {
95constexpr DWORD kDataFileLoadFlags = 95constexpr DWORD kDataFileLoadFlags =
96 LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE | LOAD_LIBRARY_AS_IMAGE_RESOURCE; 96 LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE | LOAD_LIBRARY_AS_IMAGE_RESOURCE;
97 97
98HMODULE load_shim_or_bundled(const std::string& path, bool& handled) { 98HMODULE load_shim_or_bundled(const std::string& path, DWORD flags, bool& handled) {
99 handled = false; 99 handled = false;
100 if (HMODULE h = owned_handle(path)) { 100 if (HMODULE h = owned_handle(path)) {
101 handled = true; 101 handled = true;
@@ -103,7 +103,8 @@ HMODULE load_shim_or_bundled(const std::string& path, bool& handled) {
103 } 103 }
104 const std::string dll = module_name(path); 104 const std::string dll = module_name(path);
105 if (!dll.empty()) { 105 if (!dll.empty()) {
106 if (void* h = load_bundled_module(dll, handled); handled) return reinterpret_cast<HMODULE>(h); 106 if (void* h = load_bundled_module(dll, static_cast<uint32_t>(flags), handled); handled)
107 return reinterpret_cast<HMODULE>(h);
107 } 108 }
108 return nullptr; 109 return nullptr;
109} 110}
@@ -111,7 +112,7 @@ HMODULE load_shim_or_bundled(const std::string& path, bool& handled) {
111HMODULE WINAPI load_library_a(LPCSTR name) { 112HMODULE WINAPI load_library_a(LPCSTR name) {
112 if (name) { 113 if (name) {
113 bool handled = false; 114 bool handled = false;
114 HMODULE h = load_shim_or_bundled(name, handled); 115 HMODULE h = load_shim_or_bundled(name, 0, handled);
115 if (handled) return h; 116 if (handled) return h;
116 } 117 }
117 return LoadLibraryA(name); 118 return LoadLibraryA(name);
@@ -120,7 +121,7 @@ HMODULE WINAPI load_library_a(LPCSTR name) {
120HMODULE WINAPI load_library_w(LPCWSTR name) { 121HMODULE WINAPI load_library_w(LPCWSTR name) {
121 if (name) { 122 if (name) {
122 bool handled = false; 123 bool handled = false;
123 HMODULE h = load_shim_or_bundled(narrow(name), handled); 124 HMODULE h = load_shim_or_bundled(narrow(name), 0, handled);
124 if (handled) return h; 125 if (handled) return h;
125 } 126 }
126 return LoadLibraryW(name); 127 return LoadLibraryW(name);
@@ -129,7 +130,7 @@ HMODULE WINAPI load_library_w(LPCWSTR name) {
129HMODULE WINAPI load_library_ex_a(LPCSTR name, HANDLE file, DWORD flags) { 130HMODULE WINAPI load_library_ex_a(LPCSTR name, HANDLE file, DWORD flags) {
130 if (name && (flags & kDataFileLoadFlags) == 0) { 131 if (name && (flags & kDataFileLoadFlags) == 0) {
131 bool handled = false; 132 bool handled = false;
132 HMODULE h = load_shim_or_bundled(name, handled); 133 HMODULE h = load_shim_or_bundled(name, flags, handled);
133 if (handled) return h; 134 if (handled) return h;
134 } 135 }
135 return LoadLibraryExA(name, file, flags); 136 return LoadLibraryExA(name, file, flags);
@@ -138,7 +139,7 @@ HMODULE WINAPI load_library_ex_a(LPCSTR name, HANDLE file, DWORD flags) {
138HMODULE WINAPI load_library_ex_w(LPCWSTR name, HANDLE file, DWORD flags) { 139HMODULE WINAPI load_library_ex_w(LPCWSTR name, HANDLE file, DWORD flags) {
139 if (name && (flags & kDataFileLoadFlags) == 0) { 140 if (name && (flags & kDataFileLoadFlags) == 0) {
140 bool handled = false; 141 bool handled = false;
141 HMODULE h = load_shim_or_bundled(narrow(name), handled); 142 HMODULE h = load_shim_or_bundled(narrow(name), flags, handled);
142 if (handled) return h; 143 if (handled) return h;
143 } 144 }
144 return LoadLibraryExW(name, file, flags); 145 return LoadLibraryExW(name, file, flags);
diff --git a/runtime/shims/registry.cpp b/runtime/shims/registry.cpp
index 27d8d8ec6..f6eb8487c 100644
--- a/runtime/shims/registry.cpp
+++ b/runtime/shims/registry.cpp
@@ -370,11 +370,11 @@ void* find_loaded_bundled_module(const std::string& dll_lower) {
370 return nullptr; 370 return nullptr;
371} 371}
372 372
373void* load_bundled_module(const std::string& dll_lower, bool& handled) { 373void* load_bundled_module(const std::string& dll_lower, uint32_t flags, bool& handled) {
374 handled = false; 374 handled = false;
375 for (const auto& entry : snapshot_bundled_loaders()) { 375 for (const auto& entry : snapshot_bundled_loaders()) {
376 bool loader_handled = false; 376 bool loader_handled = false;
377 void* h = entry.ops->load_bundled(entry.ctx, dll_lower, loader_handled); 377 void* h = entry.ops->load_bundled(entry.ctx, dll_lower, flags, loader_handled);
378 if (loader_handled) { 378 if (loader_handled) {
379 handled = true; 379 handled = true;
380 return h; 380 return h;
diff --git a/runtime/shims/shims.h b/runtime/shims/shims.h
index c20fdecf1..1dbf3a5bf 100644
--- a/runtime/shims/shims.h
+++ b/runtime/shims/shims.h
@@ -59,7 +59,7 @@ bool mapped_image_base(uint64_t address, uint64_t& base);
59// Loader. Registered in Loader::Loader and removed in Loader::~Loader. 59// Loader. Registered in Loader::Loader and removed in Loader::~Loader.
60struct BundledModuleOps { 60struct BundledModuleOps {
61 void* (*find_loaded)(void* ctx, const std::string& dll_lower); 61 void* (*find_loaded)(void* ctx, const std::string& dll_lower);
62 void* (*load_bundled)(void* ctx, const std::string& dll_lower, bool& handled); 62 void* (*load_bundled)(void* ctx, const std::string& dll_lower, uint32_t flags, bool& handled);
63 void* (*get_proc)(void* ctx, void* module, const std::string& sym, bool& owns_handle); 63 void* (*get_proc)(void* ctx, void* module, const std::string& sym, bool& owns_handle);
64 bool (*owns_handle)(void* ctx, void* module); 64 bool (*owns_handle)(void* ctx, void* module);
65}; 65};
@@ -67,7 +67,7 @@ void add_bundled_loader(void* ctx, const BundledModuleOps* ops);
67void remove_bundled_loader(void* ctx); 67void remove_bundled_loader(void* ctx);
68 68
69void* find_loaded_bundled_module(const std::string& dll_lower); 69void* find_loaded_bundled_module(const std::string& dll_lower);
70void* load_bundled_module(const std::string& dll_lower, bool& handled); 70void* load_bundled_module(const std::string& dll_lower, uint32_t flags, bool& handled);
71void* get_bundled_proc_address(void* module, const std::string& sym, bool& owns_handle); 71void* get_bundled_proc_address(void* module, const std::string& sym, bool& owns_handle);
72bool owns_bundled_module_handle(void* module); 72bool owns_bundled_module_handle(void* module);
73 73