Repository navigation
fix(windows): enter guest startup on an arena-backed main stack - #3965
oneandonlydean merged 5 commits into
Conversation
adriadam10
left a comment
There was a problem hiding this comment.
This changes the startup path of every Windows executable (the main thread moves to a GuestArena stack), and the only run so far is PPSA15508 on an integration branch that includes #3897 and #3925. Before this can merge:
- Answer @oneandonlydean's request from 2026-10-11: run a Windows title that already boots on
mainwith this PR alone and post where it gets to before and after. We can't run titles or Windows here, and the new tests only exist underif(WIN32). - Rebase onto
main: it conflicts incore/libs/prx/libc/CMakeLists.txt(test block) anddocs/dev/TechnicalDebt.md(line 395, adjacent to other entries).
Once both are done we can look at it again; the code itself needs no other change from what I read.
|
Resident Evil Village (PPSA01556, 01.210.000) needs this. On a local branch past its earlier stops, about 30 s in, it asks That range is the host stack the relinker reserves in the PE header (0x210000). Windows commits it on demand, so below the guard page it is only reserved. On the console the whole main stack is mapped. I checked this PR with a test that does what the title does: enter |
3467aff to
4387c49
Compare
|
Rebased onto I also ran Castlevania Dominus Collection PPSA15645/01.003.000 on pure main versus this PR alone, without #3897/#3925 or other unmerged changes:
The candidate's Windows stack bounds are This supplies a main-versus-PR startup comparison through graphics initialization, but not a title reaching its menu on main. It does not establish gameplay or performance; the transfer running alongside the observations also rules out a clean performance comparison. The PR body distinguishes this run from the earlier TLOU integration evidence. #4774 and #5406 add different operations at the same startup insertion point. Neither is stacked here; their merge order still needs coordination. The later main refresh at Prepared with AI assistance. |
|
Rebased onto |
4387c49 to
49b51d2
Compare
|
Thanks for the rebase and the Windows test run. adriadam10's review still needs one thing: a Windows title that boots on current |
|
Test run (not a code review). I merged this PR onto current
So: no regression found, and no evidence of a fix either way. |
|
Correction: The previous review comment (Oct 24) flagged an unticked checklist item, a stale head reference in the description, and an explanatory comment in Verdict: OK Findings:
Freshness envelope:
Cross-PR ledger:
|
BunnyFl
left a comment
There was a problem hiding this comment.
Reads right. In EnterGuestMainStack_nid_no_patch (core/libs/prx/libc/src/GuestStacks.cpp), the new stack copies the host main stack's reservation capacity above a 64 KiB inaccessible bottom, and the entry frame is set up for the Windows x64 convention. Rsp = top - 40 with the 64 KiB-aligned top leaves rsp % 16 == 8 at entry with 32 bytes of shadow space above a zero return address, and Rbp = 0 gives the unwinder a clean root. A failure during setup releases the reservation and clears entered before rethrowing, on the original stack. The GuestArenaUnpinWritable in that path is safe when the commit failed before anything was pinned: WindowsMappings::Unpin only decrements pages whose pins is non-zero (core/libs/prx/libc/include/WindowsMappings.hpp).
Tested on Windows 11, WinLibs GCC 15.2.0, with this head merged onto current main, after building the windows_stdio_* fixture DLLs: windows_guest_main_stack, windows_guest_main_stack_entry, windows_guest_main_stack_failure, and the relinker tests this PR edits (windows_import_modules, windows_trace_imports, windows_kernel_variant_sys, windows_kernel_variant_web) pass, 7 of 7, nothing skipped. The four relinker tests also pass on plain main with the same fixtures.
XairRrR
left a comment
There was a problem hiding this comment.
Reviewed — comments
The merge is clean, the build succeeds, the convention checks pass and the relinker tests that are registered on Linux pass. The new main-stack switch and every test that exercises it are Windows-only, so this Linux machine could not test the behaviour. I found nothing blocking.
What I ran
Head 8029f87e5872277c330494a052a3d907052a3b7b, main 9090972b7e91fd266819cbd77a8b058e177b5682, merged tree b944fb303a78e2f2d6db2ec234292c5b4501b05f. Machine: Debian 13 VM, GCC 14.2.0, Release, Ninja. The prepared build of the merged tree was used.
git diff --check 9090972b7e91fd266819cbd77a8b058e177b5682...8029f87e5872277c330494a052a3d907052a3b7b
python3 tools/check_conventions.py --base 9090972b7e91fd266819cbd77a8b058e177b5682
ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "^(windows_trace_imports|windows_import_modules|entry_stub|windows_entry_stub_bounds|guest_kernel_is_stack|guest_pthread_stack)$"
# negative control
git show 9090972b7e91fd266819cbd77a8b058e177b5682:core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp > core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp
ninja -C build -j32 -l32 relinker
ctest --test-dir build -j8 --test-load 32 -R "^(windows_trace_imports|windows_import_modules|entry_stub|windows_entry_stub_bounds)$"
git show b944fb303a78e2f2d6db2ec234292c5b4501b05f:core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp > core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp
ninja -C build -j32 -l32 relinker
git status --porcelain
Results
| Check | Result |
|---|---|
Merge into main |
Clean |
git diff --check |
Clean |
check_conventions.py |
All conventions checks passed. |
Configure, build and libs |
OK (according to build.json) |
| Selected tests (build.json) | No new failures and no timeouts. The 9 known failures also fail on main. guest_net_ctl was skipped for a reason that is not expected, which also happens on main. |
windows_import_modules, windows_trace_imports, entry_stub, windows_entry_stub_bounds, guest_kernel_is_stack, guest_pthread_stack |
6/6 passed |
windows_guest_main_stack, windows_guest_main_stack_failure, windows_guest_main_stack_entry, windows_kernel_variant_* |
Not registered on Linux (if(WIN32)) |
| Vulkan validation | Skipped: the PR changes no file under the AGC driver, the shader recompiler or VideoOut |
Negative control
I restored WindowsEntryStubBuilder.cpp from main and rebuilt relinker. windows_import_modules and windows_trace_imports still passed, so the control does not detect the change on Linux. Those tests only run the converted executable under os.name == 'nt', which includes the new missing-helper assertion. Here they only check the conversion. The three new libc tests are Windows-only and were not built. After the control I restored the merged file and rebuilt. git status --porcelain is empty.
BunnyFl's approval reports that the three new tests and the edited relinker tests pass on Windows on this head. screamm reported the same for an earlier head with identical changed lines. I could not reproduce either run.
Findings
Blocking
None.
Non-blocking
- No stack-overflow guard semantics on the new main stack:
core/libs/prx/libc/src/GuestStacks.cpp:114commits the whole stack. Thencore/libs/prx/libc/src/GuestStacks.cpp:131setsStackLimitto its lowest committed byte, and the 64 KiB region below it isPAGE_NOACCESS, not aPAGE_GUARDpage.- Why it matters: if the guest main thread overflows its stack, the kernel should report
STATUS_ACCESS_VIOLATIONinstead ofSTATUS_STACK_OVERFLOW. Unlike the host stack, there is no reserved guard region left for the overflow handler. Both the host and the console abort in this case, so the effect is limited to diagnostics. - Suggested fix: mention this in the debt entry at
docs/dev/debt/libc.md:141.
- Why it matters: if the guest main thread overflows its stack, the kernel should report
- Debt entry style: the new entry at
docs/dev/debt/libc.md:141has no final period, unlike the entries around it.
Review of the stub code: the second RUNTIME_FUNCTION reuses unwindRva. That is valid because core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp:810 emits the same prologue bytes as the main entry at :503. The stack slots [rsp+0x20..0x58] that the post-switch code reads are all written after the switch, at :859-875. The exception-table bound at :925 is equivalent to the old >= 32 check when there is one entry. The reserved table still holds 32 entries (:134). On the new stack, rsp = top - 40 gives rsp % 16 == 8 with a zero return address, as BunnyFl's review says.
Not verified
- Any Windows execution: the three new libc tests, the missing-helper regression in
windows_import_modules,windows_kernel_variant_sys/web, and the generated-ELF exit code (42 versus 89). This machine is Linux-only, and these paths are guarded byWIN32oros.name == 'nt'. - The title comparisons in the description and discussion: Castlevania PPSA15645, ccleste, ScreenTester5 and TLOU PPSA15508.
- The declared dependency on corrected #7149. In the discussion, oneandonlydean notes that a main-thread
scePthreadExitwith workers still running would exit with the TEB pointing at the guest arena stack. That fix belongs in #7149, so the merge order #7149 before #3965 matters. I did not check whether #7149 has merged.
To get this to a good state
- Have a maintainer confirm that the Windows CI run (Actions > Build with
pr=3965) passeswindows_guest_main_stack,windows_guest_main_stack_failure,windows_guest_main_stack_entry,windows_import_modules,windows_trace_importsandwindows_kernel_variant_*. - Merge only after corrected #7149, as the
Depends online says. - Optionally, record the overflow-reporting difference in the debt entry and add its final period.
Superseabas
left a comment
There was a problem hiding this comment.
Windows run of head 8029f87e58 merged onto current main 4741457fed (clean merge, local only). It covers the Windows-only tests @XairRrR couldn't run, and it finds one regression against a test that was added after this branch's base.
Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (x86_64-ucrt-posix-seh, r3), Python 3.13, Release, BUILD_TESTING=ON.
The PR's Windows tests pass. windows_guest_main_stack, windows_guest_main_stack_failure, windows_guest_main_stack_entry, windows_kernel_variant_sys, windows_kernel_variant_web, windows_import_modules, windows_trace_imports, entry_stub, windows_entry_stub_bounds, guest_kernel_is_stack, guest_pthread_stack and public_headers pass, 3 runs each. windows_guest_main_stack_entry passes 3 of 3 from PowerShell; see the PATH note below for Git Bash. On main the 9 of them that exist pass.
Regression: guest_zero_finalizer fails on Windows with this PR.
| Tree | guest_zero_finalizer |
|---|---|
main |
3 of 3 pass |
| merged | 0 of 3: AssertionError: ('windows', True, 3221225477, '', '', '') |
merged, with main's WindowsEntryStubBuilder.cpp |
passes |
3221225477is0xC0000005. The converted program crashes before it records anything.- With the assertion turned into a print (a local copy of the test), all three Windows cases crash with this PR,
zero,absentandnonzero. All three pass onmain, and the Linux cases pass on both. - The guest module in that test is built with the
THREAD_POINTERprefix (tls=True), so it reads the thread pointer, and it's loaded fromsce_module. - The test came in with
f5879c4ada(fix(relinker): preserve guest finalizers at address zero, 2026-10-24), which isn't in this branch, so it hasn't run against this change before. - In the full suite on the merge (RTX 5070 Ti,
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1), it is the only failure thatmaindoesn't also have on this machine: 4,199 of 4,205 pass. The other five are known:test_registrationandselect_tests_MissingCommandTests(#15652),windows_crash_thread_name(#15578),agc_driver_direct_write_completion(#15564) andagc_driver_quad_pixel_mask(#14341).
Red check. The merged tree with only WindowsEntryStubBuilder.cpp taken back from main fails windows_guest_main_stack_entry and windows_import_modules, so the new tests do cover the stub change. With that one file back, guest_zero_finalizer passes again.
Overlap with #7532. Since this branch's base, #7532 (merged 2026-11-03) added extern "C" EnterGuestMainStack_nid_no_patch(void* arguments, void (*entry)(void*)) to libkernel (Pthread/src/Thread.cpp). It maps a main stack at the console's address range and isn't guarded to Linux. This PR adds a libc EnterGuestMainStack_nid_no_patch(void (*entry)()) with the same name, a different signature, and an arena stack sized from the host stack. The Windows stub takes it from libc.prx with GetProcAddress, so the two don't collide at load time, and public_headers passes. Still, that leaves two main-stack implementations under one exported name in two libraries. Whether Windows should use #7532's would be worth settling here.
Smaller: test_windows_guest_main_stack.py copies the compiler runtime DLLs from the first match on PATH.
- Run from Git Bash, the first
libstdc++-6.dllonPATHhere is Git for Windows' (C:\Program Files\Git\mingw64\bin, an older GCC). The converted program then fails withFailed to load module: ...\libc.prx,GetLastError: 127. - From PowerShell, where the WinLibs copy comes first, it passes.
- Taking them from the compiler's own directory (
CMAKE_CXX_COMPILER) would avoid that. The 3-of-3 results above are from the PowerShell environment.
check_conventions.py --base main passes on the merge.
AI-assisted: yes (Claude Code)
BunnyFl
left a comment
There was a problem hiding this comment.
@eliasbruno124-dev changing my review to request changes: guest_zero_finalizer fails with this PR on Windows. cc @Superseabas, who found it. You're right, and my approval at this head missed it: the test came in with f5879c4ada (2026-10-24), which isn't in this branch, and I didn't run it.
I reproduced it. Head 8029f87e58 merged onto main 6a337633c6 (merge ba5963cf3b, clean), Windows 11 Pro 10.0.26300, WinLibs GCC, Release, one run of each:
| Test | the merge | the merge with WindowsEntryStubBuilder.cpp taken from main |
|---|---|---|
guest_zero_finalizer |
fails: AssertionError: ('windows', True, 3221225477, '', '', '') |
passes |
windows_guest_main_stack_entry |
passes | fails |
windows_import_modules |
passes | fails |
windows_guest_main_stack, windows_guest_main_stack_failure, windows_trace_imports, windows_kernel_variant_sys, windows_kernel_variant_web, entry_stub, windows_entry_stub_bounds |
pass | pass |
3221225477 is 0xC0000005. So the change in core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp is what both the new tests and the guest_zero_finalizer result turn on. I haven't looked into why the converted program crashes there, so I can't point at a line.
Please merge main into the branch, which brings the test in, and make guest_zero_finalizer pass on Windows with the stub change. I'll rerun these ten tests on the new head.
AI-assisted: yes (Claude Code)
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
Met: Windows title runs with this PR alone were posted on 10-25 (ccleste, ScreenTester5, a PPSA title) and the branch is mergeable. BunnyFl's guest_zero_finalizer request still stands.
|
Checked on Windows (11 IoT Enterprise LTSC 26100, WinLibs GCC 15.2, Release), head Reproduces the CR: Cause:
Fixture-only fix makes it pass (the stub stays untouched): -extern "C" [[noreturn]] void APS5_VABI EnterGuestMainStack_nid_no_patch(void* arguments, void (APS5_VABI* entry)(void*)) {
- entry(arguments);
+extern "C" [[noreturn]] void EnterGuestMainStack_nid_no_patch(void (*entry)()) {
+ entry();
Fail("The guest entry point returned");
}With it: One thing to settle: the same symbol would have two ABIs inside one process - libc exports the 1-argument MS-x64 copy for the stub, while libkernel still exports the 2-argument |
… guest main-stack entry The Windows entry stub now requires the host libc to export EnterGuestMainStack_nid_no_patch. The kernel variant test installs a synthetic libc.prx (the runtime image, or the empty image in the failure cases) that did not, so every case that runs the converted executable stopped with 'host libc does not provide guest main-stack entry' before reaching the import it checks. Give both images the export, as test_windows_import_modules.py does for its providers.
8029f87 to
bc0ee29
Compare
|
@BunnyFl @Superseabas @relativespace2K thank you for the reports and the trace. The branch is rebased onto Cause, as @relativespace2K found: #7532 added Fix: of the two options in that comment I took the second, one signature for the name. The libc export now has the Linux signature and passes Tested on Windows 11 Pro 10.0.26300, MSYS2 UCRT64 GCC 16.2.0-6, Release, full build of
Not tested: Linux and macOS. The description is updated; the title evidence from earlier heads is marked as such. AI-assisted: yes. |
|
@eliasbruno124-dev, the code looks right to me on bc0ee29 and I am recording a PASS. The sysv signature now matches the |
BunnyFl
left a comment
There was a problem hiding this comment.
@eliasbruno124-dev thanks: bc0ee29e4c fixes what my change request asked for (the runs below), and I'm approving it. Thanks also to @relativespace2K for the trace that found the cause and @Superseabas for the original report.
I reran the ten tests from my 2026-11-05 request plus guest_module_args, on this head merged onto main 3b7f31fa70 (merge 6c11fc7412, clean), Windows 11 Pro 10.0.26300, WinLibs GCC 15.2, Release, with relinker, guest_module_args_host and both windows_guest_main_stack* executables rebuilt:
| Test | the merge | the merge with WindowsEntryStubBuilder.cpp taken from main |
|---|---|---|
guest_zero_finalizer |
passes | passes |
windows_guest_main_stack_entry |
passes | fails: AssertionError: (89, 'Transferring control to ELF entry point\n', '') |
windows_import_modules |
passes | fails: AssertionError: (11, 'Transferring control to ELF entry point\n', '') |
guest_module_args, windows_guest_main_stack, windows_guest_main_stack_failure, windows_trace_imports, windows_kernel_variant_sys, windows_kernel_variant_web, entry_stub, windows_entry_stub_bounds |
pass | pass |
So 11 of 11 pass on the merge, none Not Run; guest_zero_finalizer, which failed at 8029f87e58 with 0xC0000005 (my change request), passes now.
The new commit reads as you describe: EnterGuestMainStack_nid_no_patch in core/libs/prx/libc/src/GuestStacks.cpp now takes (void* arguments, void (APS5_VABI* entry)(void*)) and puts arguments in Rdi for the entry, and the stub in core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp emits xor edi, edi (31 ff) and loads the entry with lea rsi, [rip+...] (48 8d 35) where it used rcx before.
Overlap: tools/pr_overlap.py --branch on this head failed closed (exit 2). 50 open pull requests share a file but conflict with main; the tool printed "cannot confirm overlap" for each. Most share only core/libs/prx/libc/CMakeLists.txt or docs/dev/debt/libc.md. Six share code this PR changes: #7149 and #9938 (GuestStacks.hpp/GuestStacks.cpp), and #11628, #11661, #11689 and #11698 (WindowsEntryStubBuilder.cpp). I searched those six patches' changed lines for EnterGuestMainStack and for the stub's entry-load bytes; none of them touches either. I did not compare the other 44 line by line.
Not tested: Linux and macOS, a title, and the main-thread-exit case @oneandonlydean asked you about, which is yours to answer.
AI-assisted: yes (Claude Code)
|
@oneandonlydean thank you. I had not tested that case, so I measured it now. It is one scratch program on one machine, not a test in the PR. What ran: a program linked against On the arena stack (this PR), output abridged: Control, the same program without the stack switch (the main thread exits on its host stack): afterwards the whole host stack range is So in this run Windows did not free the arena range when the main thread exited with a worker still running: the range stayed mapped and writable. Not covered: other Windows builds, a real title whose main thread exits this way, what the arena's own bookkeeping does with that range afterwards (nothing releases it; the PR keeps the stack until process termination by design), and the main-thread exit integration that #7149 changes. Whether this should wait for #7149 is your call; this branch does not touch Program#define _WIN32_WINNT 0x0602
#include "prx/libc/include/GuestArena.hpp"
#include "prx/libc/include/GuestStacks.hpp"
#include "prx/libkernel/include/Api.hpp"
#include "prx/libkernel/Pthread/include/Pthread.hpp"
#include "prx/libkernel/Pthread/include/ThreadLifecycle.hpp"
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <windows.h>
static std::uintptr_t stackBase;
static std::uintptr_t stackLimit;
static std::uintptr_t stackDeallocation;
static HANDLE mainThread;
static std::uintptr_t hostBase;
static std::uintptr_t hostDeallocation;
static void Report(const char* label) {
std::printf("%s: base=%#zx limit=%#zx deallocation=%#zx\n", label, stackBase, stackLimit, stackDeallocation);
for (auto cursor = stackDeallocation; cursor < stackBase;) {
MEMORY_BASIC_INFORMATION memory{};
if (VirtualQuery(reinterpret_cast<void*>(cursor), &memory, sizeof(memory)) != sizeof(memory)) {
std::printf(" VirtualQuery failed at %#zx (%lu)\n", cursor, GetLastError());
break;
}
const auto begin = reinterpret_cast<std::uintptr_t>(memory.BaseAddress);
const auto end = begin + memory.RegionSize;
std::printf(" [%#zx, %#zx) allocationBase=%#zx state=%#lx protect=%#lx type=%#lx\n", begin, end < stackBase ? end : stackBase,
reinterpret_cast<std::uintptr_t>(memory.AllocationBase), memory.State, memory.Protect, memory.Type);
cursor = end;
}
std::printf(" arena contains the writable range: %d\n",
static_cast<int>(GuestArena::GuestArenaContains_nid_postfix(reinterpret_cast<void*>(stackLimit), stackBase - stackLimit)));
std::fflush(stdout);
}
static void* APS5_VABI Worker(void*) {
const DWORD waited = WaitForSingleObject(mainThread, 10000);
DWORD code = 0;
GetExitCodeThread(mainThread, &code);
std::printf("main thread wait=%lu exit code=%lu\n", waited, code);
Report("after the main thread exited");
MEMORY_BASIC_INFORMATION host{};
VirtualQuery(reinterpret_cast<void*>(hostBase - 0x1000), &host, sizeof(host));
std::printf(" original host stack [%#zx, %#zx): top page state=%#lx allocationBase=%#zx\n", hostDeallocation, hostBase, host.State, reinterpret_cast<std::uintptr_t>(host.AllocationBase));
MEMORY_BASIC_INFORMATION memory{};
VirtualQuery(reinterpret_cast<void*>(stackBase - 0x1000), &memory, sizeof(memory));
if (memory.State == MEM_COMMIT && memory.Protect == PAGE_READWRITE) {
volatile unsigned char* top = reinterpret_cast<volatile unsigned char*>(stackBase - 0x1000);
top[0] = 0x5a;
std::printf(" top page still writable: %d\n", top[0] == 0x5a);
} else {
std::printf(" top page is no longer committed read-write\n");
}
std::fflush(stdout);
ExitProcess(0);
return nullptr;
}
static void APS5_VABI OnStack(void*) {
auto* tib = reinterpret_cast<NT_TIB*>(NtCurrentTeb());
stackBase = reinterpret_cast<std::uintptr_t>(tib->StackBase);
stackLimit = reinterpret_cast<std::uintptr_t>(tib->StackLimit);
stackDeallocation = *reinterpret_cast<std::uintptr_t*>(reinterpret_cast<unsigned char*>(tib) + 0x1478);
Report("before the main thread exits");
if (!DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &mainThread, 0, FALSE, DUPLICATE_SAME_ACCESS)) std::abort();
if (scePthreadSelf() == nullptr) std::abort();
Pthread worker = nullptr;
if (scePthreadCreate(&worker, nullptr, Worker, nullptr, "worker") != 0) std::abort();
scePthreadExit(nullptr);
std::abort();
}
int main(int argc, char**) {
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
std::setvbuf(stdout, nullptr, _IONBF, 0);
auto* tib = reinterpret_cast<NT_TIB*>(NtCurrentTeb());
hostBase = reinterpret_cast<std::uintptr_t>(tib->StackBase);
hostDeallocation = *reinterpret_cast<std::uintptr_t*>(reinterpret_cast<unsigned char*>(tib) + 0x1478);
if (argc > 1) OnStack(nullptr);
GuestStacks::EnterGuestMainStack_nid_no_patch(nullptr, OnStack);
}AI-assisted: yes. |
What
Enter Windows guest initialization and the ELF entry on a committed GuestArena stack. Native module loading stays on the host stack, preserving #679's low native-stack policy and its protection against fragmenting fixed guest mappings.
In the retained TLOU Part II Remastered PPSA15508/01.002.000 comparison, the allocator rounds the stack address down to a 1 GiB boundary and compares it with an initialized zero field. The low host stack also rounds to zero, selecting an uninitialized allocator and dereferencing null at original VA
0x1b60f2. With the guest stack, that allocation returns a valid pointer and the title goes on.The libc helper preserves the thread and TLS, updates Windows stack bounds and enters a fresh unwind root. It uses the native reservation's capacity plus a 64 KiB inaccessible bottom region and keeps the stack alive through shutdown. Setup failures clean up on the original stack; missing helper exports fail explicitly. Console stack placement, capacity and accounting remain unmeasured and are recorded in the libc technical debt.
EnterGuestMainStack_nid_no_patchnow has one signature on both systems. #7532, merged on 2026-11-03, added the Linux helper to libkernel asAPS5_VABI (void* arguments, void (APS5_VABI* entry)(void*)), andGuestModuleArgsHost.cpp, the stand-in several relinker tests install aslibc.prx, defines it that way. This branch had a one-argument Microsoft-convention export of the same name in libc, which the Windows entry stub called with the entry inrcx; against the stand-in that call jumped to whateverrsiheld, which is theguest_zero_finalizercrash Superseabas and BunnyFl reported and relativespace2K traced. The libc export now takes the same two arguments in the same convention and handsargumentsto the entry inrdi; the stub passes a null argument block and the entry inrsi(xor edi, edi; lea rsi, [rip+entry]; call rax). The stand-in is unchanged. Windows still resolves the helper fromlibc.prx, the library every Windows conversion loads, while Linux resolves it fromlibkernel.prx; the libkernel implementation is compiled for Linux only.The kernel-variant import fixtures install the runtime image as host
libc.prx, so that image must export the guest-main-stack entry helper. The maintainer's fixture correction is preserved.Merge order: #6540 and #10157 have merged, #7135 was closed unmerged on 2026-11-08. The main-thread exit integration still depends on corrected #7149, which is open and conflicts with
main; this branch does not resolve that. #7594 adds MXCSR initialization at the same startup area, a separate operation.Tested
Current head
bc0ee29e4c: the four earlier commits rebased ontomain439f320158without conflicts, authors preserved, plusfix(windows): match the Linux guest main-stack entry signature. Windows 11 Pro 10.0.26300, MSYS2 UCRT64 GCC 16.2.0-6, Release, full build, nothing else merged.main439f320158built the same way;guest_zero_finalizeris among them.windows_guest_main_stack,windows_guest_main_stack_failure,windows_guest_main_stack_entry,guest_zero_finalizer,guest_module_args,windows_import_modules,windows_trace_imports,windows_kernel_variant_sys,windows_kernel_variant_web,entry_stub,windows_entry_stub_bounds,guest_kernel_is_stackandguest_pthread_stackpass in 3 of 3 runs.WindowsGuestMainStack.cppnow also checks that the argument pointer reaches the entry.public_headerschecks andlinux_guest_stackpass, as onmain.WindowsEntryStubBuilder.cpptaken from the previous commit (entry inrcx) and only the relinker rebuilt,guest_zero_finalizer,windows_guest_main_stack_entry,windows_import_modules,windows_trace_importsand bothwindows_kernel_varianttests fail; restoring the file makes all 13 pass again.python tools/check_conventions.py --base origin/mainandgit diff --checkpass.--windows --to-intel --registry --module-dir .), NVIDIA GeForce RTX 3060 Laptop GPU, no input: runs for the 100 s limit at 600 presents per 10 s (median frame time 16.7 ms), and the dumped frames show the title's picture.main439f320158, built and converted the same way, does the same (600 presents per 10 s from second 20 on in both runs). The convertedapp.execontains the helper's name; the one made by a relinker without this change does not._WIN32blocks, the Windows entry stub builder and Windows-only tests, except the one-byte fixture change intest_windows_import_modules.py, whose converted programs run only on Windows.Earlier evidence, from heads before the signature change:
8029f87e58merged onto latermaincommits, and they passed; Superseabas, BunnyFl and relativespace2K foundguest_zero_finalizerfailing in those merges. XairRrR ran the tests registered on Linux.6239ceffcand this PR atf49abbed2merged onto it, the PR alone. The maintainer accepted it as the requested independent title comparison.main0aa4cb1cversus this PR alone at4387c499: both runs reached the same abort at the time; at original entry RSP changed from0x60fec8to0x20021ff48, with Windows stack bounds0x200010000..0x200220000.main39bac5d055with fix(cmake): keep the SEH personalities out of libxml2's export set #18086, feat(libSceAppContent): expand /download0 and give the shrink exports their size argument #18116, feat(http2): complete asynchronous send and read #11630 and fix(libSceHttp2): return DNS lookup errors #17570: without this PR the run ends with a null read atapp.exe+0x1c60f2; with8029f87e58merged it continues to an assertion on the second keyboard port after 46 s, and with feat(libSceKeyboard): open a second keyboard port with index 1 #18119 added it runs for the 200 s limit. Not repeated on the current head.a11c8f7fwith fix(libkernel): count guest module segments against the flexible memory budget #3713, fix(relinker): normalize additional module directory paths #3509, fix(ssl): retain loaded certificate authorities #3897 and fix(http2): allow completion waits without an event queue #3925: only the main-stack entry and libc differed between the run that dereferenced null and the run that mountedcore.psarcandcommon.psarc.No other open PR found that implements this Windows main-stack transition; #7532 is the merged Linux counterpart. No menu, gameplay or frame-time claim.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)