diff options
| author | admin <s0las16.224@gmail.com> | 2026-11-22 18:08:14 +0000 |
|---|---|---|
| committer | admin <s0las16.224@gmail.com> | 2026-11-22 18:08:14 +0000 |
| commit | 0327c9d27a582fa3726f42169b32c008778da924 (patch) | |
| tree | 4d95b078cb5e43ba97f96aab17a4bbc3713af86d /runtime/shims/library_loader.cpp | |
| parent | ec8ec4c9a46c6623f1a9c125afd3566da97f1e0c (diff) | |
Resolve host module GetProcAddress names through runtime shims
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Diffstat (limited to 'runtime/shims/library_loader.cpp')
| -rw-r--r-- | runtime/shims/library_loader.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/runtime/shims/library_loader.cpp b/runtime/shims/library_loader.cpp index 0093e6050..0d609fe68 100644 --- a/runtime/shims/library_loader.cpp +++ b/runtime/shims/library_loader.cpp | |||
| @@ -9,8 +9,8 @@ | |||
| 9 | // So for a module the shim registry owns (rt::shims::owns_dll: xgameruntime.dll, d3d12_xs.dll, xmem.dll, ...), these | 9 | // So for a module the shim registry owns (rt::shims::owns_dll: xgameruntime.dll, d3d12_xs.dll, xmem.dll, ...), these |
| 10 | // return a pseudo-handle, and GetProcAddress on it resolves names (and "#ordinal") through rt::shims::find. A name the | 10 | // return a pseudo-handle, and GetProcAddress on it resolves names (and "#ordinal") through rt::shims::find. A name the |
| 11 | // registry doesn't serve returns NULL with ERROR_PROC_NOT_FOUND, as a real module would, and is logged once. Every | 11 | // registry doesn't serve returns NULL with ERROR_PROC_NOT_FOUND, as a real module would, and is logged once. Every |
| 12 | // other module goes to the host unchanged. Only images mapped by the loader see these: they are bound through the | 12 | // other module uses the same named shims as static imports, falling back to the host. Only images mapped by the |
| 13 | // registry, the runtime's own code calls the host directly. | 13 | // loader see these: they are bound through the registry, the runtime's own code calls the host directly. |
| 14 | #include <windows.h> | 14 | #include <windows.h> |
| 15 | 15 | ||
| 16 | #include <cstdio> | 16 | #include <cstdio> |
| @@ -205,6 +205,16 @@ FARPROC WINAPI get_proc_address(HMODULE module, LPCSTR name) { | |||
| 205 | SetLastError(ERROR_PROC_NOT_FOUND); | 205 | SetLastError(ERROR_PROC_NOT_FOUND); |
| 206 | return nullptr; | 206 | return nullptr; |
| 207 | } | 207 | } |
| 208 | if (module && !IS_INTRESOURCE(name)) { | ||
| 209 | const DWORD error = GetLastError(); | ||
| 210 | wchar_t path[32768]; | ||
| 211 | const DWORD length = GetModuleFileNameW(module, path, static_cast<DWORD>(sizeof(path) / sizeof(path[0]))); | ||
| 212 | void* shim = nullptr; | ||
| 213 | if (length && length < sizeof(path) / sizeof(path[0])) | ||
| 214 | shim = find(module_name(narrow(path)), what); | ||
| 215 | SetLastError(error); | ||
| 216 | if (shim) return reinterpret_cast<FARPROC>(shim); | ||
| 217 | } | ||
| 208 | return GetProcAddress(module, name); | 218 | return GetProcAddress(module, name); |
| 209 | } | 219 | } |
| 210 | 220 | ||