Repository navigation
Conversation
…tatic TLS) Split the host into host.cpp (PE loader, TEB, static TLS and TLS callbacks, threads), kernel32.cpp and crt.cpp (UCRT, vcruntime140, msvcp140 std::thread, xgameruntime). build.sh builds tiny_game.exe with xwin when present. Tested on an M1 (macOS 27.0.1): guest.exe passes; tiny_game.exe passes 'hello 42', 'hello 42 tls', and 'exit-code' returns 42. Not done: eh (needs .pdata unwinding), game-file (GAME: path mapping).
_CxxThrowException captures the thrower's registers in an assembly stub; the host unwinds guest frames with the image's .pdata codes, reads the __CxxFrameHandler3 tables, runs destructor funclets, copies the catch object, calls the catch funclet and resumes at its continuation. Tested on an M1 (macOS 27.0.1): tiny_game passes 'hello 42 eh' and 'tls eh'; the new guest/eh_probe.exe throws through 4 frames (4 destructors run), catches by value and with catch(...). Not handled: rethrow, nested exceptions, __finally, std::current_exception.
GAME:\ paths resolve to the image's real folder, whatever the current directory; the image is loaded by its real path (argv[1] was overwritten by the guest's argv[0] before loading, which broke runs from another folder). Tested on an M1: tiny_game passes 'hello 42 tls eh game-file' run from another directory; exit-code, eh_probe and guest.exe still pass.
… as Cocoa vulkan-1.dll's vkGetInstanceProcAddr hands the guest MoltenVK functions behind generated stubs into one MS-to-SysV converter that also switches gs; the float-parameter commands get typed thunks. VK_KHR_win32_surface is answered with VK_EXT_metal_surface on the window's CAMetalLayer. window.mm covers the user32 calls of one window and its message pump. Needs the universal (x86_64) MoltenVK from the KhronosGroup release, since the host runs under Rosetta. Tested on an M1 (macOS 27.0.1): guest/vk_clear.exe (clang-cl + xwin) opens a 640x360 window, presents 180 cleared frames on a 1280x720 swapchain and reads back the last frame's pixel (254,127,1 as cleared). tiny_game, eh_probe and guest.exe still pass.
Static-CRT test builds load with three system DLLs; missing imports become named traps; adds locks, init-once, events, semaphores, modules, text conversion, ExitThread, and a fault report with symbols.
…for the static-CRT D3D12 tests RaiseException, RtlUnwindEx (with unwind consolidation), RtlCaptureContext, RtlLookupFunctionEntry and RtlVirtualUnwind on the existing .pdata unwinder, so /MT C++ exceptions are caught; eh_probe also builds with /MT. std::filesystem calls (attributes, directories, FindFirstFile, disposition deletes), DuplicateHandle, FormatMessageA and D3D12SerializeVersionedRootSignature (DXBC + RTS0). 35 of the 57 d3d12 tests pass under MoltenVK on an M1, 14 skip on missing Apple GPU features.
… Retina pixels, fault reports - Re-exec under Rosetta with ROSETTA_ADVERTISE_AVX=1 so CPUID reports AVX/AVX2/FMA (guest/cpuid_probe.c checks it) - user32 window calls d3d12_present_test needs; Win32 sizes are pixels, not Retina points - Bind ordinal imports (d3d12.lib's ItsNotRexed#101/ItsNotRexed#102) and stub D3D12GetDebugInterface - Fault handler restores the host gs before printing, so a guest crash no longer deadlocks in fprintf - d3d12 sweep: 36 pass, 15 skip, 6 fail (WARP/DXGI references, Metal sampler LOD bias, Metal NaN clears)
Load PE DLLs from disk with per-module TLS (gta6rt_tls_host.dll), RtlAddFunctionTable and a multi-module unwinder, RtlPcToFileHeader for any module, VirtualAlloc reserve/commit at fixed addresses, VirtualQuery, WaitForMultipleObjects. tiny_game passes under gta6rt --run with tls, eh, game-file and exit-code. scan_exe.sh lists a game image's unanswered imports and the instructions Rosetta 2 cannot run.
… under gta6rt - illegal.cpp: on the first SIGILL at an adcx/adox/insertq site, patch a jmp to a stub built from instructions Rosetta runs; clwb becomes NOPs, clzero is emulated. illegal_probe checks each against x86 semantics (incl. rsp- and rip-relative). - TLS: EXE code may read its TLS at index 0 without loading _tls_index. Under gta6rt the game takes gta6rt_tls_host.dll's index, so that DLL now gets 0 and gta6rt.exe moves to 1. Before, the game wrote over gta6rt's thread_locals. - API sets: api-ms-win-core-* resolve to kernel32 exports, api-ms-win-crt-* to any UCRT set the host registers. - Handles to host-provided DLLs point at an empty PE header, so pe_loader's RtlPcToFileHeader redirect can walk them. - Crash report: SIGTRAP, registers, and return addresses found on the stack.
…++ runtime DLLs - VirtualAlloc2 / MapViewOfFile3 / UnmapViewOfFile2 / CreateFileMappingW on mmap and shm: placeholder reserve, split, replace, section views, and VirtualQuery reports a placeholder as MEM_RESERVE. This is what xmem's physical pages and 2 MiB pools need. - The Windows thread pool (work, timers, waits, TrySubmitThreadpoolCallback) on guest threads. - GetLogicalProcessorInformation from sysctl; CreateEventA. - advapi32 RegOpenKey(Ex)W / RegQueryValueExW answer ERROR_FILE_NOT_FOUND: the unimplemented policy's 0 reads as success with an empty value. - LEONIDA_DLL_DIR: real PE DLLs from that folder (for example the x64 vcruntime140 / vcruntime140_1 of Microsoft's VC++ redistributable) win over the host stand-ins; plus the CRT entries vcruntime140 imports. - guest/pool_probe.c covers the placeholder, thread pool and processor paths (exit code 0).
… with no devices, ordinal GetProcAddress - crt_lib.cpp: the rest of the UCRT a retail title imports (math, ctype, narrow and UTF-16 strings, 32-bit long conversions, 64-bit time, stdio seeks, qsort/bsearch with guest comparators, the MS rand, errno, localeconv) - wide __stdio_common_vswprintf family on the existing formatter (%s is wchar_t* in a wide format) - GameInputCreate (GameInput.dll ordinal 1): an IGameInput that never reports a device - GetProcAddress by ordinal for host DLLs; mutexes, InitializeCriticalSection, thread priority/affinity hints, app-state notifications that never fire, std::_Random_device - crash report dumps the first words behind rbx/rcx/rsi/rdi - guest/crt_probe.c checks the Windows-specific behaviour (exit code 0)
…tFileSizeEx/GetFileSize/GetFileTime, OpenProcess The DirectStorage shim reads at an OVERLAPPED offset; the host read from the file position instead. With GetFileSizeEx missing, a title saw every archive as empty. crt_probe checks both.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in the coordination issue as: new item, claim
What and why
A native macOS host for
gta6rt, with no Wine.runtime/macos_hostis a small x86-64 Mach-O that maps the clang-cl cross-builtgta6rt.exe(and the PE images it loads) and runs it under Rosetta 2 on Apple Silicon. The Windows API surface gta6rt and a title reach is answered on POSIX and Cocoa: kernel32 (files, threads, events, mutexes, TLS, the thread pool,VirtualAllocwith real reserve/commit and placeholders), the UCRT pieces that differ from the host libc (32-bitlong, UTF-16wchar_t, the MSrand, wide printf), SEH and C++ exceptions with a multi-module unwinder, per-module static TLS, Vulkan on MoltenVK with the Win32 window as anNSWindow, and a GameInput stub with no device.Everything is under
runtime/macos_host/; nothing else in the tree changes, so it builds on no PR and conflicts with none.Two things specific to Rosetta:
clzero.scan_exe.shcounts them in an image without quoting it./GAassumption that Loader: the mapped game executable owns module TLS index 0 (RT-259) #4313 fixes in the Windows loader). Here the host's own loader gives index 0 to the TLS host and index 1 togta6rt.exe, so the two fixes don't touch each other.To build and run (Homebrew
llvm,lld,molten-vk):Tested
Apple M1, 16 GB, macOS 27.0.1, Rosetta 2, MoltenVK 1.4.2 on Metal.
gta6rtbuilt with clang-cl and the static CRT (runtime/build/windows-mac-mt).gta6rt --run tiny_game.exe -- hello 42 tls eh game-file exit-code: exit 42, every check passes.guest/):crt_probe,pool_probe,eh_probe,eh_probe_mt,cpuid_probe,illegal_probe,guest: all exit 0.isa_*measures what Rosetta runs: 11/11 float semantics match x86, TSO ordering holds, 256-bit AVX runs at about a third of native NEON throughput.d3d12_*tests: 36 of 57 pass, 15 skip, 6 fail. 4 failures need WARP/DXGI (clear, depth_resolve, fence_timing, query_rules);descriptorneeds a sampler LOD bias Metal doesn't have;uav_clearhits Metal quieting signaling-NaN payloads in clears (already noted indocs/d3d12_vulkan.md).gta6rt --rungets past stops 1 to 5 ofdocs/retail_boot_chain.mdand reads its first archive through DirectStorage. It then stops on an access violation I haven't looked at yet.AI-assisted: yes
Checklist
docs/design.md, with how it was confirmed. (No translator change.)