fix(libkernel): map shared memory and files executable on Windows #12339
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12339"
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 medazizktata on 2026-10-28T10:16:11Z.
What
On Windows, a guest
mmapwithPROT_EXECandMAP_SHAREDof a shared-memory object or a regular file threw "an executable shared file mapping is not implemented on Windows" (#12337). FreeBSD 11.4 maps these calls, and so do the Linux and macOS branches ofDoMapFileBacked_nid_no_patch:uipc_shm.c878-879 gives execute to any descriptor opened for reading;vfs_vnops.cvn_mmapallows execute unless the file system is mountednoexec.Changes:
DirectMemory.cpp, Windows branch:ReOpenFileopens withGENERIC_READ | GENERIC_EXECUTE, plusGENERIC_WRITEfor a read-write descriptor. Its protection isPAGE_EXECUTE_READorPAGE_EXECUTE_READWRITE, as CreateFileMapping requires. The extra handle is closed once the section exists. Mappings without execute take the existing path.EACCES, asshm_mmapdoes (885-887). Before, shared-memory descriptors skipped the access check inPosixMemory.cpp.SharedMemory.cpp: the owner ACE of named objects grantsGXwithGR, so a readable named object can be reopened with execute.guest_mmap_executable(guest_memory_tests executable-mappings, Windows and Linux). It runs shared protections 0-7 against a regular file opened read-write, read-only and write-only, an anonymous shm object, a named shm object opened read-write and read-only, and a JIT descriptor. For each it runs code from executable mappings, writes through writable ones, and checks the errno of refusals.GuestShmOpen.cppnow runs on Windows. Its last line (apwritepast the end of an empty object returning 0) stays off Windows: it fails there independently of this change.docs/dev/debt/libkernel.md: the Windows "noPROT_EXEC" gap is removed. What still differs is stated:fchmod;EACCESwhere FreeBSD maps it.Tested
At this head (
dbd826bc8, onmain3a40945e6), details:guest_shm_open,guest_mmap_executable0xc0000409)ctest -E agcmain: 1685/1685)guest_mmap_executableguest_shm_open,guest_mmap_executablectest -E agc-j16; the 14 failures (12 of them timeouts) all pass rerun one at a timeEarlier, on commit
46fe6f24374a:guest_shm_open,guest_mmap_executable0xc0000409)ctest -E "^agc"ctest -E "^agc"ReOpenFilepath makes both tests fail;EACCEScheck makesguest_mmap_executablefail on the errno check;tools/check_conventions.py --base origin/main: 0 errors. Twodebt-lengthwarnings, on entries that were already over 1000 characters onmain(1752 and 2861; now 1843 and 3214).Not tested:
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)EACCEScheck inDoMapFileBacked_nid_no_patch)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T11:20:44Z.
Review: COMMENTED
I reviewed the Windows section-creation and view-protection path, including the
ReOpenFileaccess mask, named-object owner ACE, shared read-only write rejection, and the new protection/access matrix. I do not see a defect in those paths in this diff. The Windows and Linux test results in the description are from46fe6f24374a, while the submitted head isdbd826bc88a03afc62cd9df46881fa06ea1d6be2; the description explicitly says the current-main application was not rerun. Please run at leastguest_shm_openandguest_mmap_executableon Windows at this exact head (and the focused executable-mapping test on Linux if available), then updateTested. I have not approved pending that refreshed evidence; hosted checks currently cover conventions/intake/labels only.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T11:39:17Z.
Review: COMMENTED
Correction to my review comment: I overlooked the author’s October 28 10:47 follow-up in this thread. It reports a Windows run on the exact current head
dbd826bc8(Windows 11, WinLibs GCC 15.2):guest_shm_openpasses,guest_mmap_executablepasses, andctest -E agcpasses 1686/1686; the control with only the PR tests also reproduces the failures on main. My statement that these results were only from the earlier46fe6fcommit was incorrect. The exact-head Windows test-evidence request is satisfied. I have not yet cleared the separate coordination point about the overlapping Windows-memory debt edits in #12296.