sceKernelPread, sceKernelPwrite and sceKernelFtruncate abort the process on Windows instead of returning errors #2423
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 reyani-dev on 2026-10-09T19:13:24Z.
On Windows,
sceKernelPreadandsceKernelPwriteare thin wrappers over the POSIXpread_nid_postfix/pwrite_nid_disambig1_nid_postfix(core/libs/prx/libkernel/File/src/Stdio.cpp). Those throwstd::runtime_erroron every failure and on a null buffer. The exception can't cross the guest boundary, so the process aborts.The Linux build's
sceKernelPread/sceKernelPwrite(the#elsebranch) returnSceErrorFromErrno(...)instead. That means the same guest call returns an error code on Linux and kills the process on Windows.ftruncate_nid_postfix/sceKernelFtruncatethrow on any host failure on both platforms.Each case below was run in its own process against current
main(Windows 11, WinLibs GCC 15.2.0 r7). Every row aborted withterminate called after throwing ... std::runtime_error:sceKernelPread(9999, buf, 4, 0)pread failed, fd=9999, errno=90x80020009(EBADF)sceKernelPwrite(9999, buf, 4, 0)pwrite failed, fd=9999, errno=90x80020009sceKernelPread(fd, buf, 4, -1)invalid argument0x80020016(EINVAL)sceKernelPread(fd, NULL, 0, 0)(valid file)invalid argument0sceKernelPwriteon anO_RDONLYdescriptorpwrite failed, fd=3, errno=50x80020009(EBADF)sceKernelFtruncate(9999, 0)ftruncate failed, error=90x80020009sceKernelFtruncateon anO_RDONLYdescriptorftruncate failed, error=130x80020016(EINVAL on FreeBSD)The zero-length
preadwith a null buffer is valid and should return 0. Some engines probe a descriptor that way.A likely fix is to give the Windows
sceKernelPread/sceKernelPwritethe same early checks andSceErrorFromErrnoreturns as the Linux branch (NativePread/NativePwritealready exist for both platforms), and to havesceKernelFtruncatereturnSceErrorFromErrnoinstead of throwing. I haven't opened a PR for two reasons: #2170 rewrites every line of these functions (descriptor isolation), and intake is currently paused for my account. I'm happy to do it after #2170 lands, or for #2170's author to fold it in.AI-assisted: yes (the probe was written and run with Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by popeee99 on 2026-10-09T20:31:05Z.
Thanks @AchrafReyani for the original report, probes and suggested direction. I independently reproduced your findings on unchanged
main(8b393b6e) and prepared a proposed patch with additional regression coverage.The patch shares Linux's scalar kernel error-return paths with Windows, separates POSIX
ftruncateerrno handling from SCE results, and checks Windows handle access/type for the reported permission errors.These are assertion counts, not process runs. Baseline failures include the reported exceptions; the harness catches them rather than reproducing a game-process abort. Actual
libc/libkernelbuilds andguest_file_errors,guest_filesystem,guest_file_vectorpassed on both platforms (3/3 each). The Linux production-source ASan+UBSan regression passed without sanitizer diagnostics.Patch, reproduction commands, before/after logs and detailed limitations. Local fix commit:
8fc84d4a.No games, macOS, CI, full-emulator or NID-patched-runtime execution, concurrent-I/O validation, or disk-full/query/offset-restoration fault injection. Windows transfers over DWORD remain unsupported. #2029 is still open and modifies the same native helper; reconciliation is required and no combined-branch test is claimed. #2170 is closed without merging.
Sharing this as reproducible evidence for the existing issue, respecting paused PR intake; no PR opened. AI-assisted with OpenAI Codex.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T20:55:25Z.
I compared the proposed patch with the current #2029 head (
458e7e42). It cannot be applied as-is: itsNativePositionedhunk restores I/O on the shared descriptor and reintroduces the offset race that #2029 fixes. I tested a local integration that preservesReOpenFileand separate handles, converts Windows scalarsceKernelPread/sceKernelPwritefailures to SCE error returns, and separatessceKernelFtruncatefrom the POSIXftruncate_nid_postfixwrapper. Linuxlibkerneland the existingguest_positioned_ioCTest build/pass (1/1), but Windows behavior still needs the reporter’s Windows harness and exact-head CI. Since #2029’s branch is in another contributor’s fork, I have not pushed commits into their branch. Could you and the PR author coordinate permission/ownership for integrating the compatible parts into #2029? The patch also needs a small correction: in its WindowsNativeFtruncate,_chsize_sreturns an errno value directly, soerrnomust be set from that value before mapping it.Imported from boykopovar/AnyPS5. Originally posted by justdoston on 2026-10-10T06:03:15Z.
Since #2170 and #2029 were closed without merging, here is a version that applies to current
mainwithout touching descriptor isolation:Branch: https://github.com/justdoston/AnyPS5/tree/fix/windows-file-operation-errors
sceKernelPread/sceKernelPwriteget the Linux checks andSceErrorFromErrnoreturns; a zero-length transfer with a null buffer returns 0.NativePositionedreportsERROR_ACCESS_DENIEDasEBADFfor reads and writes (apreadon anO_WRONLYdescriptor isEBADFon FreeBSD and Linux too), other failures stayEIO. The file-pointer handling is unchanged frommain, so the race #2029 addressed is still there, as recorded in TechnicalDebt.ftruncatereturnsEINVALfor a negative length and for a descriptor without write access (_chsize_s'sEACCESis mapped, as @MarcZX100 noted it returns the error instead of settingerrno), and passes other host errors to the guest;sceKernelFtruncatereturns the kernel error.The table's cases are checked in
guest_file_vector, which also runs on Windows (guest_directory_entriesis Linux-only, so checks there never reach the Windows build).Tested: Linux full
ctest, no new failures. Not run on Windows: the files cross-compile with MinGW-w64 GCC 16, and under Wine 10.0 (UCRT)WriteFileon an_O_RDONLYandReadFileon an_O_WRONLYdescriptor fail withERROR_ACCESS_DENIED; Wine's_chsize_sdiffers from Windows 11 (EINVALinstead ofEACCES/EBADF), so theftruncatecases rely on your Windows measurements.AI-assisted: yes. OpenAI Codex wrote the first draft; an AI agent (Claude Code) did most of the work: the review, the fixes, the tests and this comment.
Imported from boykopovar/AnyPS5. Originally posted by sktharunbalaji13-cmd on 2026-10-10T07:21:29Z.
I validated
justdoston/fix/windows-file-operation-errorsat7c706c8822a0d353dacdaa615f5fd6c45effcc44on Windows 11 using WinLibs GCC 15.2.0.The focused
guest_file_vectortest passed (1/1, 0.16 s). I configured a fresh Release build, builtguest_file_vector_testsand itslibkernel.prxdependency, and confirmed the binaries were freshly built from this branch. The test exercises the new assertions for invalid descriptors, invalid offsets/lengths, buffer handling, permission errors, and file-content preservation.This was a focused Windows run against the branch's pinned base, not a full-suite run or a rebase onto current
main. I made no changes to the branch.