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