|
34 | 34 |
|
35 | 35 | #include "ImageInspection.h" |
36 | 36 | #include "swift/Demangling/Demangle.h" |
| 37 | +#include "swift/Runtime/Atomic.h" |
37 | 38 | #include "swift/Runtime/Debug.h" |
38 | 39 | #include "swift/Runtime/Portability.h" |
39 | 40 | #include "swift/Runtime/Win32.h" |
|
64 | 65 | #include <inttypes.h> |
65 | 66 |
|
66 | 67 | #ifdef SWIFT_HAVE_CRASHREPORTERCLIENT |
67 | | -#include <atomic> |
68 | 68 | #include <malloc/malloc.h> |
69 | | - |
70 | | -#include "swift/Runtime/Atomic.h" |
| 69 | +#else |
| 70 | +static std::atomic<const char *> kFatalErrorMessage; |
71 | 71 | #endif // SWIFT_HAVE_CRASHREPORTERCLIENT |
72 | 72 |
|
73 | 73 | #include "BacktracePrivate.h" |
74 | 74 |
|
| 75 | +#include <atomic> |
| 76 | + |
75 | 77 | namespace FatalErrorFlags { |
76 | 78 | enum: uint32_t { |
77 | 79 | ReportBacktrace = 1 << 0 |
@@ -297,7 +299,23 @@ reportOnCrash(uint32_t flags, const char *message) |
297 | 299 | std::memory_order_release, |
298 | 300 | SWIFT_MEMORY_ORDER_CONSUME)); |
299 | 301 | #else |
300 | | - // empty |
| 302 | + const char *previous = nullptr; |
| 303 | + char *current = nullptr; |
| 304 | + previous = |
| 305 | + std::atomic_load_explicit(&kFatalErrorMessage, SWIFT_MEMORY_ORDER_CONSUME); |
| 306 | + |
| 307 | + do { |
| 308 | + ::free(current); |
| 309 | + current = nullptr; |
| 310 | + |
| 311 | + if (previous) |
| 312 | + swift_asprintf(¤t, "%s%s", current, message); |
| 313 | + else |
| 314 | + current = ::strdup(message); |
| 315 | + } while (!std::atomic_compare_exchange_strong_explicit(&kFatalErrorMessage, |
| 316 | + &previous, current, |
| 317 | + std::memory_order_release, |
| 318 | + SWIFT_MEMORY_ORDER_CONSUME)); |
301 | 319 | #endif // SWIFT_HAVE_CRASHREPORTERCLIENT |
302 | 320 | } |
303 | 321 |
|
@@ -421,6 +439,12 @@ void swift::swift_reportWarning(uint32_t flags, const char *message) { |
421 | 439 | warning(flags, "%s", message); |
422 | 440 | } |
423 | 441 |
|
| 442 | +#if !defined(SWIFT_HAVE_CRASHREPORTERCLIENT) |
| 443 | +std::atomic<const char *> *swift::swift_getFatalErrorMessageBuffer() { |
| 444 | + return &kFatalErrorMessage; |
| 445 | +} |
| 446 | +#endif |
| 447 | + |
424 | 448 | // Crash when a deleted method is called by accident. |
425 | 449 | SWIFT_RUNTIME_EXPORT SWIFT_NORETURN void swift_deletedMethodError() { |
426 | 450 | swift::fatalError(/* flags = */ 0, |
|
0 commit comments