fix(libc): match fdopen bad-descriptor stream behavior #24406

Closed
jagdishpanada2000-cloud wants to merge 1 commit from upstream-pr/24406 into main
jagdishpanada2000-cloud commented 2026-11-20 15:51:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jagdishpanada2000-cloud on 2026-11-20T15:51:07Z.


What

  • Make libc fdopen_nid_postfix return a stream for a closed/unknown descriptor (instead of NULL with EBADF) to match the PS5 firmware 13.60 libSceLibcInternal behavior documented in docs/dev/debt/libc.md.
  • For such a stream, fflush and fclose fail with EBADF, and read/write/seek/tell operations do not report EBADF (other outcomes for those operations remain unverified and are not claimed).
  • Update core/libs/tests/GuestStandardStreams.cpp to cover the measured behavior and add the corresponding debt fragment (docs/dev/debt/changes/fix-libc-fdopen-bad-descriptor.md).

Tested

  • Windows 11 (win32, local build-full Ninja build): tests\guest_standard_stream_tests.exe passed (exit 0), including the updated closed-descriptor fdopen case (fflush/fclose fail with EBADF; fread/fwrite/fseek/ftell do not report EBADF).
  • Not tested on PS5 hardware/firmware, in titles/homebrew, or on other host OSes.

Checklist

  • Based on current main; no other open PR implements the same functions (branch based on origin/main; remote open-PR/issue overlap could not be fully verified here because gh is unauthenticated)
  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5416198357 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24406). Originally posted by [jagdishpanada2000-cloud](https://github.com/jagdishpanada2000-cloud) on 2026-11-20T15:51:07Z. --- ### What - Make `libc` `fdopen_nid_postfix` return a stream for a closed/unknown descriptor (instead of `NULL` with `EBADF`) to match the PS5 firmware 13.60 `libSceLibcInternal` behavior documented in `docs/dev/debt/libc.md`. - For such a stream, `fflush` and `fclose` fail with `EBADF`, and read/write/seek/tell operations do not report `EBADF` (other outcomes for those operations remain unverified and are not claimed). - Update `core/libs/tests/GuestStandardStreams.cpp` to cover the measured behavior and add the corresponding debt fragment (`docs/dev/debt/changes/fix-libc-fdopen-bad-descriptor.md`). ### Tested - Windows 11 (win32, local `build-full` Ninja build): `tests\guest_standard_stream_tests.exe` passed (exit 0), including the updated closed-descriptor `fdopen` case (`fflush`/`fclose` fail with `EBADF`; `fread`/`fwrite`/`fseek`/`ftell` do not report `EBADF`). - Not tested on PS5 hardware/firmware, in titles/homebrew, or on other host OSes. ### 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 (branch based on `origin/main`; remote open-PR/issue overlap could not be fully verified here because `gh` is unauthenticated) - [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) and the licence notice of code adapted from upstream (see AGENTS.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
copilot-pull-request-reviewer[bot] commented 2026-11-20 15:51:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-20T15:51:14Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5995438867 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24406#pullrequestreview-5995438867). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-20T15:51:14Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
PrivacyOnion commented 2026-11-20 16:11:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T16:11:39Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against c9dc2ca642:

  • Conventions: tools/check_conventions.py failed.
    docs/dev/debt/changes/fix-libc-fdopen-bad-descriptor.md:1: error: [debt-fragment] A debt fragment in docs/dev/debt/changes/ must apply: each '## change' or '## remove' names text that occurs in exactly one entry of its '# <library>' file, and no other fragment changes the same entry; check with python3 tools/debt_fold.py --check: docs/dev/debt/changes/fix-libc-fdopen-bad-descriptor.md:1: text outside an operation
    (pull request): error: [pr-template] Fill in the pull request template: fill the '### What' section
    (pull request): error: [pr-template] Fill in the pull request template: fill the '### Tested' section
    (pull request): error: [pr-template] Fill in the pull request template: answer AI-assisted with yes or no
    (pull request): error: [pr-template] Fill in the pull request template: fill Depends on with #N or none
    5 findings, 5 errors; GitHub shows at most 10 error annotations, the job summary lists all
    
  • Build: guest_standard_stream_tests built cleanly.
  • CTest (guest_standard_streams, guest_standard_streams_closed_stdout, guest_standard_streams_exclusive_stdout, guest_standard_streams_reopen_closed_stdout, guest_standard_streams_update_stdout):
    1/5 Test #1371: guest_standard_streams_closed_stdout ..........   Passed    0.02 sec
    2/5 Test #1372: guest_standard_streams_exclusive_stdout .......   Passed    0.04 sec
    3/5 Test #1373: guest_standard_streams_reopen_closed_stdout ...   Passed    0.02 sec
    4/5 Test #1374: guest_standard_streams_update_stdout ..........   Passed    0.02 sec
    5/5 Test #1370: guest_standard_streams ........................   Passed    0.22 sec
    100% tests passed, 0 tests failed out of 5
    

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5995732048 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24406#pullrequestreview-5995732048). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-20T16:11:39Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `c9dc2ca642`: - **Conventions**: `tools/check_conventions.py` failed. ``` docs/dev/debt/changes/fix-libc-fdopen-bad-descriptor.md:1: error: [debt-fragment] A debt fragment in docs/dev/debt/changes/ must apply: each '## change' or '## remove' names text that occurs in exactly one entry of its '# <library>' file, and no other fragment changes the same entry; check with python3 tools/debt_fold.py --check: docs/dev/debt/changes/fix-libc-fdopen-bad-descriptor.md:1: text outside an operation (pull request): error: [pr-template] Fill in the pull request template: fill the '### What' section (pull request): error: [pr-template] Fill in the pull request template: fill the '### Tested' section (pull request): error: [pr-template] Fill in the pull request template: answer AI-assisted with yes or no (pull request): error: [pr-template] Fill in the pull request template: fill Depends on with #N or none 5 findings, 5 errors; GitHub shows at most 10 error annotations, the job summary lists all ``` - **Build**: `guest_standard_stream_tests` built cleanly. - **CTest** (`guest_standard_streams`, `guest_standard_streams_closed_stdout`, `guest_standard_streams_exclusive_stdout`, `guest_standard_streams_reopen_closed_stdout`, `guest_standard_streams_update_stdout`): ``` 1/5 Test #1371: guest_standard_streams_closed_stdout .......... Passed 0.02 sec 2/5 Test #1372: guest_standard_streams_exclusive_stdout ....... Passed 0.04 sec 3/5 Test #1373: guest_standard_streams_reopen_closed_stdout ... Passed 0.02 sec 4/5 Test #1374: guest_standard_streams_update_stdout .......... Passed 0.02 sec 5/5 Test #1370: guest_standard_streams ........................ Passed 0.22 sec 100% tests passed, 0 tests failed out of 5 ``` Requesting changes for the points above.
MarcZX10 commented 2026-11-20 16:14:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T16:14:13Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this change based on the code inspected; console behavior and the author-reported test run were not independently verified.

What I ran

Reviewed head c9dc2ca64247d55082120f863a202275bf2c7d25. No commands or tests were run; the review reader provided the prepared diff and pinned source.

Results

Check Result Note
Changed-code review passed Inspected relevant changed code
Tests not run Windows run is author-reported
PS5 behavior not run Hardware and firmware not available

Findings

Blocking

None.

Non-blocking

None.

Sources

Reviewed core/libs/prx/libc/include/FileStream.hpp, core/libs/prx/libc/src/FileAndHeap.cpp, core/libs/prx/libc/src/Formatting.cpp, core/libs/prx/libc/src/RuntimeSupport.cpp, core/libs/prx/libc/src/StandardStreams.cpp, core/libs/tests/GuestStandardStreams.cpp, and docs/dev/debt/changes/fix-libc-fdopen-bad-descriptor.md. The diff and review manifest were also read. No changed files were excluded; source files were read in targeted ranges, not in full.

Not verified

The PS5 firmware 13.60 behavior described in the PR and the Windows test run were not independently verified. Other host platforms and actual console behavior were not tested.

To get this to a good state

Nothing is required. Optional: verify the reported behavior on PS5 firmware 13.60 and run the changed test on the pinned head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5995769288 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24406#pullrequestreview-5995769288). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T16:14:13Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this change based on the code inspected; console behavior and the author-reported test run were not independently verified. ## What I ran Reviewed head `c9dc2ca64247d55082120f863a202275bf2c7d25`. No commands or tests were run; the review reader provided the prepared diff and pinned source. ## Results | Check | Result | Note | |---|---|---| | Changed-code review | passed | Inspected relevant changed code | | Tests | not run | Windows run is author-reported | | PS5 behavior | not run | Hardware and firmware not available | ## Findings ### Blocking None. ### Non-blocking None. ## Sources Reviewed `core/libs/prx/libc/include/FileStream.hpp`, `core/libs/prx/libc/src/FileAndHeap.cpp`, `core/libs/prx/libc/src/Formatting.cpp`, `core/libs/prx/libc/src/RuntimeSupport.cpp`, `core/libs/prx/libc/src/StandardStreams.cpp`, `core/libs/tests/GuestStandardStreams.cpp`, and `docs/dev/debt/changes/fix-libc-fdopen-bad-descriptor.md`. The diff and review manifest were also read. No changed files were excluded; source files were read in targeted ranges, not in full. ## Not verified The PS5 firmware 13.60 behavior described in the PR and the Windows test run were not independently verified. Other host platforms and actual console behavior were not tested. ## To get this to a good state Nothing is required. Optional: verify the reported behavior on PS5 firmware 13.60 and run the changed test on the pinned head.

Pull request closed

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!24406
No description provided.