Skip to content

macos_host: winmm, ole32, setupapi, gdi32, shell32 and oleaut32 imports SDL3 needs; GetModuleFileName with '\' separators - #5

Merged
adrbn merged 2 commits into
adrbn:mac-native-hostfrom
Lucasyudi:macos-host/sdl3-imports
Nov 23, 2026
Merged

adrbn merged 2 commits into
adrbn:mac-native-hostfrom
Lucasyudi:macos-host/sdl3-imports

Conversation

@Lucasyudi

Copy link
Copy Markdown

Claimed on ItsNotRexed/Leonida#7446: claim. Covers vakaobr's SDL3 import list from #7446.

What and why

gta6rt.exe built with SDL3 (the GameInput shim's controller backend, #8539) imports winmm, ole32, setupapi, gdi32, shell32 and oleaut32 calls the host didn't have; the gameinput ctest stopped at winmm!timeBeginPeriod.

  • win32_misc.cpp (new): the 20 calls. There is no COM, device tree or GDI on the host, so they answer as a Windows machine without the class, device or screen DC would: timeBeginPeriod/timeEndPeriod → TIMERR_NOERROR; CoInitializeEx → S_OK, CoGetApartmentType → MTA, CoCreateInstance → REGDB_E_CLASSNOTREG with *ppv = NULL; CM_* → CR_NO_SUCH_DEVNODE; gdi32 → NULL/FALSE/CLR_INVALID; ShellExecuteW → SE_ERR_FNF; SysFreeString (oleaut32 Fix spaced paths in macOS guest builds #6) no-op. SHGetFolderPathW returns ~/Library/Application Support for every CSIDL (SDL only asks for CSIDL_APPDATA). CommandLineToArgvW is real: Windows' program-name and backslash/quote rules, one block freed with LocalFree.
  • CoWaitForMultipleHandles sits in kernel32_crt.cpp next to WaitForMultipleObjects, which it reuses (timeout → RPC_S_CALLPENDING).
  • GetModuleFileNameW/A now report \ separators. SDL's SDL_SYS_GetExeName/GetBasePath split the module path at its last \, so the POSIX path made SDL_Init crash in strlen(NULL). to_host_path maps \ back to /, so the path still opens. Heads-up for your CreateProcessW: base_reservation.h:95 (the relaunch), queue_proxy_test.cpp:934 and unimplemented_policy_test.cpp:150 pass this path to it, so it has to go through to_host_path before posix_spawn/execv.
  • guest/shell_probe.c (new, built by build.sh): Microsoft's CommandLineToArgvW examples, a quoted program name with a trailing backslash, the empty line, CoWaitForMultipleHandles (any/all, timeout), the COM/winmm/setupapi answers, the SHGetFolderPathW folder, and the module path checks.

How far gameinput gets now

With this and #8539, LEONIDA_STRICT_IMPORTS=1 gta6rt.exe --dry-run lists none of these DLLs, and SDL_Init gets past the exe-name crash. gameinput_test then needs, in order (measured with a local, reverted trap that returns 0 instead of stopping):

  1. kernel32: SetConsoleCtrlHandler, FormatMessageW, RemoveVectoredExceptionHandler.
  2. Vectored exception handlers: AddVectoredExceptionHandler is a no-op, and SDL names its threads with RaiseException(0x406D1388) behind a handler that returns EXCEPTION_CONTINUE_EXECUTION, so it ends as unhandled exception 0x406d1388. Calling the registered handlers at the start of raise() in seh.cpp gets past it (tried locally, about 15 lines).
  3. SDL's joystick thread creates its message-only window from a non-main thread, and CreateWindowExW makes an NSWindow: NSInternalInconsistencyException: NSWindow should only be instantiated on the main thread!. That one is a choice about window.mm (no NSWindow for HWND_MESSAGE?), so I'm leaving it to you. Happy to send 1 and 2 as a follow-up.

Tested

Apple M4 Pro, macOS 27.2.1, Rosetta 2, MoltenVK 1.4.2 (universal release), clang/lld 23.1.6, xwin 0.10.0 SDK 10.0.26100; gta6rt cross-built with the static CRT (runtime/build/windows-mac-mt).

  • shell_probe: exit 0. A mutant (n / 2 → n in the backslash rule) fails it at check 3.
  • Host probes guest, crt_probe, pool_probe, eh_probe, eh_probe_mt, cpuid_probe: exit 0; illegal_probe: traps 21, all ok. Same as before the change.
  • gta6rt --run tiny_game -- hello 42 tls → 0, exit-code → 42. eh → 70 (unhandled C++ exception) both before and after this change, on this M4 Pro (reported on #7446).
  • d3d12_*: 61 run, 5 fail (uav_clear, fence_timing, descriptor, depth_resolve, query_rules), same set before and after.
  • On main 867d922f0 + #8539 + this branch: no winmm/ole32/setupapi/gdi32/shell32/oleaut32 entries left in the strict-imports dry run.

No game files used. AI-assisted.

🤖 Generated with Claude Code

Lucasyudi and others added 2 commits November 23, 2026 18:27
… imports SDL3 needs

gta6rt.exe built with SDL3 (the GameInput shim's controller backend) imports
these; the gameinput ctest stopped at winmm!timeBeginPeriod. COM, the device
tree and GDI answer as a machine without the class, device or screen DC;
CommandLineToArgvW follows Windows' quoting rules and CoWaitForMultipleHandles
reuses WaitForMultipleObjects. guest/shell_probe.c checks them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SDL's GetExeName and GetBasePath split the module path at its last '\', so
the host's POSIX path made SDL_Init crash in strlen(NULL). The path still
opens: to_host_path maps '\' back to '/'. shell_probe checks 19-22.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adrbn

adrbn commented Nov 23, 2026

Copy link
Copy Markdown
Owner

@Lucasyudi the eh failure you reported is fixed in e1c9d1e60: the /MD throw path only looked for a catch in the host's main image, which under gta6rt --run is gta6rt.exe rather than the game. gta6rt --run tiny_game.exe -- hello 42 tls eh game-file exit-code now exits 42 here with build.sh's /MD tiny_game. I'll review this PR next.

@adrbn
adrbn merged commit a1c8d43 into adrbn:mac-native-host Nov 23, 2026
@adrbn

adrbn commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Merged into mac-native-host (a1c8d43be), with the conflicts against #6 (build.sh now uses compile_guest) and the export list resolved. shell_probe, crt_probe, eh_probe, eh_probe_mt, vk_clear and pool_probe exit 0, and gta6rt --run tiny_game.exe -- hello 42 tls eh game-file exit-code exits 42. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants