diff options
| author | Tyrannys <80750971+Tyrannys@users.noreply.github.com> | 2026-11-25 07:41:35 -0600 |
|---|---|---|
| committer | Tyrannys <80750971+Tyrannys@users.noreply.github.com> | 2026-11-25 07:41:35 -0600 |
| commit | 02d719cdacae0a12414c9bc970812768daa49d5b (patch) | |
| tree | ee842533db6889530b702d22f422ce45fb8478fb /runtime/src/main.cpp | |
| parent | 2c7440fed8c586d4eeed50f6b81e94b5dbaf2396 (diff) | |
| parent | 384abe5b06d08e349f4b4e4394c68f036da47dc7 (diff) | |
Merge main into title-window-overflow; keep only the window-cap test
Main's ba626820e already handles a title address past
LEONIDA_TITLE_WINDOWS_MB: the persistent geometry copy backs it, or
else every view writer emits a zero-size V# (loads 0, stores dropped),
so the raw VA never reaches the GPU (#1537). That replaces this branch's
zeroed scratch window, so the runtime and docs side take main's version.
The d3d12_title_window_cap test stays, rewritten for main's behaviour:
with a cap of 0, two CBVs of private title memory are written zero-size
(no base, no records, never the raw VA), no window is made, and a
dispatch through one reads zeros. Main had no test that dispatches
through an over-cap title address.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/main.cpp')
| -rw-r--r-- | runtime/src/main.cpp | 58 |
1 files changed, 52 insertions, 6 deletions
diff --git a/runtime/src/main.cpp b/runtime/src/main.cpp index 8e3767740..f01997775 100644 --- a/runtime/src/main.cpp +++ b/runtime/src/main.cpp | |||
| @@ -72,7 +72,8 @@ void keep_title_watchdog_kicked(std::uint8_t* base) { | |||
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | // LEONIDA_PEEK="0x9e1dac0:3,0x7446510,0x98f828c" (diagnostic): a thread prints the 8-byte values at these RVAs of the | 74 | // LEONIDA_PEEK="0x9e1dac0:3,0x7446510,0x98f828c" (diagnostic): a thread prints the 8-byte values at these RVAs of the |
| 75 | // title's image (":n" = n consecutive values) every LEONIDA_PEEK_SECONDS (default 10). For answering "what does this | 75 | // title's image (":n" = n consecutive values, at most 32; "RVA>OFF" reads through the pointer stored at the RVA, at |
| 76 | // pointer + OFF, both hex) every LEONIDA_PEEK_SECONDS (default 10). For answering "what does this | ||
| 76 | // global hold at run time" without a debugger: the reverse-engineering notes (docs/re/requests.md) ask for exactly | 77 | // global hold at run time" without a debugger: the reverse-engineering notes (docs/re/requests.md) ask for exactly |
| 77 | // that. Reads are checked; nothing is written. | 78 | // that. Reads are checked; nothing is written. |
| 78 | void start_title_peek(std::uint8_t* base) { | 79 | void start_title_peek(std::uint8_t* base) { |
| @@ -93,15 +94,35 @@ void start_title_peek(std::uint8_t* base) { | |||
| 93 | char* end = nullptr; | 94 | char* end = nullptr; |
| 94 | const std::uint64_t rva = std::strtoull(at, &end, 16); | 95 | const std::uint64_t rva = std::strtoull(at, &end, 16); |
| 95 | if (end == at) break; | 96 | if (end == at) break; |
| 97 | // "RVA>OFF": the 8-byte pointer at the RVA, then the values at pointer + OFF (both hex). | ||
| 98 | bool deref = false; | ||
| 99 | std::uint64_t offset = 0; | ||
| 100 | if (*end == '>') { | ||
| 101 | deref = true; | ||
| 102 | offset = std::strtoull(end + 1, &end, 16); | ||
| 103 | } | ||
| 96 | unsigned count = 1; | 104 | unsigned count = 1; |
| 97 | if (*end == ':') count = static_cast<unsigned>(std::strtoul(end + 1, &end, 10)); | 105 | if (*end == ':') count = static_cast<unsigned>(std::strtoul(end + 1, &end, 10)); |
| 98 | char text[40]; | 106 | char text[48]; |
| 99 | std::snprintf(text, sizeof(text), " 0x%llx=", static_cast<unsigned long long>(rva)); | 107 | if (deref) |
| 108 | std::snprintf(text, sizeof(text), " 0x%llx>%llx=", static_cast<unsigned long long>(rva), | ||
| 109 | static_cast<unsigned long long>(offset)); | ||
| 110 | else | ||
| 111 | std::snprintf(text, sizeof(text), " 0x%llx=", static_cast<unsigned long long>(rva)); | ||
| 100 | line += text; | 112 | line += text; |
| 101 | for (unsigned i = 0; i < count && i < 16; ++i) { | 113 | const std::uint8_t* from = image + rva; |
| 114 | if (deref) { | ||
| 115 | std::uint64_t pointer = 0; | ||
| 116 | SIZE_T got = 0; | ||
| 117 | if (!ReadProcessMemory(GetCurrentProcess(), from, &pointer, sizeof(pointer), &got) || | ||
| 118 | got != sizeof(pointer) || !pointer) | ||
| 119 | count = 0, line += "?"; | ||
| 120 | from = reinterpret_cast<const std::uint8_t*>(pointer + offset); | ||
| 121 | } | ||
| 122 | for (unsigned i = 0; i < count && i < 32; ++i) { | ||
| 102 | std::uint64_t value = 0; | 123 | std::uint64_t value = 0; |
| 103 | SIZE_T got = 0; | 124 | SIZE_T got = 0; |
| 104 | const bool ok = ReadProcessMemory(GetCurrentProcess(), image + rva + 8ull * i, &value, | 125 | const bool ok = ReadProcessMemory(GetCurrentProcess(), from + 8ull * i, &value, |
| 105 | sizeof(value), &got) && got == sizeof(value); | 126 | sizeof(value), &got) && got == sizeof(value); |
| 106 | std::snprintf(text, sizeof(text), ok ? "%s%llx" : "%s?", i ? "," : "", | 127 | std::snprintf(text, sizeof(text), ok ? "%s%llx" : "%s?", i ? "," : "", |
| 107 | static_cast<unsigned long long>(value)); | 128 | static_cast<unsigned long long>(value)); |
| @@ -127,12 +148,14 @@ void start_title_peek(std::uint8_t* base) { | |||
| 127 | #include "mods.h" | 148 | #include "mods.h" |
| 128 | #include "pe_loader.h" | 149 | #include "pe_loader.h" |
| 129 | #include "thread_stacks.h" | 150 | #include "thread_stacks.h" |
| 151 | #include "thread_sampler.h" | ||
| 130 | #include "title_page_watch.h" | 152 | #include "title_page_watch.h" |
| 131 | #include "title_geometry_watch.h" | 153 | #include "title_geometry_watch.h" |
| 132 | #include "../shims/d3d12_trace.h" | 154 | #include "../shims/d3d12_trace.h" |
| 133 | #include "../shims/d3d12_xs_device.h" | 155 | #include "../shims/d3d12_xs_device.h" |
| 134 | #include "../shims/file_system.h" | 156 | #include "../shims/file_system.h" |
| 135 | #ifdef LEONIDA_VULKAN_DEVICE | 157 | #ifdef LEONIDA_VULKAN_DEVICE |
| 158 | #include "../shims/d3d12_compile_exit.h" | ||
| 136 | #include "../shims/package_splash.h" | 159 | #include "../shims/package_splash.h" |
| 137 | #endif | 160 | #endif |
| 138 | #include "../shims/process_shim.h" | 161 | #include "../shims/process_shim.h" |
| @@ -172,7 +195,7 @@ bool configure_first_run_ui(const std::filesystem::path& package, std::filesyste | |||
| 172 | const struct { const wchar_t* name; const wchar_t* value; } settings[] = { | 195 | const struct { const wchar_t* name; const wchar_t* value; } settings[] = { |
| 173 | {L"LEONIDA_D3D12", L"vulkan"}, {L"LEONIDA_ARENA_MB", L"2048"}, | 196 | {L"LEONIDA_D3D12", L"vulkan"}, {L"LEONIDA_ARENA_MB", L"2048"}, |
| 174 | {L"LEONIDA_GRAPHICS_STAGE_LAYOUT", L"1"}, {L"LEONIDA_PIPELINE_COMPILE", L"on-demand"}, | 197 | {L"LEONIDA_GRAPHICS_STAGE_LAYOUT", L"1"}, {L"LEONIDA_PIPELINE_COMPILE", L"on-demand"}, |
| 175 | {L"LEONIDA_GPU_LABELS", L"1"}, {L"LEONIDA_FRAME_PACING", L"1"}, | 198 | {L"LEONIDA_FRAME_PACING", L"1"}, |
| 176 | {L"LEONIDA_KEYBOARD_PAD", L"always"}, | 199 | {L"LEONIDA_KEYBOARD_PAD", L"always"}, |
| 177 | }; | 200 | }; |
| 178 | for (const auto& setting : settings) { | 201 | for (const auto& setting : settings) { |
| @@ -205,6 +228,18 @@ int usage() { | |||
| 205 | } // namespace | 228 | } // namespace |
| 206 | 229 | ||
| 207 | #ifdef LEONIDA_VULKAN_DEVICE | 230 | #ifdef LEONIDA_VULKAN_DEVICE |
| 231 | // The run ends with the title's Vulkan device alive, so no ~Device stops the background pipeline compiler: stop it | ||
| 232 | // here, before ExitProcess ends its thread, maybe inside the driver's compiler (rt::d3d12::stop_pipeline_compiles). | ||
| 233 | constexpr unsigned kExitCompileWaitMs = 2000; // a console close gives the whole process 5 s | ||
| 234 | |||
| 235 | static BOOL WINAPI stop_compiles_on_console_exit(DWORD event) { | ||
| 236 | if (event == CTRL_C_EVENT || event == CTRL_BREAK_EVENT || event == CTRL_CLOSE_EVENT) { | ||
| 237 | rt::d3d12_xs::stop_list_values(500); // as at the run's end: no list-value thread cut off inside the layer | ||
| 238 | rt::d3d12::stop_pipeline_compiles(kExitCompileWaitMs); | ||
| 239 | } | ||
| 240 | return FALSE; // the next handler (the default one: ExitProcess) ends the process, as before | ||
| 241 | } | ||
| 242 | |||
| 208 | static BOOL WINAPI show_package_window(HWND window, int command) { | 243 | static BOOL WINAPI show_package_window(HWND window, int command) { |
| 209 | const BOOL previous = ShowWindow(window, command); | 244 | const BOOL previous = ShowWindow(window, command); |
| 210 | const DWORD error = GetLastError(); | 245 | const DWORD error = GetLastError(); |
| @@ -357,6 +392,7 @@ int wmain(int argc, wchar_t** argv) { | |||
| 357 | leonida::geometry_writes::aliases.store(&rt::xmem::geometry_aliases); | 392 | leonida::geometry_writes::aliases.store(&rt::xmem::geometry_aliases); |
| 358 | leonida::kernel_writes::set_committer(&rt::xmem::commit_physical_range); | 393 | leonida::kernel_writes::set_committer(&rt::xmem::commit_physical_range); |
| 359 | rt::d3d12_xs::set_texture_page_provider(&rt::xmem::pin_mapped_data); | 394 | rt::d3d12_xs::set_texture_page_provider(&rt::xmem::pin_mapped_data); |
| 395 | leonida::kernel_writes::set_unguarder(&rt::xmem::reopen_unowned); | ||
| 360 | if (int trace_error = 0; !trace_file.empty() && !rt::startup_trace::open(trace_file.c_str(), &trace_error)) { | 396 | if (int trace_error = 0; !trace_file.empty() && !rt::startup_trace::open(trace_file.c_str(), &trace_error)) { |
| 361 | std::fprintf(stderr, trace_error == EEXIST ? "error: the trace file already exists; --trace only creates a new file\n" | 397 | std::fprintf(stderr, trace_error == EEXIST ? "error: the trace file already exists; --trace only creates a new file\n" |
| 362 | : "error: cannot create the trace file\n"); | 398 | : "error: cannot create the trace file\n"); |
| @@ -477,6 +513,10 @@ int wmain(int argc, wchar_t** argv) { | |||
| 477 | std::fflush(stdout); | 513 | std::fflush(stdout); |
| 478 | keep_title_watchdog_kicked(main_module.base); | 514 | keep_title_watchdog_kicked(main_module.base); |
| 479 | start_title_peek(main_module.base); | 515 | start_title_peek(main_module.base); |
| 516 | leonida::thread_sampler::start(main_module.base, main_module.size); // LEONIDA_SAMPLE_MS (diagnostic) | ||
| 517 | #ifdef LEONIDA_VULKAN_DEVICE | ||
| 518 | SetConsoleCtrlHandler(&stop_compiles_on_console_exit, TRUE); | ||
| 519 | #endif | ||
| 480 | int code; | 520 | int code; |
| 481 | { | 521 | { |
| 482 | auto stacks = rt::start_thread_stacks(); | 522 | auto stacks = rt::start_thread_stacks(); |
| @@ -491,6 +531,12 @@ int wmain(int argc, wchar_t** argv) { | |||
| 491 | // Not `return`: a normal host exit runs the CRT's atexit table, which the game shares with gta6rt (its | 531 | // Not `return`: a normal host exit runs the CRT's atexit table, which the game shares with gta6rt (its |
| 492 | // handlers would run against a game that has stopped) and whose last word decides the exit status. | 532 | // handlers would run against a game that has stopped) and whose last word decides the exit status. |
| 493 | // ExitProcess also skips atexit, so the TLS clone cleanup registered there is run here instead. | 533 | // ExitProcess also skips atexit, so the TLS clone cleanup registered there is run here instead. |
| 534 | // The list-value threads end first: ExitProcess must not cut one off inside the layer (in a held submission, | ||
| 535 | // holding its queues' lock). | ||
| 536 | rt::d3d12_xs::stop_list_values(500); | ||
| 537 | #ifdef LEONIDA_VULKAN_DEVICE | ||
| 538 | rt::d3d12::stop_pipeline_compiles(kExitCompileWaitMs); | ||
| 539 | #endif | ||
| 494 | rt::cleanup_tls_clones(); | 540 | rt::cleanup_tls_clones(); |
| 495 | ExitProcess(static_cast<UINT>(code)); | 541 | ExitProcess(static_cast<UINT>(code)); |
| 496 | } catch (const std::exception& e) { | 542 | } catch (const std::exception& e) { |