Skip to content

Commit b0073f2

Browse files
committed
Process: handle HRESULT exit codes properly
When a process terminates due to an unhandled exception via a `HRESULT`, the process termination status will not have `0xC000_0000` or `0xE000_0000` but rather `0x8000_0000` set. This accounts for that and properly classifies the exit as an abnormal exit. This was identified by the swift-driver test suite not properly detecting an abnormal exit of the frontend.
1 parent 483f3ff commit b0073f2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Sources/Foundation/Process.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,9 @@ open class Process: NSObject {
631631
// 3 to be an abnormal exit.
632632
var dwExitCode: DWORD = 0
633633
GetExitCodeProcess(process.processHandle, &dwExitCode)
634-
if (dwExitCode & 0xF0000000) == 0xC0000000
635-
|| (dwExitCode & 0xF0000000) == 0xE0000000
634+
if (dwExitCode & 0xF0000000) == 0x80000000 // HRESULT
635+
|| (dwExitCode & 0xF0000000) == 0xC0000000 // NTSTATUS
636+
|| (dwExitCode & 0xF0000000) == 0xE0000000 // NTSTATUS (Customer)
636637
|| dwExitCode == 3 {
637638
process._terminationStatus = Int32(dwExitCode & 0x3FFFFFFF)
638639
process._terminationReason = .uncaughtSignal

0 commit comments

Comments
 (0)