Skip to content

test(libkernel): probe the start block the main stack move keeps - #1405

Open
Thimo188 wants to merge 2 commits into
mainfrom
upstream-pr/26812
Open

Thimo188 wants to merge 2 commits into
mainfrom
upstream-pr/26812

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#26812, originally opened by Romannachwievor.

Source commit: 24543f9753b92565378d57c2342fb1299a5cd6fa. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

guest_main_stack_move fails now and then on macOS with check failed: the process start block stays mapped where dyld points. After the main stack moves, the emulator keeps the old stack from the page of argv - sizeof(char*) up to its top (ProcessStartBlockLow and ServeMainQueue in MainThreadMacOs.cpp, from boykopovar#15698) and releases the rest. The test expected the kept 64 KiB block at the address of a local variable in main. That local sits a few KiB below argv, and with stack ASLR the two addresses sometimes fall into different 64 KiB blocks. The test then probes the block below the kept range, GuestArenaMarkUsed accepts it, and the check fails.

Measured with temporary prints on an M1: in a passing run the local's block was 0x308d00000 and the kept range started at 0x308d02000; in a failing run the local's block was 0x3087a0000 and the kept range started at 0x3087b1000.

This change computes the expected block from main's argv - sizeof(char*), the same address the emulator uses. The page rounding is not repeated because 64 KiB is a multiple of the page size. The test is the only file changed and the assertion is unchanged. argv is read in main because the emulator replaces *_NSGetArgv() with copies after the move.

No open PR changes GuestMainStackMove.cpp or MainThreadMacOs.cpp. I searched open PRs for guest_main_stack_move, GuestMainStackMove and MainThreadMacOs, and none of the hits touches either file. pr_overlap.py --branch compared 2467 open PRs and found no overlap.

Tested

Apple M1, macOS 26.5, x86_64 Release under Rosetta 2. The tree was main 61cce6e86b plus boykopovar#17425, boykopovar#11049 and boykopovar#26739, which a macOS full build needs. GuestMainStackMove.cpp, MainThreadMacOs.cpp and GuestArena.hpp are byte-identical there and on this PR's base 8170c102d4.

  • This change (commit bce996ecc6): ctest --test-dir build -R '^guest_main_stack_move$' --repeat until-fail:60 passed 60 of 60, then --repeat until-fail:200 passed 200 of 200.
  • main, same build with the test reverted and rebuilt: --repeat until-fail:60 failed on the first run. 40 separate ctest runs passed 38, and 40 direct runs of guest_main_stack_move_tests passed 39. Every failure was the process start block stays mapped where dyld points.
  • The checks run only when the original stack is inside the guest arena (originalInArena). A temporary print, not part of this PR, showed that this was true in 100 of 100 runs with the change, and all 100 passed.

Head 24543f9753 only merges 9 later main commits, none of which touch the test, MainThreadMacOs.cpp or GuestArena.hpp.

Linux and Windows were not run. The test is built only for macOS x86_64.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: yes (Claude Code)

Summary by CodeRabbit

  • Tests
    • Updated validation of guest memory mapping near process startup to account for aligned memory addresses. This improves the accuracy of automated checks without changing user-facing behavior.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Guest stack mapping test

Layer / File(s) Summary
Update the guest-arena mapping check
core/libs/tests/GuestMainStackMove.cpp
The test stores the original argv address and derives kept from the aligned address immediately below it.

Suggested reviewers: javierudp

Change: Other

Merge Risk: Minimal · up to 24543

This is a test-only change that makes the stack move test deterministic under stack address randomization. It has no production impact and I see no merge-blocking risk.

Security architecture risk: Minimal · up to 24543

The test now checks the guest-arena block associated with the original argument vector instead of a block inferred from a local stack variable. The assertion and production behavior are unchanged.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 1
  • Waived: $0.25 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5be724f2-3bc1-41e0-b9e5-8c8c61dd1c2e
Commits

Reviewing files that changed from the base of the PR and between 4131f51 and 24543f9.

Files selected for processing: 1

  • core/libs/tests/GuestMainStackMove.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants