fix(libkernel): accept flock on a directory descriptor on Windows #9101

Merged
xXPBSXx merged 1 commit from upstream-pr/9101 into main 2026-10-22 17:42:04 +00:00
xXPBSXx commented 2026-10-21 12:17:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T12:17:36Z.


What

On Windows, flock on a directory descriptor aborted the process: the call reached LockFileEx, which rejects a directory handle, and flock_nid_postfix turned that into a runtime_error. FreeBSD 11.4's sys_flock accepts any vnode descriptor, so a directory succeeds. A directory descriptor now returns 0 without taking a lock. The debt entry says that no lock is held, so two descriptors of one directory never conflict. A bad how still fails with EBADF, a socket or pipe still with EOPNOTSUPP. Linux and macOS are unchanged (they use the host flock).

Tested

Windows 10 (19045), WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, on main 3e91c8edf5 plus this commit:

  • ctest -R '^guest_file_lock_directory$' passes 3 of 3; with Stdio.cpp restored to main (the new case kept) it fails 3 of 3 (exit code 0xc0000409).
  • ctest -R 'guest_file_lock|guest_filesystem$|guest_posix_filesystem|guest_kernel_fcntl|guest_dup|guest_append': 13 of 13 pass.
  • python tools/check_conventions.py --base upstream/main passes; git merge-tree against main is clean.
  • Not tested: Linux, macOS, a console, a title run.

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; silent stubs are listed in technical debt (the directory flock no-op is a debt entry in libkernel.md)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: #9100
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4951402992 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9101). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T12:17:36Z. --- ### What On Windows, `flock` on a directory descriptor aborted the process: the call reached `LockFileEx`, which rejects a directory handle, and `flock_nid_postfix` turned that into a `runtime_error`. FreeBSD 11.4's `sys_flock` accepts any vnode descriptor, so a directory succeeds. A directory descriptor now returns 0 without taking a lock. The debt entry says that no lock is held, so two descriptors of one directory never conflict. A bad `how` still fails with `EBADF`, a socket or pipe still with `EOPNOTSUPP`. Linux and macOS are unchanged (they use the host `flock`). ### Tested Windows 10 (19045), WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`, on `main` 3e91c8edf5 plus this commit: - `ctest -R '^guest_file_lock_directory$'` passes 3 of 3; with `Stdio.cpp` restored to `main` (the new case kept) it fails 3 of 3 (exit code `0xc0000409`). - `ctest -R 'guest_file_lock|guest_filesystem$|guest_posix_filesystem|guest_kernel_fcntl|guest_dup|guest_append'`: 13 of 13 pass. - `python tools/check_conventions.py --base upstream/main` passes; `git merge-tree` against `main` is clean. - Not tested: Linux, macOS, a console, a title run. ### 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 - [x] Unimplemented paths throw; silent stubs are listed in technical debt (the directory `flock` no-op is a debt entry in libkernel.md) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: #9100 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes AI-assisted (Claude Code).
cadenasynyster commented 2026-10-21 21:43:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-21T21:43:37Z.


Independent Windows run of this PR (head 0e2252f63), on Windows 11; the description's run is Windows 10.

Environment: Windows 11 10.0.26300, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7 (MinGW), Release, BUILD_TESTING=ON.

Results:

  • PR head: all 7 guest_file_lock* tests pass, 3/3 runs (--repeat until-fail:3), including guest_file_lock_directory.
  • Baseline: I kept the PR's tests and CMake and replaced only core/libs/prx/libkernel/File/src/Stdio.cpp with the merge-base version (3e91c8edf). guest_file_lock_directory fails with flock_nid_postfix: flock failed, fd=3, error=87 (ERROR_INVALID_PARAMETER from LockFileEx on the directory handle); the other 6 still pass. I restored the PR's file afterwards.

Not run: Linux/macOS, the wider selection in the description, the full repository CTest, and any title.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6327217151 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9101#issuecomment-6327217151). Originally posted by [cadenasynyster](https://github.com/cadenasynyster) on 2026-10-21T21:43:37Z. --- Independent Windows run of this PR (head 0e2252f63), on Windows 11; the description's run is Windows 10. **Environment:** Windows 11 10.0.26300, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7 (MinGW), Release, BUILD_TESTING=ON. **Results:** - PR head: all 7 `guest_file_lock*` tests pass, 3/3 runs (`--repeat until-fail:3`), including `guest_file_lock_directory`. - Baseline: I kept the PR's tests and CMake and replaced only `core/libs/prx/libkernel/File/src/Stdio.cpp` with the merge-base version (3e91c8edf). `guest_file_lock_directory` fails with `flock_nid_postfix: flock failed, fd=3, error=87` (`ERROR_INVALID_PARAMETER` from `LockFileEx` on the directory handle); the other 6 still pass. I restored the PR's file afterwards. **Not run:** Linux/macOS, the wider selection in the description, the full repository CTest, and any title. AI-assisted: yes
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!9101
No description provided.