Always use _exit to terminate (for now)

This commit is contained in:
Luke Street 2025-10-09 13:14:59 -06:00
parent dc5a91c480
commit e185629d19
6 changed files with 18 additions and 7 deletions

View File

@ -1,5 +1,6 @@
#include "common.h"
#include "context.h"
#include "kernel32/internal.h"
#include "modules.h"
#include <csignal>
@ -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) {

View File

@ -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<int>(dwExceptionCode));
exitInternal(dwExceptionCode);
}
PVOID WIN_FUNC AddVectoredExceptionHandler(ULONG First, PVECTORED_EXCEPTION_HANDLER Handler) {

View File

@ -183,5 +183,6 @@ inline bool isPseudoCurrentThreadHandle(HANDLE h) {
void tryMarkExecutable(void *mem);
void setLastErrorFromErrno();
[[noreturn]] void exitInternal(DWORD exitCode);
} // namespace kernel32

View File

@ -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<int>(exitCode));
}
void WIN_FUNC ExitProcess(UINT uExitCode) {
HOST_CONTEXT_GUARD();
DEBUG_LOG("ExitProcess(%u)\n", uExitCode);
exit(static_cast<int>(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<int>(uExitCode));
exitInternal(uExitCode);
}
auto process = wibo::handles().getAs<ProcessObject>(hProcess);
if (!process) {

View File

@ -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

View File

@ -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) {