|
| 1 | +/* |
| 2 | + For more information, please see: http://software.sci.utah.edu |
| 3 | +
|
| 4 | + The MIT License |
| 5 | +
|
| 6 | + Copyright (c) 2020 Scientific Computing and Imaging Institute, |
| 7 | + University of Utah. |
| 8 | +
|
| 9 | + Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | + copy of this software and associated documentation files (the "Software"), |
| 11 | + to deal in the Software without restriction, including without limitation |
| 12 | + the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | + and/or sell copies of the Software, and to permit persons to whom the |
| 14 | + Software is furnished to do so, subject to the following conditions: |
| 15 | +
|
| 16 | + The above copyright notice and this permission notice shall be included |
| 17 | + in all copies or substantial portions of the Software. |
| 18 | +
|
| 19 | + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 24 | + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 25 | + DEALINGS IN THE SOFTWARE. |
| 26 | +*/ |
| 27 | + |
| 28 | + |
| 29 | +#ifndef CORE_UTILS_QUICKEXIT_H |
| 30 | +#define CORE_UTILS_QUICKEXIT_H |
| 31 | + |
| 32 | +#include <cstdlib> |
| 33 | + |
| 34 | +namespace SCIRun |
| 35 | +{ |
| 36 | +namespace Core |
| 37 | +{ |
| 38 | + |
| 39 | +/// Terminates the process immediately, skipping static destructors and atexit |
| 40 | +/// handlers, while still propagating @a code to the caller (e.g. CTest). Used in |
| 41 | +/// regression mode to avoid hangs and crashes in async teardown paths where |
| 42 | +/// streaming execution threads outlive the GUI objects. |
| 43 | +/// |
| 44 | +/// Apple always takes _Exit so that one build runs on every supported macOS. |
| 45 | +/// quick_exit entered libSystem in macOS 15.0, which breaks both directions: |
| 46 | +/// |
| 47 | +/// - Against SDKs older than 15, it is not declared at all. Both spellings fail to |
| 48 | +/// compile -- "quick_exit" as an undeclared identifier, "std::quick_exit" as a |
| 49 | +/// reference to an unresolved using declaration, since libc++'s <cstdlib> has no |
| 50 | +/// ::quick_exit to pull in. |
| 51 | +/// - Against the 15 SDK it is declared ("void quick_exit(int) __dead2;" in |
| 52 | +/// _stdlib.h) gated only on __DARWIN_C_LEVEL/C11 -- a compile-time feature gate |
| 53 | +/// carrying no availability annotation -- so the compiler can neither warn nor |
| 54 | +/// weak-link. The object gets a hard _quick_exit reference and aborts on load on |
| 55 | +/// macOS < 15 with "dyld: Symbol not found: _quick_exit". |
| 56 | +/// |
| 57 | +/// The trigger is the SDK, not the host: a macOS 14 machine with Xcode 16 installed |
| 58 | +/// builds the broken binary. Gating on __MAC_OS_X_VERSION_MIN_REQUIRED does not help |
| 59 | +/// either, because the deployment target is not pinned -- it follows the build host, |
| 60 | +/// and so reads 150000 on exactly the builders that emit the hard reference. |
| 61 | +/// |
| 62 | +/// The two branches are equivalent only so long as nothing registers at_quick_exit |
| 63 | +/// handlers: _Exit does not run them. |
| 64 | +[[noreturn]] inline void quickExit(int code) |
| 65 | +{ |
| 66 | +#ifdef __APPLE__ |
| 67 | + std::_Exit(code); |
| 68 | +#else |
| 69 | + std::quick_exit(code); |
| 70 | +#endif |
| 71 | +} |
| 72 | + |
| 73 | +}} |
| 74 | + |
| 75 | +#endif |
0 commit comments