feat(libkernel): support named shared memory on Windows #7299
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7299"
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 qpavyros on 2026-10-17T22:17:42Z.
What
Latest review fix: the protected per-object DACL no longer grants the Administrators group full access. The protected namespace directory retains its Administrators entry. Owner read/write grants and the existing unlink/last-close behavior are unchanged. The Windows fixture reads the object's ACL and rejects any Administrators allow entry before checking the mode-0400 reopen behavior.
Review follow-up: classification first checks the mutex-protected named-descriptor map. An untracked descriptor returns before CRT handle lookup, path-buffer allocation or Windows path queries. The normalized temporary root is initialized once per process and shared by naming and validation. Close and successful map removal use one critical section to prevent a recycled descriptor from losing its new registration. The debt entry specifies the namespace shared by processes using the same host-user temporary root, and the existing host-stdio bookkeeping/reaping limitation.
Windows currently throws for named
shm_openandshm_unlink. Implement named objects as SHA-1-named files in a protected per-user temporary directory. Exclusive creation, open/truncate, descriptor I/O, owner mode changes, and unlink/recreate now work across processes. Unlink detaches the name while existing descriptors retain the original object; the last tracked guest-descriptor close or a later open reaps the detached file.Namespace and object-identity mutexes serialize creation/unlink and resize/write operations. Preserve read-only access through
dup/dup2, perform native atomic target replacement, and suppress the CRT invalid-parameter handler while probing closed descriptors. Keep positioned transfers and named-object truncation serialized without recursively taking an alias's positioned lock.Windows owner read/write bits are represented; guest group/other classes are not represented independently. File-backed guest
mmapremains unsupported. These limits and the lack of console measurement are recorded indocs/dev/debt/libkernel.md.Tested
82be5c28f, with maina6dcea927merged without rewriting the published branch.82be5c28f: all three standalone cases (normal,--short-temp,--long-short-temp) passed with exit code 0, no skips and no timeouts. The runner confirmed an Administrator token. The new object-DACL inspection and existing mode-0400 read/write-open assertions therefore passed under both ordinary and elevated tokens. The short-path cases verified genuine 8.3 aliases, including the resolved path exceeding MAX_PATH.python tools/check_conventions.py --base origin/main: 0 errors, two existing debt-length warnings.git diff --checkpassed.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 copilot-pull-request-reviewer[bot] on 2026-10-17T22:17:47Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T22:18:17Z.
Progress report (
a6dcea9→82be5c2)📈 System libraries: 42.35% (+0.02%, +2 implemented functions)
✅ 2 implemented
shm_open_nid_postfixshm_unlink_nid_postfixImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T23:09:34Z.
Thanks, this reads carefully: rename-on-unlink with share-delete handles, the last-close reap, the protected directory ACL and the identity mutex all hold up, and the Linux path is unchanged apart from the shared name helper.
One request. On Windows, every guest
write,lseek,close,ftruncate,fchmodanddup2on any descriptor now goes throughIsHostSharedMemoryDescriptor(File/src/SharedMemory.cpp:61-96):_get_osfhandle, a zeroed 32768-wchar buffer,GetFinalPathNameByHandleW, andabsolute(temp_directory_path() / ...). On main it returnedfalseimmediately. ThroughSharedMemoryLockandCloseSharedMemoryDescriptor_nid_no_patchthat now runs on the normal file I/O path of every title. Since every named descriptor is already recorded insharedDescriptorAccess(on open,dup,dup2and the internal duplicate), could you check that map first and returnfalsewhen the descriptor isn't in it, and compute the root path once? If you'd rather keep the path check, a before/after on an I/O-heavy title would settle it.Small, not blocking: the Windows debt entry could say, as the Linux one does, that the namespace is per host user and shared by every AnyPS5 process, so two titles using the same name share the object.
Imported from boykopovar/AnyPS5. Originally posted by UmillD on 2026-10-18T00:25:43Z.
Independent Windows validation of the review-follow-up head
b5b471da8d37ac363276fa8a73b3c4533c36216e.Windows 11 Home Single Language 10.0.26300, Ryzen 7 9700X; WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release,
BUILD_TESTING=ON, bundled dependencies. No elevation, GPU or game run. Test processes used an isolated temporary root.The PR merged cleanly into pinned
maina8581d3331a20766183a9cf8e1b376be826885e7; integrated tree00803f2b7725c866140ca0d4b7df6ee705702247. The control retained the PR's test fixtures and test/link configuration, with the four changed File production files restored byte-for-byte from main. The candidate restored just those four integrated files. Both selected-target builds succeeded;libc.prxSHA-256 is identical between phases andlibkernel.prxdiffers.guest_shm_openshm_opennot implementedguest_named_shm_windowsshm_unlinknot implementedThe new Windows fixture exercised untracked/closed descriptor rejection; concurrent descriptor close/reuse; exclusive creation with 12 contenders; unlink/recreate while old descriptors remain open; read-only writes, including zero-length and EOF writes;
dup/dup2access and last-close cleanup; two child processes plus the parent resizing/writing; and positioned reads racing a resize through an alias. Its existing content, size, file-position and orphan-cleanup assertions all passed.Neighboring
guest_jit_shared_memory,guest_dup,guest_positioned_closeandguest_append_writespassed once in both phases (4/4 each). Candidate total 14/14 executions, zero skipped. Serial CTest, focused--repeat until-fail:5; existing individual timeouts preserved, including 20 s forguest_named_shm_windows. No timeouts or memory-guard terminations.Scope: independent focused Windows regression coverage. This is not a full-suite run, Linux/macOS or console validation, title test, file-backed guest mmap test, or evidence of an I/O performance improvement. No production or fixture edits were needed locally.
AI-assisted testing and report: yes (Codex).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T08:57:20Z.
Review: CHANGES_REQUESTED
The full Windows build fails
guest_named_shm_windowson this head:named descriptor was not tracked (guest errno=73), fromVerifyUntrackedDescriptor(GuestNamedShmWindows.cpp:65).guest_shm_openpasses in the same run, so it is not infra.Likely cause:
WindowsNamedRoot()(SharedMemory.cpp:53) is built fromtemp_directory_path()as returned, andIsHostSharedMemoryDescriptorcompares it with the path fromGetFinalPathNameByHandleW, which is always the long form. On the runnerTEMPis an 8.3 short path (C:\Users\RUNNER~1\...), so the prefix never matches and every named descriptor is classified as not shared memory. Local runs with a short user name (UmillD's, yours) don't show it.Suggested fix: resolve the root once to its final path (open the created directory and call
GetFinalPathNameByHandleW, orGetLongPathNameW) and use that for both naming and validation. A test that creates the objects under a short-nameTEMPwould pin it.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T11:26:04Z.
Review: CHANGES_REQUESTED
The full Windows build on
66c9dabacstill fails, now past the 8.3 problem (the log confirms the real short alias is exercised):guest_named_shm_windows:mode 0400 allowed a later read-write open (guest errno=0)(GuestNamedShmWindows.cpp:322).guest_named_shm_windows_short_tempandguest_named_shm_windows_long_short_temp:child failed: wait=0 exit=1, the same fixture run in a child.guest_shm_openand the rest pass in the same run, and main does not have these failures.Likely cause:
SetWindowsNamedPermissions(SharedMemory.cpp:285) always adds(A;OICI;FA;;;BA)to the object's DACL. The runner account is an elevated Administrator, so the BA entry grants write on a mode 0400 object and the open succeeds. The local runs were non-elevated, which is why the test passed there.Needs a decision from you: either drop the Administrators entry from the per-object DACL (keeping it only on the directory) so the owner bits are what decides, or keep it and make the test skip the permission checks when the process token is elevated, documenting in the debt entry that admins bypass the mode bits. Please rerun the three tests on an elevated shell to confirm.
Imported from boykopovar/AnyPS5. Originally posted by qpavyros on 2026-10-21T23:05:47Z.
Fixed the per-object Administrators bypass in
82be5c28f. The object DACL no longer contains the BA allow entry; the protected directory keeps its Administrators entry. The fixture now inspects the actual object ACL before exercising the existing mode-0400 reopen checks. No permission assertions were skipped or weakened.Merged main
a6dcea927without force-pushing. Fresh focused results: Windows 8/8 (all three named Windows cases passed, no skips) and WSL Linux 10/10; conventions reports 0 errors and diff checks pass.The requested elevated-token rerun is now complete on the same published head
82be5c28f: normal, --short-temp and --long-short-temp all exited 0 without skips or timeouts. The runner confirmed an Administrator token. Both short-path variants exercised genuine 8.3 aliases, including the resolved path exceeding MAX_PATH. The object-DACL inspection and existing mode-0400 reopen assertions passed under elevation as well. Updated the description with this result.