Repository navigation
Macos m4 - #6222
Macos m4#6222PlutoDeveloper wants to merge 30 commits into
Conversation
macOS has no /proc/self/maps or MAP_FIXED_NOREPLACE, so the arena never came up and every guest allocation threw. Enumerate host regions with mach_vm_region and reserve free chunks with a fixed mach_vm_map, which fails instead of replacing. This skips dyld, the Rosetta runtime, and ranges the kernel never lets a process map (0x10_0000_0000-0x70_0000_0000). The POSIX commit/protection paths now build on macOS unchanged. Adds standalone guest_arena tests (x86_64 under Rosetta and arm64).
Move the explanatory comments into docs/dev/debt/libc.md, as the conventions require.
Use @loader_path rpaths, Mach-O underscored export and asm symbols, Darwin stat/clock names, and keep the userfaultfd image backing Linux-only.
Port file, socket, thread, signal-context, Mach-O asm and module-loader code paths to Darwin. Directory reads resume by rewinding to the block cookie and skipping returned entries, since APFS reports no per-entry offsets.
Use an unlinked POSIX shared-memory object as physical memory, enable the POSIX mapping paths on macOS, place hinted mappings with mach_vm_map, and answer VirtualQuery with mach_vm_region. Record the remaining macOS shared-memory and module-list gaps as debt.
Replace std::atomic<std::shared_ptr> where libc++ lacks it, read page protection and stack bounds through Mach, keep udmabuf Linux-only, map thread priority to QoS, build libjpeg-turbo for the target architecture and skip the GNU-only --exclude-libs on Apple.
Keep libc's guest stack guard off the host ___stack_chk_guard symbol so patched libraries bind the system one, open POSIX shared memory without O_CLOEXEC, read process arguments with _NSGetArgv, and register a plain executable's Mach-O segments as the main image.
Load libvulkan.1.dylib, enable portability enumeration on the instance and VK_KHR_portability_subset on the device.
Cocoa requires windows and events on the process main thread, so Aps5StartGuest runs the guest on its own thread and serves a main-thread task queue that the video-out present loop runs on.
Report guest eh_frame tables from sceKernelGetModuleInfoForUnwind, skip a PT_DYNAMIC inside a no-access segment, route sceSysmoduleGetModuleInfoForUnwind through it, and find process parameters through the guest program headers.
…barycentrics Clamp viewport depth and depth bounds when VK_EXT_depth_range_unrestricted is missing on macOS, and skip draws that need barycentrics when neither the extension nor geometry shaders are usable.
Every vertex shader that exports a position also writes gl_ClipDistance (the all-zero position clip), but the rect-list control shader only declared gl_Position. On MoltenVK the stages exchange vertices through a buffer laid out from both interfaces: the undeclared clip distance became a padding member ahead of gl_Position, so the control shader read zeros and rejected every rect-list draw. Full-screen post passes were dropped and the HDR light buffers reached the screen unresolved. The control and evaluation shaders now carry the clip distance like the non-rect path does, interpolated for the fourth corner, so the zero position clip also applies to rect-lists on every driver.
…nrestricted depth
MoltenVK exposes VK_KHR_fragment_shader_barycentric but its MSL step rejects PerVertexKHR, so the extension is disabled there and a pixel shader whose I/J VGPRs outlive their v_interp_p1/p2 pairs fell back to the geometry-stage emulation, which MoltenVK cannot run either: those draws were skipped (PPSA28997's characters and foreground sprites). A new target flag, fragmentBarycentricBuiltins, enables the extension for its built-ins only. The host interpolation check then keeps the leftover I/J reads (all perspective or all linear) and reads them from BaryCoordKHR/BaryCoordNoPerspKHR, while the interpolated attributes stay hardware varyings. Apple GPUs return unnormalized perspective weights unless the fragment function reads [[position]], so each perspective read keeps a neutral use of gl_FragCoord.w. Devices with the full extension are unaffected; the request serialization moves to 19.
Metal refuses a no-copy buffer over pages of mixed protection, so a single write-watched page made MoltenVK fail the whole host import. PPSA28997's label ranges were then copied, and every label stored there drained the GPU (about 900 times a second). Release the watched pages for the import and count them as written. Title screen at 1080p on an M1 Pro: 19 -> 24 FPS, GPU idle per frame 13.7 -> 2.3 ms, GPU mutex waits 928 -> 28 ms per 10 s.
The profile reports' sync and caller sites printed absolute addresses on macOS, which cannot be symbolized; use dladdr like the Windows path.
ShaderCacheDirectory found the executable through /proc/self/exe, which macOS lacks, so both the shader disk cache and the Vulkan pipeline cache were off and every run rebuilt every shader and pipeline. Use _NSGetExecutablePath there. PPSA28997 title screen, second run: pipeline builds 155 -> 34 ms and 333 -> 101 ms per 10 s at the two load points, longest draw 49 -> 19 ms.
Conflicts resolved: - shader request serializer: version 24 keeps upstream fields 19-23 and adds fragmentBarycentricBuiltins - ShaderDiskCache.cpp, DirectMemory.cpp: upstream version - GuestAllocations.cpp: upstream RangePatch with uintptr_t address - Pipeline.cpp: upstream depth bias with macOS depth bounds - debt docs: macOS entries kept alongside upstream's
- equeue: kqueue EVFILT_VNODE backend for file watches (no inotify) - jit: back shared memory with an unlinked temp file; Rosetta cannot execute code mapped from shm_open - statvfs/fstatfs: O_EVTONLY in place of O_PATH, parent volume fallback - agc driver: take page writability from the write watch, since mprotect based watching reports watched pages as read-only - small fixes: clock duration cast, includes, MAP_STACK, stack bounds
Conflicts resolved by keeping both sides: Stdio.cpp (macOS directory resume and upstream chflags helpers) and the libSceAgcDriver debt entries.
MoltenVK's SPIR-V to MSL step turns every NoContraction operation into a call to a [[clang::optnone]] helper (spvFAdd, spvFSub, spvFMul), which made PPSA28997's title screen take 35.8 ms of GPU time a frame instead of 14.5 ms on an M1 Pro. A new SpirvTarget flag, pixelContraction, set from VK_DRIVER_ID_MOLTENVK, drops NoContraction in pixel programs only; other stages and the f64 error-free emulation stay exact. The flag is part of the cache key and the request serialization (version 25).
…ound With APS5_ASYNC_PIPELINES=1, a recorded draw whose pipeline is not cached queues the build on background threads (APS5_ASYNC_PIPELINE_THREADS, default 2) and is not drawn until the pipeline exists, instead of stalling the frame for vkCreateGraphicsPipelines. On MoltenVK a build took 100 to 860 ms and caused 25 of 26 long frames in a 30-minute PPSA28997 session; with the mode on, no frame waits for a pipeline. Lease-holding, synchronous and key-less draws still build in the draw, a failed background build is retried there, and device teardown waits for pending builds. Off by default.
Conflict resolved by keeping both includes in Stdio.cpp (map for the macOS directory resume, memory from upstream).
setup-game.sh unwraps a decrypted dump's SELF files, relinks them for Rosetta, links the rest of the dump into app0/ and the build's libraries into libs/, and copies run.sh (MoltenVK settings, background pipeline builds) and run-profile.sh (timestamped profile logs). profile_summary.py summarizes a profile log by scene weight and lists the longest stalls.
Upstream merged the macOS kqueue file events (boykopovar#5749), so our backend is dropped in favour of it. Linux keeps upstream's link-map main-program check; macOS keeps the dyld image base. Our two shader-target fields move to request serialization version 27, after upstream's version 26.
boykopovar#5101 Upstream's ImportWatched opens the watched pages for the host import itself, so releasing them one level higher is no longer needed.
The conventions only allow notes under docs/dev and docs/user.
Our barycentric and pixel-contraction target flags follow upstream's linked call fallbacks, so the upgraded fixtures carry two more bytes.
Request serialization becomes version 30: upstream's quad masks (27-29) first, then the macOS target flags. The AgcDriver AtomicSharedPtr is dropped for libc's general one. Draw keeps stencil replay ahead of background pipeline builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- libc: libSystem's __cxa_thread_atexit returns void, so its "result" was read as an error, the context freed, and the destructor later ran through freed memory at thread exit (as on mugurc's macos-port). - GPU tests load libvulkan.1.dylib and opt into portability enumeration on macOS, so they find MoltenVK instead of skipping. - Tests that use Linux-only APIs (udmabuf, /dev/full, RUSAGE_THREAD, --no-as-needed, ELF dynamic strings) are limited to Linux; the formatting test uses the native va_list, the raise-exception test's SIGUSR1 constant no longer clashes with the macOS macro and its asm uses APS5_ASM_FUNCTION, and the generic category test casts a non-const vtable slot. - docs: macOS requirements and test commands, checked on an Apple M4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Closing this: it bundles 100+ files across unrelated topics (libkernel/libc runtime, guest arena tests, recompiler barycentrics and rect-list changes, AgcDriver pipelines, macOS docs and scripts), the description and checklist are empty, and it conflicts with CONTRIBUTING asks for one topic per PR with a filled template, tests and technical-debt entries for each piece. If you want a specific part in (for example the barycentric built-ins fallback mentioned by @DavidSamir), please reopen or open it as its own PR based on current |
What
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)