libkernel (Windows): mmap with PROT_EXEC of a shared-memory object or regular file fails #12337
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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:09:33Z.
What happens
On Windows hosts, a guest
mmapwithPROT_EXECandMAP_SHAREDof a shared-memory object (anonymous or named) or of a regular file fails. The Windows branch ofDoMapFileBacked_nid_no_patchthrows on purpose (core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp:1196at46fe6f243):mmap_nid_postfixreports it asEOPNOTSUPP(theENOTSUPcatch inPosixMemory.cpp). The Linux and macOS branches of the same function map these calls, and FreeBSD 11.4 allows them:uipc_shm.cshm_mmap, lines 878-879 gives execute to any descriptor opened for reading (maxprot |= VM_PROT_EXECUTE | VM_PROT_READ);vfs_vnops.cvn_mmapallows execute unless the file system is mountednoexec.The check in
core/libs/tests/GuestShmOpen.cppthat runs code from such a mapping is compiled only off Windows. #7974, which added it, describes Windows as failing "by design". Was that meant as a policy, or as the current gap?The cause, on the Windows side: an executable view needs a section created with
PAGE_EXECUTE_READorPAGE_EXECUTE_READWRITE. That in turn needs a file handle withGENERIC_EXECUTE(CreateFileMapping: "must be created with the GENERIC_READ and GENERIC_EXECUTE access rights"). Descriptor handles do not have it, and the owner ACE of named objects (SharedMemory.cpp:286,GRWD) does not grant it either.A related case: on Windows, a shared writable mapping of a shared-memory descriptor opened read-only does not fail with
EACCES, as FreeBSD'sshm_mmapdoes (lines 885-887). The access check inPosixMemory.cpp:208-215is applied only to descriptors that are not shared memory.Title, test or build step
guest_shm_openwith its executable block enabled on Windows (homebrew or test code; no commercial title known to hit this).AnyPS5 commit
46fe6f243System
Windows 11 Pro 10.0.26200, Intel Core i5-12600KF, NVIDIA RTX 4060 (driver 610.88), WinLibs GCC 15.2.0 r7 (
x86_64-ucrt-posix-seh), Release,BUILD_TESTING=ON.Steps to reproduce
core/libs/tests/GuestShmOpen.cpp, remove the#ifndef _WIN32/#endifaround the block that writesmov eax, 42; retinto the anonymous object and maps it with protection 5. The last line of the block (pwritetothirdreturning 0) checks a different behaviour and fails on Windows independently, so keep that one guarded.cmake --build build --target guest_shm_open_testsctest --test-dir build -R "^guest_shm_open$" --output-on-failureLog
Fails 3 of 3 runs. With
Requirechanged to print the failing line, it stops atRequire(executable != reinterpret_cast<void*>(static_cast<std::uintptr_t>(-1))), right after themmap.What was checked
GENERIC_EXECUTE(ReOpenFile) only when execute is requested, create the section asPAGE_EXECUTE_READorPAGE_EXECUTE_READWRITE, and close the extra handle once the section exists;GXalongsideGRin the named-object owner ACE;EACCESfor the read-only case above.ctest -E "^agc"run (1578 tests) differs only in the two target tests.