diff --git a/dll/crt.cpp b/dll/crt.cpp index f713677..6191928 100644 --- a/dll/crt.cpp +++ b/dll/crt.cpp @@ -1,5 +1,6 @@ #include "common.h" #include "context.h" +#include "kernel32/internal.h" #include "modules.h" #include @@ -291,7 +292,7 @@ void WIN_ENTRY exit(int status) { (*it)(); } } - ::_exit(status); + kernel32::exitInternal(status); } void WIN_ENTRY _cexit() { @@ -310,7 +311,7 @@ void WIN_ENTRY _cexit() { void WIN_ENTRY _exit(int status) { HOST_CONTEXT_GUARD(); DEBUG_LOG("_exit(%i)\n", status); - ::_exit(status); + kernel32::exitInternal(status); } void WIN_ENTRY abort(void) { diff --git a/dll/kernel32/errhandlingapi.cpp b/dll/kernel32/errhandlingapi.cpp index d261b09..8c572aa 100644 --- a/dll/kernel32/errhandlingapi.cpp +++ b/dll/kernel32/errhandlingapi.cpp @@ -3,6 +3,7 @@ #include "common.h" #include "context.h" #include "errors.h" +#include "internal.h" namespace { @@ -35,7 +36,7 @@ void WIN_FUNC RaiseException(DWORD dwExceptionCode, DWORD dwExceptionFlags, DWOR (void)dwExceptionFlags; (void)nNumberOfArguments; (void)lpArguments; - exit(static_cast(dwExceptionCode)); + exitInternal(dwExceptionCode); } PVOID WIN_FUNC AddVectoredExceptionHandler(ULONG First, PVECTORED_EXCEPTION_HANDLER Handler) { diff --git a/dll/kernel32/internal.h b/dll/kernel32/internal.h index 87139f1..1cc4907 100644 --- a/dll/kernel32/internal.h +++ b/dll/kernel32/internal.h @@ -183,5 +183,6 @@ inline bool isPseudoCurrentThreadHandle(HANDLE h) { void tryMarkExecutable(void *mem); void setLastErrorFromErrno(); +[[noreturn]] void exitInternal(DWORD exitCode); } // namespace kernel32 diff --git a/dll/kernel32/processthreadsapi.cpp b/dll/kernel32/processthreadsapi.cpp index 207c54f..aceced9 100644 --- a/dll/kernel32/processthreadsapi.cpp +++ b/dll/kernel32/processthreadsapi.cpp @@ -312,17 +312,24 @@ DWORD_PTR WIN_FUNC SetThreadAffinityMask(HANDLE hThread, DWORD_PTR dwThreadAffin return processMask; } +[[noreturn]] void exitInternal(DWORD exitCode) { + DEBUG_LOG("exitInternal(%u)\n", exitCode); + // We have some problems cleaning up when shutting down with exit; + // temporarily use _exit to terminate without running cleanup + _exit(static_cast(exitCode)); +} + void WIN_FUNC ExitProcess(UINT uExitCode) { HOST_CONTEXT_GUARD(); DEBUG_LOG("ExitProcess(%u)\n", uExitCode); - exit(static_cast(uExitCode)); + exitInternal(uExitCode); } BOOL WIN_FUNC TerminateProcess(HANDLE hProcess, UINT uExitCode) { HOST_CONTEXT_GUARD(); DEBUG_LOG("TerminateProcess(%p, %u)\n", hProcess, uExitCode); if (isPseudoCurrentProcessHandle(hProcess)) { - exit(static_cast(uExitCode)); + exitInternal(uExitCode); } auto process = wibo::handles().getAs(hProcess); if (!process) { diff --git a/dll/mscoree.cpp b/dll/mscoree.cpp index bd270a4..ffcfccf 100644 --- a/dll/mscoree.cpp +++ b/dll/mscoree.cpp @@ -1,5 +1,6 @@ #include "common.h" #include "context.h" +#include "kernel32/internal.h" #include "modules.h" namespace mscoree { @@ -7,7 +8,7 @@ namespace mscoree { void WIN_FUNC CorExitProcess(int exitCode) { HOST_CONTEXT_GUARD(); DEBUG_LOG("CorExitProcess(%i)\n", exitCode); - exit(exitCode); + kernel32::exitInternal(exitCode); } } // namespace mscoree diff --git a/dll/msvcrt.cpp b/dll/msvcrt.cpp index f464a2f..bf19eb7 100644 --- a/dll/msvcrt.cpp +++ b/dll/msvcrt.cpp @@ -2741,7 +2741,7 @@ namespace msvcrt { void WIN_ENTRY exit(int status) { HOST_CONTEXT_GUARD(); VERBOSE_LOG("exit(%d)\n", status); - _Exit(status); + kernel32::exitInternal(status); } int WIN_ENTRY wcsncmp(const uint16_t *string1, const uint16_t *string2, size_t count) {