Repository navigation
feat(libc): implement ftrylockfile - #3564
Merged
Merged
Conversation
Porpoise PPSA99764 stops after pthread_attr_* (boykopovar#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). h05OHOMZNMw is ftrylockfile by tools/nid_names.py and aerolib.csv (zecoxao/sce_symbols 2883963a); ps5-payload-dev/sdk f5d40f02 declares `int ftrylockfile(FILE *)` in include/freebsd/stdio.h. ftrylockfile tries the same host CRT stream lock that flockfile, funlockfile and every locking host stdio call on the stream take, so no second lock exists beside the one stdio uses. It returns 0 when the lock is acquired or already owned by the caller (recursive, released by as many funlockfile calls) and -1 when another thread holds it, as FreeBSD 8c639945 lib/libc/stdio/_flock_stub.c:89-104 does. Linux calls glibc ftrylockfile. UCRT has no try variant of _lock_file, so Windows calls TryEnterCriticalSection on the CRITICAL_SECTION that _lock_file enters (__crt_stdio_stream_data::_lock, ucrt/inc/corecrt_internal_stdio.h, same layout in Windows SDK 10.0.19041, 10.0.22621 and 10.0.26100). A null or closed stream throws. The UCRT layout dependency is recorded in TechnicalDebt. guest_standard_streams covers trylock on an unlocked stream, re-entry by the owner, failure from another thread while held (also after one of two unlocks and while another thread holds flockfile), stdio calls from another thread blocking on the trylock-held lock, release order, and null and closed streams. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
9 tasks done
10 tasks done
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Implement
ftrylockfile(NIDh05OHOMZNMw) inlibc. 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).
ftrylockfiletries the same host CRT stream lock thatflockfile,funlockfileand every locking host stdio call on the stream take. It returns0when acquired or already owned by the caller, and-1when another thread holds it, following FreeBSD 11.4_flock_stub.c(8c639945). Linux calls glibcftrylockfile; Windows callsTryEnterCriticalSectionon the UCRT stream lock (__crt_stdio_stream_data::_lock). Null or closed streams throw. Recorded inTechnicalDebt.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-failurepassed (0.16 s)python3 tools/check_conventions.py --base upstream/mainpassedpython3 tools/check_test_registration.py buildpassed (647 tests registered)readelf -s build/core/libs/libs/libc.prxexportsh05OHOMZNMwChecklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)