Repository navigation
fix(libkernel): append positioned writes on an O_APPEND descriptor on macOS - #10543
Conversation
… macOS macOS pwrite and pwritev write at the given offset even when the descriptor was opened with O_APPEND. FreeBSD's vn_write appends to an O_APPEND regular file whatever the offset and leaves the file offset unchanged, and Linux pwrite appends too. On macOS, sceKernelPwrite, pwrite, sceKernelPwritev, pwritev and the AIO write commands now append such writes with writev and restore the file offset, as boykopovar#8359 does on Windows. Co-authored-by: Himansh Raj <67262056+iamthehimansh@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed WritevAtEnd and 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.
imellag
left a comment
There was a problem hiding this comment.
Tested head 954a8e1a9d on Apple M4 Pro, macOS 27.0.1, Apple clang 21, x86-64 under Rosetta 2. The tree is main 3fcb5e4d76 plus the open macOS build PRs, with #10552 at its current head e60d9dfa3a, which no longer has its own O_APPEND fallback, 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:
- Without this PR, 12 pass.
guest_aioaborts with "Aio check failed at line 456" andguest_append_writeswith "append check failed at line 94". - With it, all 14 pass.
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 of sceKernelPwritev in Stdio.cpp. #10552 adds if (iovcnt == 0) return 0; on the same line where this PR adds the File::WritevAtEnd call. I kept both, the iovcnt check first, and that is the tree the results above come from. Whichever of the two lands second needs that resolution.
AI-assisted: yes
|
Measured on a PS5 (a payload calling the console's |
Test report: #10543 (O_APPEND / WritevAtEnd on macOS)Tested on: Apple M2 MacBook Air, macOS 27.2 (26B118), x86_64 Release build under Rosetta 2, AppleClang 21.0.0, Ninja. Conflict: the PR does not merge cleanly onto this stack (one conflict, with our #10552). Hunk:
Broad run: Not checked: Linux/Windows builds; behaviour of O_APPEND on real guest titles; whether the PR as pushed passes AI-assisted: yes (Claude Code) |
|
Checked the diff against FreeBSD's |
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 f07439e (2026-10-23, "fix(libkernel): append positioned writes on an O_APPEND file on macOS"), at the same three call sites with
writevand 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 withmainat 1e20650, 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 fix(libc): leave a stream that is reading untouched in fflush on macOS #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 fix(libc): rename over a dangling symbolic link on macOS #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