fix(libkernel): return EWOULDBLOCK from a contended LOCK_NB flock #1764
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1764"
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 Zurisen on 2026-10-08T18:41:54Z.
What
Fixes #1763.
flock_nid_postfixreturns -1 with guest errno 35 (EWOULDBLOCK) whenLOCK_NBis set and the host reports the lock as held:ERROR_LOCK_VIOLATIONon Windows,EWOULDBLOCKon Linux. This follows FreeBSDflock(2). Other failures still throw. As on FreeBSD, a failedLOCK_NBconversion leaves the descriptor without a lock.Builds on #1755 (merged): on Windows its per-descriptor lock state is what makes a contended request fail with
ERROR_LOCK_VIOLATIONand not with a stacked-lock error.Tested
Windows 11 (10.0.26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, RTX 4070 Laptop:
guest_filesystemgains contention cases on two descriptors of one file:LOCK_EX | LOCK_NBandLOCK_SH | LOCK_NBagainst an exclusive lock,LOCK_EX | LOCK_NBagainst a shared lock (all -1 with errno 35), shared locks on both descriptors, an exclusive lock once the other descriptor unlocks, andLOCK_SH | LOCK_EX | LOCK_NB | 0x10taking an exclusive lock (decoded as FreeBSD does in #1755), so a sharedLOCK_NBrequest from the other descriptor fails with errno 35.error=33); with it the cases pass.ctestwithANYPS5_REQUIRE_VULKAN=1 --repeat until-fail:3: 610/611 passed on6635c7ab.libstarget builds. The failure,pr_overlap_encoding, also fails on main locally: it patchessubprocess._text_encoding, which Python 3.10 does not have.guest_filesystemon Ubuntu 24.04 (comment below) before the combined-operation case was added.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 MarcZX10 on 2026-10-08T20:58:55Z.
Current-main check: this branch is 21 commits behind
main0447793. CONTRIBUTING asks PR branches to stay based on currentmain; please rebase the dependent change while preservingDepends on #1755. No checks are currently reported on this head, so the rebase should also give us a check result for this PR.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T21:36:06Z.
Update:
mainhas since advanced from0447793through364a56btoaa258760(#1826). This dependent branch remains based on an older main; when rebasing, please keepDepends on #1755. The364a56bbaseline Build was cancelled before Linux CTest, and a new baseline run is in progress onaa258760.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T21:55:34Z.
Current-base update: this dependent branch is 30 commits behind
main94b1eecb(merge base4ddbf049). The latest-main Build is green, including the buffer-format test; please rebase while preservingDepends on #1755and rerun checks on the final head.Imported from boykopovar/AnyPS5. Originally posted by nauroth on 2026-10-09T11:46:48Z.
Linux run, since the description says it wasn't run there: Ubuntu 24.04, GCC 13.3.0, glibc 2.39, Release. The two commits apply as one clean diff onto current main (
d70b899), so the rebase should be painless, andguest_filesystempasses 3/3 with--repeat until-fail:3, including the new contention block (EWOULDBLOCK= 35 on both the exclusive and shared non-blocking requests while the other descriptor holds the lock).I also compared the Windows tracking with FreeBSD's
sys_flock:LOCK_UNwith nothing held succeeding, and an upgrade or downgrade being a release followed by a new acquire (with the documented window in between), both match. One difference that doesn't matter in practice: for an operation with none ofLOCK_SH|LOCK_EX|LOCK_UN, FreeBSD returnsEBADFand LinuxEINVAL;File::FlockpicksEINVAL, butflock_nid_postfixthrows on anything except theLOCK_NBcontention anyway, so the two hosts stay consistent.Imported from boykopovar/AnyPS5. Originally posted by Zurisen on 2026-10-09T16:22:18Z.
@nauroth Thanks for the Linux run and the
sys_flockcomparison. TheEBADF/EINVALdifference is settled in #1755 (e9f28257):flock_nid_postfixnow decodes the operation assys_flockdoes, so an operation without a lock type fails withEBADFon both hosts. This branch adds a contention case for the decoding:LOCK_SH | LOCK_EX | LOCK_NB | 0x10takes an exclusive lock, and a sharedLOCK_NBrequest from the other descriptor fails with 35.@MarcZX100 Rebased onto
d70b8998on top of the updated #1755, keepingDepends on #1755; 506/507 pass locally on Windows (pr_overlap_encodingalso fails on main with Python 3.10).Imported from boykopovar/AnyPS5. Originally posted by Rohan03x on 2026-10-10T01:13:14Z.
Tested on Windows with Palworld (PPSA23126, v01.102.999). Windows 11 22621, GCC 15.2.0 UCRT Release, this PR (a61c8792) merged onto main
1f0c9fefplus local unimplemented-export declarations the title needs to start.Before (main): start-up aborts in sentry-native's lock handling: a second open of
/temp0/.sentry-native/<uuid>.run.lock, thenflock_nid_postfix: flock failed, fd=5, error=33.After: no flock error; start-up continues (engine threads, GPU init, settings file written) and stops later on unrelated problems. ctest: 0 failed of 559, 3 skipped, same as main.
Limits: one title; that the call uses
LOCK_NBis inferred from error 33, not observed. AI-assisted: yes.Imported from boykopovar/AnyPS5. Originally posted by Zurisen on 2026-10-10T04:58:43Z.
Rebased onto
bc40a6b5on top of the updated #1755, keepingDepends on #1755. Full suite locally on Windows: 605/606; the failure ispr_overlap_encoding, which also fails on main with Python 3.10.Imported from boykopovar/AnyPS5. Originally posted by Zurisen on 2026-10-10T06:00:57Z.
#1755 is merged, so this is rebased onto
6635c7aband now holds only its own two commits. Full suite locally on Windows: 610/611; the failure ispr_overlap_encoding, which also fails on main with Python 3.10.