fix(libkernel): fail lseek on a pipe with ESPIPE on Windows #4672

Merged
milescoviello merged 1 commit from upstream-pr/4672 into main 2026-10-13 15:13:36 +00:00
milescoviello commented 2026-10-12 18:27:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-12T18:27:00Z.


What

Fixes #4670. Carries @DavidSamir's fix branch from that issue (DavidSamir:fix/libkernel-lseek-pipe-windows, 32f49a97), keeping the commit and its authorship; it is cherry-picked onto current main, with the declaration conflict #4536 left in GuestFilesystem.cpp resolved by keeping both.

On Windows, lseek and sceKernelLseek succeeded on a pipe and returned a position, and with SEEK_END the number of bytes waiting in it, because NativeLseek calls _lseeki64 and Windows accepts a position on a pipe handle. FreeBSD's lseek(2) fails with ESPIPE when the descriptor "is associated with a pipe, socket, or FIFO", and the Linux build already does. Windows NativeLseek now makes the same _lseeki64 call, so a closed or invalid descriptor fails as before, and then returns ESPIPE when the handle's type is FILE_TYPE_PIPE. Linux is unchanged.

guest_filesystem checks both ends of a pipe: lseek fails with errno 29 and sceKernelLseek returns 0x8002001D for SEEK_SET, SEEK_CUR and SEEK_END, the bytes written before are read back unchanged, and after close lseek fails with errno 9.

Tested

  • From the issue: Windows 11, WinLibs MinGW-w64 GCC 15.2.0, Release: with main's Open.cpp the new checks fail and with the fix guest_filesystem passes 5/5; a 97-operation file probe differs in one line, lseek on a pipe; eleven catalog titles end the same way with both sets of libraries; full ctest 973/973. About 0.1 µs is added to each seek by the GetFileType call.
  • Linux, added for this carry: Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, rebased onto main 9df77462 after #4536 (which added a declaration next to this one in GuestFilesystem.cpp; both are kept). guest_filesystem, guest_kernel_fcntl, guest_dup and guest_poll pass, and all 310 guest_* tests pass. The new checks also pass with main's Open.cpp, as expected since only the Windows path changes. I could not run Windows myself.
  • tools/check_conventions.py --base upstream/main passes.

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
  • Unblocks: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4833431218 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4672). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-12T18:27:00Z. --- ### What Fixes #4670. Carries @DavidSamir's fix branch from that issue (`DavidSamir:fix/libkernel-lseek-pipe-windows`, `32f49a97`), keeping the commit and its authorship; it is cherry-picked onto current `main`, with the declaration conflict #4536 left in `GuestFilesystem.cpp` resolved by keeping both. On Windows, `lseek` and `sceKernelLseek` succeeded on a pipe and returned a position, and with `SEEK_END` the number of bytes waiting in it, because `NativeLseek` calls `_lseeki64` and Windows accepts a position on a pipe handle. FreeBSD's `lseek(2)` fails with `ESPIPE` when the descriptor "is associated with a pipe, socket, or FIFO", and the Linux build already does. Windows `NativeLseek` now makes the same `_lseeki64` call, so a closed or invalid descriptor fails as before, and then returns `ESPIPE` when the handle's type is `FILE_TYPE_PIPE`. Linux is unchanged. `guest_filesystem` checks both ends of a pipe: `lseek` fails with errno 29 and `sceKernelLseek` returns `0x8002001D` for `SEEK_SET`, `SEEK_CUR` and `SEEK_END`, the bytes written before are read back unchanged, and after `close` `lseek` fails with errno 9. ### Tested - From the issue: Windows 11, WinLibs MinGW-w64 GCC 15.2.0, Release: with `main`'s `Open.cpp` the new checks fail and with the fix `guest_filesystem` passes 5/5; a 97-operation file probe differs in one line, `lseek` on a pipe; eleven catalog titles end the same way with both sets of libraries; full `ctest` 973/973. About 0.1 µs is added to each seek by the `GetFileType` call. - Linux, added for this carry: Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, rebased onto `main` 9df77462 after #4536 (which added a declaration next to this one in `GuestFilesystem.cpp`; both are kept). `guest_filesystem`, `guest_kernel_fcntl`, `guest_dup` and `guest_poll` pass, and all 310 `guest_*` tests pass. The new checks also pass with `main`'s `Open.cpp`, as expected since only the Windows path changes. I could not run Windows myself. - `tools/check_conventions.py --base upstream/main` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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] Unblocks: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
adriadam10 commented 2026-10-13 14:56:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:56:17Z.


Checked on the PR merged onto current main: scoped build and ctest (147 tests, guest_filesystem included) pass; no conflicts with #4973 or #4992. The change is Windows-only, so Linux is unchanged. ESPIPE (29) matches the guest value used in Stdio.cpp. Windows behaviour is covered by the full Build; merging once it is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148428678 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4672#issuecomment-6148428678). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T14:56:17Z. --- Checked on the PR merged onto current main: scoped build and ctest (147 tests, `guest_filesystem` included) pass; no conflicts with #4973 or #4992. The change is Windows-only, so Linux is unchanged. `ESPIPE` (29) matches the guest value used in `Stdio.cpp`. Windows behaviour is covered by the full Build; merging once it is green.
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!4672
No description provided.