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 a692a6224..1705bf5e4 100644 --- a/runtime/shims/process.cpp +++ b/runtime/shims/process.cpp | |||
| @@ -489,30 +489,30 @@ wchar_t** current_wide_environment() { | |||
| 489 | return _wenviron; | 489 | return _wenviron; |
| 490 | } | 490 | } |
| 491 | 491 | ||
| 492 | // msvcrt.dll: int __getmainargs(int* argc, char*** argv, char*** env, int expand, void* startinfo) | 492 | // msvcrt.dll: int __getmainargs(int* argc, char*** argv, char*** env, int expand, void* startinfo). A nonzero |
| 493 | int __cdecl game_getmainargs(int* argc, char*** argv, char*** env, int, void*) { | 493 | // `expand` (the CRT's _dowildcard) expands wildcards in the arguments, as _configure_narrow_argv's mode 2 does. |
| 494 | if (const int error = game_configure_narrow_argv(1)) return error; | 494 | int __cdecl game_getmainargs(int* argc, char*** argv, char*** env, int expand, void*) { |
| 495 | if (!argc || !argv) return -1; | ||
| 496 | if (const int error = game_configure_narrow_argv(expand ? 2 : 1)) return error; | ||
| 495 | *argc = g_argc; | 497 | *argc = g_argc; |
| 496 | *argv = g_argv_ptr; | 498 | *argv = g_argv_ptr; |
| 497 | if (env) *env = current_environment(); | 499 | if (env) *env = current_environment(); |
| 498 | return 0; | 500 | return 0; |
| 499 | } | 501 | } |
| 500 | int __cdecl game_wgetmainargs(int* argc, wchar_t*** argv, wchar_t*** env, int, void*) { | 502 | int __cdecl game_wgetmainargs(int* argc, wchar_t*** argv, wchar_t*** env, int expand, void*) { |
| 501 | if (const int error = game_configure_wide_argv(1)) return error; | 503 | if (!argc || !argv) return -1; |
| 504 | if (const int error = game_configure_wide_argv(expand ? 2 : 1)) return error; | ||
| 502 | *argc = g_argc; | 505 | *argc = g_argc; |
| 503 | *argv = g_wargv_ptr; | 506 | *argv = g_wargv_ptr; |
| 504 | if (env) *env = current_wide_environment(); | 507 | if (env) *env = current_wide_environment(); |
| 505 | return 0; | 508 | return 0; |
| 506 | } | 509 | } |
| 507 | 510 | ||
| 508 | struct EntryCall { | 511 | // `p` is the entry point itself: run_entry can return (another thread ended the run) before this thread first runs, |
| 509 | void* entry; | 512 | // so nothing of run_entry's frame may be read here. |
| 510 | }; | ||
| 511 | |||
| 512 | DWORD WINAPI game_thread(void* p) { | 513 | DWORD WINAPI game_thread(void* p) { |
| 513 | auto* call = static_cast<EntryCall*>(p); | ||
| 514 | // An EXE entry point (mainCRTStartup and friends) takes the PEB pointer and returns the process exit code. | 514 | // An EXE entry point (mainCRTStartup and friends) takes the PEB pointer and returns the process exit code. |
| 515 | auto entry = reinterpret_cast<DWORD(WINAPI*)(void*)>(call->entry); | 515 | auto entry = reinterpret_cast<DWORD(WINAPI*)(void*)>(p); |
| 516 | const DWORD code = entry(nullptr); | 516 | const DWORD code = entry(nullptr); |
| 517 | end_run(static_cast<int>(code)); // returning from the entry point is an exit too | 517 | end_run(static_cast<int>(code)); // returning from the entry point is an exit too |
| 518 | } | 518 | } |
| @@ -554,8 +554,7 @@ int run_entry(void* entry, size_t stack_bytes) { | |||
| 554 | g_done = CreateEventW(nullptr, TRUE, FALSE, nullptr); | 554 | g_done = CreateEventW(nullptr, TRUE, FALSE, nullptr); |
| 555 | if (!g_done) return -1; | 555 | if (!g_done) return -1; |
| 556 | g_running = true; | 556 | g_running = true; |
| 557 | EntryCall call{entry}; | 557 | HANDLE thread = CreateThread(nullptr, stack_bytes, game_thread, entry, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr); |
| 558 | HANDLE thread = CreateThread(nullptr, stack_bytes, game_thread, &call, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr); | ||
| 559 | if (!thread) { | 558 | if (!thread) { |
| 560 | g_running = false; | 559 | g_running = false; |
| 561 | CloseHandle(g_done); | 560 | CloseHandle(g_done); |