Skip to content

Commit 072692c

Browse files
authored
Provide additional explanation for the Windows signal handling stuff. (#1182)
1 parent c171888 commit 072692c

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

Sources/Testing/ExitTests/ExitTest.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,30 @@ extension ExitTest {
245245
#if os(Windows)
246246
// Windows does not support signal handling to the degree UNIX-like systems
247247
// do. When a signal is raised in a Windows process, the default signal
248-
// handler simply calls `exit()` and passes the constant value `3`. To allow
249-
// us to handle signals on Windows, we install signal handlers for all
248+
// handler simply calls `_exit()` and passes the constant value `3`. To
249+
// allow us to handle signals on Windows, we install signal handlers for all
250250
// signals supported on Windows. These signal handlers exit with a specific
251251
// exit code that is unlikely to be encountered "in the wild" and which
252252
// encodes the caught signal. Corresponding code in the parent process looks
253253
// for these special exit codes and translates them back to signals.
254+
//
255+
// Microsoft's documentation for `_Exit()` and `_exit()` indicates they
256+
// behave identically. Their documentation for abort() can be found at
257+
// https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/abort?view=msvc-170
258+
// and states: "[...] abort calls _exit to terminate the process with exit
259+
// code 3 [...]".
260+
//
261+
// The Wine project's implementation of raise() calls `_exit(3)` by default.
262+
// See https://github.com/wine-mirror/wine/blob/master/dlls/msvcrt/except.c
263+
//
264+
// Finally, an official copy of the UCRT sources (not up to date) is hosted
265+
// at https://www.nuget.org/packages/Microsoft.Windows.SDK.CRTSource . That
266+
// repository doesn't have an official GitHub mirror, but you can manually
267+
// navigate to misc/signal.cpp:481 to see the implementation of SIG_DFL
268+
// (which, again, calls `_exit(3)` unconditionally.)
254269
for sig in [SIGINT, SIGILL, SIGFPE, SIGSEGV, SIGTERM, SIGBREAK, SIGABRT, SIGABRT_COMPAT] {
255270
_ = signal(sig) { sig in
256-
_Exit(STATUS_SIGNAL_CAUGHT_BITS | sig)
271+
_exit(STATUS_SIGNAL_CAUGHT_BITS | sig)
257272
}
258273
}
259274
#endif

0 commit comments

Comments
 (0)