Skip to content

fix(libkernel): keep host standard streams open on guest close - #4242

Closed
MarcZX10 wants to merge 1 commit into
boykopovar:mainfrom
MarcZX10:codex/carry-host-stream-close-3295
Closed

MarcZX10 wants to merge 1 commit into
boykopovar:mainfrom
MarcZX10:codex/carry-host-stream-close-3295

Conversation

@MarcZX10

Copy link
Copy Markdown
Contributor

What

Carries the single commit from SynnZer0's intake-closed #3295, preserving the original commit author. The fix records which of descriptors 0–2 were open when libkernel initialized and returns EBADF from close/sceKernelClose for those descriptors, keeping host standard streams from being closed and reused for guest files. Descriptors that were closed at initialization remain available to guest open and close calls.

This addresses #4223's reproduced failure: repeated sceKernelClose(0) calls can otherwise close stdin, let a later guest file reuse fd 0, and close that file while another thread reads it. The carried change was replayed onto current main without conflicts. Its changes to Open.cpp and Stdio.cpp also merge cleanly with open PR #3840.

Tested

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 in TechnicalDebt (n/a)
  • 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 (n/a)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (carried commit from SynnZer0)

Guest descriptors are host C runtime descriptors. Closing descriptor 0, 1
or 2 closed the host process's standard stream, and the runtime then gave
that number to the next file opened anywhere in the process, including
files libkernel opens itself, such as the APR reader's. The title's next
close of the same number closed that file mid-read.

close and sceKernelClose now fail with EBADF for descriptors 0 to 2 that
were open when libkernel loaded, and leave them open. A standard
descriptor that was not open at load can still be opened and closed by
the guest.

PPSA21703 calls sceKernelClose(0) repeatedly while loading asset
bundles, which made APR reads return 0 or a part of the requested bytes
and raised UCRT invalid parameter reports from close.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 9c30f0e)
@MarcZX10

Copy link
Copy Markdown
Contributor Author

Closing this because the active contribution rules prohibit carrying code from intake-paused PRs; this branch directly carried #3295. The #4223 report independently confirms the defect, but this PR will not proceed as a carry.

@MarcZX10 MarcZX10 closed this Oct 12, 2026
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