upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/shims/registry.cpp
diff options
context:
space:
mode:
authorjaybeebabageyus <jaybeebabageyus@users.noreply.github.com>2026-11-22 16:21:16 +0100
committerjaybeebabageyus <jaybeebabageyus@users.noreply.github.com>2026-11-22 16:21:16 +0100
commit47f4cdc643f3fca3f87a34d9a4718f250d7cd905 (patch)
tree0ff132d81a5a655525d5a851adaabfaa10ac1fa2 /runtime/shims/registry.cpp
parent6a6704df1592e1dc4a3215ddf1423a78adb52045 (diff)
runtime: route LoadLibrary/GetProcAddress of bundled package DLLs through rt::Loader
Diffstat (limited to 'runtime/shims/registry.cpp')
-rw-r--r--runtime/shims/registry.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/runtime/shims/registry.cpp b/runtime/shims/registry.cpp
index 4c6a0d60b..27d8d8ec6 100644
--- a/runtime/shims/registry.cpp
+++ b/runtime/shims/registry.cpp
@@ -323,6 +323,85 @@ void remove_module_lookup(void* ctx) {
323 } 323 }
324} 324}
325 325
326namespace {
327
328struct BundledLoaderEntry {
329 void* ctx;
330 const BundledModuleOps* ops;
331};
332
333// Immortal: late mapped-DLL detach or atexit handlers may call GetProcAddress/FreeLibrary during process teardown.
334std::mutex& bundled_loader_mutex() {
335 static auto* m = new std::mutex;
336 return *m;
337}
338
339std::vector<BundledLoaderEntry>& bundled_loaders() {
340 static auto* v = new std::vector<BundledLoaderEntry>;
341 return *v;
342}
343
344std::vector<BundledLoaderEntry> snapshot_bundled_loaders() {
345 std::lock_guard lock(bundled_loader_mutex());
346 return bundled_loaders();
347}
348
349} // namespace
350
351void add_bundled_loader(void* ctx, const BundledModuleOps* ops) {
352 if (!ctx || !ops) return;
353 std::lock_guard lock(bundled_loader_mutex());
354 bundled_loaders().push_back({ctx, ops});
355}
356
357void remove_bundled_loader(void* ctx) {
358 std::lock_guard lock(bundled_loader_mutex());
359 auto& list = bundled_loaders();
360 for (auto it = list.begin(); it != list.end(); ++it)
361 if (it->ctx == ctx) {
362 list.erase(it);
363 break;
364 }
365}
366
367void* find_loaded_bundled_module(const std::string& dll_lower) {
368 for (const auto& entry : snapshot_bundled_loaders())
369 if (void* h = entry.ops->find_loaded(entry.ctx, dll_lower)) return h;
370 return nullptr;
371}
372
373void* load_bundled_module(const std::string& dll_lower, bool& handled) {
374 handled = false;
375 for (const auto& entry : snapshot_bundled_loaders()) {
376 bool loader_handled = false;
377 void* h = entry.ops->load_bundled(entry.ctx, dll_lower, loader_handled);
378 if (loader_handled) {
379 handled = true;
380 return h;
381 }
382 }
383 return nullptr;
384}
385
386void* get_bundled_proc_address(void* module, const std::string& sym, bool& owns_handle) {
387 owns_handle = false;
388 for (const auto& entry : snapshot_bundled_loaders()) {
389 bool loader_owns = false;
390 void* fn = entry.ops->get_proc(entry.ctx, module, sym, loader_owns);
391 if (loader_owns) {
392 owns_handle = true;
393 return fn;
394 }
395 }
396 return nullptr;
397}
398
399bool owns_bundled_module_handle(void* module) {
400 for (const auto& entry : snapshot_bundled_loaders())
401 if (entry.ops->owns_handle(entry.ctx, module)) return true;
402 return false;
403}
404
326Table::Table(const Entry* entries, size_t count) { 405Table::Table(const Entry* entries, size_t count) {
327 for (size_t i = 0; i < count; ++i) table()[lower_ascii(entries[i].dll) + "!" + entries[i].name] = entries[i].fn; 406 for (size_t i = 0; i < count; ++i) table()[lower_ascii(entries[i].dll) + "!" + entries[i].name] = entries[i].fn;
328} 407}