|
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"
|
|
66 | 67 | #ifdef SWIFT_HAVE_CRASHREPORTERCLIENT
|
67 | 68 | #include <atomic>
|
68 | 69 | #include <malloc/malloc.h>
|
69 |
| - |
70 |
| -#include "swift/Runtime/Atomic.h" |
| 70 | +#else |
| 71 | +static _Atomic char *kFatalErrorMessage; |
71 | 72 | #endif // SWIFT_HAVE_CRASHREPORTERCLIENT
|
72 | 73 |
|
73 | 74 | #include "BacktracePrivate.h"
|
@@ -297,7 +298,24 @@ reportOnCrash(uint32_t flags, const char *message)
|
297 | 298 | std::memory_order_release,
|
298 | 299 | SWIFT_MEMORY_ORDER_CONSUME));
|
299 | 300 | #else
|
300 |
| - // empty |
| 301 | + char *previous = nullptr, *current = nullptr; |
| 302 | + previous = |
| 303 | + std::atomic_load_explicit(&kFatalErrorMessage, SWIFT_MEMORY_ORDER_CONSUME); |
| 304 | + |
| 305 | + do { |
| 306 | + if (current) { |
| 307 | + free(current); |
| 308 | + current = nullptr; |
| 309 | + } |
| 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,10 @@ void swift::swift_reportWarning(uint32_t flags, const char *message) {
|
421 | 439 | warning(flags, "%s", message);
|
422 | 440 | }
|
423 | 441 |
|
| 442 | +const char * _Atomic *swift::swift_getFatalErrorMessageBuffer() { |
| 443 | + return &kFatalErrorMessage; |
| 444 | +} |
| 445 | + |
424 | 446 | // Crash when a deleted method is called by accident.
|
425 | 447 | SWIFT_RUNTIME_EXPORT SWIFT_NORETURN void swift_deletedMethodError() {
|
426 | 448 | swift::fatalError(/* flags = */ 0,
|
|
0 commit comments