feat(libSceLibcInternal): implement __fflush #14872

Merged
heditrigui merged 6 commits from upstream-pr/14872 into main 2026-11-07 00:56:35 +00:00
heditrigui commented 2026-11-01 21:59:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by heditrigui on 2026-11-01T21:59:08Z.


What

Implements __fflush in libSceLibcInternal (core/libs/prx/libSceLibcInternal/Stream.cpp), replacing its inventory stub declaration in InventoryExports.cpp (libSceLibcInternalInventory_262_nid_no_patch):

  • __fflush (NID E1iwBYkG3CM): reuses fflush_nid_postfix(stream) rather than FreeBSD 11.4 libc's unlocked single-stream helper (fflush.c @8c639945a4): acquires stream locks and returns -1 with EBADF (9) on a closed stream (where FreeBSD returns 0 for a stream with 0 flags). Passing nullptr flushes all open streams and returns 0 when all writes succeed or EOF on write error.

Tested

  • Added unit tests in core/libs/tests/GuestLibcInternalStream.cpp (guest_libc_internal_stream_tests) verifying:
    • Writing to an open file stream and calling __fflush_nid_postfix(stream) flushes the payload to disk matching disk contents before calling fclose_nid_postfix.
    • Closing a stream via FileStream::Close() and calling __fflush_nid_postfix(&closedStream) fails returning -1 with errno == 9 (EBADF).
    • Multi-stream pending flush: opening concurrent streams (streamA and streamB), writing uncommitted payloads to both, and calling __fflush_nid_postfix(nullptr) commits both files' payloads to disk before fclose.
  • Ran python tools/check_conventions.py --base upstream/main --head HEAD (all conventions checks passed; 0 errors).
  • Ran python core/libs/tests/test_public_headers.py --audit-only (399 libraries, 26,744 exports checked; 0 errors).

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5111984007 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14872). Originally posted by [heditrigui](https://github.com/heditrigui) on 2026-11-01T21:59:08Z. --- ### What Implements `__fflush` in `libSceLibcInternal` (`core/libs/prx/libSceLibcInternal/Stream.cpp`), replacing its inventory stub declaration in `InventoryExports.cpp` (`libSceLibcInternalInventory_262_nid_no_patch`): - `__fflush` (NID `E1iwBYkG3CM`): reuses `fflush_nid_postfix(stream)` rather than FreeBSD 11.4 libc's unlocked single-stream helper (`fflush.c` @8c639945a4): acquires stream locks and returns -1 with `EBADF` (9) on a closed stream (where FreeBSD returns 0 for a stream with 0 flags). Passing `nullptr` flushes all open streams and returns 0 when all writes succeed or EOF on write error. ### Tested - Added unit tests in `core/libs/tests/GuestLibcInternalStream.cpp` (`guest_libc_internal_stream_tests`) verifying: - Writing to an open file stream and calling `__fflush_nid_postfix(stream)` flushes the payload to disk matching disk contents *before* calling `fclose_nid_postfix`. - Closing a stream via `FileStream::Close()` and calling `__fflush_nid_postfix(&closedStream)` fails returning `-1` with `errno == 9` (`EBADF`). - Multi-stream pending flush: opening concurrent streams (`streamA` and `streamB`), writing uncommitted payloads to both, and calling `__fflush_nid_postfix(nullptr)` commits both files' payloads to disk before `fclose`. - Ran `python tools/check_conventions.py --base upstream/main --head HEAD` (all conventions checks passed; 0 errors). - Ran `python core/libs/tests/test_public_headers.py --audit-only` (399 libraries, 26,744 exports checked; 0 errors). ### 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 - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!14872
No description provided.