feat(libkernel_sys): implement pwrite through the shared POSIX provider #9019
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9019"
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 yabanana on 2026-10-21T09:54:06Z.
What
Implement libkernel_sys pwrite through libkernel's existing shared 64-bit POSIX provider, retaining descriptor handling, checked argument precedence, guest-memory read preparation and errno translation. Both public exports use the same implementation through PosixPwrite_nid_no_patch; forwarding public symbols would collide after NID patching.
Windows anonymous shared-memory writes remain bounded in positioned, buffered and scalar paths. Fixed-size metadata survives descriptor duplication/reuse. The existing named-object dispatch still follows the anonymous clamp, preserving named-object locking, access checks and bounds. Harry Zixuan Kang's scalar-write fix remains included with authorship.
The merge with main retains its virtual-directory guard in the shared provider, write-access checks before offset/null errors and WriteSync handling. The typed public pwrite declaration remains unique. Export/signature references: PS5 3.20 table and FreeBSD 11.4 write(2).
The Windows named-memory suite is split into basic lifecycle/permissions, descriptor reuse, resize/read and cross-process resize/write cases. All four run in each of the default, short-temp and long-short-temp modes: 12 CTest cases. Stress function bodies, iteration counts and assertions are retained; TIMEOUT stays 20 and the alias modes retain SKIP_RETURN_CODE 77. PROCESSORS accounts for two-thread and three-process cases. No-argument manual execution still runs all phases.
Tested
4 November review update: remote head
1e6b6947b31ab6dcb75e7c31663438d388a16268retained, including the maintainer's merge. No source change by this update. BunnyFl's native Windows report tests that head merged cleanly with main f6232fcfda:all15 selected cases pass, including both sys pwrite modes,12 named-memory path/phase cases and mapping, with no skips. Exact integration SHA/toolchain version were not supplied; this remains attributed contributor evidence. The firmware13.42 disassembly supports the syscall476 POSIX wrapper shape, not kernel checks or the unresolved maximum-offset row.B-Howell's earlier-head validation reports29/29 Windows tests3x including aliases,14 Linux tests3x, and a control where both sys pwrite modes abort with main's throwing export. That report belongs to79b02b3bdb integrated with its stated main, not automatically to this head.
Coordination:#13730 declares dependency on#9019 and reuses the same helper; its separate self-import issue is owned there. The closed#11969 write carrier has been replaced by#12700, whose body preserves the accepted#9019-first order and puts IoWrite/WithIoDescriptor inside PosixPwrite_nid_no_patch. Felipebmaitan's report documents34 sys-provider cases and a failing wrong-boundary control on the composed write tree, with no native Windows/combined#13730 qualification. No title unblock is claimed; Unblocks remains none, consistent with CONTRIBUTING and the reviewer's correction.
29 October refresh: head
79b02b3bdbb4301d6f7638d8026b4374b7e22803, integrated mainf7e84c4cf1609cc10bac95a44cd431805e5ebc8a. The Windows test conflict retains main's anonymous-descriptor classification regression byte-for-byte in the basic/all phase, without dropping the existing split cases. The requested maximum-offset discrepancy is recorded in libkernel_sys debt; provider behaviour and errno translation are unchanged. Per the maintainer's 29 October response, #9019 goes before #11969, whose cancellation/admission wrappers must then live inside PosixPwrite_nid_no_patch. No combined cancellation-stack execution is claimed.18/18 focused Linux full-kernel executions pass, including both pwrite modes, descriptor and shared-memory regressions. Complete public-header audit/compilation passes: 373 libraries / 13,451 exports; conventions and whitespace pass. GCC 13.3, Alpine 6.12.110, QEMU system 8.2.2 TCG, cpu=max,smap=off, two vCPUs, 1536 MiB; fresh SHA256-verified binaries. The Windows fixture's new integration has not been run locally on Windows. Previous SMAP-on failure and native Windows/8.3 limits remain explicit; earlier reports below retain their original revisions.
28 October refresh: head
d0ac6078bf381adce895d321fb459c33083d5c01, mainc02d287bd0eb9fe0718940b2735811e97c2eb509integrated by normal merge, preserving published ancestry. 18/18 focused Linux full-kernel executions pass on SHA256-verified binaries (GCC 13.3, Alpine 6.12.110, QEMU system 8.2.2 TCG, two vCPUs, 1536 MiB, cpu=max,smap=off). Tests/assertions were not changed. With SMAP enabled, the general kernel test hits a kernel fault at the new upstream context-restore IRET and times out; this CPU profile is not qualified by this refresh. No blanket native-hardware or zero-failure claim is made. Public-header ownership audit passes (368 libraries / 13,051 exports); conventions and whitespace checks pass. Fresh supported Windows runtime/full maintainer CI remains required. Earlier results below retain their original revisions.Earlier 26 October head
82fafdc208f5f1ab7e4784a98bf90e0f3f02705e, main84ffc1ae2d968f506505498e49405430ef2f804bintegrated with a normal merge; no published-history rewrite.23/23 Linux full-kernel executions pass: both pwrite DLL modes, common filesystem/vector regressions, descriptor/dup/fcntl/append suites, six named-memory suites, explicit sync/fcntl-sync checks and archive/plain/mmap directory regressions. The fixture also checks read-only access precedence with a null buffer and negative offset. GCC 13.3 cross compiler hosted on ARM64 / Ubuntu 24.04; SHA256-verified binaries execute in Alpine 6.12.110-0-virt under QEMU system 8.2.2 TCG cpu=max, two vCPUs, 1536 MiB. CPU execution is emulated; syscalls execute in the guest kernel.
All-library public-header audit, standalone and combined compilation pass: 368 libraries, 12,234 exports, using native ARM64 Python with the x86-64 cross compiler and unchanged ABI asserts. 33 skip-checker tests, conventions and whitespace checks pass. The actual CMake registration block produces all 12 combinations with the expected arguments, unchanged timeouts/skip policy and processor accounting; all four existing stress-function bodies compare byte-for-byte with the preceding head.
Changed Windows providers and the final named-memory fixture pass MinGW 13.2 UCRT syntax checks; the pwrite fixture cross-links with the available MinGW 13.2 runtime. This is not supported-toolchain native execution.
ycbuzi's latest native rerun tests this exact
82fafdc208head merged cleanly onto the then-current main (integration SHA not supplied): Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0 r7 UCRT Release, Ryzen 9 7900. Both pwrite modes and all four default-path named-memory phases pass three times idle and three times with 12 CPU-burning loops: 36 successful executions. Every supported phase stays below 0.7 s. All eight alias-mode cases skip with 77 because the drives lack 8.3 aliases; they are not covered by that report. The load is CPU-only, distinct from the earlier parallel build's CPU/disk workload, so the earlier 21.04 s timeout is not treated as an equivalent-load comparison.Please dispatch fresh full Linux/Windows CI on a runner with 8.3 alias creation and run
ctest --repeat until-fail:3 -R '^(guest_kernel_sys_pwrite(_patched)?|guest_named_shm_windows.*)$' --output-on-failureon WinLibs, including a representative CPU/disk workload. All eight alias-mode cases need a volume with 8.3 alias creation. No local native Windows, macOS, console or title execution was performed for this documentation update; the native results above are attributed to the contributor.Maximum-offset limitation (now recorded in debt; follow-up inputs outstanding): the console EFBIG row still lacks exact count/flags/payload. The prior
c1082f49d3probe through both real providers returned 0 for count 0 and guest EINVAL for counts 1/2 at INT64_MAX on an ordinary O_RDWR file. That evidence remains tied to its original head. No blanket EINVAL remapping was added; the exact console inputs remain requested in the existing thread. Separate macOS append work stays in #10543.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)Imported from boykopovar/AnyPS5. Originally posted by yabanana on 2026-10-21T12:25:22Z.
The vector-test verification gap is now closed on the unchanged PR head
aaad8e9b8a.I ran the exact main and candidate ELF binaries in a complete Linux x86-64 guest: Alpine kernel 6.12.110-0-virt, QEMU system 8.2.2 TCG, 2 vCPUs and 1536 MiB RAM.
guest_file_vectorandguest_file_vector_memorypass on both revisions, including inaccessible iovec tables. All seven candidate executions pass. Main's five existing tests pass; both new pwrite cases fail at the original stub as expected. SHA256 checks confirm all 24 copied test/library binaries match the original builds.No product code, test expectations or syscall handling changed. The earlier ENOSYS was specific to QEMU user-mode; the full guest kernel executes
process_vm_readv. This is still emulated CPU execution, not physical x86-64 or Windows validation. The PR description now records the completed check and preserves the original failure history. Maintainer-dispatched full CI remains pending.Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T17:50:59Z.
Windows run of
aaad8e9b8amerged ontomain745b394629(c72b1a55b4, clean), the build and runtime the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,BUILD_TESTING=ON.libkernel_sysbuilds, butguest_kernel_sys_pwrite_testsdoes not link, and once it does the test stops twice before the end. In order:undefined reference to '__gxx_personality_v0'fromGuestKernelSysPwrite.cpp,NidCompute.cppandSha1.cpp.core/libscompiles with-fno-asynchronous-unwind-tables, which on MinGW selects DWARF unwinding, so the objects need the DWARF personality. Tests normally get it fromlibc, and this target does not linklibc.patched_libraries_testsis in the same position and adds-fasynchronous-unwind-tableson MinGW. With that one line the target links:Missing symbol __error_nid_postfix(unpatched) andMissing symbol 9BcDykPmo1I(patched).libkernel.prximports__error;libc.prxexports it (objdump -pof both).dlsymon a handle also searches the library's dependencies, butGetProcAddresslooks only in that module. Loadinglibc.prxas well and taking__errorfrom it gets past this on Windows and is the same on Linux.writeAt(shared, "tail", 4, 0x3ffe)on the 0x4000-byteSHM_ANONobject returns 4, not 2. This is not the forwarding: in the same run, libkernel's ownpwriteon that object also returns 4. Afterwardslseek(shared, 0, SEEK_END)returns 0x4002 andpreadof 8 bytes at 0x3ff8 returns 8. So on Windows,main'spwriteextends an anonymous shared memory object, and this test is the first to check that there.Every check before line 138 passes in both modes once 1 and 2 are applied. Not run: lines 139 onward, a fix for the shared memory write, a title.
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T13:36:43Z.
Review: COMMENTED
Checked against main
522e32e3b6:DescriptorControl.hpp/.cpp:2d1fa5aea5addedbool pipeas the third member ofEntry(DescriptorControl.cpp:117-121) and copies it withEntry{false, source.status, source.pipe}(:608), exactly where this PR addsfixedSizeWrites.Entry{false, original.status, original.fixedSizeWrites}(:569) andEntry{..., fixedSizeWrites}(:559) forms. With both members present those still compile, but put the SHM flag intopipe, so a dup'edSHM_ANONdescriptor would lose the clamp and be treated as a pipe, andshm_openwould mark its descriptor as a pipe. Copying the whole entry (Entry copy = source; copy.closeOnExec = false;) or designated initializers avoid that.PwriteSharedMemory_nid_no_patchcall fromNativePositionedTransferloses nothing on Windows, sinceIsHostSharedMemoryDescriptoris Linux-only on main.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T20:04:53Z.
Review: COMMENTED
Correction (2026-11-01): this review's claim that maintainers close PRs without a title ID is wrong. CONTRIBUTING allows
Unblocks: none; a title is only required when the PR fixes a title. The technical points below are unaffected.These exports come from the libkernel_sys discovery list and the PR names no title ID ("Unblocks: none") and no log line showing a title calling
pwritethrough libkernel_sys onmain. The reference given is a PS5 3.20 export table and FreeBSD man pages, which show that the symbol exists, not that anything running reaches it. Please add the title and the log line; without them export-only work is routinely closed.Two smaller points: the diff also changes
SharedMemory.cpp,Open.cppandStdio.cpp(Windows anonymous shared-memory bounding andWriteSynchandling), which is a behavior change to existing paths beyond wiring one export; could that be a separate PR with its own reproduction? And the branch has conflicted withmainmore than once inDescriptorControl, so the merge result should be re-tested on the final head.Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-03T03:55:07Z.
Review: APPROVED
Windows run of the current head, plus a firmware check of the wrapper.
Windows 11, WinLibs GCC, Release,
BUILD_TESTING=ON, head1e6b6947b3merged onto currentmainf6232fcfda(clean merge). All 15 selected tests pass:guest_kernel_sys_pwriteand_patched;guest_named_shm_windows*cases (lifecycle, reuse, resize/read, resize/write, each in the default,short_tempandlong_short_tempmodes), with no skips on this machine;guest_named_shm_windows_mapping.I didn't run a negative control. The tests call the new
pwriteexports, which presumably can't pass onmain's throwing stub, but I didn't swap files to show it.Firmware 13.42:
system/common/lib/libkernel_sys.sprx(sha2563d361753f6c472cd5442bf92652b4a1dee04051297a0155fe197ede0c2002d4a) supports the FreeBSD model. This is disassembly only, not measured on a console. Thepwriteexport (C2kJ-byS5rM,0x13630) isjmp 0x1f90, and0x1f90is a baremov $0x1dc,%rax; mov %rcx,%r10; syscallthat jumps to the errno setter at0xd4on carry. That's FreeBSD's syscall 476,pwrite, which suggests the POSIX-1/errno contract this PR follows is the console's shape. The kernel-side checks, such as your recordedINT64_MAXrow, remain unmeasured, as the debt entry says.@harisibrar1's
Entryconcern is addressed.RememberDescriptoruses designated initialisers, and duplication copies the whole entry (pipeandfixedSizeWritesincluded) before clearingcloseOnExec(core/libs/prx/libkernel/File/src/DescriptorControl.cppon this head).