Files
AnyPS5/docs/dev/debt/changes/fix-libkernel-macos-pwrite-append.md
Jon Daniel 4e9c5b8281 fix(libkernel): lock macOS append-mode positioned writes against offset changes
macOS pwrite and pwritev write at the given offset even under O_APPEND, so
an append-mode positioned write appends with writev and seeks back. Nothing
covered that sequence, so a concurrent seek, read or write on the same
description could see the end-of-file offset or have its own change undone.
The write and seek back now hold the descriptor's positioned-transfer lock,
shared with its duplicates as on Windows, and read, write, readv, writev and
lseek take it while the descriptor is in append mode.
2026-11-22 00:22:57 -05:00

971 B

libkernel

change [sceKernelPwrite, pwrite, sceKernelPwritev, pwritev]

  • sceKernelPwrite, pwrite, sceKernelPwritev, pwritev and the AIO write commands (libkernel) on an O_APPEND regular file on macOS append with writev and seek back to the previous offset, because macOS pwrite and pwritev write at the given offset even under O_APPEND (measured on macOS 27.2.1), where FreeBSD appends and leaves the offset unchanged. The write and the seek back hold the descriptor's positioned-transfer lock, shared with its duplicates, which libkernel's read, write, readv, writev and lseek also take while the descriptor is in append mode. Offset changes made without that lock can still interleave: a libc stream that macOS hands to its BSD stdio, another process sharing the description, and a call already running when fcntl turns O_APPEND on