diff options
Diffstat (limited to 'runtime/shims/process.cpp')
| -rw-r--r-- | runtime/shims/process.cpp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/runtime/shims/process.cpp b/runtime/shims/process.cpp index 2c37292e2..29663a92f 100644 --- a/runtime/shims/process.cpp +++ b/runtime/shims/process.cpp | |||
| @@ -417,30 +417,30 @@ wchar_t** current_wide_environment() { | |||
| 417 | return _wenviron; | 417 | return _wenviron; |
| 418 | } | 418 | } |
| 419 | 419 | ||
| 420 | // msvcrt.dll: int __getmainargs(int* argc, char*** argv, char*** env, int expand, void* startinfo) | 420 | // msvcrt.dll: int __getmainargs(int* argc, char*** argv, char*** env, int expand, void* startinfo). A nonzero |
| 421 | int __cdecl game_getmainargs(int* argc, char*** argv, char*** env, int, void*) { | 421 | // `expand` (the CRT's _dowildcard) expands wildcards in the arguments, as _configure_narrow_argv's mode 2 does. |
| 422 | if (const int error = game_configure_narrow_argv(1)) return error; | 422 | int __cdecl game_getmainargs(int* argc, char*** argv, char*** env, int expand, void*) { |
| 423 | if (!argc || !argv) return -1; | ||
| 424 | if (const int error = game_configure_narrow_argv(expand ? 2 : 1)) return error; | ||
| 423 | *argc = g_argc; | 425 | *argc = g_argc; |
| 424 | *argv = g_argv_ptr; | 426 | *argv = g_argv_ptr; |
| 425 | if (env) *env = current_environment(); | 427 | if (env) *env = current_environment(); |
| 426 | return 0; | 428 | return 0; |
| 427 | } | 429 | } |
| 428 | int __cdecl game_wgetmainargs(int* argc, wchar_t*** argv, wchar_t*** env, int, void*) { | 430 | int __cdecl game_wgetmainargs(int* argc, wchar_t*** argv, wchar_t*** env, int expand, void*) { |
| 429 | if (const int error = game_configure_wide_argv(1)) return error; | 431 | if (!argc || !argv) return -1; |
| 432 | if (const int error = game_configure_wide_argv(expand ? 2 : 1)) return error; | ||
| 430 | *argc = g_argc; | 433 | *argc = g_argc; |
| 431 | *argv = g_wargv_ptr; | 434 | *argv = g_wargv_ptr; |
| 432 | if (env) *env = current_wide_environment(); | 435 | if (env) *env = current_wide_environment(); |
| 433 | return 0; | 436 | return 0; |
| 434 | } | 437 | } |
| 435 | 438 | ||
| 436 | struct EntryCall { | 439 | // `p` is the entry point itself: run_entry can return (another thread ended the run) before this thread first runs, |
| 437 | void* entry; | 440 | // so nothing of run_entry's frame may be read here. |
| 438 | }; | ||
| 439 | |||
| 440 | DWORD WINAPI game_thread(void* p) { | 441 | DWORD WINAPI game_thread(void* p) { |
| 441 | auto* call = static_cast<EntryCall*>(p); | ||
| 442 | // An EXE entry point (mainCRTStartup and friends) takes the PEB pointer and returns the process exit code. | 442 | // An EXE entry point (mainCRTStartup and friends) takes the PEB pointer and returns the process exit code. |
| 443 | auto entry = reinterpret_cast<DWORD(WINAPI*)(void*)>(call->entry); | 443 | auto entry = reinterpret_cast<DWORD(WINAPI*)(void*)>(p); |
| 444 | const DWORD code = entry(nullptr); | 444 | const DWORD code = entry(nullptr); |
| 445 | end_run(static_cast<int>(code)); // returning from the entry point is an exit too | 445 | end_run(static_cast<int>(code)); // returning from the entry point is an exit too |
| 446 | } | 446 | } |
| @@ -480,8 +480,7 @@ int run_entry(void* entry, size_t stack_bytes) { | |||
| 480 | g_done = CreateEventW(nullptr, TRUE, FALSE, nullptr); | 480 | g_done = CreateEventW(nullptr, TRUE, FALSE, nullptr); |
| 481 | if (!g_done) return -1; | 481 | if (!g_done) return -1; |
| 482 | g_running = true; | 482 | g_running = true; |
| 483 | EntryCall call{entry}; | 483 | HANDLE thread = CreateThread(nullptr, stack_bytes, game_thread, entry, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr); |
| 484 | HANDLE thread = CreateThread(nullptr, stack_bytes, game_thread, &call, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr); | ||
| 485 | if (!thread) { | 484 | if (!thread) { |
| 486 | g_running = false; | 485 | g_running = false; |
| 487 | CloseHandle(g_done); | 486 | CloseHandle(g_done); |