feat(libkernel): support named shared memory on Windows #5276
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5276"
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 Nixitov on 2026-10-13T16:18:19Z.
What
Named shared memory was missing on Windows:
shm_open/shm_unlinkof a named object calledNotImplemented_nid_no_patch, while the Linux path (hostshm_openunder/dev/shm,HostShmLock,NamedHostPath) already implements them. That kept both functions pending in the progress report and left 22 prepared titles that importshm_open(2 importshm_unlink) without named shared memory on Windows.The host object is now a file under the temporary directory named after the SHA-1 of the guest name (the same digest the Linux path hashes), opened with
CreateFileWandFILE_SHARE_DELETEso thatshm_unlinkwhile a descriptor is open removes the name as it does on the console.O_CREAT/O_EXCL/O_TRUNCselect the matchingCreateFileWdisposition, and the host errors map to the guest's (EEXIST,ENOENT,EACCES,EINVAL,ENOSPC,EROFS,ENAMETOOLONG).The validation and hashing move into a shared
NamedHostObject(the SHA-1 helper was already portable and linked into libkernel), andNamedValidationGuestErrormaps the validation errors on Windows. The Linux path is otherwise unchanged.Tested
Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release.
guest_shm_opennow covers a named object — create,ftruncate, write, reopen, read back,O_EXCLon an existing name (EEXIST), unlink, reopen (ENOENT), and unlink of an absent name (ENOENT); it passes. The test previously asserted that the Windows named path threw.tools/progress.py: libkernel 569 → 571 implemented (shm_open,shm_unlink); overall 88.12% → 88.17%.python tools/check_conventions.py --base origin/mainpasses.NamedHostObject.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 github-actions[bot] on 2026-10-13T16:18:59Z.
Progress report (
a98d42d→d753560)📈 System libraries: 88.24% (+0.05%, +2 implemented functions)
✅ 2 implemented
shm_open_nid_postfixshm_unlink_nid_postfixImported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T01:15:30Z.
Review: COMMENTED
Reusing the Linux path's validation and SHA-1 naming is good. Two differences between a file under
%TEMP%and the Linux backing (/dev/shm, tmpfs) are worth handling:1. Lazy writer I/O. With
FILE_ATTRIBUTE_NORMAL, the object is an ordinary NTFS file. Once a title maps it and writes to it, the cache manager's lazy writer flushes dirty pages to disk, and under memory pressure the pages are paged out to the file rather than the pagefile. For shared memory used as an IPC ring or a large shared buffer, that is continuous disk writes that tmpfs never does.FILE_ATTRIBUTE_TEMPORARYtells the cache manager to keep the data in memory and avoid writing it back while memory is available, which is the closest Windows equivalent to tmpfs. It's a one-flag change, in bothCreateFileWcalls.2. Lifetime across reboots.
/dev/shmis emptied at reboot, but%TEMP%isn't. An object a title created and never unlinked (common, since many programs rely on reboot to clean up) is still there on the next run, possibly days later. A latershm_open(name, O_CREAT | O_EXCL)then fails withEEXIST, and a plainO_CREATreopens stale contents of the old size. On Linux that only happens within one boot, and the console doesn't keep its shm namespace across a title restart either. Options:anyps5-shm-<boot id or process start time>/) and remove it at startup if it's stale; oranyps5-shm-*files older than the current boot at libkernel init.Either keeps a crash from leaving objects behind for the next session. Whichever is chosen, the debt entry should note how it differs from tmpfs.
Imported from boykopovar/AnyPS5. Originally posted by Nixitov on 2026-10-14T01:39:13Z.
Both taken, thanks.
1.
FILE_ATTRIBUTE_TEMPORARY. The named object is now opened with it, so the cache manager keeps the data in memory while memory is available rather than writing it back to NTFS — the closest match to tmpfs. (The anonymous file already used_O_TEMPORARY.)2. Lifetime across reboots. Named objects now live in
%TEMP%\anyps5-shm, and on first use the directory is cleared when it predates the current boot (its last write is older thannow - GetTickCount64). So an object a title left behind can't fail a laterO_CREAT | O_EXCLor reopen stale contents — that session's objects are gone, matching/dev/shmbeing emptied at reboot. The debt entry now records how the Windows backing differs from tmpfs.guest_shm_open(which covers a named object) passes and conventions pass.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T01:46:33Z.
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/libkernel/File/src/SharedMemory.cppL16-18docs/dev/debt/libkernel.mdL113Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:30:03Z.
Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.
Pull request closed