upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/main.cpp
AgeCommit message (Collapse)Author
12 daysMerge TreXito's unmerged PRs: translator fixes, fuzzers, CPU emulation, ↵ubiquitarianism
xapu/chad shims Merged from the TreXito/mangrove copy of the original repository, which carried contributor pull requests that were never merged here. Kept: rdna2spirv fixes (ds_append/ds_consume, v_ldexp_f16 under MODE.FP_ROUND, thread-group SGPR, fma exact), the differential fuzzers (dot, vint, wint, vrel, cvt, f16misc, salu, mode) with their tests, the exe/import fail-fast and int3 cause tools, Zen 2 instruction emulation (cpu_emulation.h) and the xapu.dll/chad.dll shims. Not taken, because they conflict with different implementations already on main: the D3D12 Xbox-ABI layer, xmem, acphal, loader TLS, f64_diff, DirectStorage (needs the typed-error zlib inflate), and the copy's own MANGROVE.md and README changes.
12 daysMerge remote-tracking branch 'origin/pr/8964'ItsNotRexed
# Conflicts: # runtime/shims/d3d12_vulkan_device.cpp
12 daysMerge remote-tracking branch 'origin/pr/9754'ItsNotRexed
# Conflicts: # scripts/build_runtime.ps1
12 daysgta6rt: --init/--run stop with a clear message on a host without AVXSenne Cools
The game runs AVX code from its TLS callbacks on, so a CPU or OS without AVX (a QEMU qemu64 guest) died with a bare 0xC000001D. Check CPUID.1 AVX/OSXSAVE and XCR0 YMM state first, print one line and exit 4 (3 is LEONIDA_UNIMPLEMENTED=stop). --dry-run is unchanged and LEONIDA_SKIP_CPU_CHECK=1 skips the check. AI-assisted.
12 daysd3d12_xs: slot 133 commits the buffer's xmem pages before the host-pointer ↵Raavve
import xmem commits physical pages on first touch (#7556), so a range the title has mapped but not written yet is still MEM_RESERVE when it places a buffer on it through device slot 133, and the Vulkan layer's import (#7218) refuses reserved pages and answers with its fallback buffer, which the title's writes never reach. Slot 133 now calls a registered pages hook (set_placed_at_va_pages_hook, next to set_placed_at_va_handler) with the buffer's range before the handler; gta6rt registers rt::xmem::commit_physical_range. A failed commit is logged once and the handler still runs. Textures don't call it. The Vulkan layer doesn't link xmem. Tests: xs_proxy_mock_test checks the hook order, arguments, failure and texture cases; the new d3d12_xmem_placed_test places a buffer on untouched xmem physical pages and checks the fallback without the hook, and with it the import and a GPU copy reading the CPU's writes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
12 daysd3d12: a shader path that is not UTF-8 never throws, and LEONIDA_SHADERS is ↵Jan Trencansky
absolute - A shader_path.txt that is not UTF-8 no longer throws out of Create*PipelineState: MSVC's STL reports the failed conversion as std::system_error, not filesystem_error. configured_shader_directory() returns the reason instead, and DeviceState::library() catches every std::exception, so the "invalid translated shader path" message prints and the pipeline fails. The reader of the file itself is unchanged. - A relative LEONIDA_SHADERS no longer follows the current directory: gta6rt makes it absolute at startup, next to --game-dir and --overlay, and ShaderLibrary::load keeps an absolute folder for the modules it reads later. Tests: d3d12_shader_path_test (new, Windows, no GPU) and a relative-folder check in shader_library_test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
12 daysMerge branch 'pr7111' into ladder-frameASTROWwwW
# Conflicts: # docs/runtime_imports.md # runtime/CMakeLists.txt
12 daysMerge main into runtime/emulate-zen2-insns (keep both the cpu_emulation and ↵Krashgamer
xg_xs test targets) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
12 daysMerge remote-tracking branch 'upstream/main' into rebase/4313-on-042c5f378Roberto0953
# Conflicts: # runtime/CMakeLists.txt # runtime/README.md # runtime/src/pe_loader.cpp
12 daysgta6rt: emulate the Zen 2 instructions a desktop CPU may lack ↵Krashgamer
(INSERTQ/EXTRQ, CLZERO, MONITORX/MWAITX, CLWB) The executable uses SSE4a INSERTQ, CLZERO and MONITORX/MWAITX (AMD only) and CLWB (Intel since Ice Lake) without asking CPUID (docs/cpu_features.md). A host without one raises #UD there. src/cpu_emulation.h adds a vectored handler that recognises those encodings at the faulting RIP, does the same work on the CONTEXT and steps past the instruction; gta6rt installs it before any image code runs, after the startup trace's handler so it runs first. One [rt] line names what the host lacks, one more per instruction on first use. cpu_emulation_test checks the decoder on hand-written encodings, the bit-field helpers and apply() on a synthetic CONTEXT, then runs every form for real from an executable buffer: natively on a Zen host, through the handler on an Intel one, with the same expected values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
12 daysruntime: retain import report when initialization fails (#6835)RaulOrtizSanchez
Squash-merged after diff review of PR #6835 - RT-486: Retain the import binding report when initialization fails
12 daysMerge remote-tracking branch 'origin/main' into rt/exe-tls-slot0mariuslozo-boop
# Conflicts: # runtime/src/main.cpp
12 daysMods: first-person view, the base (camera section, view-mode getter hook)ItsNotRexed
mod.json gains "camera": {"view_mode": "first_person"|"default", "first_person_value", "contexts"}. gta6rt --view-mode-getter RVA hooks the game's view-mode getter with a result-override thunk (code_hooks.h: the original runs, then its result and first argument go through leonida::mods::override_view_mode), so the listed contexts answer first person and the others keep the game's mode. mods/first_person asks for it on foot. docs/modding.md records why switching a mode is enough: the game's tuning data refers to a first-person view (FirstPersonDirectionDot, UseFirstPersonCameraMatrix on cloth capsules, FIRST_PERSON_VIEW hit-reaction recovery, a firstpersonshooter HUD texture; RDR2's engine branch), while GTA V's camera class names are not present by joaat. The context numbering and the first-person enum value (4, GTA V's) are manifest settings to confirm in the executable. ctest mods and code_hooks cover the parser, the override and the thunk on x64 code in memory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
12 daysMods: the archetype hook, --archetype-lookup RVA[,ARG]ItsNotRexed
code_hooks.h hooks a function of the mapped game image without patching it: every direct call/jmp rel32 to it in the image's executable sections is pointed at a thunk that saves rcx/rdx/r8/r9 and xmm0-3, passes the hash (argument 0 or 1) through leonida::mods::active().remap() and jumps on to the original. gta6rt installs it right after mapping, before any image code runs, and logs how many call sites it redirected, so a --dry-run with a candidate RVA tells whether it is the archetype lookup. ctest code_hooks runs the thunk on x64 functions written into memory (call and tail jump remapped, r8 preserved, a branch elsewhere left byte for byte). With the executable's lookup RVA this applies mods/mandy_prison_intro; docs/modding.md says how to find it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
12 daysMods: mod.json manifests with archetype swaps, and the Mandy prison-intro modItsNotRexed
gta6rt reads mods/<folder>/mod.json next to gta6rt.exe (or --mods DIR), checks each and logs it. An archetype swap names two models the game has (by joaat name or 0x hash): when the game asks for `from` it gets `to`. The swaps are loaded into leonida::mods::active(); they apply once the game's archetype lookup is hooked, which needs the executable's address for it (docs/modding.md, Day one). mods/mandy_prison_intro swaps Lucia's player model player_story000_00 (0xE472B687) for cs_mandy (0xD7C0CDFF), the ids measured in the packs tables; mods_test checks joaat reproduces both. Conditions narrower than "always" are refused until a hook provides mission state. No game data in either. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 daysLoader: reserve TLS index 0 at start, with a home template that copies the EXE'smariuslozo-boop
Fixes from the review of the index-0 change: - The lazy move at the first executable map stopped other threads and swapped their slots, guarded by a "thread is inside gta6rt.exe" check. That is not enough: MSVC keeps &ThreadLocalStoragePointer[_tls_index] across calls (zlib_inflate saves it at [rbp-80h] across memset, push_back and inflate_codes, then reads _Init_thread_epoch through it), so a thread stopped in the heap or memset still reads the wrong slot afterwards. The move is now rt::reserve_tls_index0(), done once at process start: gta6rt calls it from a .CRT$XCT initializer, before its own static initializers and before any of its threads; the CRT startup frames above it hold no TLS slot address (checked in the disassembly). It swaps slots 0 and home on the calling thread only; no thread enumeration, suspension, TEB writes or TlsAlloc mark are left. - The home clone's block was the helper's 514 bytes, smaller than gta6rt.exe's 1398-byte TLS. The home clone is now written from gta6rt_tls_host.dll with its TLS directory pointed at a new 16 KiB export, gta6rt_tls_home_template, filled with a copy of the EXE's template and its alignment (LdrpAllocateTls copies End - Start and ignores SizeOfZeroFill, so the zero fill is part of the range). Every new thread then has a fresh copy of gta6rt.exe's TLS at the home index from its first instruction, so no adoption step or window before the helper's DLL_THREAD_ATTACH is left. The mapped template is checked against the EXE's after the load. - The owner is GetModuleHandleW(nullptr) with _tls_index 0, not any module whose index reads 0. - A primary helper without gta6rt_tls_host_set_thread_event is refused. - An executable that does not get index 0 (no reservation, or another executable holds it) is refused by --run and --init with an error; its /GA code would read and write another module's TLS through slot 0. The README no longer says it "reads the first one's slot 0". - Thread attach installs every module's copy before any TLS callback runs, as Windows allocates all blocks before the first DllMain. - Tests: loader_tls_index0 (runs) checks this EXE's block moving from slot 0 to the home index by identity, the home template's size and content, and that the getter reads slot 0 with its _tls_index pointing elsewhere (fails for a non-/GA build of the fixture); loader_tls_index0_threads reserves while threads are being created, with one suspended thread that has no TLS array yet and tiny_thread_hook.dll running test code before the helper's DLL_THREAD_ATTACH; loader_tls_index0_noreserve maps without the reservation. The tiny_tls_ga.cpp comment names the real test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 daysMerge pull request #3303 from Doffi4ItsNotRexed
13 daysMerge pull request #2957 from Shrey RatnaItsNotRexed
13 daysMerge pull request #2070 from jaybeebabageyusItsNotRexed
13 daysMerge upstream main into RT-207Doffi4
13 daysRuntime: preserve Unicode in the console path diagnosticDoffi4
13 daysMerge remote-tracking branch 'upstream/main' into 2070-lifecycle-fixjaybeebabageyus
# Conflicts: # runtime/src/pe_loader.cpp # runtime/src/pe_loader.h # runtime/test/loader_tls_test.cpp
13 daysruntime: scope the TLS clone purge to ownerless files, clean clones before ↵jaybeebabageyus
ExitProcess, per-slot thread-event errors The startup purge deleted every leonida_tls_host_*.dll in the temp directory, so it could remove the clone of a concurrent process that had copied its helper but not reached LoadLibraryExW yet. Clones are now copied to a staging name and renamed into place while the copy step's guard handle is open, so a final-name clone never exists without a handle, and the purge skips files that fail an exclusive open or whose owner process (from the file name) is still alive. std::atexit cleanup never ran on the --run path because main ends with ExitProcess; the loader now exposes cleanup_tls_clones() and main calls it before ExitProcess (atexit still covers normal exits). on_host_thread_event wrapped the whole slot loop in one try/catch, so one throwing slot killed the events for every other module. The catch is now per slot, and the detach path releases the slot even when the callbacks threw, instead of leaking the block to the OS loader. README and the initialize_tls comment no longer claim only one mapped TLS module can be live; the loader_tls_test gained purge-ownership and explicit-cleanup checks.
13 daysgta6rt: GAME: and the overlay are absolute, so a bare image name has a game ↵Shrey Ratna
folder `gta6rt --run game.exe`, started from the game folder, set the game folder to the image's parent path, which is empty for a bare name: the run printed `console paths: GAME: -> , writes -> overlay` and every GAME: open failed with ERROR_PATH_NOT_FOUND. A relative --game-dir or --overlay worked only until the title changed its current directory. main.cpp now makes both absolute at startup (keeping the path as given if absolute() fails). New CTest run_tiny_game_dir: tiny_game's opt-in `game-file` check moves its current directory, then reads GAME:\tiny_game_probe.txt; check_game_dir.cmake runs it by bare name and with `--game-dir .`. Without the fix both fail (open errors 3 and 2); with it both pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 daysInitialize game command line before process-attach callbacksadmin
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
13 daysStartup trace: never replace an existing file; write UTF-8 onlyLeonardo Guimaraes
Review on #1756 (Vonsek): - The trace is opened before the loader reads the image, so `wb` could truncate an input named by mistake (the image itself). open() now uses "x" mode and fails with EEXIST on an existing path; gta6rt says so and exits with 2. - OutputDebugStringA text is in the ANSI code page. It is converted to UTF-8 before quoting, so a byte such as 0xE9 no longer breaks the JSON lines. Host module names now come from GetModuleFileNameW, converted to UTF-8, for the same reason. startup_trace_test: an existing file is refused with EEXIST and its bytes survive, the trace stays off; an ANSI debug string with 0xE9 appears as its UTF-8 form and the whole file is valid UTF-8.
13 daysRuntime: opt-in startup trace (gta6rt --trace FILE)Leonardo Guimaraes
Writes one JSON object per line, flushed per event: module maps, TLS callbacks, DllMain results, the first call of each unimplemented import with its caller as module+RVA, OutputDebugString text, exceptions with module+RVA and a short unwind, and the exit code. A vectored handler records and returns EXCEPTION_CONTINUE_SEARCH, so behaviour is unchanged. Off by default. startup_trace_test builds a synthetic DLL image (no game data) and checks each event kind.
13 daysMerge remote-tracking branch 'origin/main' into runtime-reserve-fixed-baseAsh Hopkins
# Conflicts: # runtime/CMakeLists.txt # runtime/src/main.cpp
13 daysruntime: reserve a relocation-less image's range before arm64 Wine takes itAsh Hopkins
An EXE without .reloc can only run at its ImageBase (0x140000000 by default; RT-22 asks whether the game's is one). Under arm64 Wine on macOS (CrossOver's arm64 bottles, x86-64 code under FEX) the process's own start-up allocations sit at 0x100000000 and up before gta6rt runs, so such an image failed with "preferred base is taken". gta6rt now starts itself again suspended when the image has no relocations and its range is not free, reserves [ImageBase, ImageBase + SizeOfImage) in the new process, resumes it and returns its exit code; the loader commits the image inside that reservation. LEONIDA_BASE_RESERVED tells the new process, which does not start itself again. Where the range is free at start-up (Windows, x86-64 Wine) nothing changes. tiny_game_fixed is the stand-in game linked /FIXED at 0x140000000; run_tiny_game_fixed and run_tiny_game_fixed_exit_code run it. Arm64 bottle (CrossOver Preview 20260821, M2 Max): it maps at 0x140000000 and both tests pass, --dry-run and --init exit 0; with the relaunch disabled it fails as before. The Rosetta (x86-64) bottle passes them too. The in-process loader tests that build relocation-less images (loader, pe_loader_bounds, unimplemented_policy) still fail on arm64. AI-assisted. No game files.
13 daysgta6rt: map GAME: console paths, and send writes to an overlay (RT-97)HQasper
A mapped title names its files on the console's drives, but nothing mapped them: the file calls went straight to the host and --game-dir was only used to find modules, so the first file a title opens at boot would fail. New shims for CreateFile*, FindFirstFile*/FindNextFile*/FindClose, GetFileAttributes*/ GetFileAttributesEx* and DeleteFile* (kernel32, kernelbase and the api-ms-win-core-file sets) map a GAME: path under --game-dir, and send every open that can write and every delete to --overlay (default <game-dir>\overlay), which reads and listings prefer. A write-open copies the package file into the overlay first, so OPEN_EXISTING keeps its bytes, and a delete of a package file leaves a marker instead of removing it, so the package is never modified. A path that climbs above GAME: with ".." or names another drive is refused with ERROR_INVALID_NAME. A path without the prefix is still a host path. The prefixes and the overlay come from ivall/xcl (GPL-2.0-only), as facts only, no code. file_system ctest: 43 checks over folders in %TEMP%, covering mapping and case, copy-up and read preference, a new file in folders the package lacks, delete and re-create, the merged listing, host-path passthrough, the escape refusal and the narrow variants. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
13 daysprocess shim: keep the game's command line wide so a non-ASCII argument ↵Emre Demir
can't crash --run (RT-84) main.cpp turned each game argument into std::filesystem::path::string(), which throws std::system_error under MSVC when the ANSI code page has no mapping for a character. Nothing caught it, so gta6rt --run ended in 0xc0000409 before the game started. set_command_line now takes wide strings: __wargv and GetCommandLineW hold the arguments exactly, and the narrow argv and GetCommandLineA are their CP_ACP text from WideCharToMultiByte, which replaces a character the code page lacks instead of failing, as the CRT does. process_cmdline_test passes wide arguments and checks a Latin-1 one and a Greek, Cyrillic and CJK one that no single-byte code page holds, so the crash is covered on every system locale, not only 1253.
13 daysgta6rt: refuse more than one of --dry-run, --init and --run (#886)Felix Croasdale
--dry-run --run set both flags, so the dry run initialised the modules and called the entry point. gta6rt now takes exactly one mode and prints the usage (exit 2) otherwise. Three ctest cases run the stand-in game with two modes and fail if it is mapped or run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 daysRuntime: add opt-in D3D12 call tracingmohamedsaad.lahlou
14 daysruntime: LEONIDA_UNIMPLEMENTED=log|fail|stop policy for imports with no bindingAlxcBTW
An unimplemented import used to return 0 silently, which is S_OK for an HRESULT function with its out parameters never written. The thunk now passes the caller's return address and rcx/rdx/r8/r9 to a shared stub, and LEONIDA_UNIMPLEMENTED picks the behaviour: - log (default): exactly as before. - fail: E_NOTIMPL for imports known to return HRESULT (D3D12Create*/Serialize*, CreateDXGIFactory*, XGameRuntimeInitialize, and the GDK XAsync/XTaskQueue/ XUser/XStore/XGameSave/XPackage/XGameUi families minus their documented void/bool/int functions), 0 otherwise. - stop: print the import, the caller as module+RVA and the four argument registers, then break under a debugger or exit with code 3. --dry-run now counts unimplemented imports by return class. The stub zeroes xmm0 and has unwind info, so float callers and debuggers are unaffected. unimplemented_policy_test builds a synthetic image and checks all three modes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
14 daysruntime: rename shims/process.h to process_shim.h (it hid the CRT's ↵ItsNotRexed
<process.h> from <thread>) With runtime/shims on the include path, <thread>'s #include <process.h> found #316's header, so _beginthreadex was undeclared in d3d12_com.cpp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
14 daysRuntime: install static TLS for mapped imagesKam471
14 daysRuntime: gta6rt --run, and a stand-in game executable run through the loaderIAmNotSiob
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.
14 daysRuntime: initialise a loaded module's TLS and DllMainAyinaki
Mapping an image never ran anything. TLS callbacks and DllMain were documented as the caller's, and nothing called them, so a module that needs either could not be brought up at all. Loader::initialise() now allocates the module's TLS slot, copies the template and SizeOfZeroFill into it, writes the slot index into the image, runs the TLS callbacks with DLL_PROCESS_ATTACH, then calls the entry point of a DLL as DllMain. Every address it follows is bounded like the rest of the loader: the directory, the template, the index, the callback table and each callback, with a 1 MiB ceiling on the block. Only DLLs get DllMain; an EXE's entry point has a different signature and stays the caller's to run, and --dry-run still runs nothing. The tests build an image whose TLS callback and DllMain are real machine-code stubs that store a sentinel, so they check the code actually executed rather than merely being parsed.
2026-11-20Initial commit: Leonida, build-it-yourself PC port groundworkNotRexed
Shader pipeline (carve, FSSM unpack, gfx1013 disassembly, RDNA2 to SPIR-V), asset export via rpf9-explorer's Core (submodule), PE loader and shim skeleton, and make_game.py, which builds from the user's own copy of the game. No game data, keys or executables are included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>