From a0c424622ab2698cc9eb7d8a0902136f7b89a928 Mon Sep 17 00:00:00 2001 From: Alastair Houghton Date: Mon, 3 Nov 2025 10:24:05 +0000 Subject: [PATCH] [Observation] Add threading fatal error handler. When the Threading library experiences a fatal error, we need to tell it what to do. --- .../Sources/Observation/CMakeLists.txt | 1 + .../Sources/Observation/ThreadingError.cpp | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 stdlib/public/Observation/Sources/Observation/ThreadingError.cpp diff --git a/stdlib/public/Observation/Sources/Observation/CMakeLists.txt b/stdlib/public/Observation/Sources/Observation/CMakeLists.txt index 2e7259a1421..09bc8524d5c 100644 --- a/stdlib/public/Observation/Sources/Observation/CMakeLists.txt +++ b/stdlib/public/Observation/Sources/Observation/CMakeLists.txt @@ -19,6 +19,7 @@ add_swift_target_library(swiftObservation ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS ObservationRegistrar.swift ObservationTracking.swift Observations.swift + ThreadingError.cpp ThreadLocal.cpp ThreadLocal.swift diff --git a/stdlib/public/Observation/Sources/Observation/ThreadingError.cpp b/stdlib/public/Observation/Sources/Observation/ThreadingError.cpp new file mode 100644 index 00000000000..d6ff578d6f2 --- /dev/null +++ b/stdlib/public/Observation/Sources/Observation/ThreadingError.cpp @@ -0,0 +1,26 @@ +//===--- ThreadingError.cpp - Error handling support code -----------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +#include "swift/Threading/Errors.h" +#include +#include + +// Handle fatal errors from the threading library +SWIFT_ATTRIBUTE_NORETURN +SWIFT_FORMAT(1, 2) +void swift::threading::fatal(const char *format, ...) { + va_list val; + + va_start(val, format); + vfprintf(stderr, format, val); + abort(); +}