fix(libs): share Windows flock state between duplicated descriptors #4516
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4516"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-12T14:09:33Z.
What
On Windows,
flockkept its state per descriptor. Afterdup,dup2orF_DUPFD,LOCK_UNthrough the copy returned success but left the file locked, and a repeated exclusive lock through the copy returnedEWOULDBLOCKor waited on its own lock.fclosealso left stale state behind: a new file reusing that descriptor could report a successful lock without acquiring one.Share one lock state between descriptor aliases and serialize its transitions. Keep independent opens separate and discard a descriptor's reference when it is closed or its stream is reopened, including a failed
freopen. The shared owner lives in libc so both stdio and libkernel can reach it; the existing libkernel helpers delegate to it. Blocking lock calls hold only that open file description's mutex. The Linux path continues to use the host'sflock.Six Windows regression cases cover duplication before and after acquisition, alias chains, last-close release, descriptor reuse,
dup2replacement, repeated locking, shared/exclusive conversions and failed upgrades, concurrent callers, independent blocking waits,fdopen,fclose, successful and failedfreopen, and contention between separate processes. The helper exports use_nid_no_patch.Tested
Windows, Release, supported WinLibs MinGW-w64 GCC 15.2.0 (
x86_64-ucrt-posix-seh, r7). No title-specific run.cmake --build build-runtime --parallel 8.ctest --test-dir build-runtime --output-on-failure --parallel 4 --timeout 120; 967 passed, 7 expected skips, 0 failures across 974 registered tests.tools/check_skips.py --job windows,tools/check_test_registration.py,tools/check_conventions.py --base origin/main, andtools/pr_overlap.py --branch HEAD --repo boykopovar/AnyPS5passed. No overlap with open pull requests.Validation for this PR is limited to the Windows runtime. Full Linux runtime build and tests were not run and are not planned for this PR. The new lock manager and lifecycle hooks are guarded by
_WIN32; Linuxflockcontinues to use the host implementation.Checklist
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)Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T16:31:31Z.
Windows test: head
bd842bc7dmerged onto currentmaind592d54e1(clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release,-j2: full build 0 errors; ctest with the filterguest_file_lock: guest_file_lock_duplicate passed, guest_file_lock_lifetime passed, guest_file_lock_conversion passed, guest_file_lock_threads passed, guest_file_lock_streams passed, guest_file_lock_process passed (6 test(s), 0 failed);python tools/check_conventions.py --base upstream/mainpassed. I did not run the new tests againstmainwithout the change.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T16:40:51Z.
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.
main)docs/dev/TechnicalDebt.mdL726docs/dev/TechnicalDebt.mdL726docs/dev/TechnicalDebt.mdL726docs/dev/TechnicalDebt.mdL726docs/dev/TechnicalDebt.mdL726docs/dev/TechnicalDebt.mdL726docs/dev/TechnicalDebt.mdL726docs/dev/TechnicalDebt.mdL726docs/dev/TechnicalDebt.mdL726docs/dev/TechnicalDebt.mdL726docs/dev/TechnicalDebt.mdL726core/libs/prx/libc/include/FileStream.hppL14, L78-79docs/dev/TechnicalDebt.mdL726