Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 1 | //===------------------------ exception.cpp -------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | ee11c31 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | #include <stdlib.h> |
Howard Hinnant | 84f697e | 2013-07-23 16:05:56 +0000 | [diff] [blame] | 10 | #include <stdio.h> |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 11 | |
| 12 | #include "exception" |
Peter Collingbourne | 4d7da9a | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 13 | #include "new" |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 14 | |
Eric Fiselier | b0da5fa | 2017-01-03 01:18:48 +0000 | [diff] [blame] | 15 | #if defined(__APPLE__) && !defined(LIBCXXRT) && \ |
| 16 | !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 17 | #include <cxxabi.h> |
Howard Hinnant | 4ad4eee | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 18 | |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 19 | using namespace __cxxabiv1; |
David Chisnall | 1d58106 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 20 | #define HAVE_DEPENDENT_EH_ABI 1 |
Howard Hinnant | 4ad4eee | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 21 | #ifndef _LIBCPPABI_VERSION |
| 22 | using namespace __cxxabiapple; |
| 23 | // On Darwin, there are two STL shared libraries and a lower level ABI |
Marshall Clow | f98383c | 2013-11-11 23:27:19 +0000 | [diff] [blame] | 24 | // shared library. The globals holding the current terminate handler and |
Howard Hinnant | 4ad4eee | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 25 | // current unexpected handler are in the ABI library. |
| 26 | #define __terminate_handler __cxxabiapple::__cxa_terminate_handler |
| 27 | #define __unexpected_handler __cxxabiapple::__cxa_unexpected_handler |
| 28 | #endif // _LIBCPPABI_VERSION |
Benjamin Kramer | af9fc2c | 2015-10-16 11:14:30 +0000 | [diff] [blame] | 29 | #elif defined(LIBCXXRT) || defined(LIBCXX_BUILDING_LIBCXXABI) |
David Chisnall | 1d58106 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 30 | #include <cxxabi.h> |
| 31 | using namespace __cxxabiv1; |
Richard Smith | ffd7467 | 2012-07-11 09:35:47 +0000 | [diff] [blame] | 32 | #if defined(LIBCXXRT) || defined(_LIBCPPABI_VERSION) |
| 33 | #define HAVE_DEPENDENT_EH_ABI 1 |
| 34 | #endif |
Benjamin Kramer | af9fc2c | 2015-10-16 11:14:30 +0000 | [diff] [blame] | 35 | #elif !defined(__GLIBCXX__) // defined(LIBCXX_BUILDING_LIBCXXABI) |
Eric Fiselier | 637dd95 | 2016-09-28 22:08:13 +0000 | [diff] [blame] | 36 | _LIBCPP_SAFE_STATIC static std::terminate_handler __terminate_handler; |
| 37 | _LIBCPP_SAFE_STATIC static std::unexpected_handler __unexpected_handler; |
Benjamin Kramer | af9fc2c | 2015-10-16 11:14:30 +0000 | [diff] [blame] | 38 | #endif // defined(LIBCXX_BUILDING_LIBCXXABI) |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 39 | |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 40 | namespace std |
| 41 | { |
| 42 | |
Michael J. Spencer | 7deadc8 | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 43 | #if !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION) && !defined(__GLIBCXX__) |
Howard Hinnant | 4ad4eee | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 44 | |
David Chisnall | 1d58106 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 45 | // libcxxrt provides implementations of these functions itself. |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 46 | unexpected_handler |
| 47 | set_unexpected(unexpected_handler func) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 48 | { |
Howard Hinnant | e65e8e3 | 2010-12-02 16:45:21 +0000 | [diff] [blame] | 49 | return __sync_lock_test_and_set(&__unexpected_handler, func); |
| 50 | } |
| 51 | |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 52 | unexpected_handler |
| 53 | get_unexpected() _NOEXCEPT |
Howard Hinnant | e65e8e3 | 2010-12-02 16:45:21 +0000 | [diff] [blame] | 54 | { |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 55 | return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0); |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Richard Smith | cabd392 | 2012-07-26 02:04:22 +0000 | [diff] [blame] | 58 | _LIBCPP_NORETURN |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 59 | void |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 60 | unexpected() |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 61 | { |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 62 | (*get_unexpected())(); |
Howard Hinnant | 34468d4 | 2010-08-22 13:53:14 +0000 | [diff] [blame] | 63 | // unexpected handler should not return |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 64 | terminate(); |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 65 | } |
| 66 | |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 67 | terminate_handler |
| 68 | set_terminate(terminate_handler func) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 69 | { |
Howard Hinnant | e65e8e3 | 2010-12-02 16:45:21 +0000 | [diff] [blame] | 70 | return __sync_lock_test_and_set(&__terminate_handler, func); |
| 71 | } |
| 72 | |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 73 | terminate_handler |
| 74 | get_terminate() _NOEXCEPT |
Howard Hinnant | e65e8e3 | 2010-12-02 16:45:21 +0000 | [diff] [blame] | 75 | { |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 76 | return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0); |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Marshall Clow | eae03f6 | 2013-11-19 18:05:03 +0000 | [diff] [blame] | 79 | #ifndef __EMSCRIPTEN__ // We provide this in JS |
Richard Smith | cabd392 | 2012-07-26 02:04:22 +0000 | [diff] [blame] | 80 | _LIBCPP_NORETURN |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 81 | void |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 82 | terminate() _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 83 | { |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 84 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 85 | try |
| 86 | { |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 87 | #endif // _LIBCPP_NO_EXCEPTIONS |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 88 | (*get_terminate())(); |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 89 | // handler should not return |
Ed Schouten | 7a44145 | 2015-03-10 07:57:43 +0000 | [diff] [blame] | 90 | fprintf(stderr, "terminate_handler unexpectedly returned\n"); |
Peter Collingbourne | 5f845a7 | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 91 | ::abort(); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 92 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 93 | } |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 94 | catch (...) |
| 95 | { |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 96 | // handler should not throw exception |
Ed Schouten | 7a44145 | 2015-03-10 07:57:43 +0000 | [diff] [blame] | 97 | fprintf(stderr, "terminate_handler unexpectedly threw an exception\n"); |
Peter Collingbourne | 5f845a7 | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 98 | ::abort(); |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 99 | } |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 100 | #endif // _LIBCPP_NO_EXCEPTIONS |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 101 | } |
Marshall Clow | eae03f6 | 2013-11-19 18:05:03 +0000 | [diff] [blame] | 102 | #endif // !__EMSCRIPTEN__ |
Howard Hinnant | 4ad4eee | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 103 | #endif // !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION) |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 104 | |
Marshall Clow | e6a76af | 2015-06-02 22:25:23 +0000 | [diff] [blame] | 105 | #if !defined(LIBCXXRT) && !defined(__GLIBCXX__) && !defined(__EMSCRIPTEN__) |
Marshall Clow | 209dacc | 2015-06-02 15:33:38 +0000 | [diff] [blame] | 106 | bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; } |
| 107 | |
Marshall Clow | 209dacc | 2015-06-02 15:33:38 +0000 | [diff] [blame] | 108 | int uncaught_exceptions() _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 109 | { |
Eric Fiselier | b0da5fa | 2017-01-03 01:18:48 +0000 | [diff] [blame] | 110 | #if !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) && \ |
| 111 | (defined(__APPLE__) || defined(_LIBCPPABI_VERSION)) |
Marshall Clow | 209dacc | 2015-06-02 15:33:38 +0000 | [diff] [blame] | 112 | // on Darwin, there is a helper function so __cxa_get_globals is private |
| 113 | # if _LIBCPPABI_VERSION > 1101 |
| 114 | return __cxa_uncaught_exceptions(); |
| 115 | # else |
| 116 | return __cxa_uncaught_exception() ? 1 : 0; |
| 117 | # endif |
Howard Hinnant | 3472f5b | 2012-02-29 15:37:30 +0000 | [diff] [blame] | 118 | #else // __APPLE__ |
Howard Hinnant | 408927e | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 119 | # if defined(_MSC_VER) && ! defined(__clang__) |
Marshall Clow | 209dacc | 2015-06-02 15:33:38 +0000 | [diff] [blame] | 120 | _LIBCPP_WARNING("uncaught_exceptions not yet implemented") |
Howard Hinnant | 408927e | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 121 | # else |
| 122 | # warning uncaught_exception not yet implemented |
| 123 | # endif |
Marshall Clow | 209dacc | 2015-06-02 15:33:38 +0000 | [diff] [blame] | 124 | fprintf(stderr, "uncaught_exceptions not yet implemented\n"); |
Peter Collingbourne | 5f845a7 | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 125 | ::abort(); |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 126 | #endif // __APPLE__ |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Howard Hinnant | 408927e | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 129 | |
Howard Hinnant | 4ad4eee | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 130 | #ifndef _LIBCPPABI_VERSION |
| 131 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 132 | exception::~exception() _NOEXCEPT |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 133 | { |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 136 | const char* exception::what() const _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 137 | { |
| 138 | return "std::exception"; |
| 139 | } |
| 140 | |
David Chisnall | ba252b8 | 2012-03-14 14:11:13 +0000 | [diff] [blame] | 141 | #endif // _LIBCPPABI_VERSION |
| 142 | #endif //LIBCXXRT |
Michael J. Spencer | 7deadc8 | 2012-11-30 21:02:29 +0000 | [diff] [blame] | 143 | #if !defined(_LIBCPPABI_VERSION) && !defined(__GLIBCXX__) |
David Chisnall | ba252b8 | 2012-03-14 14:11:13 +0000 | [diff] [blame] | 144 | |
| 145 | bad_exception::~bad_exception() _NOEXCEPT |
| 146 | { |
| 147 | } |
| 148 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 149 | const char* bad_exception::what() const _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 150 | { |
| 151 | return "std::bad_exception"; |
| 152 | } |
| 153 | |
David Chisnall | ba252b8 | 2012-03-14 14:11:13 +0000 | [diff] [blame] | 154 | #endif |
| 155 | |
Peter Collingbourne | 4d7da9a | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 156 | #if defined(__GLIBCXX__) |
| 157 | |
| 158 | // libsupc++ does not implement the dependent EH ABI and the functionality |
| 159 | // it uses to implement std::exception_ptr (which it declares as an alias of |
| 160 | // std::__exception_ptr::exception_ptr) is not directly exported to clients. So |
| 161 | // we have little choice but to hijack std::__exception_ptr::exception_ptr's |
| 162 | // (which fortunately has the same layout as our std::exception_ptr) copy |
| 163 | // constructor, assignment operator and destructor (which are part of its |
| 164 | // stable ABI), and its rethrow_exception(std::__exception_ptr::exception_ptr) |
| 165 | // function. |
| 166 | |
| 167 | namespace __exception_ptr |
| 168 | { |
| 169 | |
| 170 | struct exception_ptr |
| 171 | { |
| 172 | void* __ptr_; |
| 173 | |
| 174 | exception_ptr(const exception_ptr&) _NOEXCEPT; |
| 175 | exception_ptr& operator=(const exception_ptr&) _NOEXCEPT; |
| 176 | ~exception_ptr() _NOEXCEPT; |
| 177 | }; |
| 178 | |
| 179 | } |
| 180 | |
| 181 | _LIBCPP_NORETURN void rethrow_exception(__exception_ptr::exception_ptr); |
| 182 | |
| 183 | #endif |
Howard Hinnant | 4ad4eee | 2012-02-02 20:48:35 +0000 | [diff] [blame] | 184 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 185 | exception_ptr::~exception_ptr() _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 186 | { |
David Chisnall | 1d58106 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 187 | #if HAVE_DEPENDENT_EH_ABI |
| 188 | __cxa_decrement_exception_refcount(__ptr_); |
Peter Collingbourne | 4d7da9a | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 189 | #elif defined(__GLIBCXX__) |
| 190 | reinterpret_cast<__exception_ptr::exception_ptr*>(this)->~exception_ptr(); |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 191 | #else |
Howard Hinnant | 408927e | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 192 | # if defined(_MSC_VER) && ! defined(__clang__) |
| 193 | _LIBCPP_WARNING("exception_ptr not yet implemented") |
| 194 | # else |
| 195 | # warning exception_ptr not yet implemented |
| 196 | # endif |
Ed Schouten | 7a44145 | 2015-03-10 07:57:43 +0000 | [diff] [blame] | 197 | fprintf(stderr, "exception_ptr not yet implemented\n"); |
Peter Collingbourne | 5f845a7 | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 198 | ::abort(); |
Peter Collingbourne | 4d7da9a | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 199 | #endif |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 202 | exception_ptr::exception_ptr(const exception_ptr& other) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 203 | : __ptr_(other.__ptr_) |
| 204 | { |
David Chisnall | 1d58106 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 205 | #if HAVE_DEPENDENT_EH_ABI |
| 206 | __cxa_increment_exception_refcount(__ptr_); |
Peter Collingbourne | 4d7da9a | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 207 | #elif defined(__GLIBCXX__) |
| 208 | new (reinterpret_cast<void*>(this)) __exception_ptr::exception_ptr( |
| 209 | reinterpret_cast<const __exception_ptr::exception_ptr&>(other)); |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 210 | #else |
Howard Hinnant | 408927e | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 211 | # if defined(_MSC_VER) && ! defined(__clang__) |
| 212 | _LIBCPP_WARNING("exception_ptr not yet implemented") |
| 213 | # else |
| 214 | # warning exception_ptr not yet implemented |
| 215 | # endif |
Ed Schouten | 7a44145 | 2015-03-10 07:57:43 +0000 | [diff] [blame] | 216 | fprintf(stderr, "exception_ptr not yet implemented\n"); |
Peter Collingbourne | 5f845a7 | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 217 | ::abort(); |
Peter Collingbourne | 4d7da9a | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 218 | #endif |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 221 | exception_ptr& exception_ptr::operator=(const exception_ptr& other) _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 222 | { |
David Chisnall | 1d58106 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 223 | #if HAVE_DEPENDENT_EH_ABI |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 224 | if (__ptr_ != other.__ptr_) |
| 225 | { |
David Chisnall | 1d58106 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 226 | __cxa_increment_exception_refcount(other.__ptr_); |
| 227 | __cxa_decrement_exception_refcount(__ptr_); |
Howard Hinnant | 34468d4 | 2010-08-22 13:53:14 +0000 | [diff] [blame] | 228 | __ptr_ = other.__ptr_; |
| 229 | } |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 230 | return *this; |
Peter Collingbourne | 4d7da9a | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 231 | #elif defined(__GLIBCXX__) |
| 232 | *reinterpret_cast<__exception_ptr::exception_ptr*>(this) = |
| 233 | reinterpret_cast<const __exception_ptr::exception_ptr&>(other); |
| 234 | return *this; |
| 235 | #else |
Howard Hinnant | 408927e | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 236 | # if defined(_MSC_VER) && ! defined(__clang__) |
| 237 | _LIBCPP_WARNING("exception_ptr not yet implemented") |
| 238 | # else |
| 239 | # warning exception_ptr not yet implemented |
| 240 | # endif |
Ed Schouten | 7a44145 | 2015-03-10 07:57:43 +0000 | [diff] [blame] | 241 | fprintf(stderr, "exception_ptr not yet implemented\n"); |
Peter Collingbourne | 5f845a7 | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 242 | ::abort(); |
Peter Collingbourne | 4d7da9a | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 243 | #endif |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 246 | nested_exception::nested_exception() _NOEXCEPT |
Howard Hinnant | e4f9272 | 2010-05-27 17:06:52 +0000 | [diff] [blame] | 247 | : __ptr_(current_exception()) |
| 248 | { |
| 249 | } |
| 250 | |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 251 | #if !defined(__GLIBCXX__) |
| 252 | |
Howard Hinnant | 1bc52cf | 2011-05-26 18:23:59 +0000 | [diff] [blame] | 253 | nested_exception::~nested_exception() _NOEXCEPT |
Howard Hinnant | e4f9272 | 2010-05-27 17:06:52 +0000 | [diff] [blame] | 254 | { |
| 255 | } |
| 256 | |
Peter Collingbourne | dc00995 | 2013-10-06 22:13:16 +0000 | [diff] [blame] | 257 | #endif |
| 258 | |
Richard Smith | cabd392 | 2012-07-26 02:04:22 +0000 | [diff] [blame] | 259 | _LIBCPP_NORETURN |
Howard Hinnant | e4f9272 | 2010-05-27 17:06:52 +0000 | [diff] [blame] | 260 | void |
Howard Hinnant | 8df9629 | 2011-05-26 17:07:32 +0000 | [diff] [blame] | 261 | nested_exception::rethrow_nested() const |
Howard Hinnant | e4f9272 | 2010-05-27 17:06:52 +0000 | [diff] [blame] | 262 | { |
| 263 | if (__ptr_ == nullptr) |
| 264 | terminate(); |
| 265 | rethrow_exception(__ptr_); |
| 266 | } |
| 267 | |
Peter Collingbourne | 4d7da9a | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 268 | #if !defined(__GLIBCXX__) |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 269 | |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 270 | exception_ptr current_exception() _NOEXCEPT |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 271 | { |
David Chisnall | 1d58106 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 272 | #if HAVE_DEPENDENT_EH_ABI |
Howard Hinnant | 34468d4 | 2010-08-22 13:53:14 +0000 | [diff] [blame] | 273 | // be nicer if there was a constructor that took a ptr, then |
| 274 | // this whole function would be just: |
| 275 | // return exception_ptr(__cxa_current_primary_exception()); |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 276 | exception_ptr ptr; |
David Chisnall | 1d58106 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 277 | ptr.__ptr_ = __cxa_current_primary_exception(); |
Howard Hinnant | 34468d4 | 2010-08-22 13:53:14 +0000 | [diff] [blame] | 278 | return ptr; |
Peter Collingbourne | 4d7da9a | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 279 | #else |
Howard Hinnant | 408927e | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 280 | # if defined(_MSC_VER) && ! defined(__clang__) |
| 281 | _LIBCPP_WARNING( "exception_ptr not yet implemented" ) |
| 282 | # else |
| 283 | # warning exception_ptr not yet implemented |
| 284 | # endif |
Ed Schouten | 7a44145 | 2015-03-10 07:57:43 +0000 | [diff] [blame] | 285 | fprintf(stderr, "exception_ptr not yet implemented\n"); |
Peter Collingbourne | 5f845a7 | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 286 | ::abort(); |
Peter Collingbourne | 4d7da9a | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 287 | #endif |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Peter Collingbourne | 4d7da9a | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 290 | #endif // !__GLIBCXX__ |
| 291 | |
Richard Smith | cabd392 | 2012-07-26 02:04:22 +0000 | [diff] [blame] | 292 | _LIBCPP_NORETURN |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 293 | void rethrow_exception(exception_ptr p) |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 294 | { |
David Chisnall | 1d58106 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 295 | #if HAVE_DEPENDENT_EH_ABI |
| 296 | __cxa_rethrow_primary_exception(p.__ptr_); |
Howard Hinnant | 34468d4 | 2010-08-22 13:53:14 +0000 | [diff] [blame] | 297 | // if p.__ptr_ is NULL, above returns so we terminate |
Howard Hinnant | ffb308e | 2010-08-22 00:03:27 +0000 | [diff] [blame] | 298 | terminate(); |
Peter Collingbourne | 4d7da9a | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 299 | #elif defined(__GLIBCXX__) |
| 300 | rethrow_exception(reinterpret_cast<__exception_ptr::exception_ptr&>(p)); |
| 301 | #else |
Howard Hinnant | 408927e | 2013-10-04 21:14:44 +0000 | [diff] [blame] | 302 | # if defined(_MSC_VER) && ! defined(__clang__) |
| 303 | _LIBCPP_WARNING("exception_ptr not yet implemented") |
| 304 | # else |
| 305 | # warning exception_ptr not yet implemented |
| 306 | # endif |
Ed Schouten | 7a44145 | 2015-03-10 07:57:43 +0000 | [diff] [blame] | 307 | fprintf(stderr, "exception_ptr not yet implemented\n"); |
Peter Collingbourne | 5f845a7 | 2013-10-06 22:13:24 +0000 | [diff] [blame] | 308 | ::abort(); |
Peter Collingbourne | 4d7da9a | 2013-10-06 22:13:21 +0000 | [diff] [blame] | 309 | #endif |
Nick Kledzik | d1a61bb | 2010-05-14 20:19:37 +0000 | [diff] [blame] | 310 | } |
David Chisnall | 3954f44 | 2012-02-29 12:59:17 +0000 | [diff] [blame] | 311 | } // std |