LibCore: Add immediate process termination helper
Add Core::Process::terminate_immediately() as the shared primitive for terminating a process without running exit-time destructors. Use _exit() on POSIX and TerminateProcess() on Windows.
This commit is contained in:
parent
2635c334b0
commit
8c7b5b4de6
3 changed files with 18 additions and 0 deletions
|
|
@ -7,6 +7,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/ByteString.h>
|
||||
#include <AK/ScopeGuard.h>
|
||||
#include <AK/String.h>
|
||||
|
|
@ -257,6 +258,12 @@ ErrorOr<Process> Process::spawn(StringView path, ReadonlySpan<StringView> argume
|
|||
return process;
|
||||
}
|
||||
|
||||
void Process::terminate_immediately(int status)
|
||||
{
|
||||
_exit(status);
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
ErrorOr<String> Process::get_name()
|
||||
{
|
||||
#if defined(AK_OS_SERENITY)
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ public:
|
|||
|
||||
static ErrorOr<String> get_name();
|
||||
|
||||
[[noreturn]] static void terminate_immediately(int status);
|
||||
|
||||
static void wait_for_debugger_and_break();
|
||||
static ErrorOr<bool> is_being_debugged();
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Utf16View.h>
|
||||
#include <AK/Vector.h>
|
||||
|
|
@ -99,6 +100,14 @@ ErrorOr<Process> Process::spawn(StringView path, ReadonlySpan<StringView> argume
|
|||
});
|
||||
}
|
||||
|
||||
void Process::terminate_immediately(int status)
|
||||
{
|
||||
// TerminateProcess() is stronger than the CRT's _exit(), since it skips
|
||||
// DLL detach notifications and the other ExitProcess() teardown paths.
|
||||
TerminateProcess(GetCurrentProcess(), static_cast<UINT>(status));
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
// Get the full path of the executable file of the current process
|
||||
ErrorOr<String> Process::get_name()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue