fix(libkernel): return errors from file operation failures #2620
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2620"
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 oneandonlydean on 2026-10-10T08:28:48Z.
Carrying @justdoston's fix for #2423 while PR intake is paused. The change is theirs (from
justdoston/AnyPS5:fix/windows-file-operation-errors, 7c706c88).What
sceKernelPread/sceKernelPwriteget the Linux build's checks andSceErrorFromErrnoreturns. A zero-length transfer with a null buffer returns 0.NativePositionedreportsERROR_ACCESS_DENIEDasEBADF(apreadon anO_WRONLYdescriptor isEBADFon FreeBSD and Linux too); other failures stayEIO. The file-pointer handling is unchanged.ftruncatereturnsEINVALfor a negative length and for a descriptor without write access, and passes other host errors to the guest.sceKernelFtruncatereturns the kernel error.Why
On Windows these calls wrapped the POSIX functions, which throw on every failure, so the guest process aborted with
terminate called after throwing ... std::runtime_error(for examplepread failed, fd=9999, errno=9) where Linux returns an error. Measured on Windows 11 in the issue:sceKernelPread(9999, buf, 4, 0)0x80020009sceKernelPwrite(9999, buf, 4, 0)0x80020009sceKernelPread(fd, buf, 4, -1)0x80020016sceKernelPread(fd, NULL, 0, 0)0sceKernelPwriteonO_RDONLY0x80020009sceKernelFtruncate(9999, 0)0x80020009sceKernelFtruncateonO_RDONLY0x80020016ftruncatethrew on host failures on both platforms.Tested
guest_file_vectorchecks every case in the table, and runs on Windows too.ctest, no new failures; Windows cross-compiled with MinGW-w64 GCC 16 and checked under Wine 10.0.guest_file_vectorpasses on a fresh Release build of 7c706c88.tools/check_conventions.pypasses, and the branch merges cleanly with currentmain.Fixes #2423
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 adriadam10 on 2026-10-10T08:50:31Z.
Checked on Linux: build and ctest green (80 tests in libkernel/libs),
guest_file_vectorpasses and fails when theStdio.cppchange is reverted. The Windows branches rely on the Windows 11 run by @sktharunbalaji13-cmd and the MinGW/Wine run; merging once CI is green.Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-10T09:25:49Z.
Since this landed,
mainfails two tests on Windows (Linux passes). Onmain3d1a7d90, merged with an unrelated libkernel change in my fork CI (run 38040339170), the Windows job reports 2 failed out of 698, and I get the same locally on plainmain(WinLibs GCC 15.2.0, Release):Both checks predate this PR and assumed the old Windows
sceKernelPread, which went throughpread_nid_postfix:GuestMemory.cpp:992(from676bbea3) expectssceKernelPread(fd, mapped, page, 0)into a page made read-only bysceKernelMprotectto throw. With this PR, Windows returns an error code instead, as Linux already did, sorefusedstays false. The check probably wants== SCE_KERNEL_ERROR_EFAULT(0x8002000E) now, or whatever the Linux path returns for that case.GuestFileVector.cpp:174(from #1777,/dev/urandom) expectssceKernelPread(random, noise + 32, 16, 1000) == 16. A direct probe on Windowsmain:sceKernelOpen("/dev/urandom")gives fd 3;sceKernelReadreturns 16;sceKernelPreadat offset 0 or 1000 returns0x8002001D(ESPIPE).The Windows path now goes through
NativePositioned_nid_no_patch, which refuses the positioned read on the random device. FreeBSD'spreadon a character device succeeds and ignores the offset, which is what the test (and Linux) expects.sceKernelPreadv(random, pieces, 1, 1000)on line 173 still passes, so the vector path already handles the device. Only the scalarsceKernelPreaddiffers.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-10T09:33:06Z.
A fix for both Windows failures @AchrafReyani describes above, ready to cherry-pick:
LeandroLP23:fix/windows-pread-tests(5f80f12d, one commit onmain42542127, merges cleanly onto currentmain). I can't open it as a PR while intake is limited.Stdio.cpp(+1 line): the WindowssceKernelPreadnow reads the random devices first withFile::ReadRandomDevice, at the same point as the Linux version. Without it, a positioned read of/dev/urandomreachedNativePositionedand failed withESPIPE(GuestFileVector.cpp:174).GuestMemory.cpp: the Windows-only check at line 992 expectedsceKernelPreadinto a page made read-only bysceKernelMprotectto throw. Since this PR it returns an SCE error instead, so the check now requiresSCE_KERNEL_ERROR_EFAULT, the same result the AIO read of that page two lines below already expects. No production change for this one.Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release:
guest_memoryandguest_file_vectorpass 3/3 (both fail on plainmain), the full non-GPU ctest passes (449/449), conventions pass.AI-assisted: yes (Claude Code).