libc: ftrylockfile is absent (Porpoise, RetroArch); fix branch ready #3548

Closed
opened 2026-10-11 13:00:49 +00:00 by screamm · 1 comment
screamm commented 2026-10-11 13:00:49 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-11T13:00:49Z.


libc (libSceLibcInternal) does not export ftrylockfile (NID h05OHOMZNMw) while flockfile/funlockfile are merged (#3081). From the relink registry order it is the predicted next stop of Porpoise (PPSA99764, call site 0x8EC37) after its current pathconf stop, and RetroArch (PPSA99169, 0xA4A27) imports it; not yet observed in a run.

Fix branch ready: screamm:feat/libc-ftrylockfile (f54d933b, one commit on main a11c8f7f). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commit as is.

  • ftrylockfile(FILE*) in RuntimeSupport.cpp tries the same per-stream lock flockfile and every locking stdio call take (no second lock): 0 when acquired or already held by the caller (counted, so matching funlockfile calls are needed), -1 when another thread holds it, as FreeBSD 11.4 _flock_stub.c (8c639945); Linux uses glibc's ftrylockfile; Windows has no try variant of _lock_file, so it calls TryEnterCriticalSection on the lock object _lock_file enters, located through the UCRT stream layout (__crt_stdio_stream_data::_lock, identical in Windows SDK 10.0.19041, 10.0.22621 and 10.0.26100 sources). Null and closed streams throw. TechnicalDebt records what the lock protects and the UCRT layout dependency; the test would catch a layout change.
  • guest_standard_streams gains trylock on an unlocked stream and re-entrant by the owner, -1 from another thread while held and after one of two unlocks, an fputc from another thread blocking until the last unlock, -1 while flockfile holds it, and the null/closed throws; a deliberately broken trylock makes it abort.

Tested on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including libs: guest_standard_streams 3/3; ctest -j8 -E "^agc_driver_|^video_out_flip" 532/536, the failures being the known windows_exceptions (#3411), guest_kernel_sys (symlink: Function not implemented, #3491/#3510), guest_filesystem (directory time, #3518) and one agc_driver heap-corruption flake; with main's RuntimeSupport.cpp the extended test fails; tools/check_conventions.py --base main and git diff --check pass. Not run on Linux.

Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5801280355 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3548). Originally posted by [screamm](https://github.com/screamm) on 2026-10-11T13:00:49Z. --- libc (libSceLibcInternal) does not export `ftrylockfile` (NID `h05OHOMZNMw`) while `flockfile`/`funlockfile` are merged (#3081). From the relink registry order it is the predicted next stop of Porpoise (PPSA99764, call site 0x8EC37) after its current `pathconf` stop, and RetroArch (PPSA99169, 0xA4A27) imports it; not yet observed in a run. **Fix branch ready:** [`screamm:feat/libc-ftrylockfile`](https://github.com/screamm/AnyPS5/tree/feat/libc-ftrylockfile) (`f54d933b`, one commit on `main` `a11c8f7f`). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commit as is. - `ftrylockfile(FILE*)` in `RuntimeSupport.cpp` tries the same per-stream lock `flockfile` and every locking stdio call take (no second lock): 0 when acquired or already held by the caller (counted, so matching `funlockfile` calls are needed), -1 when another thread holds it, as FreeBSD 11.4 `_flock_stub.c` (`8c639945`); Linux uses glibc's `ftrylockfile`; Windows has no try variant of `_lock_file`, so it calls `TryEnterCriticalSection` on the lock object `_lock_file` enters, located through the UCRT stream layout (`__crt_stdio_stream_data::_lock`, identical in Windows SDK 10.0.19041, 10.0.22621 and 10.0.26100 sources). Null and closed streams throw. TechnicalDebt records what the lock protects and the UCRT layout dependency; the test would catch a layout change. - `guest_standard_streams` gains trylock on an unlocked stream and re-entrant by the owner, -1 from another thread while held and after one of two unlocks, an `fputc` from another thread blocking until the last unlock, -1 while `flockfile` holds it, and the null/closed throws; a deliberately broken trylock makes it abort. **Tested** on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including `libs`: `guest_standard_streams` 3/3; `ctest -j8 -E "^agc_driver_|^video_out_flip"` 532/536, the failures being the known `windows_exceptions` (#3411), `guest_kernel_sys` (`symlink: Function not implemented`, #3491/#3510), `guest_filesystem` (directory time, #3518) and one `agc_driver` heap-corruption flake; with `main`'s `RuntimeSupport.cpp` the extended test fails; `tools/check_conventions.py --base main` and `git diff --check` pass. Not run on Linux. Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).
blawesom commented 2026-10-11 14:01:56 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-11T14:01:56Z.


Independent verification on Linux (the gap noted in the report): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON.

  • The branch is already based on current main — no rebase needed, the commit (f54d933bd) is unchanged.
  • tools/check_conventions.py --base origin/main and git diff --check pass.
  • The stdio lock tests pass, including the new ftrylockfile cases.
  • Full suite: 832/832 passed (all tests including the Vulkan suites on AMD RX 9070 XT / RADV).

The branch is also mirrored at blawesom:verify/3548 for anyone carrying.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109818659 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3548#issuecomment-6109818659). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-11T14:01:56Z. --- Independent verification on **Linux** (the gap noted in the report): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`. - The branch is already based on current `main` — no rebase needed, the commit (`f54d933bd`) is unchanged. - `tools/check_conventions.py --base origin/main` and `git diff --check` pass. - The stdio lock tests pass, including the new ftrylockfile cases. - Full suite: **832/832 passed** (all tests including the Vulkan suites on AMD RX 9070 XT / RADV). The branch is also mirrored at [`blawesom:verify/3548`](https://github.com/blawesom/AnyPS5/tree/verify/3548) for anyone carrying.
Sign in to join this conversation.
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#3548
No description provided.