fix(libkernel): flush only the paths the guest changed in sceKernelSync on Windows #1093
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1093"
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 kjhq on 2026-10-07T10:39:48Z.
What
On Windows,
sceKernelSyncopened every writable volume (\\.\Volume{...}) withGENERIC_WRITEand calledFlushFileBuffers. Opening a volume that way needs administrator rights, so in a normal user sessionCreateFileWfailed withERROR_ACCESS_DENIEDandsceKernelSyncthrew. PPSA17221 (Minecraft) calls it and stopped there.sceKernelSyncno longer opens volumes on Windows. Instead:RecordWrittenPath_nid_no_patch). Entries come from:sceKernelOpenwith write access,O_CREATorO_TRUNCfopen/freopenwith aw,aor+modemkdir/sceKernelMkdir,sceKernelRmdir, truncatechmod/fchmodandutimes/futimessceKernelSync(SyncWrittenPaths_nid_no_patch) does three things:LastWriteTime) since the previous call.GENERIC_WRITEandFILE_FLAG_BACKUP_SEMANTICSand callsFlushFileBuffers.ERROR_ACCESS_DENIED(for example a read-only file) orERROR_SHARING_VIOLATION(another handle denies write sharing).FlushFileBuffersneeds aGENERIC_WRITEhandle, so these files cannot be flushed. Skipping one only affects durability; the guest reads the same data.sync()and clears the registry.TechnicalDebt gets two entries:
RecordWrittenPath_nid_no_patchis not flushed bysceKernelSyncon Windows.An earlier revision of this PR skipped volumes that denied access and added a TechnicalDebt entry for it. That entry is removed again.
Test:
guest_kernel_syncchecks these things:fopen("a"),mkdir, rename andsceKernelChmodare recorded.sceKernelOpenandfopen("r")are not.sceKernelSyncruns.sceKernelSyncreturns aftersceKernelChmod(..., 0444)has made a recorded file read-only.sceKernelSyncreturns while another handle holds a recorded file open withFILE_SHARE_READ.Which job covers which claim:
sceKernelSyncissync(), so this job covers only the registry: what is recorded, what is not, and that an unlinked path is dropped after a sync.Title
PPSA17221 (Minecraft) needs #716 to load the modules in its app root. Every run below is current
main+ #716 + the PRs of this set (#1088, #1091–#1096), plus local changes outside it:With all of them the title loads a world. The line below is from a run with only this PR left out, Windows 11, WinLibs GCC, normal user session.
Without it the title terminates about 5 s after start:
Tested
Windows 11, WinLibs GCC, normal (non-elevated) user session:
guest_kernel_syncwithout theERROR_ACCESS_DENIED/ERROR_SHARING_VIOLATIONskip fails withOpening ...\kernel_sync_probe\read_only.bin for sync: Access is denied. With it the test passed in 3 of 3 runs.ctest -R "guest_kernel_sync|guest_filesystem|guest_appcontent|savedata_core_write_replacement|savedata_replace_file_failure": 5/5 passed.Debian 13 (WSL2), GCC 14.2.0, rebased on main
e705d430: fullctest, 1 of 426 failed. The failure istls_function_coverage(alu-exec-xor-3exits with SIGSEGV), and maine705d430fails it the same way.guest_kernel_syncpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T12:09:51Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libc/src/General.cppL9, L70-71core/libs/prx/libkernel/File/src/Open.cppL118Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T06:19:19Z.
Review: CHANGES_REQUESTED
Thanks, the approach (no volume handles, flush what the guest touched) looks right, and Linux/Windows CI and the full ctest on current main are green. A few things to fix:
core/libs/prx/libc/src/General.cpp:109(FlushPath): opening withGENERIC_WRITEfails withERROR_ACCESS_DENIEDon a read-only file, and with a sharing violation if another handle denies write sharing, and both throw out ofsceKernelSync.chmod/fchmodare recorded (Stdio.cpp:43), so a guest that makes a file read-only and then syncs hits the same kind of failure this PR fixes.FlushFileBuffersrequiresGENERIC_WRITE, so a read-only handle is no alternative: skip files that can't be opened for writing (read-only, sharing violation), record that in TechnicalDebt (the flush only affects durability, the guest sees the same data), and add a test row for a read-only file.RecordWrittenPath_nid_no_patchare flushed now; writers that don't call it (any host-side write in other libs that skips the registry) are no longer covered bysceKernelSyncon Windows. Please add a line todocs/dev/TechnicalDebt.mdsaying so (not at the end of its section).core/libs/tests/GuestKernelSync.cpp: on Linux it only exercises the registry; the flush itself is covered only by the Windows CI job. Fine, but the PR body should say which job covers which claim, and the test should include the read-only case above so Windows pins it.Imported from boykopovar/AnyPS5. Originally posted by kjhq on 2026-10-08T08:30:47Z.
Thanks for the review. Changes:
FlushPathnow skips a file whose open for writing fails withERROR_ACCESS_DENIED(read-only) orERROR_SHARING_VIOLATION. Other errors still throw.sceKernelPreadentry. One says only paths recorded throughRecordWrittenPath_nid_no_patchare flushed. The other says files that cannot be opened for writing are skipped.guest_kernel_syncmakes a recorded file read-only withsceKernelChmod(..., 0444)and syncs. On Windows it also syncs while another handle holds the file open withFILE_SHARE_READ.Without the skip, the new test fails on Windows in a non-elevated session with
Opening ...\\kernel_sync_probe\\read_only.bin for sync: Access is denied. With the skip it passed in 3 of 3 runs. The branch is rebased on maine705d430and squashed into one commit.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T08:58:52Z.
Review: APPROVED
Checked: build + full ctest on current main + this PR (427/427),
guest_kernel_syncfails to build without the change, and the three points from my review are addressed (skip onERROR_ACCESS_DENIED/ERROR_SHARING_VIOLATION, the two TechnicalDebt lines, read-only and sharing-violation rows in the test). The Windows flush itself is covered only by the Windows CI job. Merging once CI is green.Note: #1079 also edits
General.cppand conflicts with this one, so whichever lands second rebases.