diff options
Diffstat (limited to 'runtime/shims/registry.cpp')
| -rw-r--r-- | runtime/shims/registry.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/runtime/shims/registry.cpp b/runtime/shims/registry.cpp index bf6df91a0..52c168484 100644 --- a/runtime/shims/registry.cpp +++ b/runtime/shims/registry.cpp | |||
| @@ -375,6 +375,85 @@ void remove_module_lookup(void* ctx) { | |||
| 375 | } | 375 | } |
| 376 | } | 376 | } |
| 377 | 377 | ||
| 378 | namespace { | ||
| 379 | |||
| 380 | struct BundledLoaderEntry { | ||
| 381 | void* ctx; | ||
| 382 | const BundledModuleOps* ops; | ||
| 383 | }; | ||
| 384 | |||
| 385 | // Immortal: late mapped-DLL detach or atexit handlers may call GetProcAddress/FreeLibrary during process teardown. | ||
| 386 | std::mutex& bundled_loader_mutex() { | ||
| 387 | static auto* m = new std::mutex; | ||
| 388 | return *m; | ||
| 389 | } | ||
| 390 | |||
| 391 | std::vector<BundledLoaderEntry>& bundled_loaders() { | ||
| 392 | static auto* v = new std::vector<BundledLoaderEntry>; | ||
| 393 | return *v; | ||
| 394 | } | ||
| 395 | |||
| 396 | std::vector<BundledLoaderEntry> snapshot_bundled_loaders() { | ||
| 397 | std::lock_guard lock(bundled_loader_mutex()); | ||
| 398 | return bundled_loaders(); | ||
| 399 | } | ||
| 400 | |||
| 401 | } // namespace | ||
| 402 | |||
| 403 | void add_bundled_loader(void* ctx, const BundledModuleOps* ops) { | ||
| 404 | if (!ctx || !ops) return; | ||
| 405 | std::lock_guard lock(bundled_loader_mutex()); | ||
| 406 | bundled_loaders().push_back({ctx, ops}); | ||
| 407 | } | ||
| 408 | |||
| 409 | void remove_bundled_loader(void* ctx) { | ||
| 410 | std::lock_guard lock(bundled_loader_mutex()); | ||
| 411 | auto& list = bundled_loaders(); | ||
| 412 | for (auto it = list.begin(); it != list.end(); ++it) | ||
| 413 | if (it->ctx == ctx) { | ||
| 414 | list.erase(it); | ||
| 415 | break; | ||
| 416 | } | ||
| 417 | } | ||
| 418 | |||
| 419 | void* find_loaded_bundled_module(const std::string& dll_lower) { | ||
| 420 | for (const auto& entry : snapshot_bundled_loaders()) | ||
| 421 | if (void* h = entry.ops->find_loaded(entry.ctx, dll_lower)) return h; | ||
| 422 | return nullptr; | ||
| 423 | } | ||
| 424 | |||
| 425 | void* load_bundled_module(const std::string& dll_lower, bool& handled) { | ||
| 426 | handled = false; | ||
| 427 | for (const auto& entry : snapshot_bundled_loaders()) { | ||
| 428 | bool loader_handled = false; | ||
| 429 | void* h = entry.ops->load_bundled(entry.ctx, dll_lower, loader_handled); | ||
| 430 | if (loader_handled) { | ||
| 431 | handled = true; | ||
| 432 | return h; | ||
| 433 | } | ||
| 434 | } | ||
| 435 | return nullptr; | ||
| 436 | } | ||
| 437 | |||
| 438 | void* get_bundled_proc_address(void* module, const std::string& sym, bool& owns_handle) { | ||
| 439 | owns_handle = false; | ||
| 440 | for (const auto& entry : snapshot_bundled_loaders()) { | ||
| 441 | bool loader_owns = false; | ||
| 442 | void* fn = entry.ops->get_proc(entry.ctx, module, sym, loader_owns); | ||
| 443 | if (loader_owns) { | ||
| 444 | owns_handle = true; | ||
| 445 | return fn; | ||
| 446 | } | ||
| 447 | } | ||
| 448 | return nullptr; | ||
| 449 | } | ||
| 450 | |||
| 451 | bool owns_bundled_module_handle(void* module) { | ||
| 452 | for (const auto& entry : snapshot_bundled_loaders()) | ||
| 453 | if (entry.ops->owns_handle(entry.ctx, module)) return true; | ||
| 454 | return false; | ||
| 455 | } | ||
| 456 | |||
| 378 | Table::Table(const Entry* entries, size_t count) { | 457 | Table::Table(const Entry* entries, size_t count) { |
| 379 | for (size_t i = 0; i < count; ++i) table()[lower_ascii(entries[i].dll) + "!" + entries[i].name] = entries[i].fn; | 458 | for (size_t i = 0; i < count; ++i) table()[lower_ascii(entries[i].dll) + "!" + entries[i].name] = entries[i].fn; |
| 380 | } | 459 | } |