fix(libkernel): return guest errors from file resizing #2041
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2041"
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 STUPIDCONTEM on 2026-10-09T05:40:32Z.
Evidence review (2026-10-09)
Closed by maintainer; not ready to reopen. Required evidence: Title ID and a log showing the title stops at the file-resize throw. Existing throws are intentional pending that need.
Game/title ID: none verified. No PS5 title execution is claimed.
Deferred after maintainer review: reopening requires a title ID and a log showing execution stops at the existing throw. Synthetic error-path tests do not establish that requirement. See maintainer feedback. The patch and test results below are preserved as historical evidence; this change is excluded from the current proposed integration.
What
sceKernelFtruncateand POSIXftruncatethrew exceptions for ordinary invalid arguments and native failures. Return encoded kernel errors fromsceKernelFtruncate, preserving errno, and translate those results into-1plus guest errno in the POSIX wrapper.On Windows, check the original descriptor's object type and granted write access before
_chsize_s. This rejects read-only descriptors even when the requested size is unchanged, distinguishes invalid descriptors from non-regular files, and leaves genuine native resize failures intact. Open guest sockets return EINVAL; closed/invalid socket descriptors return EBADF. Successful resizing retains the existing host implementation.Error ordering and write-access requirements follow FreeBSD 11 kern_ftruncate and truncate(2). Windows uses documented NtQueryObject access information and _chsize_s. Linux already rejects read-only descriptors with EINVAL and retains its native ftruncate call.
Tested
Windows 10 Pro 19045, WinLibs GCC 15.2.0 UCRT/posix/SEH r7, Ninja Release, BUILD_TESTING=ON, SPIRV-Tools disabled. Based directly on
f145139676a48306681d3a4d5fabf83938759daf; independent of #2029 and #2030. An independent review checked the implementation and expanded the success cases.guest_file_resizefails against upstream with an unhandled invalid_argument exception for negative length.libsbuild passed.Linux and PS5 hardware/titles were not run. This change does not add concurrent resize guarantees or replace the existing host resize implementation. The open shm_open PR #1860 uses ftruncate but does not implement these functions.
Checklist
main; no other open PR implements the same change (historical base; current readiness not asserted)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T06:08:14Z.
Review: APPROVED
Reviewed the complete diff, including the Windows descriptor checks and guest/POSIX error translation. The regression exercises successful resize behavior and the invalid descriptor, length, file type, and access cases. I built the exact head on Linux with GCC 12; guest_file_resize passed (1/1), and conventions/diff checks pass. The PR description reports a full Windows suite pass; I could not independently reproduce Windows here. GitHub currently reports no upstream check results for this fork head.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T08:55:56Z.
Closing: on main these paths throw, which is allowed until a title needs the console's error codes. Reopen with the title ID and the log line if one stops at the throw.
Pull request closed