fix(windows): enter guest startup on an arena-backed main stack #3965

Merged
eliasbruno124-dev merged 5 commits from upstream-pr/3965 into main 2026-11-14 03:20:23 +00:00
eliasbruno124-dev commented 2026-10-11 20:00:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by eliasbruno124-dev on 2026-10-11T20:00:47Z.


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_patch now has one signature on both systems. #7532, merged on 2026-11-03, added the Linux helper to libkernel as APS5_VABI (void* arguments, void (APS5_VABI* entry)(void*)), and GuestModuleArgsHost.cpp, the stand-in several relinker tests install as libc.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 in rcx; against the stand-in that call jumped to whatever rsi held, which is the guest_zero_finalizer crash Superseabas and BunnyFl reported and relativespace2K traced. The libc export now takes the same two arguments in the same convention and hands arguments to the entry in rdi; the stub passes a null argument block and the entry in rsi (xor edi, edi; lea rsi, [rip+entry]; call rax). The stand-in is unchanged. Windows still resolves the helper from libc.prx, the library every Windows conversion loads, while Linux resolves it from libkernel.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 onto main 439f320158 without conflicts, authors preserved, plus fix(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.

  • All 247 tests of the relinker directory pass, as they do on main 439f320158 built the same way; guest_zero_finalizer is 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_stack and guest_pthread_stack pass in 3 of 3 runs. WindowsGuestMainStack.cpp now also checks that the argument pointer reaches the entry.
  • The 65 public_headers checks and linux_guest_stack pass, as on main.
  • Negative control: with WindowsEntryStubBuilder.cpp taken from the previous commit (entry in rcx) and only the relinker rebuilt, guest_zero_finalizer, windows_guest_main_stack_entry, windows_import_modules, windows_trace_imports and both windows_kernel_variant tests fail; restoring the file makes all 13 pass again.
  • python tools/check_conventions.py --base origin/main and git diff --check pass.
  • Castlevania Dominus Collection PPSA15645/01.003.000, converted with this head's relinker (--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. main 439f320158, built and converted the same way, does the same (600 presents per 10 s from second 20 on in both runs). The converted app.exe contains the helper's name; the one made by a relinker without this change does not.
  • Linux and macOS not built or run here; the changed code is inside _WIN32 blocks, the Windows entry stub builder and Windows-only tests, except the one-byte fixture change in test_windows_import_modules.py, whose converted programs run only on Windows.

Earlier evidence, from heads before the signature change:

  • JJenkx, BunnyFl and Superseabas ran the PR's Windows tests on 8029f87e58 merged onto later main commits, and they passed; Superseabas, BunnyFl and relativespace2K found guest_zero_finalizer failing in those merges. XairRrR ran the tests registered on Linux.
  • screamm: ccleste PPSA59322 and ScreenTester5 PPSA69420 reach the same running state on Windows 11 with main 6239ceffc and this PR at f49abbed2 merged onto it, the PR alone. The maintainer accepted it as the requested independent title comparison.
  • Castlevania Dominus Collection PPSA15645/01.003.000, main 0aa4cb1c versus this PR alone at 4387c499: both runs reached the same abort at the time; at original entry RSP changed from 0x60fec8 to 0x20021ff48, with Windows stack bounds 0x200010000..0x200220000.
  • TLOU Part II PPSA15508/01.002.000 on the machine above, 2026-11-10, main 39bac5d055 with #18086, #18116, #11630 and #17570: without this PR the run ends with a null read at app.exe+0x1c60f2; with 8029f87e58 merged it continues to an assertion on the second keyboard port after 46 s, and with #18119 added it runs for the 200 s limit. Not repeated on the current head.
  • TLOU Part II, integration a11c8f7f with #3713, #3509, #3897 and #3925: only the main-stack entry and libc differed between the run that dereferenced null and the run that mounted core.psarc and common.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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #7149 after its reviewed corrections, for the main-thread exit integration
  • Fixes: none
  • Unblocks: PPSA15508 #5468 (the stack-allocation stop in the documented integration; not standalone playability)
  • GPUs tested: n/a (Windows startup/libc change; the title runs used an NVIDIA GeForce RTX 3060 Laptop GPU, driver 621.01, Windows 11)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4821923768 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965). Originally posted by [eliasbruno124-dev](https://github.com/eliasbruno124-dev) on 2026-10-11T20:00:47Z. --- ### 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_patch` now has one signature on both systems. #7532, merged on 2026-11-03, added the Linux helper to libkernel as `APS5_VABI (void* arguments, void (APS5_VABI* entry)(void*))`, and `GuestModuleArgsHost.cpp`, the stand-in several relinker tests install as `libc.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 in `rcx`; against the stand-in that call jumped to whatever `rsi` held, which is the `guest_zero_finalizer` crash Superseabas and BunnyFl reported and relativespace2K traced. The libc export now takes the same two arguments in the same convention and hands `arguments` to the entry in `rdi`; the stub passes a null argument block and the entry in `rsi` (`xor edi, edi; lea rsi, [rip+entry]; call rax`). The stand-in is unchanged. Windows still resolves the helper from `libc.prx`, the library every Windows conversion loads, while Linux resolves it from `libkernel.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 <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Current head `bc0ee29e4c`: the four earlier commits rebased onto `main` `439f320158` without conflicts, authors preserved, plus `fix(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. - All 247 tests of the relinker directory pass, as they do on `main` `439f320158` built the same way; `guest_zero_finalizer` is 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_stack` and `guest_pthread_stack` pass in 3 of 3 runs. `WindowsGuestMainStack.cpp` now also checks that the argument pointer reaches the entry. - The 65 `public_headers` checks and `linux_guest_stack` pass, as on `main`. - Negative control: with `WindowsEntryStubBuilder.cpp` taken from the previous commit (entry in `rcx`) and only the relinker rebuilt, `guest_zero_finalizer`, `windows_guest_main_stack_entry`, `windows_import_modules`, `windows_trace_imports` and both `windows_kernel_variant` tests fail; restoring the file makes all 13 pass again. - `python tools/check_conventions.py --base origin/main` and `git diff --check` pass. - Castlevania Dominus Collection PPSA15645/01.003.000, converted with this head's relinker (`--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. `main` `439f320158`, built and converted the same way, does the same (600 presents per 10 s from second 20 on in both runs). The converted `app.exe` contains the helper's name; the one made by a relinker without this change does not. - Linux and macOS not built or run here; the changed code is inside `_WIN32` blocks, the Windows entry stub builder and Windows-only tests, except the one-byte fixture change in `test_windows_import_modules.py`, whose converted programs run only on Windows. Earlier evidence, from heads before the signature change: - JJenkx, BunnyFl and Superseabas ran the PR's Windows tests on `8029f87e58` merged onto later `main` commits, and they passed; Superseabas, BunnyFl and relativespace2K found `guest_zero_finalizer` failing in those merges. XairRrR ran the tests registered on Linux. - [screamm](https://github.com/boykopovar/AnyPS5/pull/3965#issuecomment-6182497783): ccleste PPSA59322 and ScreenTester5 PPSA69420 reach the same running state on Windows 11 with main `6239ceffc` and this PR at `f49abbed2` merged onto it, the PR alone. The maintainer [accepted it](https://github.com/boykopovar/AnyPS5/pull/3965#issuecomment-6227033200) as the requested independent title comparison. - Castlevania Dominus Collection PPSA15645/01.003.000, `main` `0aa4cb1c` versus this PR alone at `4387c499`: both runs reached the same abort at the time; at original entry RSP changed from `0x60fec8` to `0x20021ff48`, with Windows stack bounds `0x200010000..0x200220000`. - TLOU Part II PPSA15508/01.002.000 on the machine above, 2026-11-10, `main` `39bac5d055` with #18086, #18116, #11630 and #17570: without this PR the run ends with a null read at `app.exe+0x1c60f2`; with `8029f87e58` merged it continues to an assertion on the second keyboard port after 46 s, and with #18119 added it runs for the 200 s limit. Not repeated on the current head. - TLOU Part II, integration `a11c8f7f` with #3713, #3509, #3897 and #3925: only the main-stack entry and libc differed between the run that dereferenced null and the run that mounted `core.psarc` and `common.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 <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #7149 after its reviewed corrections, for the main-thread exit integration <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: PPSA15508 #5468 (the stack-allocation stop in the documented integration; not standalone playability) <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a (Windows startup/libc change; the title runs used an NVIDIA GeForce RTX 3060 Laptop GPU, driver 621.01, Windows 11) <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
oneandonlydean commented 2026-10-11 23:19:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:19:49Z.


Could you run a Windows title that already boots on main with this PR alone and post where it gets to before and after? Every title's main thread moves to the new stack, and the only title run so far is PPSA15508 on an integration branch with #3897 and #3925.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115031829 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#issuecomment-6115031829). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T23:19:49Z. --- Could you run a Windows title that already boots on main with this PR alone and post where it gets to before and after? Every title's main thread moves to the new stack, and the only title run so far is PPSA15508 on an integration branch with #3897 and #3925.
adriadam10 commented 2026-10-13 10:11:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T10:11:33Z.

Review: DISMISSED


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 main with 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 under if(WIN32).
  • Rebase onto main: it conflicts in core/libs/prx/libc/CMakeLists.txt (test block) and docs/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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5501977499 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#pullrequestreview-5501977499). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T10:11:33Z. **Review:** DISMISSED --- 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 `main` with 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 under `if(WIN32)`. - Rebase onto `main`: it conflicts in `core/libs/prx/libc/CMakeLists.txt` (test block) and `docs/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.
EagleBearerYS commented 2026-10-13 13:41:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-13T13:41:05Z.


Resident Evil Village (PPSA01556, 01.210.000) needs this. On a local branch past its earlier stops, about 30 s in, it asks sceKernelIsStack for its main thread's stack and protects the whole range with CPU read/write. Without this PR, that call aborts:

[memory] protect 000000016ace0000+0x210000 prot=0xc2
what():  mprotect of uncommitted memory outside the guest arena
FATAL: abort()

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 EnterGuestMainStack_nid_no_patch, call sceKernelIsStack, protect the whole range with 0xc2, then write to its lowest page. With this PR's GuestStacks change it passes, because the stack is arena memory and the arena path commits its lowest 64 KiB placeholder. Setup: Windows 11, WinLibs GCC 15.2.0 r7, Release, RTX 3070 Laptop.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6146894959 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#issuecomment-6146894959). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-13T13:41:05Z. --- Resident Evil Village (PPSA01556, 01.210.000) needs this. On a local branch past its earlier stops, about 30 s in, it asks `sceKernelIsStack` for its main thread's stack and protects the whole range with CPU read/write. Without this PR, that call aborts: ``` [memory] protect 000000016ace0000+0x210000 prot=0xc2 what(): mprotect of uncommitted memory outside the guest arena FATAL: abort() ``` 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 `EnterGuestMainStack_nid_no_patch`, call `sceKernelIsStack`, protect the whole range with 0xc2, then write to its lowest page. With this PR's `GuestStacks` change it passes, because the stack is arena memory and the arena path commits its lowest 64 KiB placeholder. Setup: Windows 11, WinLibs GCC 15.2.0 r7, Release, RTX 3070 Laptop.
eliasbruno124-dev commented 2026-10-13 21:33:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by eliasbruno124-dev on 2026-10-13T21:33:08Z.


Rebased onto 0aa4cb1c and resolved the libc test block, startup diagnostic and debt conflicts. At 4387c499, the full runtime build, nine focused stack/context tests and all 121 relinker tests pass on Windows 11 with WinLibs GCC 15.2.0 r7. The upstream tracing fixture needed the main-stack helper; its assertions and the explicit missing-helper regression remain intact. CTest ran noninteractively with unchanged timeouts.

I also ran Castlevania Dominus Collection PPSA15645/01.003.000 on pure main versus this PR alone, without #3897/#3925 or other unmerged changes:

Observation Main 0aa4cb1c PR 4387c499
Original ELF entry and 12 title modules Reached and verified Reached and verified
Stack pointer at entry 0x60fec8 0x20021ff48
Vulkan/swapchain Initialized, 1152x648 Initialized, 1152x648
Next stop scePadUnknown_n3kSX62fgNo not implemented Same stop
sceVideoOutSubmitFlip calls 0 0

The candidate's Windows stack bounds are 0x200010000..0x200220000. Inputs, other runtime libraries and settings were identical, and actual loaded module paths were checked. Both used the same readable SELF-to-ELF staging with original relative filenames and same-name resource mappings; the original dump stayed unchanged. No input or return-value substitution was used.

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 8d98e8851 merges cleanly with this branch and does not change these entry/stack functions.

Prepared with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6155660313 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#issuecomment-6155660313). Originally posted by [eliasbruno124-dev](https://github.com/eliasbruno124-dev) on 2026-10-13T21:33:08Z. --- Rebased onto `0aa4cb1c` and resolved the libc test block, startup diagnostic and debt conflicts. At `4387c499`, the full runtime build, nine focused stack/context tests and all 121 relinker tests pass on Windows 11 with WinLibs GCC 15.2.0 r7. The upstream tracing fixture needed the main-stack helper; its assertions and the explicit missing-helper regression remain intact. CTest ran noninteractively with unchanged timeouts. I also ran Castlevania Dominus Collection PPSA15645/01.003.000 on pure main versus this PR alone, without #3897/#3925 or other unmerged changes: | Observation | Main `0aa4cb1c` | PR `4387c499` | | --- | --- | --- | | Original ELF entry and 12 title modules | Reached and verified | Reached and verified | | Stack pointer at entry | `0x60fec8` | `0x20021ff48` | | Vulkan/swapchain | Initialized, 1152x648 | Initialized, 1152x648 | | Next stop | `scePadUnknown_n3kSX62fgNo not implemented` | Same stop | | `sceVideoOutSubmitFlip` calls | 0 | 0 | The candidate's Windows stack bounds are `0x200010000..0x200220000`. Inputs, other runtime libraries and settings were identical, and actual loaded module paths were checked. Both used the same readable SELF-to-ELF staging with original relative filenames and same-name resource mappings; the original dump stayed unchanged. No input or return-value substitution was used. 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 `8d98e8851` merges cleanly with this branch and does not change these entry/stack functions. Prepared with AI assistance.
oneandonlydean commented 2026-10-14 05:19:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T05:19:57Z.


Rebased onto main; the only conflict was the docs/dev/debt/libc.md entry next to the new Windows direct-memory one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6161500936 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#issuecomment-6161500936). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T05:19:57Z. --- Rebased onto `main`; the only conflict was the `docs/dev/debt/libc.md` entry next to the new Windows direct-memory one.
oneandonlydean commented 2026-10-14 05:35:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T05:35:27Z.


Thanks for the rebase and the Windows test run. adriadam10's review still needs one thing: a Windows title that boots on current main, run with this PR alone, showing where it gets to before and after (title ID, GPU/OS). @EagleBearerYS, could you run Resident Evil Village on this head on top of main?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6161685518 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#issuecomment-6161685518). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T05:35:27Z. --- Thanks for the rebase and the Windows test run. adriadam10's review still needs one thing: a Windows title that boots on current `main`, run with this PR alone, showing where it gets to before and after (title ID, GPU/OS). @EagleBearerYS, could you run Resident Evil Village on this head on top of `main`?
EagleBearerYS commented 2026-10-14 07:15:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-14T07:15:49Z.


Resident Evil Village (PPSA01556, 01.210.000) doesn't boot on plain current main on this PC, so both runs below add the same things to main, spelled out. Same machine and base for both: RTX 3070 Laptop GPU (8 GB), driver 617.42, Windows 11 Home 10.0.26300, main 0b6d033b8.

  • Plain main prepares every shader at registration, and here that gave a black screen for 10 minutes (private memory at 21.9 GB, heading for the commit limit). Both runs add local commits that prepare each shader at its first draw instead (APS5_RE8_LAZY_PREPARE=1, with APS5_NO_GPL=1). They don't touch memory mapping or stacks.
  • main also aborts 19 s in since #5596 (a 419 MiB address-based copy; reported there, fix in #5688). Both runs raise that guard with APS5_ADDRESS_COPY_MAX_MIB=512.

Before (main plus the above, relinked with main's relinker): it stops 93 s in, before the first dialog:

what():  mprotect of uncommitted memory outside the guest arena

That's the mprotect emulation's check for memory outside the guest arena (DirectMemory.cpp:135). This run had no trace, so the failing range wasn't printed.

After (the same plus this PR at 49b51d205, relinked with this PR's relinker, plus a local commit that only adds prints under APS5_TRACE_MAIN_STACK=1): the main thread switches to the arena-backed stack as designed. Its rsp lands in the same guest stack range as in eliasbruno124-dev's Castlevania table (0x20021ff48 at entry):

[main-stack] thread 18724: host stack 0x410000-0x610000 (deallocation 0x400000), guest stack 0x200010000-0x200220000 (allocation 0x200000000), rsp after the switch 0x20021ffd8

Village then stops 44 s in, also before the first dialog, on the same check, but for another thread's own host stack:

[mprotect] thread 5340: 0x1b0c00000+0x210000 prot 0x3; uncommitted region 0x1b0c00000+0xd000 state 0x2000 type 0x20000 allocation base 0x1b0c00000; this thread's stack 0x1b0c10000-0x1b0e10000
  what():  mprotect of uncommitted memory outside the guest arena
FATAL: abort() (SIGABRT) on thread 5340

Thread 5340 isn't the main thread (18724). The range is its whole 0x210000 host stack allocation, outside the guest arena, protected read-write. Its lowest 0xd000 is still only reserved (MEM_RESERVE), so the emulation throws.

So this PR alone doesn't get Village past this check. With it, the main thread's stack is arena-backed, and the stop is on another thread's host stack.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6163027875 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#issuecomment-6163027875). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-14T07:15:49Z. --- Resident Evil Village (PPSA01556, 01.210.000) doesn't boot on plain current `main` on this PC, so both runs below add the same things to `main`, spelled out. Same machine and base for both: RTX 3070 Laptop GPU (8 GB), driver 617.42, Windows 11 Home 10.0.26300, `main` 0b6d033b8. - Plain `main` prepares every shader at registration, and here that gave a black screen for 10 minutes (private memory at 21.9 GB, heading for the commit limit). Both runs add local commits that prepare each shader at its first draw instead (`APS5_RE8_LAZY_PREPARE=1`, with `APS5_NO_GPL=1`). They don't touch memory mapping or stacks. - `main` also aborts 19 s in since #5596 (a 419 MiB address-based copy; reported there, fix in #5688). Both runs raise that guard with `APS5_ADDRESS_COPY_MAX_MIB=512`. **Before** (`main` plus the above, relinked with `main`'s relinker): it stops 93 s in, before the first dialog: ``` what(): mprotect of uncommitted memory outside the guest arena ``` That's the mprotect emulation's check for memory outside the guest arena (`DirectMemory.cpp:135`). This run had no trace, so the failing range wasn't printed. **After** (the same plus this PR at 49b51d205, relinked with this PR's relinker, plus a local commit that only adds prints under `APS5_TRACE_MAIN_STACK=1`): the main thread switches to the arena-backed stack as designed. Its `rsp` lands in the same guest stack range as in eliasbruno124-dev's Castlevania table (0x20021ff48 at entry): ``` [main-stack] thread 18724: host stack 0x410000-0x610000 (deallocation 0x400000), guest stack 0x200010000-0x200220000 (allocation 0x200000000), rsp after the switch 0x20021ffd8 ``` Village then stops 44 s in, also before the first dialog, on the same check, but for another thread's own host stack: ``` [mprotect] thread 5340: 0x1b0c00000+0x210000 prot 0x3; uncommitted region 0x1b0c00000+0xd000 state 0x2000 type 0x20000 allocation base 0x1b0c00000; this thread's stack 0x1b0c10000-0x1b0e10000 what(): mprotect of uncommitted memory outside the guest arena FATAL: abort() (SIGABRT) on thread 5340 ``` Thread 5340 isn't the main thread (18724). The range is its whole 0x210000 host stack allocation, outside the guest arena, protected read-write. Its lowest 0xd000 is still only reserved (`MEM_RESERVE`), so the emulation throws. So this PR alone doesn't get Village past this check. With it, the main thread's stack is arena-backed, and the stop is on another thread's host stack.
eliasbruno124-dev commented 2026-10-14 09:58:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by eliasbruno124-dev on 2026-10-14T09:58:54Z.


Rebased the maintained 49b51d205 head onto 66f894761; the new head is 147d1158b. The sole conflict was the shared import-test fixture. Both contribution commits and their runtime code are preserved.

Windows validation passes: full packaged runtime/relinker build, 10 focused stack/runtime tests, 123 relinker tests, conventions and whitespace checks. The initial occupied-base test timed out under interactive Windows error handling; the unchanged test passes with CTest's --interactive-debug-mode 0. No assertions or timeouts were relaxed; #5675 already addresses that test's dialog handling.

The requested comparison with a title already booting on main remains open. This rebase adds no new title or gameplay evidence.

Prepared with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6165762812 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#issuecomment-6165762812). Originally posted by [eliasbruno124-dev](https://github.com/eliasbruno124-dev) on 2026-10-14T09:58:54Z. --- Rebased the maintained `49b51d205` head onto `66f894761`; the new head is `147d1158b`. The sole conflict was the shared import-test fixture. Both contribution commits and their runtime code are preserved. Windows validation passes: full packaged runtime/relinker build, 10 focused stack/runtime tests, 123 relinker tests, conventions and whitespace checks. The initial occupied-base test timed out under interactive Windows error handling; the unchanged test passes with CTest's `--interactive-debug-mode 0`. No assertions or timeouts were relaxed; #5675 already addresses that test's dialog handling. The requested comparison with a title already booting on main remains open. This rebase adds no new title or gameplay evidence. Prepared with AI assistance.
eliasbruno124-dev commented 2026-10-14 18:50:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by eliasbruno124-dev on 2026-10-14T18:50:57Z.


Rebased onto ed835aa76 after #5406 merged; the new head is f49abbed2. Both conflicts are resolved while preserving complete unresolved-import reporting and the fixture's two options. An unresolved import still fails before the main-stack transition. The contribution's runtime behavior and tracing-fixture correction are retained.

Windows validation passes: full packaged runtime/relinker build, 10 focused stack/runtime tests, all 126 relinker tests, conventions and whitespace checks. CTest ran noninteractively with unchanged assertions and timeouts. The candidate also merges cleanly into e27ff7c54.

The requested comparison with a title already booting on current main remains open; this rebase adds no new title or gameplay evidence.

Prepared with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6175846815 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#issuecomment-6175846815). Originally posted by [eliasbruno124-dev](https://github.com/eliasbruno124-dev) on 2026-10-14T18:50:57Z. --- Rebased onto `ed835aa76` after #5406 merged; the new head is `f49abbed2`. Both conflicts are resolved while preserving complete unresolved-import reporting and the fixture's two options. An unresolved import still fails before the main-stack transition. The contribution's runtime behavior and tracing-fixture correction are retained. Windows validation passes: full packaged runtime/relinker build, 10 focused stack/runtime tests, all 126 relinker tests, conventions and whitespace checks. CTest ran noninteractively with unchanged assertions and timeouts. The candidate also merges cleanly into `e27ff7c54`. The requested comparison with a title already booting on current main remains open; this rebase adds no new title or gameplay evidence. Prepared with AI assistance.
screamm commented 2026-10-15 01:46:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-15T01:46:43Z.


Windows run of this head alone, merged onto main 6239ceffc (clean merge; it also merges cleanly onto the newer 2559e9623, not built).

  • Head f49abbed2, base 6239ceffc.
  • Host: Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, NVIDIA RTX 4070.
  • Build: the full build and libs pass with 0 errors. There are no warnings in the files this PR touches; the only warning, -Wstringop-overread in libSceAgc ShaderFusion.cpp, is also on main.
  • Tests, --repeat until-fail:3, all 13 passed 3/3:
    • new: windows_guest_main_stack, windows_guest_main_stack_failure, windows_guest_main_stack_entry
    • changed: windows_import_modules, windows_trace_imports
    • stack/context controls: guest_kernel_is_stack, guest_kernel_stack_protect, guest_pthread_stack, guest_sigaltstack, guest_user_context, guest_user_context_exit, entry_stub, entry_point_bounds
  • Non-GPU suite (ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip'): 804/811. These six timed out while the host was busy with other builds and passed when rerun one at a time: conventions_ci_gate, debt_split, hardware_oracle_compare, check_compile, guest_raise_exception, windows_diagnostic_fixture_isolation. check_main_sync also fails on plain main here: it expects sp ace é.txt, but the console code page prints sp ace é.txt. On plain main the same suite gave 794/808, and every runtime failure passed when rerun alone.

Titles: catalog homebrew, each relinked with that side's own relinker and libs. Each ran 60 s in a window (ANYPS5_REQUIRE_DISPLAY=1, SDL_VIDEODRIVER=windows) with no input. The main thread's stack bounds were read from its TEB 10 s in.

main 6239ceffc this PR merged onto it
ccleste PPSA59322 Transferring control to ELF entry point, presents continuously, still running at 60 s, no stop line same
ccleste window title at 60 s (two runs) ccleste | FPS: 59.83 (3401), ccleste | FPS: 53.42 (3071) ccleste | FPS: 85.81 (4778), ccleste | FPS: 33.31 (2130)
ScreenTester5 PPSA69420 ELF entry, Swapchain created ... extent=1484x835 images=2, test screen shown, still running at 60 s, no stop line same
ScreenTester5 window title at 60 s ScreenTester5 | FPS: 0.00 (2) (two runs) ScreenTester5 | FPS: 0.00 (2)
Main-thread TEB StackLimit..StackBase / DeallocationStack 0x410000..0x610000 / 0x400000 (both titles, every run) 0x200010000..0x200220000 / 0x200000000 (both titles, every run)
  • Apart from timing, the logs are the same. ScreenTester5's 29 lines are identical once addresses are masked. ccleste's differ only in the order of shader preparation, plus one line in the first main run: wsi/videoout: 119.88 Hz accepted, but a vblank comes every 22.584 ms; 59.94 Hz restored.
  • The frame counts depend on host load, not on this change: the same build gave 3071–3401 frames on main and 2130–4778 with the PR.
  • The first guest arena allocation after startup now sits above the stack reservation. ScreenTester5's first thread argument is arg=0000000200000150 on main and arg=0000000200220150 with the PR.

Verdict: on Windows the build, the tests above and the non-GPU suite pass. ccleste and ScreenTester5 reach the same point on main and with this PR alone, with no new stop, and the main thread runs on the arena-backed stack (0x200010000..0x200220000).

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6182497783 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#issuecomment-6182497783). Originally posted by [screamm](https://github.com/screamm) on 2026-10-15T01:46:43Z. --- Windows run of this head alone, merged onto `main` `6239ceffc` (clean merge; it also merges cleanly onto the newer `2559e9623`, not built). - Head `f49abbed2`, base `6239ceffc`. - Host: Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, NVIDIA RTX 4070. - Build: the full build and `libs` pass with 0 errors. There are no warnings in the files this PR touches; the only warning, `-Wstringop-overread` in libSceAgc `ShaderFusion.cpp`, is also on `main`. - Tests, `--repeat until-fail:3`, all 13 passed 3/3: - new: `windows_guest_main_stack`, `windows_guest_main_stack_failure`, `windows_guest_main_stack_entry` - changed: `windows_import_modules`, `windows_trace_imports` - stack/context controls: `guest_kernel_is_stack`, `guest_kernel_stack_protect`, `guest_pthread_stack`, `guest_sigaltstack`, `guest_user_context`, `guest_user_context_exit`, `entry_stub`, `entry_point_bounds` - Non-GPU suite (`ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip'`): 804/811. These six timed out while the host was busy with other builds and passed when rerun one at a time: `conventions_ci_gate`, `debt_split`, `hardware_oracle_compare`, `check_compile`, `guest_raise_exception`, `windows_diagnostic_fixture_isolation`. `check_main_sync` also fails on plain `main` here: it expects `sp ace é.txt`, but the console code page prints `sp ace é.txt`. On plain `main` the same suite gave 794/808, and every runtime failure passed when rerun alone. Titles: catalog homebrew, each relinked with that side's own relinker and libs. Each ran 60 s in a window (`ANYPS5_REQUIRE_DISPLAY=1`, `SDL_VIDEODRIVER=windows`) with no input. The main thread's stack bounds were read from its TEB 10 s in. | | `main` `6239ceffc` | this PR merged onto it | |---|---|---| | ccleste PPSA59322 | `Transferring control to ELF entry point`, presents continuously, still running at 60 s, no stop line | same | | ccleste window title at 60 s (two runs) | `ccleste \| FPS: 59.83 (3401)`, `ccleste \| FPS: 53.42 (3071)` | `ccleste \| FPS: 85.81 (4778)`, `ccleste \| FPS: 33.31 (2130)` | | ScreenTester5 PPSA69420 | ELF entry, `Swapchain created ... extent=1484x835 images=2`, test screen shown, still running at 60 s, no stop line | same | | ScreenTester5 window title at 60 s | `ScreenTester5 \| FPS: 0.00 (2)` (two runs) | `ScreenTester5 \| FPS: 0.00 (2)` | | Main-thread TEB StackLimit..StackBase / DeallocationStack | `0x410000..0x610000` / `0x400000` (both titles, every run) | `0x200010000..0x200220000` / `0x200000000` (both titles, every run) | - Apart from timing, the logs are the same. ScreenTester5's 29 lines are identical once addresses are masked. ccleste's differ only in the order of shader preparation, plus one line in the first `main` run: `wsi/videoout: 119.88 Hz accepted, but a vblank comes every 22.584 ms; 59.94 Hz restored`. - The frame counts depend on host load, not on this change: the same build gave 3071–3401 frames on `main` and 2130–4778 with the PR. - The first guest arena allocation after startup now sits above the stack reservation. ScreenTester5's first thread argument is `arg=0000000200000150` on `main` and `arg=0000000200220150` with the PR. Verdict: on Windows the build, the tests above and the non-GPU suite pass. ccleste and ScreenTester5 reach the same point on `main` and with this PR alone, with no new stop, and the main thread runs on the arena-backed stack (`0x200010000..0x200220000`). AI-assisted (Claude Code).
oneandonlydean commented 2026-10-17 00:03:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T00:03:22Z.


@adriadam10 your first point is covered now: screamm ran ccleste and ScreenTester5, which both boot on main, with this PR alone on main 6239ceffc (Windows 11, RTX 4070), and both behave the same before and after; only the main-thread stack moves into the arena. The head has only been rebased since then (the changed lines are identical to f49abbed2), and it merges cleanly with current main. Could you take another look?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6227033200 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#issuecomment-6227033200). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T00:03:22Z. --- @adriadam10 your first point is covered now: screamm ran ccleste and ScreenTester5, which both boot on main, with this PR alone on main 6239ceffc (Windows 11, RTX 4070), and both behave the same before and after; only the main-thread stack moves into the arena. The head has only been rebased since then (the changed lines are identical to `f49abbed2`), and it merges cleanly with current main. Could you take another look?
Pouare514 commented 2026-10-17 14:00:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-17T14:00:57Z.


Coordination evidence for this PR + #7149 (guest pthread/fiber stacks):

(a) Entry stub active: combo with old libs (pre-guest-stack) fails with GetLastError 127 on missing guest main-stack entry, confirming the new stub path is taken.

(b) Combo fixes TLOU NdJob allocator crash: 13 NdJobWorkerThreads on guest stacks (0x1404xxbc80), no 0x1a54d81 fault, Vulkan ready + swapchain 1472x828. The two halves are complementary, files disjoint, no duplication.

(c) Behavior change: new stub chdirs to exe dir while old stub preserved launch cwd, so layouts without local app0/sce_sys hit param.json not found (AppMetadata ResolvePath/current_path). Consider documenting cwd requirement in USAGE.md or keeping cwd fallback.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234796532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#issuecomment-6234796532). Originally posted by [Pouare514](https://github.com/Pouare514) on 2026-10-17T14:00:57Z. --- Coordination evidence for this PR + #7149 (guest pthread/fiber stacks): (a) Entry stub active: combo with old libs (pre-guest-stack) fails with GetLastError 127 on missing guest main-stack entry, confirming the new stub path is taken. (b) Combo fixes TLOU NdJob allocator crash: 13 NdJobWorkerThreads on guest stacks (0x1404xxbc80), no 0x1a54d81 fault, Vulkan ready + swapchain 1472x828. The two halves are complementary, files disjoint, no duplication. (c) Behavior change: new stub chdirs to exe dir while old stub preserved launch cwd, so layouts without local app0/sce_sys hit `param.json not found` (AppMetadata ResolvePath/current_path). Consider documenting cwd requirement in USAGE.md or keeping cwd fallback.
oneandonlydean commented 2026-10-17 14:15:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T14:15:34Z.


Thanks for the coordination evidence. Review at 5247944b7: the entry path looks good. The second RUNTIME_FUNCTION gives a proper unwind root, it runs once, and cleanup happens on the original stack. It still merges cleanly with main and with #7149.

One item holds it, and the fix belongs in #7149. If the main thread calls scePthreadExit while workers are running, Windows exits the thread through _endthreadex -> ExitThread with the TEB still pointing at the guest arena stack. That's the same class as the #7149 blocker, and new with this PR, since today main exits from the host stack. Details and the suggested single fix in scePthreadExit are on #7149. Normal exit/ExitProcess is fine.

On (c), the cwd change: this PR doesn't cause it. The stub's SetCurrentDirectoryW to the exe dir is already on main (WindowsEntryStubBuilder.cpp) and at this PR's merge-base, and the diff doesn't touch it; the comparison was against pre-10-10 stubs/libs. A launch-cwd note in USAGE.md would be a separate change against main.

Planned order: #6540 -> #7135 -> #7149 (fixed) -> #3965.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234957688 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#issuecomment-6234957688). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T14:15:34Z. --- Thanks for the coordination evidence. Review at 5247944b7: the entry path looks good. The second RUNTIME_FUNCTION gives a proper unwind root, it runs once, and cleanup happens on the original stack. It still merges cleanly with main and with #7149. One item holds it, and the fix belongs in #7149. If the main thread calls `scePthreadExit` while workers are running, Windows exits the thread through `_endthreadex` -> `ExitThread` with the TEB still pointing at the guest arena stack. That's the same class as the #7149 blocker, and new with this PR, since today main exits from the host stack. Details and the suggested single fix in `scePthreadExit` are on #7149. Normal exit/ExitProcess is fine. On (c), the cwd change: this PR doesn't cause it. The stub's `SetCurrentDirectoryW` to the exe dir is already on main (`WindowsEntryStubBuilder.cpp`) and at this PR's merge-base, and the diff doesn't touch it; the comparison was against pre-10-10 stubs/libs. A launch-cwd note in USAGE.md would be a separate change against main. Planned order: #6540 -> #7135 -> #7149 (fixed) -> #3965.
BunnyFl commented 2026-11-02 21:54:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T21:54:45Z.

Review: APPROVED


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5743945183 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#pullrequestreview-5743945183). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T21:54:45Z. **Review:** APPROVED --- 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 commented 2026-11-02 22:15:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T22:15:08Z.

Review: COMMENTED


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:114 commits the whole stack. Then core/libs/prx/libc/src/GuestStacks.cpp:131 sets StackLimit to its lowest committed byte, and the 64 KiB region below it is PAGE_NOACCESS, not a PAGE_GUARD page.
    • Why it matters: if the guest main thread overflows its stack, the kernel should report STATUS_ACCESS_VIOLATION instead of STATUS_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.
  • Debt entry style: the new entry at docs/dev/debt/libc.md:141 has 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 by WIN32 or os.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 scePthreadExit with 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) passes windows_guest_main_stack, windows_guest_main_stack_failure, windows_guest_main_stack_entry, windows_import_modules, windows_trace_imports and windows_kernel_variant_*.
  • Merge only after corrected #7149, as the Depends on line says.
  • Optionally, record the overflow-reporting difference in the debt entry and add its final period.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5744165506 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#pullrequestreview-5744165506). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-02T22:15:08Z. **Review:** COMMENTED --- # 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:114` commits the whole stack. Then `core/libs/prx/libc/src/GuestStacks.cpp:131` sets `StackLimit` to its lowest committed byte, and the 64 KiB region below it is `PAGE_NOACCESS`, not a `PAGE_GUARD` page. - **Why it matters:** if the guest main thread overflows its stack, the kernel should report `STATUS_ACCESS_VIOLATION` instead of `STATUS_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`. - **Debt entry style**: the new entry at `docs/dev/debt/libc.md:141` has 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 by `WIN32` or `os.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 `scePthreadExit` with 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`) passes `windows_guest_main_stack`, `windows_guest_main_stack_failure`, `windows_guest_main_stack_entry`, `windows_import_modules`, `windows_trace_imports` and `windows_kernel_variant_*`. - Merge only after corrected #7149, as the `Depends on` line says. - Optionally, record the overflow-reporting difference in the debt entry and add its final period. <!-- anyps5-bots job=2570 head=8029f87e5872277c330494a052a3d907052a3b7b -->
Superseabas commented 2026-11-05 16:22:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-05T16:22:44Z.

Review: COMMENTED


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
  • 3221225477 is 0xC0000005. 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, absent and nonzero. All three pass on main, and the Linux cases pass on both.
  • The guest module in that test is built with the THREAD_POINTER prefix (tls=True), so it reads the thread pointer, and it's loaded from sce_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 that main doesn't also have on this machine: 4,199 of 4,205 pass. The other five are known: test_registration and select_tests_MissingCommandTests (#15652), windows_crash_thread_name (#15578), agc_driver_direct_write_completion (#15564) and agc_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.dll on PATH here is Git for Windows' (C:\Program Files\Git\mingw64\bin, an older GCC). The converted program then fails with Failed 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)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5788250718 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#pullrequestreview-5788250718). Originally posted by [Superseabas](https://github.com/Superseabas) on 2026-11-05T16:22:44Z. **Review:** COMMENTED --- 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 | - `3221225477` is `0xC0000005`. 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`, `absent` and `nonzero`. All three pass on `main`, and the Linux cases pass on both. - The guest module in that test is built with the `THREAD_POINTER` prefix (`tls=True`), so it reads the thread pointer, and it's loaded from `sce_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 that `main` doesn't also have on this machine: 4,199 of 4,205 pass. The other five are known: `test_registration` and `select_tests_MissingCommandTests` (#15652), `windows_crash_thread_name` (#15578), `agc_driver_direct_write_completion` (#15564) and `agc_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.dll` on `PATH` here is Git for Windows' (`C:\Program Files\Git\mingw64\bin`, an older GCC). The converted program then fails with `Failed 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 commented 2026-11-05 17:33:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-05T17:33:17Z.

Review: CHANGES_REQUESTED


@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)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5789234765 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#pullrequestreview-5789234765). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-05T17:33:17Z. **Review:** CHANGES_REQUESTED --- @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)
BunnyFl commented 2026-11-12 10:31:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-12T10:31:27Z.

Review: APPROVED


@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)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5872871022 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3965#pullrequestreview-5872871022). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-12T10:31:27Z. **Review:** APPROVED --- @eliasbruno124-dev thanks: `bc0ee29e4c` fixes what [my change request](https://github.com/boykopovar/AnyPS5/pull/3965#pullrequestreview-5789234765) 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](https://github.com/boykopovar/AnyPS5/pull/3965#pullrequestreview-5789234765)), 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](https://github.com/boykopovar/AnyPS5/pull/7149) and [#9938](https://github.com/boykopovar/AnyPS5/pull/9938) (`GuestStacks.hpp`/`GuestStacks.cpp`), and [#11628](https://github.com/boykopovar/AnyPS5/pull/11628), [#11661](https://github.com/boykopovar/AnyPS5/pull/11661), [#11689](https://github.com/boykopovar/AnyPS5/pull/11689) and [#11698](https://github.com/boykopovar/AnyPS5/pull/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)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!3965
No description provided.