pe: resolve forwarded exports through the host resolver #205
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/208"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by raulmoracode on 2026-11-21T18:23:45Z.
Change
pe_map_exportreturned null for every forwarded export: the address table entry points back into the export directory, and the lookup stopped there. Windows resolves the same entry throughGetProcAddressby loading the target module.This adds
pe_map_export_resolved(mapped, name, resolve). It shares the export walk withpe_map_exportand, when the entry is a forwarder, parsesModule.SymbolorModule.#ordinaland calls the host resolver thatpe_map_imagealready receives.pe_map_exportis unchanged and still returns null for a forwarder.The export walk moved into one
find_exporthelper, so both entry points apply the same live page-protection checks added in #167.Fixes #206
Verification
Commit
0250ec3on Windows 10 22H2 build 19045.6466, VS Build Tools 2022 17.14, MSVC 14.44.35207, Windows SDK 10.0.26100, CMake 4.4.4, Python 3.12.10.Result:
Full build: 228/228 targets. The CPU group passes 28/28.
Evidence and follow-up
The fixture is
tests/cpu/forwarder.asmwithforwarder.def:The linker only accepts that forwarder when the target module's import library is linked as well, even though the resulting DLL has no import descriptor (
dumpbin /importsis empty), sope_map_imagestill maps it without a resolver.Controls in the test:
pe_map_exportmust return null for the forwarder, an absent name must return null, and a resolver that returns null must return null. The local export is the positive control that the shared walk still returns ordinary addresses.Not covered: the
Module.#ordinalform is parsed but has no fixture, and a forwarder whose target module fails to load returns null without a diagnostic. Both are candidates for a follow-up.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T19:04:48Z.
The per-call resolver API is approved for #206. The caller keeps the mapping live throughout lookup. Both entry points return the same local address without invoking the resolver. The existing entry point continues to return null on forwarders. The new entry point synchronously uses the pe_map_image callback ABI, preserves the module spelling, passes (module, symbol, 0) or (module, nullptr, ordinal), and returns the callback result unchanged. Loading the target and following further forwarders belong to the host. The mapper does not cache the callback.
At
0250ec35, the Windows named-forwarder comparison, local RVA, absent name and refusing-resolver checks are already present. Please extend cpu_native_forwarder to check the exact ordinal callback arguments and a null resolver. In the parser, require ASCII decimal digits in the range 1–65535 after #. strtoul accepts a leading plus or whitespace, so cover malformed input such as #+1 and verify it returns null without calling the resolver. Bound the readable forwarder string, including its terminator, to the export directory. Include a case whose terminator falls just outside that directory. Please post the focused Windows result on the updated SHA.Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-21T19:05:52Z.
I tested the ordinal-only forwarding path on Windows x64 at
0250ec3. Bothpe_map_export_resolvedand WindowsGetProcAddressresolved the forwarder tocpu_ordinal_provider.#77at the same address. The callback received a null name and ordinal 77. The named forwarder and local export also matched Windows, and the refusing resolver returned null.MSVC LINK rejected the direct ordinal definition in my fixture. I shortened an existing forwarder string in a private copy of the source-built DLL and used that same copy for both lookups.
cpu_native_forwarder,cpu_aot_ordinal_importandcpu_aot_import_callall passed. I have a source-only test patch ready if you'd like to include this case.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T03:44:20Z.
@RonLogic, please share the source-only ordinal control you tested here, or link its commit, so the PR author can reuse it. @raulmoracode, that independent Windows run covers the valid ordinal callback. Please integrate it if suitable and keep the malformed ordinal and export-directory terminator controls from the existing review separate; those exercise different rejection paths.
Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-22T11:19:15Z.
Thanks for asking for the source. I checked the merged
cpu_native_forwardertest. It already covers the exact ordinal callback arguments, a null resolver, malformed ordinal strings, and a terminator outside the export directory. The remaining distinction is comparison with Windows for a real ordinal-only export. I adapted my earlier source-only control to current main and kept the existing cases intact.On Windows x64,
cpu_native_forwarderpassed with the added comparison. WindowsGetProcAddressandpe_map_export_resolvedreturned the same address forcpu_ordinal_provider.#77, and the resolver received(module, nullptr, 77). The optional test-only change is RonLogic/Xbox2Windows@768be85.