Skip to content

Commit 5d095bc

Browse files
author
Jason Mittertreiner
committed
Have Windows Call Signaled Callback on Crashes
The signaled callback is treated more as a general crash handler clean up wise. While it doesn't 100% line up, have Windows call the signaled callback on exit codes considered to be errors.
1 parent 003850f commit 5d095bc

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

lib/Basic/Default/TaskQueue.inc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,22 @@ bool TaskQueue::execute(TaskBeganCallback Began, TaskFinishedCallback Finished,
143143
stderrContents = stderrBuffer.get()->getBuffer();
144144
}
145145

146-
if (ReturnCode == -2) {
146+
#if defined(_WIN32)
147+
// Wait() sets the upper two bits of the return code to indicate warnings
148+
// (10) and errors (11).
149+
//
150+
// This isn't a true signal on Windows, but we'll treat it as such so that
151+
// we clean up after it properly
152+
bool crashed = ReturnCode & 0xC0000000;
153+
#else
147154
// Wait() returning a return code of -2 indicates the process received
148155
// a signal during execution.
156+
bool crashed = ReturnCode == -2;
157+
#endif
158+
if (crashed) {
149159
if (Signalled) {
150160
TaskFinishedResponse Response =
151-
Signalled(PI.Pid, ErrMsg, stdoutContents, stderrContents, T->Context, None, TaskProcessInformation(PI.Pid));
161+
Signalled(PI.Pid, ErrMsg, stdoutContents, stderrContents, T->Context, ReturnCode, TaskProcessInformation(PI.Pid));
152162
ContinueExecution = Response != TaskFinishedResponse::StopExecution;
153163
} else {
154164
// If we don't have a Signalled callback, unconditionally stop.

test/Driver/assert.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Windows programs cannot fail due to a signal
2-
// UNSUPPORTED: windows
31
// RUN: not %swiftc_driver -emit-executable -o %t.exe %s -Xfrontend -debug-assert-immediately 2>&1 | %FileCheck %s
42
// RUN: not %swiftc_driver -emit-executable -o %t.exe %s -Xfrontend -debug-assert-after-parse 2>&1 | %FileCheck %s
53

test/Driver/crash.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Windows programs cannot fail due to a signal
2-
// UNSUPPORTED: windows
31
// RUN: not %swiftc_driver -emit-executable -o %t.exe %s -Xfrontend -debug-crash-immediately 2>&1 | %FileCheck %s
42

53
// RUN: not %swiftc_driver -emit-executable -o %t.exe %s -Xfrontend -debug-crash-after-parse 2>&1 | %FileCheck %s

0 commit comments

Comments
 (0)