Repository navigation
Conversation
Flyander
left a comment
There was a problem hiding this comment.
One nonzero-commit path remains in the CRT wrappers. _beginthreadex only rewrites stack_size == 0; a nonzero size without STACK_SIZE_PARAM_IS_A_RESERVATION is the initial commit, and the reserve still comes from the host executable. _beginthread likewise only substitutes zero, so a nonzero request below the host reserve keeps the host's smaller reserve. Both can still create a mapped-game thread whose stack cannot grow to the game's SizeOfStackReserve.
The Windows CRT and thread-stack contracts confirm that a nonzero size without the reservation flag is a commit size, while zero uses the executable's default stack: https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/beginthread-beginthreadex?view=msvc-170 and https://learn.microsoft.com/en-us/windows/win32/procthread/thread-stack-size. Please apply the same reserve policy to nonzero _beginthreadex calls when the reservation flag is absent, and to nonzero _beginthread calls (which have no flag parameter), or document those paths as unsupported. A fixture case with a small nonzero CRT commit would catch the current gap.
Conflicts with upstream's API-set ExitProcess/GetCommandLine entries, the tiny_game_fixed fixture and the program-path set_command_line (ItsNotRexed#2861/ItsNotRexed#2661): kept both sides; the RT-119 CreateThread/_beginthread entries sit beside the EXIT_PROCESS/COMMAND_LINE macros, and main.cpp sets the stack reserve and the command line before initialise(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- CreateThread with a nonzero size and no STACK_SIZE_PARAM_IS_A_RESERVATION now gets the image reserve (raised to a 1 MiB-rounded commit if larger) with the flag; an explicit reservation is left untouched. - _beginthread gets the same size-0 substitution as _beginthreadex and is registered under the UCRT and msvcrt import names. - Extend CreateThread registration to the processthreads API-set variants and document the import scope and the commit-size trade-off. - Tests cover both new paths and check that the nonzero reserve stays at the image size.
0af9b81 to
1bdfc69
Compare
|
@Flyander Thanks for catching the nonzero commit case. Fixed in |
|
Tested 1bdfc69 on Windows 11 (MSVC RelWithDebInfo): full runtime build, then ctest for the shim/loader tests (loader, pe_loader, loader_tls, dll_thread_calls, unimplemented_policy, startup_trace, xmem, process_cmdline, file_system, winhttp_offline, xgameruntime, run_tiny_*, allocator_proxy) — 28 of 28 passed. AI-assisted. |
Claimed as RT-119 in the coordination issue. Finding by @dracbat.
What and why
The loader records the mapped PE32+ image's
SizeOfStackReserveandSizeOfStackCommit. It configures the reserve before TLS callbacks orDllMaincan create threads. The entry-point thread uses that reserve, with the previous 8 MiB fallback for an image that specifies zero.CreateThreadand_beginthreadexuse the same reserve policy. A size of zero uses the mapped image's reserve. A nonzero commit gets the larger of the image reserve and the commit rounded up to 1 MiB. Both cases passSTACK_SIZE_PARAM_IS_A_RESERVATIONand use the host's default initial commit. An explicit nonzero reservation is passed through._beginthreadexretains the caller's other flags, includingCREATE_SUSPENDED, and its unsigned stack argument caps the size the shim can pass. The import shims cover the kernel and CRT aliases listed indocs/runtime_imports.md.Mapped-image reserves are unsupported for
_beginthreadat any size. Its public API accepts only a commit size, so passing the reserve would charge that much against the system commit limit for each thread. Substituting_beginthreadexwould change the handle lifetime. The native CRT continues to handle_beginthreadand_endthread, preserving automatic handle closure. These semantics are documented in the CRT reference and the Win32 stack reference.SizeOfStackCommitis recorded for inspection. The Win32 APIs used here accept a single stack size.CreateRemoteThread(Ex)and threads created inside host DLLs continue to use the host policies. All fixtures are synthetic.Tested
Windows 11 Pro build 26200, MSVC 19.44.35229, NVIDIA GeForce RTX 5070 Ti with driver 617.42. CMake/Ninja RelWithDebInfo,
-j 4.aa2988cc. Both builds emitted the same MSVC C4456 and GLSL precision warnings.CreateThreadand_beginthreadex. The native 64 KiB_beginthreadpath measured 1 MiB and its_endthreadclosed the original handle. The shim test also checked explicit reservations, thread IDs, suspension, and 1 MiB rounding._beginthreadexlogic. Both tests failed and the fixture measured 1 MiB for its 64 KiB_beginthreadexrequest. Both tests passed after restoring the change.d3d12_fence_timingrun stalled and was stopped after 134 seconds. That test passed in 2.50 seconds on an isolated upstream retry.Checklist
AI-assisted.
Merge order: #2152 depends on this PR.