fix(libkernel): recognize Windows anonymous shared memory descriptors #11403
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11403"
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 MarcZX10 on 2026-10-26T11:03:04Z.
What
On Windows, anonymous
shm_open(SHM_ANON, ...)creates a temporary file but did not register the descriptor as shared memory.fchflagstherefore treated it like an ordinary file instead of returningEINVAL, and descriptor duplication/close tracking did not preserve its shared-memory classification.Create anonymous shared-memory files under the private Windows shared-memory root, track them as shared-memory descriptors, and add regression coverage for
fchflags, duplication, close, and descriptor reuse.Tested
x86_64-w64-mingw32-g++ -std=c++20 -D_WIN32 -D_fflush_nolock=fflush -fsyntax-only ... SharedMemory.cpp— passed.GuestNamedShmWindows.cpp— passed.git diff --check upstream/main...HEAD— passed.tools/check_conventions.py --base upstream/main --head HEAD— passed.guest_named_shm_windowswas not run locally. The automatic PR Windows product job is skipped by path policy, and the documented manual workflow dispatch requires repository admin rights; there is no hosted Windows runtime result for this head.Checklist
main; no duplicate implementation found by the open-PR overlap scanImported from boykopovar/AnyPS5. Originally posted by rahul05ranjan on 2026-10-26T12:53:53Z.
Review: COMMENTED
Traced the Windows anonymous path end to end; the fix is consistent on every side I checked.
IsHostSharedMemoryDescriptoraccepts exactly<resolved temp>\AnyPS5\shm\<40 hex>.dat— no separator in the relative part, first 40 chars hex,.datsuffix (SharedMemory.cpp:110ff).CreateAnonymousFilenow names files SHA1(random || pid || serial) in hex — 40 chars plus.dat, precisely the shape the validator accepts, so the tracked descriptor and the path check agree instead of the oldanyps5-shm-...names that never validated.reinterpret_cast<const char*>(1)is the anonymous sentinel (anonymousObject, SharedMemory.cpp:161), soshm_open(1, ReadWrite, 0600)really exercises the anonymous route. And sinceshm_open_nid_postfixrejectsO_RDONLYfor the anonymous object before calling in,TrackSharedMemoryDescriptor(..., true)'s writable flag can't be wrong here.temp_directory_path()with arandom_device-seeded, counter-suffixed name; they sit underAnyPS5\shmwith an explicit private DACL (SYSTEM/administrators/owner full, no other ACEs),_O_CREAT | _O_EXCLagainst squatting, and the reparse-point check on the directories. That closes the predictable-name and inherited-ACL exposure the old placement had — with TMP redirected to a shared directory, other local accounts could previously read or pre-create the emulator's guest shared memory.One gap worth a look:
EnsurePrivateWindowsDirectoryapplies the private DACL only at creation and toleratesERROR_ALREADY_EXISTS. A<temp>\AnyPS5that already exists (older build, or anything under the same user) keeps whatever ACL it was created with — the code validates it's a directory and not a reparse point, but never its ACL. If the intent is "objects under this root are readable only by the owner", the existing-directory path would want aGetNamedSecurityInfocheck or a repair step.