hle(kernel, files), loader(native): Win32 module paths/exports, DisableThreadLibraryCalls & DLL_THREAD_DETACH order, caller backtraces, and MiniDumpWriteDump #570

Open
opened 2026-11-28 05:23:39 +00:00 by github-bot · 2 comments
Owner

@⁠Sheffy007 on GitHub · 2026-11-28 05:19 UTC · original

Refs #460, #525

Problem

Several Win32 module, path, thread-notification, and diagnostic APIs on the native macOS path diverge from the Windows loader and HLE contracts:

  1. GetModuleFileNameW / GetModuleFileNameA return raw macOS POSIX paths (/Users/.../Game.exe) instead of mounted Win32 drive paths (G:\Game.exe), and leave LastError unset on invalid handles:
    • native_run.rs mounts the package folder as G: and sets GetCommandLineW() to G:\<exe>, but kernel::title_path returns the host POSIX path with / and no drive letter, breaking Win32 callers that split on \ (wcsrchr, _wsplitpath_s, GetFullPathNameW, CRT _get_wpgmptr, XLaunchNewGame).
    • Invalid module handles return 0 without setting ERROR_MOD_NOT_FOUND (126).
  2. GetProcAddress on the main executable (NULL or GetModuleHandle(NULL)) ignores PE exports and leaves LastError unset, and dbghelp.dll!MiniDumpWriteDump logs an unimplemented warning on every run (#521):
    • host::get_proc_address only checks TitleDlls and fake_dll, missing exports on the main NativeImage (D3D12SDKVersion, NvOptimusEnablement, AmdPowerXpressRequestHighPerformance, or title exports) and returning NULL with LastError == 0.
    • Breakpad probes dbghelp.dll!MiniDumpWriteDump at startup (GetProcAddress: not implemented dll="dbghelp.dll" symbol=MiniDumpWriteDump in #521).
  3. DisableThreadLibraryCalls and DLL_THREAD_DETACH violate the Windows loader contract:
    • Most DLLs call DisableThreadLibraryCalls(hinstDLL) inside DllMain(DLL_PROCESS_ATTACH), which runs before register_dll_thread_notices(&dll.image) is called, so the call is silently lost and DllMain continues receiving thread notices.
    • DisableThreadLibraryCalls on native macOS unconditionally returns 1 (TRUE) even for DLLs with static TLS (where Windows fails with FALSE) and for invalid handles.
    • notify_threads(DLL_THREAD_DETACH) notifies modules in forward load order and runs TLS callbacks before DllMain, instead of reverse load order with DllMain before TLS callbacks as Windows does.
  4. Native kernel::host::callers() always returns "":
    • exit, abort, terminate, _invalid_parameter_noinfo_noreturn, TerminateProcess, and refused-DLL logs print from="" instead of unwinding title callers (dll+0xrva < image+0xrva).
  5. Narrow/auxiliary host_posix::files helpers (DeleteFileA, CreateDirectoryA, RemoveDirectoryA, GetDiskFreeSpaceW, GetFullPathNameW/A) are missing.

Proposed Fix

  • Translate GetModuleFileNameW/A paths through mounted host_posix::files drives (G:\..., longest-prefix match, round-tripping cleanly through files::translate) and set ERROR_MOD_NOT_FOUND on unknown handles; add DeleteFileA, CreateDirectoryA, RemoveDirectoryA, GetDiskFreeSpaceW, and GetFullPathNameW/A in host_posix::files.
  • Track mapped NativeImage metadata/exports so GetProcAddress resolves exports on the main executable and sets ERROR_PROC_NOT_FOUND / ERROR_MOD_NOT_FOUND accurately; provide a clean ERROR_NOT_SUPPORTED stub for dbghelp.dll!MiniDumpWriteDump on non-Windows hosts.
  • Fix native::disable_thread_calls (honouring calls made during DllMain(DLL_PROCESS_ATTACH), rejecting images with static TLS, and returning None for non-images) and reverse module + callback order on DLL_THREAD_DETACH.
  • Implement native::dump::caller_locations() and wire kernel::host::callers() on native macOS.
**@⁠Sheffy007** on GitHub · 2026-11-28 05:19 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/566) Refs #460, #525 ### Problem Several Win32 module, path, thread-notification, and diagnostic APIs on the native macOS path diverge from the Windows loader and HLE contracts: 1. **`GetModuleFileNameW` / `GetModuleFileNameA` return raw macOS POSIX paths (`/Users/.../Game.exe`) instead of mounted Win32 drive paths (`G:\Game.exe`), and leave `LastError` unset on invalid handles:** - `native_run.rs` mounts the package folder as `G:` and sets `GetCommandLineW()` to `G:\<exe>`, but `kernel::title_path` returns the host POSIX path with `/` and no drive letter, breaking Win32 callers that split on `\` (`wcsrchr`, `_wsplitpath_s`, `GetFullPathNameW`, CRT `_get_wpgmptr`, `XLaunchNewGame`). - Invalid module handles return `0` without setting `ERROR_MOD_NOT_FOUND` (`126`). 2. **`GetProcAddress` on the main executable (`NULL` or `GetModuleHandle(NULL)`) ignores PE exports and leaves `LastError` unset, and `dbghelp.dll!MiniDumpWriteDump` logs an unimplemented warning on every run (`#521`):** - `host::get_proc_address` only checks `TitleDll`s and `fake_dll`, missing exports on the main `NativeImage` (`D3D12SDKVersion`, `NvOptimusEnablement`, `AmdPowerXpressRequestHighPerformance`, or title exports) and returning `NULL` with `LastError == 0`. - Breakpad probes `dbghelp.dll!MiniDumpWriteDump` at startup (`GetProcAddress: not implemented dll="dbghelp.dll" symbol=MiniDumpWriteDump` in `#521`). 3. **`DisableThreadLibraryCalls` and `DLL_THREAD_DETACH` violate the Windows loader contract:** - Most DLLs call `DisableThreadLibraryCalls(hinstDLL)` inside `DllMain(DLL_PROCESS_ATTACH)`, which runs *before* `register_dll_thread_notices(&dll.image)` is called, so the call is silently lost and `DllMain` continues receiving thread notices. - `DisableThreadLibraryCalls` on native macOS unconditionally returns `1` (`TRUE`) even for DLLs with static TLS (where Windows fails with `FALSE`) and for invalid handles. - `notify_threads(DLL_THREAD_DETACH)` notifies modules in forward load order and runs TLS callbacks before `DllMain`, instead of reverse load order with `DllMain` before TLS callbacks as Windows does. 4. **Native `kernel::host::callers()` always returns `""`:** - `exit`, `abort`, `terminate`, `_invalid_parameter_noinfo_noreturn`, `TerminateProcess`, and refused-DLL logs print `from=""` instead of unwinding title callers (`dll+0xrva < image+0xrva`). 5. **Narrow/auxiliary `host_posix::files` helpers (`DeleteFileA`, `CreateDirectoryA`, `RemoveDirectoryA`, `GetDiskFreeSpaceW`, `GetFullPathNameW`/`A`) are missing.** ### Proposed Fix - Translate `GetModuleFileNameW`/`A` paths through mounted `host_posix::files` drives (`G:\...`, longest-prefix match, round-tripping cleanly through `files::translate`) and set `ERROR_MOD_NOT_FOUND` on unknown handles; add `DeleteFileA`, `CreateDirectoryA`, `RemoveDirectoryA`, `GetDiskFreeSpaceW`, and `GetFullPathNameW`/`A` in `host_posix::files`. - Track mapped `NativeImage` metadata/exports so `GetProcAddress` resolves exports on the main executable and sets `ERROR_PROC_NOT_FOUND` / `ERROR_MOD_NOT_FOUND` accurately; provide a clean `ERROR_NOT_SUPPORTED` stub for `dbghelp.dll!MiniDumpWriteDump` on non-Windows hosts. - Fix `native::disable_thread_calls` (honouring calls made during `DllMain(DLL_PROCESS_ATTACH)`, rejecting images with static TLS, and returning `None` for non-images) and reverse module + callback order on `DLL_THREAD_DETACH`. - Implement `native::dump::caller_locations()` and wire `kernel::host::callers()` on native macOS.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 05:23:39 +00:00
Author
Owner

@⁠Sheffy007 on GitHub · 2026-11-28 05:19 UTC · original

/claim

**@⁠Sheffy007** on GitHub · 2026-11-28 05:19 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/566#issuecomment-7234595258) /claim
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-28 05:19 UTC · original

Claimed by @⁠Sheffy007. Open a draft pull request with Refs #566 in its description within 24 hours, or the claim expires.

**@⁠github-actions[bot]** on GitHub · 2026-11-28 05:19 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/566#issuecomment-7234596921) Claimed by @⁠Sheffy007. Open a draft pull request with `Refs #566` in its description within 24 hours, or the claim expires.
This discussion has been locked. Commenting is limited to contributors.
No description provided.