fix(libkernel): append positioned writes on an O_APPEND descriptor on macOS #10543
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10543"
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 maximilianfv on 2026-10-24T09:18:18Z.
What
On macOS,
pwriteandpwritevwrite at the given offset even on a descriptor opened withO_APPEND. FreeBSD'svn_writeappends to anO_APPENDregular file whatever the offset and leaves the file offset unchanged, and Linuxpwriteappends too. A standalone C probe on macOS shows the difference: on anO_APPENDdescriptor,write"AAAA",pwrite"BB" at 0 andpwritev"CC" at 0 leave the file as "CCAA" with the offset at 4 (the probe printscontents=CCAA size=4 pos_after=4).This adds
File::WritevAtEnd(Apple only, declared next to the Windows-onlyWriteAtEnd). WhenFile::Appendsreports the descriptor appends andfstatsays it is a regular file, it saves the offset, writes withwritevand seeks back, keepingerrnofrom the write; otherwise it returns -2 and the caller falls through topwrite/pwritevas before. It is called from:NativePwriteinStdio.cpp(sceKernelPwrite,pwrite)sceKernelPwritev(and sopwritev)NativePwriteinAio.cpp(the AIO write commands)This is the macOS counterpart of #8359 (merged, Windows, by Evrim Cicek), whose checks in
guest_append_writesandguest_aiofail on macOS without it. The design follows #8359; no code is taken from it.Prior art: the closed whole-port PR #8658 by Himansh Raj (iamthehimansh) carried the same change for macOS in commit
f07439ee8d(2026-10-23, "fix(libkernel): append positioned writes on an O_APPEND file on macOS"), at the same three call sites withwritevand a seek back, and parts of this change match it closely, so Himansh Raj is credited as co-author on the commit. The differences: #8658 readsfcntl(F_GETFL)instead of the guest flag table (File::Appends), has no regular-file check, useswritein the AIO path, skips the seek back when the firstlseekfails, and adds no debt entry. #8658 was closed and split into smaller PRs; none of them, and no open PR, carries this change. #7201 does not touch these paths.POSIX has no positioned-transfer lock (
LockPositionedTransferexists only on Windows), so another thread seeking or transferring on the same or a duplicated descriptor between the write and the seek back can see the end-of-file offset or have its own seek undone. The new entry indocs/dev/debt/libkernel.mdrecords this.Tested
Apple M1 Pro, macOS 27.0.1, x86_64 build under Rosetta 2.
mainalone does not build on macOS, so this was tested in a tree made of mugurc's macOS series merged withmainat1e20650e84, plus the macOS build parts of #10419 and other macOS build and test fixes that are not yet PRs. Only this change was toggled between the two runs.ctestof 14 file I/O tests:guest_append_writes,guest_aio,guest_kernel_sys_aio,file_position,guest_file_vector,guest_file_vector_memory,guest_append_streams,guest_posix_filesystem,guest_sendfile,guest_standard_streams,file_streams,guest_host_streams,file_identity,guest_filesystem.guest_append_writesaborts with "append check failed at line 94" andguest_aiowith "Aio check failed at line 413";guest_standard_streamsandguest_filesystemabort.guest_append_writesandguest_aiopass;guest_standard_streamsandguest_filesystemstill abort at the same places.The two remaining failures are separate macOS gaps this PR does not touch, and they fail the same way with and without it:
guest_standard_streamsstops at "fflush of a "r" stream that is reading changed the data read next"; the open #8920 (tkcm01) addresses this.guest_filesystemstops atGuestFilesystem.cpp:884(rename onto a dangling symbolic link), located with lldb on a-O0build in both states; the open #9911 (tkcm01) addresses this.Not tested on Linux or Windows. Their code paths are unchanged: all new code is under
__APPLE__.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T10:41:05Z.
Review: APPROVED
Reviewed
WritevAtEndand its call sites in regular positioned writes, vector writes, and AIO. The fallback is limited to descriptors marked append and regular files; it preserves the write error and avoids writing when it cannot save the current offset. I also checked the shared-path overlap with #10552: this PR provides the more complete helper and its regular-file/seekability guards, so #10552 should reuse or coordinate with it. The known race with concurrent offset-changing operations is explicitly recorded in the debt entry; this approval is for the tested sequential behavior and does not claim that concurrency limitation is solved. The contributor reports the macOS append/AIO regression tests passing; hosted eligibility, conventions, intake, labels, and report pass, while hosted build jobs were skipped by the eligibility gate. I did not rerun macOS tests locally.Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-24T20:00:47Z.
Review: APPROVED
Tested head
954a8e1a9don Apple M4 Pro, macOS 27.0.1, Apple clang 21, x86-64 under Rosetta 2. The tree ismain3fcb5e4d76plus the open macOS build PRs, with #10552 at its current heade60d9dfa3a, which no longer has its ownO_APPENDfallback, and the parts of mugurc's series that #7201 also carries. Only this PR was toggled between the two runs.On the same 14 file I/O tests as in the description:
guest_aioaborts with "Aio check failed at line 456" andguest_append_writeswith "append check failed at line 94".guest_standard_streamsandguest_filesystempass here too, because this tree already has the fixes for them.One merge note. This PR conflicts textually with #10552 in the
__APPLE__block ofsceKernelPwritevinStdio.cpp. #10552 addsif (iovcnt == 0) return 0;on the same line where this PR adds theFile::WritevAtEndcall. I kept both, theiovcntcheck first, and that is the tree the results above come from. Whichever of the two lands second needs that resolution.AI-assisted: yes