[PR #1565] loader: a run-time LoadLibrary takes the LEONIDA_COMPAT_DIR module too (RT-COMPAT-DIR-RUNTIME-LOADS) #1589

Open
opened 2026-11-26 20:21:46 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1565
Author: @Mike7581
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: rt-compat-dir-runtime-loads


📝 Commits (2)

  • 582e14d loader: a run-time LoadLibrary takes the LEONIDA_COMPAT_DIR module too
  • 2cca47b loader: compat run-time loads honour LoadLibraryEx flags and Windows-loaded dependencies

📊 Changes

8 files changed (+496 additions, -37 deletions)

View changed files

📝 runtime/CMakeLists.txt (+1 -0)
📝 runtime/README.md (+9 -2)
📝 runtime/shims/library_loader.cpp (+50 -7)
📝 runtime/shims/registry.cpp (+22 -0)
📝 runtime/shims/shims.h (+11 -0)
📝 runtime/src/pe_loader.cpp (+137 -24)
📝 runtime/src/pe_loader.h (+17 -1)
📝 runtime/test/loader_test.cpp (+249 -3)

📄 Description

Claimed in the coordination issue as: RT-COMPAT-DIR-RUNTIME-LOADS (#1562, since #14 is at the 2,500-comment cap)

What and why

LEONIDA_COMPAT_DIR only applied to static imports (runtime/README.md: "a run-time LoadLibrary of the same name does not yet"). A mapped image's LoadLibrary of a module the folder holds got the shim's pseudo-handle instead of the drop-in DLL, and GetProcAddress on the compat DLL's real handle looked the name up in the shim of the same module name first. One console module could then be served half by the drop-in and half by the shim, which the static step exists to prevent.

Now shims::BundledModuleOps gains compat_module / owns_compat_handle, answered by rt::Loader from the same compat_handle() its static step (resolve_compat) uses, so both get one HMODULE per module. In shims/library_loader.cpp:

  • LoadLibrary* checks the compat folder before the shim registry and the bundled package DLLs;
  • GetModuleHandle* answers a compat module's handle once loaded and NULL before (never the shim's pseudo-handle);
  • GetProcAddress on a compat handle gives only that DLL's exports;
  • FreeLibrary on it returns TRUE and keeps it loaded (it is the Loader's reference, static imports may be bound through it; compat modules already stay for the process lifetime).

A compat file Windows refuses fails that LoadLibrary with Windows' error (logged) instead of throwing into the title. runtime/README.md is updated.

Tested

  • loader_test now links shims/library_loader.cpp and gains test_compat_runtime_loads, eight cases with a synthetic drop-in DLL and the test shim module: without the folder the shim still answers; with it, GetModuleHandle is NULL before the load, LoadLibraryW returns the compat DLL, GetModuleHandle (with and without .dll) returns it after, GetProcAddress gives Answer (42) and not the shim's F, a static import in the same Loader binds to the same export, FreeLibrary keeps it loaded, and a file Windows refuses (error 193) fails the load without the shim or a throw. loader: 103 ok, 0 FAIL.
  • Full ctest: 376/377; the one failure is ws2_offline under -j 4 (loopback bind failures; it failed the same way here on a run without this change), which passes 3/3 run alone.

GPUs tested: n/a (CPU only). Built with MSVC (VS 2022 Build Tools 17.14) + Ninja via scripts\build_runtime.ps1, Windows 11 Pro 10.0.26200.

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1565 **Author:** [@Mike7581](https://github.com/Mike7581) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `rt-compat-dir-runtime-loads` --- ### 📝 Commits (2) - [`582e14d`](https://github.com/ubiquitarianism/leonida/commit/582e14d922ad9b24a63ba55f7b8e57bd4aef3c08) loader: a run-time LoadLibrary takes the LEONIDA_COMPAT_DIR module too - [`2cca47b`](https://github.com/ubiquitarianism/leonida/commit/2cca47b5c8971c885961c35741ab8b0f0debaa01) loader: compat run-time loads honour LoadLibraryEx flags and Windows-loaded dependencies ### 📊 Changes **8 files changed** (+496 additions, -37 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+1 -0) 📝 `runtime/README.md` (+9 -2) 📝 `runtime/shims/library_loader.cpp` (+50 -7) 📝 `runtime/shims/registry.cpp` (+22 -0) 📝 `runtime/shims/shims.h` (+11 -0) 📝 `runtime/src/pe_loader.cpp` (+137 -24) 📝 `runtime/src/pe_loader.h` (+17 -1) 📝 `runtime/test/loader_test.cpp` (+249 -3) </details> ### 📄 Description Claimed in the coordination issue as: RT-COMPAT-DIR-RUNTIME-LOADS (#1562, since #14 is at the 2,500-comment cap) ### What and why `LEONIDA_COMPAT_DIR` only applied to static imports (`runtime/README.md`: "a run-time `LoadLibrary` of the same name does not yet"). A mapped image's `LoadLibrary` of a module the folder holds got the shim's pseudo-handle instead of the drop-in DLL, and `GetProcAddress` on the compat DLL's real handle looked the name up in the shim of the same module name first. One console module could then be served half by the drop-in and half by the shim, which the static step exists to prevent. Now `shims::BundledModuleOps` gains `compat_module` / `owns_compat_handle`, answered by `rt::Loader` from the same `compat_handle()` its static step (`resolve_compat`) uses, so both get one `HMODULE` per module. In `shims/library_loader.cpp`: - `LoadLibrary*` checks the compat folder before the shim registry and the bundled package DLLs; - `GetModuleHandle*` answers a compat module's handle once loaded and NULL before (never the shim's pseudo-handle); - `GetProcAddress` on a compat handle gives only that DLL's exports; - `FreeLibrary` on it returns TRUE and keeps it loaded (it is the Loader's reference, static imports may be bound through it; compat modules already stay for the process lifetime). A compat file Windows refuses fails that `LoadLibrary` with Windows' error (logged) instead of throwing into the title. `runtime/README.md` is updated. ### Tested - `loader_test` now links `shims/library_loader.cpp` and gains `test_compat_runtime_loads`, eight cases with a synthetic drop-in DLL and the test shim module: without the folder the shim still answers; with it, `GetModuleHandle` is NULL before the load, `LoadLibraryW` returns the compat DLL, `GetModuleHandle` (with and without `.dll`) returns it after, `GetProcAddress` gives `Answer` (42) and not the shim's `F`, a static import in the same Loader binds to the same export, `FreeLibrary` keeps it loaded, and a file Windows refuses (error 193) fails the load without the shim or a throw. `loader`: 103 ok, 0 FAIL. - Full `ctest`: 376/377; the one failure is `ws2_offline` under `-j 4` (loopback bind failures; it failed the same way here on a run without this change), which passes 3/3 run alone. GPUs tested: n/a (CPU only). Built with MSVC (VS 2022 Build Tools 17.14) + Ninja via `scripts\build_runtime.ps1`, Windows 11 Pro 10.0.26200. AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1589
No description provided.