fix(libc): return native fopen errors #4822

Merged
MarcZX10 merged 2 commits from upstream-pr/4822 into main 2026-10-14 02:36:12 +00:00
MarcZX10 commented 2026-10-12 22:56:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T22:56:32Z.


What

fopen_nid_postfix now returns nullptr and preserves the native errno whenever the host cannot open the requested stream. Previously, failures other than ENOENT or exclusive-create EEXIST could turn into an uncaught exception after an extension lookup. This makes the Windows access-denied result for opening an existing directory follow fopen's failure contract.

Adds a regression that opens a directory in a mode that fails on each host (rb on Windows, wb on POSIX) and checks that the native error is retained. This does not claim that Windows directory streams behave like FreeBSD directory streams; the limitation is recorded in docs/dev/debt/libc.md.

Tested

  • Debian 12 x86-64, GCC 12.2, Release, BUILD_TESTING=ON: file_streams, guest_fiopen, guest_standard_streams, guest_directory, and guest_filesystem pass (5/5).
  • tools/check_conventions.py --base upstream/main and git diff --check upstream/main...HEAD pass.
  • No Windows build or title run was available locally; the Windows-specific rb directory case is included for hosted Windows CI.

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
  • Unblocks: PPSA99902 #4443
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4835962087 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4822). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T22:56:32Z. --- ### What `fopen_nid_postfix` now returns `nullptr` and preserves the native `errno` whenever the host cannot open the requested stream. Previously, failures other than `ENOENT` or exclusive-create `EEXIST` could turn into an uncaught exception after an extension lookup. This makes the Windows access-denied result for opening an existing directory follow `fopen`'s failure contract. Adds a regression that opens a directory in a mode that fails on each host (`rb` on Windows, `wb` on POSIX) and checks that the native error is retained. This does not claim that Windows directory streams behave like FreeBSD directory streams; the limitation is recorded in `docs/dev/debt/libc.md`. ### Tested - Debian 12 x86-64, GCC 12.2, Release, `BUILD_TESTING=ON`: `file_streams`, `guest_fiopen`, `guest_standard_streams`, `guest_directory`, and `guest_filesystem` pass (5/5). - `tools/check_conventions.py --base upstream/main` and `git diff --check upstream/main...HEAD` pass. - No Windows build or title run was available locally; the Windows-specific `rb` directory case is included for hosted Windows CI. ### 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] Unblocks: PPSA99902 #4443 - [x] AI-assisted: yes
MarcZX10 commented 2026-10-12 23:00:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T23:00:11Z.


Additional validation: MinGW-w64 GCC 12 -Wall -Wextra -Werror -fsyntax-only compilation passes for both FileAndHeap.cpp and the updated FileStreams.cpp. This is a Windows-target syntax check, not a runtime test; the hosted workflow currently builds only the relinker target.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6134249446 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4822#issuecomment-6134249446). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T23:00:11Z. --- Additional validation: MinGW-w64 GCC 12 `-Wall -Wextra -Werror -fsyntax-only` compilation passes for both `FileAndHeap.cpp` and the updated `FileStreams.cpp`. This is a Windows-target syntax check, not a runtime test; the hosted workflow currently builds only the relinker target.
Amoenus commented 2026-10-12 23:28:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-12T23:28:18Z.


Windows runtime validation of exact head 77ede919c460fbe1acbfe2bf4d927fb3db0a6416: all five groups ×20 pass (100 executions, no skips) — file_streams, guest_fiopen, guest_standard_streams, guest_directory, guest_filesystem. Observed individual durations: 0.01–0.35s. Windows 11 Enterprise 26200, WinLibs GCC15.2.0r7, Ninja Release / testing ON, bundled dependencies. The five native targets, conventions against pinned main 43e3a70f8, and diff checks pass.

For a Windows failing-main control, I kept your regression fixture unchanged and rebuilt only FileAndHeap.cpp from main 43e3a70f8143f014f621c48abbdb137fffd7346e. file_streams aborts with fopen_nid_postfix: open failed ... Permission denied, CTest exit 0xC0000409. Restoring your exact implementation gives the repeated passes above. The source and runtime are restored to your head; tracked source is clean. This verifies the Windows directory rb failure path retaining EACCES alongside existing positive stream controls.

ctest --test-dir <build> --parallel 1 --repeat until-fail:20 --timeout 30 --output-on-failure -R "^(file_streams|guest_fiopen|guest_standard_streams|guest_directory|guest_filesystem)$"

Full Windows build and patched system libraries of the same unchanged head now pass, along with conventions and test registration. Full NVIDIA suite: 1011 passed / 0 failed / 8 skipped of 1019, maximum observed test 22.808s (ctest --parallel 2 --timeout 30). RTX5080 / driver610.62; AnyPS5 shader cache disabled, driver-cache coldness unverified. Skips: agc_driver_stencil_ref_export, guest_video_out_high_frame_rate, video_out_flip_lifetime, video_out_flip_reopen, video_out_flip_controls, video_out_flip_overlay, video_out_flip_unopened, guest_video_out_wqhd_detection_no_vulkan. Conditional title comparison now completed: Sonic Unleashed Recompiled, PPSA99902 / 01.003.000, same fixed f609 conversion and frozen 6cc runtime. Fresh control aborts at the existing Inspire directory / fopen permission-denied exception after 10.126s. Replacing only libc.prx with the integration build of your exact FileAndHeap.cpp (retaining the game's private prerequisite exports) changes the observed abort to poll: descriptor 3 is not a socket / descriptor5 on another thread after 9.981s. All other123 runtime-library hashes and executable hash match. Both runs exit0xC0000409 with no frames or timeout; originals, runtime, converted guest and user data are restored/hash-verified. This removes the observed fopen exception from the replay; it does not establish rendering, gameplay or unchanged whole-main startup. The next poll guard is already tracked in #3521, with overlapping open #3644/#3649; a subsequent scalar observer confirms read pipes, and the #3644 kernel-only comparison now renders startup and reaches the existing private MSAA guard after789.240s, with originals/runtime/user data restored. This is still a conditional two-fix stack, not whole-main startup or gameplay. Title evidence and preserved-assets checks are maintained in #4814 and Game bring-up #4443. The template's Unblocks line can use PPSA99902 #4443 to link the required bring-up discussion, keeping #4814 as the issue reference. AI-assisted: Codex; author responsible.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6134583756 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4822#issuecomment-6134583756). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-12T23:28:18Z. --- Windows runtime validation of exact head `77ede919c460fbe1acbfe2bf4d927fb3db0a6416`: **all five groups ×20 pass (100 executions, no skips)** — `file_streams`, `guest_fiopen`, `guest_standard_streams`, `guest_directory`, `guest_filesystem`. Observed individual durations: 0.01–0.35s. Windows 11 Enterprise 26200, WinLibs GCC15.2.0r7, Ninja Release / testing ON, bundled dependencies. The five native targets, conventions against pinned main `43e3a70f8`, and diff checks pass. For a Windows failing-main control, I kept your regression fixture unchanged and rebuilt only `FileAndHeap.cpp` from main `43e3a70f8143f014f621c48abbdb137fffd7346e`. `file_streams` aborts with `fopen_nid_postfix: open failed ... Permission denied`, CTest exit `0xC0000409`. Restoring your exact implementation gives the repeated passes above. The source and runtime are restored to your head; tracked source is clean. This verifies the Windows directory `rb` failure path retaining EACCES alongside existing positive stream controls. ```text ctest --test-dir <build> --parallel 1 --repeat until-fail:20 --timeout 30 --output-on-failure -R "^(file_streams|guest_fiopen|guest_standard_streams|guest_directory|guest_filesystem)$" ``` Full Windows build and patched system libraries of the same unchanged head now pass, along with conventions and test registration. **Full NVIDIA suite: 1011 passed / 0 failed / 8 skipped of 1019**, maximum observed test 22.808s (`ctest --parallel 2 --timeout 30`). RTX5080 / driver610.62; AnyPS5 shader cache disabled, driver-cache coldness unverified. Skips: `agc_driver_stencil_ref_export`, `guest_video_out_high_frame_rate`, `video_out_flip_lifetime`, `video_out_flip_reopen`, `video_out_flip_controls`, `video_out_flip_overlay`, `video_out_flip_unopened`, `guest_video_out_wqhd_detection_no_vulkan`. **Conditional title comparison now completed:** Sonic Unleashed Recompiled, PPSA99902 / 01.003.000, same fixed f609 conversion and frozen 6cc runtime. Fresh control aborts at the existing `Inspire` directory / `fopen` permission-denied exception after 10.126s. Replacing **only libc.prx** with the integration build of your exact `FileAndHeap.cpp` (retaining the game's private prerequisite exports) changes the observed abort to `poll: descriptor 3 is not a socket` / descriptor5 on another thread after 9.981s. All other123 runtime-library hashes and executable hash match. Both runs exit0xC0000409 with no frames or timeout; originals, runtime, converted guest and user data are restored/hash-verified. This removes the observed fopen exception from the replay; it does not establish rendering, gameplay or unchanged whole-main startup. The next poll guard is already tracked in [#3521](https://github.com/boykopovar/AnyPS5/issues/3521), with overlapping open #3644/#3649; a subsequent scalar observer confirms read pipes, and [the #3644 kernel-only comparison](https://github.com/boykopovar/AnyPS5/pull/3644#issuecomment-6135121778) now renders startup and reaches the existing private MSAA guard after789.240s, with originals/runtime/user data restored. This is still a conditional two-fix stack, not whole-main startup or gameplay. Title evidence and preserved-assets checks are maintained in [#4814](https://github.com/boykopovar/AnyPS5/issues/4814) and [Game bring-up #4443](https://github.com/boykopovar/AnyPS5/discussions/4443). The template's `Unblocks` line can use `PPSA99902 #4443` to link the required bring-up discussion, keeping #4814 as the issue reference. AI-assisted: Codex; author responsible.
oneandonlydean commented 2026-10-13 02:43:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T02:43:07Z.


Please add a docs/dev/debt/libc.md entry: on Windows fopen of a directory in a read mode fails with EACCES, where FreeBSD opens it. The description says this isn't claimed to match; the debt file should say it too, since that is the call PPSA99902 makes.

Unblocks should name the bring-up discussion (PPSA99902 #4443). Then this can go in.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6137039879 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4822#issuecomment-6137039879). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T02:43:07Z. --- Please add a `docs/dev/debt/libc.md` entry: on Windows `fopen` of a directory in a read mode fails with `EACCES`, where FreeBSD opens it. The description says this isn't claimed to match; the debt file should say it too, since that is the call PPSA99902 makes. `Unblocks` should name the bring-up discussion (`PPSA99902 #4443`). Then this can go in.
MarcZX10 commented 2026-10-13 03:12:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T03:12:24Z.


Addressed the review points: docs/dev/debt/libc.md now records that Windows fopen of a directory in a read mode fails with EACCES, while FreeBSD opens it; the PR checklist now links Unblocks: PPSA99902 #4443. I also rebased the PR onto current main. The updated head passes tools/check_conventions.py --base upstream/main and git diff --check; the previously reported Windows and Linux validation remains on the code unchanged by this follow-up.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6137363130 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4822#issuecomment-6137363130). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T03:12:24Z. --- Addressed the review points: `docs/dev/debt/libc.md` now records that Windows `fopen` of a directory in a read mode fails with `EACCES`, while FreeBSD opens it; the PR checklist now links `Unblocks: PPSA99902 #4443`. I also rebased the PR onto current `main`. The updated head passes `tools/check_conventions.py --base upstream/main` and `git diff --check`; the previously reported Windows and Linux validation remains on the code unchanged by this follow-up.
nicolasfalesy commented 2026-10-13 07:24:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T07:24:55Z.


Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto main 7e181fcc3 together with #4927, #4903, #4877, #4822 and #4823 (no conflicts): file_streams passes. With this PR's source change reverted (test kept), file_streams fails on Linux, so the check guards the change on Linux too.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140513038 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4822#issuecomment-6140513038). Originally posted by [nicolasfalesy](https://github.com/nicolasfalesy) on 2026-10-13T07:24:55Z. --- Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto `main` 7e181fcc3 together with #4927, #4903, #4877, #4822 and #4823 (no conflicts): `file_streams` passes. With this PR's source change reverted (test kept), `file_streams` fails on Linux, so the check guards the change on Linux too.
MarcZX10 commented 2026-10-13 07:44:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T07:44:15Z.


Rebased again onto current main after the debt-file conflict returned; the updated debt entry retains the current unwind note and records the Windows directory-read EACCES behavior. The checklist still links PPSA99902 #4443, and the rebased patch passes git diff --check. Thanks for the Linux control run: it shows file_streams fails when this PR’s source change is reverted while its regression test is kept, and passes with the implementation included. That is useful Linux-side regression evidence; the Windows runtime and title results above remain attributed to their reported heads/stacks.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140809070 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4822#issuecomment-6140809070). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T07:44:15Z. --- Rebased again onto current `main` after the debt-file conflict returned; the updated debt entry retains the current unwind note and records the Windows directory-read `EACCES` behavior. The checklist still links `PPSA99902 #4443`, and the rebased patch passes `git diff --check`. Thanks for the Linux control run: it shows `file_streams` fails when this PR’s source change is reverted while its regression test is kept, and passes with the implementation included. That is useful Linux-side regression evidence; the Windows runtime and title results above remain attributed to their reported heads/stacks.
github-actions[bot] commented 2026-10-13 09:25:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T09:25:39Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5033 docs/dev/debt/libc.md L47
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142482039 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4822#issuecomment-6142482039). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T09:25:39Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5033 | `docs/dev/debt/libc.md` [L47](https://github.com/boykopovar/AnyPS5/blob/0df6e295c52e7cd6afa394ed35513bd252045c74/docs/dev/debt/libc.md#L47) | | |
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!4822
No description provided.