TSC API for detecting abnormal process termination on Windows

Hey all,

While working on the new driver I ran into an inconsistency between how the process abstractions in TSCBasic and swift-corelibs-foundation handle abnormal exits on Windows, and I was hoping to get some advice on the best way to solve it. Currently, TSCBasic.Process uses Foundation.Process under the hood when running on Windows, and exposes an ExitStatus API which excludes the uncaughtSignal case that's present on Darwin/Linux. However, Foundation.Process is currently setting its terminationReason to uncaughtSignal and clearing the top 2 bits of the exit code if it represents an abnormal exit according to the criteria here: swift-corelibs-foundation/Process.swift at f17b5a25bbc604126a8c6aca8b0b75c2e0291a6c · apple/swift-corelibs-foundation · GitHub. As a result, right now there's no way for TSCBasic.Process clients to check if an exit was abnormal, because the bits that would indicate an error have already been cleared, and the underlying terminationReason isn't exposed.

I see two possible solutions to this problem:

  1. Modify TSCBasic.Process.ExitStatus to include an uncaughtSignal case to match the one in Foundation.Process and directly forward the terminationReason. The terminology would be incorrect, but it's less invasive than the alternative.

  2. Update Foundation so that it returns an unmodified exit code and doesn't misuse the uncaughtSignal terminationReason on Windows. This feels like it has the potential to break existing programs, but I'm really not sure :man_shrugging:.

Does anyone have an idea on which approach would be better, or if there's another alternative I should consider? Ideally I think we'd change the Foundation API to make more sense on other platforms, but I assume that's a nonstarter.

1 Like