Skip to content

fix(libkernel): allow delete sharing for open Windows files - #3677

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
MarcZX10:carry/libkernel-delete-sharing-3316
Oct 11, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
MarcZX10:carry/libkernel-delete-sharing-3316

Conversation

@MarcZX10

Copy link
Copy Markdown
Contributor

What

On Windows, sceKernelOpen currently uses _wopen without delete sharing. As a result, a guest cannot unlink an open file or rename an open source file, although those operations work on the Linux build and match the documented FreeBSD behavior. Open descriptors should continue to access the original file after its name is removed or moved, while a new file can take the old name.

This carries David Samir's commit from issue #3316, with the original commit author preserved. I rebased it onto current main and moved the added regression block earlier in GuestFilesystem.cpp to avoid the active test additions near the end of that file.

Open PR #2144 separately changes Windows scalar file error handling in Open.cpp; it does not implement delete sharing. The PRs touch the same file and should be rechecked/rebased if either merges first.

Tested

  • The issue author reports Windows 11 / WinLibs GCC 15.2 tests for the carried change: guest_filesystem passes 5/5, 3,276 _wopen comparison cases agree with the replacement, 50,000 open/close cycles retain the same timing, and a multithreaded create/write/unlink/recreate workload passes. Their full suite reports 770 passed and 5 skipped. These runs were on an earlier base and were not repeated here.
  • The issue author also reports Linux WSL2 / GCC 13.3 guest_filesystem passing 3/3 on the carried change. I did not rerun that target locally.
  • Locally: tools/check_conventions.py --base upstream/main and git diff --check pass.
  • Not tested here: Windows, native console behavior, or rename-over-existing-open-destination semantics. The latter remains outside this fix.

Checklist

  • Based on current main; no other open PR implements the same behavior
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (review, rebase, and PR preparation)

Fixes #3316

…ndows

FreeBSD removes or renames a file that is still open; the descriptor stays usable. _wopen opens without FILE_SHARE_DELETE, so sceKernelUnlink returned EACCES and rename failed while the guest held a descriptor. sceKernelOpen now opens through CreateFileW with delete sharing and keeps the flag, mode and error mapping of _wopen.

(cherry picked from commit 2f5ada5)
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the CreateFileW replacement against the old _wopen behaviour: access mode, CREAT/EXCL/TRUNC dispositions, APPEND/BINARY flags passed to _open_osfhandle, read-only attribute from mode, inheritable handle, handle closed if _open_osfhandle fails. guest_filesystem passes on Linux and the conventions check is green. The Windows behaviour rests on the Windows 11 runs reported in #3316 (not reproducible here); merging.

@adriadam10
adriadam10 merged commit 6c6c555 into boykopovar:main Oct 11, 2026
15 checks passed
oneandonlydean pushed a commit that referenced this pull request Oct 12, 2026
fopen opened its stream with _wfopen, which shares read and write
access but not delete access. While the guest held a stream open,
rename of its file failed with EIO and remove with EBUSY. POSIX rename
and remove work on open files, as on Linux and FreeBSD, and since
#3677 the descriptors sceKernelOpen returns share delete access.

fopen now creates the handle with CreateFileW sharing read, write and
delete, with the access and creation disposition of the mode, and
wraps it with _open_osfhandle and _wfdopen, keeping append mode. A
failed CreateFileW sets errno through the error mapping #3677 added to
libkernel's NativeOpen, which moves to libc as
WindowsOpenError_nid_no_patch so that both use it. freopen still
reopens through _wfreopen; TechnicalDebt records it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libkernel: a guest cannot unlink or rename a file it has open on Windows; fix branch ready

3 participants