fix(tests): run guest_main_stack without the ASan fake stack #16089

Merged
xXPBSXx merged 1 commit from upstream-pr/16089 into main 2026-11-12 21:55:46 +00:00
xXPBSXx commented 2026-11-05 16:28:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-11-05T16:28:17Z.


What

The guest_main_stack and guest_main_stack_adopted tests fail in the Sanitizers nightly of 2026-11-04 (head 1c8c0efc8c) with GuestMainStack failed at line 68. Under ASan the test's local local (GuestMainStack.cpp:61), whose address is passed to sceKernelIsStack, can sit on ASan's fake stack (detect_stack_use_after_return), which is outside the guest main stack. sceKernelIsStack then returns 0 with start and end left at 0; printing the values before line 68 gave low=0 high=0 and an address in the host's fake-stack range instead of 0x1007eeffc000, so the high == ConsoleMainStackTop check fails.

The sibling tests that take stack addresses (guest_kernel_is_stack, guest_kernel_stack_protect, guest_thread_self, guest_pthread_stack, guest_raise_exception) already register add_asan_test_options(<test> detect_stack_use_after_return=0). This PR adds the same line for the two guest_main_stack tests. It is not caused by #15436: the test file from before #15436 fails the same way against current production code.

Changes one file, core/libs/prx/libkernel/CMakeLists.txt (+2).

Tested

  • Ubuntu 24.04 in WSL, GCC 13.3, Release, ANYPS5_ENABLE_ASAN=ON with -g1 -fsanitize=undefined -fno-sanitize=vptr, ASAN_OPTIONS=detect_leaks=0, UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1, APS5_SKIP_TIMING_TESTS=1, as in sanitizers.yml.
  • Nightly head 1c8c0efc8c, tests unchanged (red): both tests failed in 3 of 3 runs. With detect_stack_use_after_return=0 added to ASAN_OPTIONS: passed in 3 of 3 runs. With this change: passed in 3 of 3 runs, and ctest -V shows ASAN_OPTIONS=string_append::detect_stack_use_after_return=0.
  • Main a992b80376 (fresh checkout, cmake and ninja exited 0, build 416 s), tests unchanged (red): both failed in 3 of 3 runs. With this change applied as a patch, rebuilt: passed in 3 of 3 runs. The three files this PR and the tests depend on (libkernel/CMakeLists.txt, GuestMainStack.cpp, Thread.cpp) are identical between a992b80376 and the base d63781e9ce of this commit.
  • The test file from before #15436 against current production code, detect_leaks=0 only: failed in 2 of 2 runs at line 68.
  • python -I tools/check_conventions.py --base upstream/main passed and git diff --check is clean.
  • Not run: Windows and macOS (the tests are Linux only, libkernel/CMakeLists.txt).

Overlap

All 1845 open pull requests were checked on 2026-11-05 at 14:43 UTC against main 03cfa4c067; the changed files of each PR come from git diff --name-only against its merge base, finished 16:05 UTC. 49 PRs change core/libs/prx/libkernel/CMakeLists.txt or core/libs/tests/GuestMainStack.cpp, and every one had a fetchable ref. For each, git merge-tree with this head and with main alone gives the same result for 47 of them (30 merge cleanly either way, 17 already conflict with main on their own); the other 2 conflict with main alone but merge cleanly with this head. No PR conflicts only because of this change. #15691 changes GuestMainStack.cpp and Thread.cpp; it merges cleanly with this head and with main. This head merges cleanly with main 4741457fed (git merge-tree exit 0). Depends on: none.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5174989003 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16089). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-11-05T16:28:17Z. --- ### What The `guest_main_stack` and `guest_main_stack_adopted` tests fail in the Sanitizers nightly of 2026-11-04 (head 1c8c0efc8c) with `GuestMainStack failed at line 68`. Under ASan the test's local `local` (`GuestMainStack.cpp:61`), whose address is passed to `sceKernelIsStack`, can sit on ASan's fake stack (`detect_stack_use_after_return`), which is outside the guest main stack. `sceKernelIsStack` then returns 0 with `start` and `end` left at 0; printing the values before line 68 gave `low=0 high=0` and an address in the host's fake-stack range instead of `0x1007eeffc000`, so the `high == ConsoleMainStackTop` check fails. The sibling tests that take stack addresses (`guest_kernel_is_stack`, `guest_kernel_stack_protect`, `guest_thread_self`, `guest_pthread_stack`, `guest_raise_exception`) already register `add_asan_test_options(<test> detect_stack_use_after_return=0)`. This PR adds the same line for the two `guest_main_stack` tests. It is not caused by #15436: the test file from before #15436 fails the same way against current production code. Changes one file, `core/libs/prx/libkernel/CMakeLists.txt` (+2). ### Tested - Ubuntu 24.04 in WSL, GCC 13.3, Release, `ANYPS5_ENABLE_ASAN=ON` with `-g1 -fsanitize=undefined -fno-sanitize=vptr`, `ASAN_OPTIONS=detect_leaks=0`, `UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1`, `APS5_SKIP_TIMING_TESTS=1`, as in `sanitizers.yml`. - Nightly head 1c8c0efc8c, tests unchanged (red): both tests failed in 3 of 3 runs. With `detect_stack_use_after_return=0` added to `ASAN_OPTIONS`: passed in 3 of 3 runs. With this change: passed in 3 of 3 runs, and `ctest -V` shows `ASAN_OPTIONS=string_append::detect_stack_use_after_return=0`. - Main a992b80376 (fresh checkout, cmake and ninja exited 0, build 416 s), tests unchanged (red): both failed in 3 of 3 runs. With this change applied as a patch, rebuilt: passed in 3 of 3 runs. The three files this PR and the tests depend on (`libkernel/CMakeLists.txt`, `GuestMainStack.cpp`, `Thread.cpp`) are identical between a992b80376 and the base d63781e9ce of this commit. - The test file from before #15436 against current production code, `detect_leaks=0` only: failed in 2 of 2 runs at line 68. - `python -I tools/check_conventions.py --base upstream/main` passed and `git diff --check` is clean. - Not run: Windows and macOS (the tests are Linux only, `libkernel/CMakeLists.txt`). ### Overlap All 1845 open pull requests were checked on 2026-11-05 at 14:43 UTC against main 03cfa4c0679db4e16dba070263451ef5a6e4cdff; the changed files of each PR come from `git diff --name-only` against its merge base, finished 16:05 UTC. 49 PRs change `core/libs/prx/libkernel/CMakeLists.txt` or `core/libs/tests/GuestMainStack.cpp`, and every one had a fetchable ref. For each, `git merge-tree` with this head and with `main` alone gives the same result for 47 of them (30 merge cleanly either way, 17 already conflict with `main` on their own); the other 2 conflict with `main` alone but merge cleanly with this head. No PR conflicts only because of this change. #15691 changes `GuestMainStack.cpp` and `Thread.cpp`; it merges cleanly with this head and with `main`. This head merges cleanly with `main` 4741457fed (`git merge-tree` exit 0). Depends on: none. ### Checklist - [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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/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!16089
No description provided.