Skip to content

Fail fast when SetHeapSize cannot change host page protections - #127

Closed
nocmt wants to merge 1 commit into
seedds:mainfrom
nocmt:fix/set-heap-size-failure
Closed

nocmt wants to merge 1 commit into
seedds:mainfrom
nocmt:fix/set-heap-size-failure

Conversation

@nocmt

@nocmt nocmt commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Fail fast when SetHeapSize cannot change host page protections

Problem

SetHeapSize checks whether a requested size fits the heap and application pool, but ignores a failure from the subsequent host mprotect call. It then updates g_heap_cur and returns success to the guest. After a failed growth or shrink, the published heap size and readability/accounting checks can therefore disagree with the host page protections.

Change

Check the result before publishing the new size or guest output registers. On failure, report the requested size and errno through the existing die path.

This follows the existing fail-fast policy used for failed host protection changes in MapMemory and MapPhysicalMemory. It does not invent an errno-to-Horizon Result mapping or attempt to continue after a potentially partial host protection change. Requests that leave the heap size unchanged still make no host call and return successfully.

The production change is one line. It does not change reservation sizing, application-pool limits, alignment rules, environment overrides, or game profiles.

Regression coverage

The new test includes the production hle_svc.c and calls svc_dispatch(0x01) directly. Test-only wrappers inject mprotect failures and observe the state immediately before the real abort; no production test hook or public API is added. Successful operations use real protection changes on a small anonymous mapping, without game files.

Coverage includes growth, shrink, full release, regrowth, unchanged sizes, exact protection ranges, readable boundaries, memory accounting, and injected ENOMEM/EACCES failures. Failure cases verify that the original heap size and guest registers remain unpublished before termination.

Validation

  • make -C dm/host/tests GAME=010015100B514000 heap_size: passed with UndefinedBehaviorSanitizer and -Wall -Werror.
  • Production hle_svc.c syntax check and git diff --check: passed.
  • Negative control against the unmodified production file from current main (7a029f6): failed as expected because the dispatcher returned after an injected protection failure.
  • Patch replay onto the clean baseline and execution of the replayed test: passed.
  • Full host suite: attempted but not completed; the existing Vorbis debug build stalled in dsymutil before the suite recipe executed. No full-suite pass is claimed.

Based on current main at 7a029f66d92c951ae6a86e38bb34eeb0cb7527e3. The targeted regression test, production syntax check and whitespace check were rerun after updating to this baseline.

Limits

This is a fail-fast consistency fix, not guest error recovery or rollback of partial host changes. Failure injection returns before the real system call and does not reproduce OS-specific partial-failure behavior. No game boot, iOS build, or device validation was performed.

seedds added a commit that referenced this pull request Oct 25, 2026
Apply PR #127 and require the regression test's abort handler to observe a validated production fatal path. Unrelated assertion failures can no longer pass the injected-failure cases.

Co-authored-by: nocmt <[email protected]>
@seedds

seedds commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Applied to main in 9ba44da with Co-authored-by: nocmt [email protected].

The production SetHeapSize fix is included. I also corrected the regression test: its SIGABRT handler now accepts success only after heap_abort() validates the production fatal path and unpublished state. Previously, an assertion failure could trigger SIGABRT and incorrectly pass the failure cases.

Validation:

  • Targeted heap_size test passed with UndefinedBehaviorSanitizer and -Wall -Werror.
  • Production hle_svc.c syntax check and git diff --check passed.
  • Confirmed the original test incorrectly passes when the protection-failure branch returns 0xD401.
  • Confirmed the corrected test rejects that error return and rejects removal of the protection-failure check.

The full host suite and game/device validation were not rerun. Closing this PR because the corrected change has been incorporated into main. Thanks for the fix.

@seedds seedds closed this Oct 25, 2026
seedds added a commit that referenced this pull request Oct 25, 2026
Incorporate the active SVC improvements from PR #151 around the existing
alias bitmap and mapping registry. Serialize heap changes, physical maps,
stack ownership and memory queries with one lock; report committed alias
runs and borrowed sources; initialize reused logical pages while preserving
live neighbors and lazy first exposure. Retain PR #127's fail-fast host
protection policy and the log formats parsed by the NSP heap probe.

Game smoke tests exposed two integration requirements: Raging Loop's SDK
extends committed windows across borrowed stack sources, so allow recommit
that preserves existing bytes; Tears of the Kingdom's audio helper needs
guest-backed stacks, so allocate host-created guest-thread stacks through
SDK malloc and free them after thread destruction and copyback.

Keep SDK reservation ownership and existing patches. The unused host
reservation allocator from #151 is not included.

Validation: full host suite; focused UBSan, ASan and ThreadSanitizer tests;
real dirty-tracker concurrency tests; heap-probe parser compatibility; Mac
host builds; iOS arm64 syntax checks; all 60 profile layout checks.
Raging Loop and Tears of the Kingdom passed guest-thread self-checks and
ran to deliberate timeouts after the startup fixes. Their shader caches
are stale for this checkout, so rendering/performance are not validated.
No IPA build or iOS device validation was performed.

Co-authored-by: b4f8abbb24dbf56a7d0280f296e16eeb <51352400+b4f8abbb24dbf56a7d0280f296e16eeb@users.noreply.github.com>
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
Apply PR seedds#127 and require the regression test's abort handler to observe a validated production fatal path. Unrelated assertion failures can no longer pass the injected-failure cases.

Co-authored-by: nocmt <[email protected]>
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
Incorporate the active SVC improvements from PR seedds#151 around the existing
alias bitmap and mapping registry. Serialize heap changes, physical maps,
stack ownership and memory queries with one lock; report committed alias
runs and borrowed sources; initialize reused logical pages while preserving
live neighbors and lazy first exposure. Retain PR seedds#127's fail-fast host
protection policy and the log formats parsed by the NSP heap probe.

Game smoke tests exposed two integration requirements: Raging Loop's SDK
extends committed windows across borrowed stack sources, so allow recommit
that preserves existing bytes; Tears of the Kingdom's audio helper needs
guest-backed stacks, so allocate host-created guest-thread stacks through
SDK malloc and free them after thread destruction and copyback.

Keep SDK reservation ownership and existing patches. The unused host
reservation allocator from seedds#151 is not included.

Validation: full host suite; focused UBSan, ASan and ThreadSanitizer tests;
real dirty-tracker concurrency tests; heap-probe parser compatibility; Mac
host builds; iOS arm64 syntax checks; all 60 profile layout checks.
Raging Loop and Tears of the Kingdom passed guest-thread self-checks and
ran to deliberate timeouts after the startup fixes. Their shader caches
are stale for this checkout, so rendering/performance are not validated.
No IPA build or iOS device validation was performed.

Co-authored-by: b4f8abbb24dbf56a7d0280f296e16eeb <51352400+b4f8abbb24dbf56a7d0280f296e16eeb@users.noreply.github.com>
ltrdpper pushed a commit to ltrdpper/BananaNative that referenced this pull request Nov 11, 2026
…ix, 12 GB memory, foldable inner screen, Pokopia frame cap

Memory maps (seedds#127, seedds#132): background pipeline compiles on Turnip are serialized (vk-psoasync / vk-psopt through the heavy-compile hold), contiguous placed segments are joined across pools at submission start, unplace copies through sw_mmap_fixed instead of mremap so the kernel merges anonymous VMAs again, and past 2,000 split anonymous maps the dirty tracker releases its protections once (one re-upload) so guest VMAs merge.
Launcher: android:appCategory="game" (seedds#110); the game fills a foldable's near-square inner screen (GameOrientation.fixedLandscape from the maximum window metrics); overlay blocks inset from rounded corners and cutouts (seedds#105, OverlayInset); Prepare texts say whether the code rewrite or a shader translation runs and that shaders are kept; no "Ready, with limits" dialog at start.
Frame rate: Ocarina of Time (`0400486024DEC000`) fps_limit 60 (was 30). Pokémon Pokopia (`0400A3A01EE4C000`) fps_limit 60 with the new launcher key fps_limit_present: the host limiter's caps are offered with a note that they pace the presents only (seedds#143).
Skipped work: the Vulkan replay counts draws and dispatches skipped for causes of the device (no mesh shading, refused shaders or pipelines, missing features) and warns once per run past DM_VK_SKIP_WARN percent (default 5) in two 300-frame windows in a row; the launcher shows a small notice.
Textures: the pool-read line counts images made again for an ID made before (diagnostic, seedds#131).
Docs: Fire Emblem Fortune's Weave's note links only existing reference entries; docs_patches classifies av1_decoder.
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