Repository navigation
Runtime: register each mapped image's x64 unwind table (.pdata) - #176
Merged
Merged
Conversation
2 tasks done
Owner
…RtlAddFunctionTable Images the loader maps by hand are unknown to the system unwinder, so an exception raised in or passing through one couldn't be dispatched and killed the process. load() now validates the exception directory (entries in bounds, sorted, non-overlapping; zero-length entries allowed, as in System32's symcryptk.dll) and registers it; the loader removes it before freeing the image. Rules measured over 3,780 x64 System32 images (5,023,071 entries) and the 16 package DLLs. Tests: loader_test covers registration, removal and six corrupt tables on hand-built images; pe_loader_test checks a fixture SEH fault is caught by the image's own handler (fails without registration) and, with LEONIDA_GAME_DIR, every package DLL's table. AI-assisted.
Spaghetih
force-pushed
the
runtime/unwind-tables
branch
from
November 21, 2026 22:19
44af346 to
27d1b11
Compare
Contributor
Contributor
Author
|
Thanks @Kam471! I test-merged #93 ( |
1 of 2 tasks
S1m0ne1997
added a commit
to S1m0ne1997/Leonida
that referenced
this pull request
Nov 21, 2026
ItsNotRexed#93 is TLS only; FSR host imports are 82 on current main AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IAmNotSiob
added a commit
to IAmNotSiob/Leonida
that referenced
this pull request
Nov 21, 2026
IAmNotSiob
added a commit
to IAmNotSiob/Leonida
that referenced
this pull request
Nov 21, 2026
…mage known to RtlPcToFileHeader, not only ItsNotRexed#176's tables
ItsNotRexed
pushed a commit
that referenced
this pull request
Nov 21, 2026
… loader gta6rt --run <exe> [-- args] maps and binds the executable, initialises its modules and calls its entry point on a game thread. shims/process.cpp answers the process-level imports through the game's own import table: argv/argc and GetCommandLine are the game's (UCRT api-set/ucrtbase and msvcrt forms), and exit/_exit/quick_exit/ExitProcess/abort end the run with that exit code instead of the host. gta6rt then exits with the game's code directly, so the game's atexit handlers don't run during host shutdown. tiny_game.exe (CTest run_tiny_game, run_tiny_game_exit_code) does what a title does in its first second: arguments, a static initializer, a 4 MiB allocation, a file round trip, a thread, and xgameruntime.dll imports, which the shim registry answers instead of the link-time stub. thread_local and a C++ exception are opt-in (LEONIDA_RUN_TLS / LEONIDA_RUN_EH) until #93 and #176.
2 tasks done
S1m0ne1997
added a commit
to S1m0ne1997/Leonida
that referenced
this pull request
Nov 22, 2026
ItsNotRexed#93 is TLS only; FSR host imports are 82 on current main AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
S1m0ne1997
added a commit
to S1m0ne1997/Leonida
that referenced
this pull request
Nov 22, 2026
…d#176 AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Item: RT-8 (#156). Overlaps the unwind part of #93 (RT-1); coordination proposed there.
What and why
runtime/README.mdlisted this as a known limit: "The loader does not yet register x64 unwind tables". Images theloader maps by hand are invisible to the system unwinder, so an exception raised in a mapped image (or passing
through one of its frames) can't be dispatched. Even an exception the image handles itself takes the process down,
and stack walks stop at the first mapped frame.
Changes
Loader::load()now callsregister_unwind()afterprotect_sections(). It validates the exception directory andregisters it with
RtlAddFunctionTable.Modulerecords the table and its entry count.RtlLookupFunctionEntrybinary-searches it and followsUnwindDatawithout bounds checks. The loader rejects, with a message: a directory outside the image, an entryending before it starts or past
SizeOfImage, entries out of order or overlapping, and unwind data outside theimage. As the system loader does, a trailing partial entry is ignored.
DLLs. Every table is sorted, non-overlapping and in bounds. One shipped image (
symcryptk.dll) has a zero-lengthentry (
BeginAddress == EndAddress), so that is allowed. No entry uses the indirect form (UnwindDatabit 0).~LoadercallsRtlDeleteFunctionTablebefore it frees the image, so no stale table points at freed memory.docs/design.mdis updated, anddocs/runtime_imports.mdgets per-DLL unwind entry counts (counts only, like the sizes already there).Tests
loader_test(hand-built images): the table is registered andRtlLookupFunctionEntryreturns the right entryand image base; it is gone after the loader is destroyed; a trailing partial entry is ignored; a zero-length entry
is accepted; six corrupt tables are rejected.
pe_loader_test:tiny_dllgainstiny_fault_caught, a__try/__exceptaround a read through a pointer.Called with
nullptrfrom the test, the access violation must be handled by the mapped image's own handler.With
register_unwinddisabled this check, and the two lookup checks, fail (the fault escapes to the test'souter handler). Verified both ways.
pe_loader_test, optional (LEONIDA_GAME_DIR): for every DLL present (all 16 not required), the wholedirectory is registered, every entry resolves to itself, and the entry point is covered. Coverage is either
direct, or through
jmp rel32thunks:libHttpClient.GDK.dll's entry point is an incremental-link thunk, whichhas no entry of its own.
Tested on
scripts/build_runtime.ps1(CMake + Ninja, RelWithDebInfo). Builds without warnings,and
ctest: 7/7.pe_loader_testwithLEONIDA_GAME_DIRon a local Xbox Series 1.0.2.1 package (files read in place): 105checks, 0 failures. All 16 DLLs map, bind and register their unwind tables.
game_scarlett_master.exe, which isn't in the package.Notes
Loader::load(), as Loader: initialise dependencies before their importers #140 does. Whichever merges second will have a one-line conflict there.Checklist