feat(libc): implement ftrylockfile #3564

Merged
Aathish-D merged 1 commit from upstream-pr/3564 into main 2026-10-11 21:34:01 +00:00
Aathish-D commented 2026-10-11 13:16:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aathish-D on 2026-10-11T13:16:53Z.


What

Implement ftrylockfile (NID h05OHOMZNMw) in libc. Resolves #3548.

Porpoise (PPSA99764) stops after pthread_attr_* (#3494) with the predicted:

FAIL: unresolved ELF import h05OHOMZNMw from libSceLibcInternal.prx

(idx 311, call site 0x8EC37); RetroArch (PPSA99169) imports it at idx 448 (call site 0xA4A27).

ftrylockfile tries the same host CRT stream lock that flockfile, funlockfile and every locking host stdio call on the stream take. It returns 0 when acquired or already owned by the caller, and -1 when another thread holds it, following FreeBSD 11.4 _flock_stub.c (8c639945). Linux calls glibc ftrylockfile; Windows calls TryEnterCriticalSection on the UCRT stream lock (__crt_stdio_stream_data::_lock). Null or closed streams throw. Recorded in TechnicalDebt.md.

Carried from @screamm's branch referenced in #3548.

Tested

Linux (x86_64, GCC 15, Ninja, Release), full build with libs:

  • ctest --test-dir build -R "^guest_standard_streams$" --output-on-failure passed (0.16 s)
  • python3 tools/check_conventions.py --base upstream/main passed
  • python3 tools/check_test_registration.py build passed (647 tests registered)
  • Checked readelf -s build/core/libs/libs/libc.prx exports h05OHOMZNMw

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
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4819329978 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3564). Originally posted by [Aathish-D](https://github.com/Aathish-D) on 2026-10-11T13:16:53Z. --- ### What Implement `ftrylockfile` (NID `h05OHOMZNMw`) in `libc`. Resolves #3548. Porpoise (PPSA99764) stops after `pthread_attr_*` (#3494) with the predicted: FAIL: unresolved ELF import h05OHOMZNMw from libSceLibcInternal.prx (idx 311, call site 0x8EC37); RetroArch (PPSA99169) imports it at idx 448 (call site 0xA4A27). `ftrylockfile` tries the same host CRT stream lock that `flockfile`, `funlockfile` and every locking host stdio call on the stream take. It returns `0` when acquired or already owned by the caller, and `-1` when another thread holds it, following FreeBSD 11.4 `_flock_stub.c` (`8c639945`). Linux calls glibc `ftrylockfile`; Windows calls `TryEnterCriticalSection` on the UCRT stream lock (`__crt_stdio_stream_data::_lock`). Null or closed streams throw. Recorded in `TechnicalDebt.md`. Carried from @screamm's branch referenced in #3548. ### Tested Linux (x86_64, GCC 15, Ninja, Release), full build with `libs`: - `ctest --test-dir build -R "^guest_standard_streams$" --output-on-failure` passed (0.16 s) - `python3 tools/check_conventions.py --base upstream/main` passed - `python3 tools/check_test_registration.py build` passed (647 tests registered) - Checked `readelf -s build/core/libs/libs/libc.prx` exports `h05OHOMZNMw` ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
github-actions[bot] commented 2026-10-11 13:29:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T13:29:08Z.


Progress report (a11c8f7 → 9c7aa0d)

📈 System libraries: 85.82% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libc ftrylockfile_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109531534 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3564#issuecomment-6109531534). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T13:29:08Z. --- <!-- progress-report --> ### Progress report (a11c8f7 → 9c7aa0d) 📈 **System libraries**: 85.82% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `ftrylockfile_nid_postfix` | </details>
adriadam10 commented 2026-10-11 21:33:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:33:57Z.


Checked build and ctest on Linux (guest_standard_streams passes, and fails to link without the change), ftrylockfile semantics against FreeBSD _flock_stub.c, TechnicalDebt entry, no overlap with #3527/#3412; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114021901 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3564#issuecomment-6114021901). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:33:57Z. --- Checked build and ctest on Linux (`guest_standard_streams` passes, and fails to link without the change), `ftrylockfile` semantics against FreeBSD `_flock_stub.c`, TechnicalDebt entry, no overlap with #3527/#3412; merging.
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!3564
No description provided.