blob: 8d30e5ce429a7d57833a0c6c07e90de979dfff63 [file] [log] [blame]
Marshall Clowe2dcb752011-07-20 15:04:39 +00001//===------------------------- cxa_exception.cpp --------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//
9// This file implements the "Exception Handling APIs"
Jonathan Roelofsc5f7e6f2014-02-12 04:49:09 +000010// http://mentorembedded.github.io/cxx-abi/abi-eh.html
Marshall Clowe2dcb752011-07-20 15:04:39 +000011//
12//===----------------------------------------------------------------------===//
13
14#include "cxxabi.h"
15
16#include <exception> // for std::terminate
Howard Hinnant862c4a02013-06-17 18:10:34 +000017#include <cstring> // for memset
Marshall Clowe2dcb752011-07-20 15:04:39 +000018#include "cxa_exception.hpp"
Howard Hinnant5ec91832011-12-07 21:16:40 +000019#include "cxa_handlers.hpp"
Igor Kudrind9edde42016-10-07 08:48:28 +000020#include "fallback_malloc.h"
Eli Friedman17a47b92018-04-16 22:00:14 +000021#include "include/atomic_support.h"
Marshall Clowe2dcb752011-07-20 15:04:39 +000022
Petr Hosek229e0852017-09-13 23:35:07 +000023#if __has_feature(address_sanitizer)
Eric Fiselierc4600cc2017-09-14 22:37:34 +000024extern "C" void __asan_handle_no_return(void);
Petr Hosek229e0852017-09-13 23:35:07 +000025#endif
26
Howard Hinnantafcf7ac2012-01-22 19:14:27 +000027// +---------------------------+-----------------------------+---------------+
28// | __cxa_exception | _Unwind_Exception CLNGC++\0 | thrown object |
29// +---------------------------+-----------------------------+---------------+
30// ^
31// |
32// +-------------------------------------------------------+
33// |
34// +---------------------------+-----------------------------+
35// | __cxa_dependent_exception | _Unwind_Exception CLNGC++\1 |
36// +---------------------------+-----------------------------+
37
Marshall Clowe2dcb752011-07-20 15:04:39 +000038namespace __cxxabiv1 {
Howard Hinnant6830b2a2012-01-24 18:15:20 +000039
Marshall Clowe2dcb752011-07-20 15:04:39 +000040// Utility routines
Howard Hinnantafcf7ac2012-01-22 19:14:27 +000041static
42inline
43__cxa_exception*
Howard Hinnant47cb85482012-01-30 16:07:00 +000044cxa_exception_from_thrown_object(void* thrown_object)
Howard Hinnantafcf7ac2012-01-22 19:14:27 +000045{
46 return static_cast<__cxa_exception*>(thrown_object) - 1;
Marshall Clow9b454bc2011-08-15 18:06:47 +000047}
Marshall Clowe2dcb752011-07-20 15:04:39 +000048
Howard Hinnantafcf7ac2012-01-22 19:14:27 +000049// Note: This is never called when exception_header is masquerading as a
50// __cxa_dependent_exception.
51static
52inline
53void*
Howard Hinnant47cb85482012-01-30 16:07:00 +000054thrown_object_from_cxa_exception(__cxa_exception* exception_header)
Howard Hinnantafcf7ac2012-01-22 19:14:27 +000055{
56 return static_cast<void*>(exception_header + 1);
Marshall Clow9b454bc2011-08-15 18:06:47 +000057}
Marshall Clowe2dcb752011-07-20 15:04:39 +000058
Marshall Clow87694492011-08-09 15:09:41 +000059// Get the exception object from the unwind pointer.
60// Relies on the structure layout, where the unwind pointer is right in
61// front of the user's exception object
Howard Hinnantafcf7ac2012-01-22 19:14:27 +000062static
63inline
64__cxa_exception*
Howard Hinnant47cb85482012-01-30 16:07:00 +000065cxa_exception_from_exception_unwind_exception(_Unwind_Exception* unwind_exception)
Howard Hinnantafcf7ac2012-01-22 19:14:27 +000066{
67 return cxa_exception_from_thrown_object(unwind_exception + 1 );
Marshall Clow9b454bc2011-08-15 18:06:47 +000068}
Marshall Clow87694492011-08-09 15:09:41 +000069
Eric Fiselierc74a2e12017-03-04 02:04:45 +000070// Round s up to next multiple of a.
71static inline
72size_t aligned_allocation_size(size_t s, size_t a) {
73 return (s + a - 1) & ~(a - 1);
74}
75
76static inline
77size_t cxa_exception_size_from_exception_thrown_size(size_t size) {
78 return aligned_allocation_size(size + sizeof (__cxa_exception),
79 alignof(__cxa_exception));
Marshall Clow9b454bc2011-08-15 18:06:47 +000080}
Marshall Clow87694492011-08-09 15:09:41 +000081
Marshall Clow611a55a2018-10-10 16:18:37 +000082void __setExceptionClass(_Unwind_Exception* unwind_exception, uint64_t newValue) {
83 ::memcpy(&unwind_exception->exception_class, &newValue, sizeof(newValue));
84 }
85
86
87static void setOurExceptionClass(_Unwind_Exception* unwind_exception) {
88 __setExceptionClass(unwind_exception, kOurExceptionClass);
Howard Hinnantafcf7ac2012-01-22 19:14:27 +000089}
90
Howard Hinnant47cb85482012-01-30 16:07:00 +000091static void setDependentExceptionClass(_Unwind_Exception* unwind_exception) {
Marshall Clow611a55a2018-10-10 16:18:37 +000092 __setExceptionClass(unwind_exception, kOurDependentExceptionClass);
Marshall Clow9b454bc2011-08-15 18:06:47 +000093}
Marshall Clow87694492011-08-09 15:09:41 +000094
95// Is it one of ours?
Marshall Clow611a55a2018-10-10 16:18:37 +000096uint64_t __getExceptionClass(const _Unwind_Exception* unwind_exception) {
97// On x86 and some ARM unwinders, unwind_exception->exception_class is
98// a uint64_t. On other ARM unwinders, it is a char[8]
99// See: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0038b/IHI0038B_ehabi.pdf
100// So we just copy it into a uint64_t to be sure.
101 uint64_t exClass;
102 ::memcpy(&exClass, &unwind_exception->exception_class, sizeof(exClass));
103 return exClass;
104}
105
106bool __isOurExceptionClass(const _Unwind_Exception* unwind_exception) {
107 return (__getExceptionClass(unwind_exception) & get_vendor_and_language) ==
108 (kOurExceptionClass & get_vendor_and_language);
Marshall Clow9b454bc2011-08-15 18:06:47 +0000109}
Marshall Clow87694492011-08-09 15:09:41 +0000110
Howard Hinnant47cb85482012-01-30 16:07:00 +0000111static bool isDependentException(_Unwind_Exception* unwind_exception) {
Marshall Clow611a55a2018-10-10 16:18:37 +0000112 return (__getExceptionClass(unwind_exception) & 0xFF) == 0x01;
Marshall Clow9b454bc2011-08-15 18:06:47 +0000113}
114
Howard Hinnant6ccae152011-12-08 19:35:18 +0000115// This does not need to be atomic
Howard Hinnant47cb85482012-01-30 16:07:00 +0000116static inline int incrementHandlerCount(__cxa_exception *exception) {
Howard Hinnant6ccae152011-12-08 19:35:18 +0000117 return ++exception->handlerCount;
Marshall Clow9b454bc2011-08-15 18:06:47 +0000118}
119
Howard Hinnant6ccae152011-12-08 19:35:18 +0000120// This does not need to be atomic
Howard Hinnant47cb85482012-01-30 16:07:00 +0000121static inline int decrementHandlerCount(__cxa_exception *exception) {
Howard Hinnant6ccae152011-12-08 19:35:18 +0000122 return --exception->handlerCount;
Marshall Clow9b454bc2011-08-15 18:06:47 +0000123}
Marshall Clow87694492011-08-09 15:09:41 +0000124
Howard Hinnant5ec91832011-12-07 21:16:40 +0000125/*
Marshall Clow87694492011-08-09 15:09:41 +0000126 If reason isn't _URC_FOREIGN_EXCEPTION_CAUGHT, then the terminateHandler
127 stored in exc is called. Otherwise the exceptionDestructor stored in
128 exc is called, and then the memory for the exception is deallocated.
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000129
130 This is never called for a __cxa_dependent_exception.
Marshall Clow87694492011-08-09 15:09:41 +0000131*/
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000132static
133void
134exception_cleanup_func(_Unwind_Reason_Code reason, _Unwind_Exception* unwind_exception)
135{
136 __cxa_exception* exception_header = cxa_exception_from_exception_unwind_exception(unwind_exception);
Marshall Clow9b454bc2011-08-15 18:06:47 +0000137 if (_URC_FOREIGN_EXCEPTION_CAUGHT != reason)
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000138 std::__terminate(exception_header->terminateHandler);
Howard Hinnantd0bfbb32012-02-01 18:44:21 +0000139 // Just in case there exists a dependent exception that is pointing to this,
140 // check the reference count and only destroy this if that count goes to zero.
141 __cxa_decrement_exception_refcount(unwind_exception + 1);
Marshall Clow9b454bc2011-08-15 18:06:47 +0000142}
Marshall Clow87694492011-08-09 15:09:41 +0000143
Eric Fiselier71e32922017-03-01 02:23:54 +0000144static _LIBCXXABI_NORETURN void failed_throw(__cxa_exception* exception_header) {
Marshall Clow87694492011-08-09 15:09:41 +0000145// Section 2.5.3 says:
146// * For purposes of this ABI, several things are considered exception handlers:
147// ** A terminate() call due to a throw.
148// and
149// * Upon entry, Following initialization of the catch parameter,
150// a handler must call:
Marshall Clow9b454bc2011-08-15 18:06:47 +0000151// * void *__cxa_begin_catch(void *exceptionObject );
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000152 (void) __cxa_begin_catch(&exception_header->unwindHeader);
153 std::__terminate(exception_header->terminateHandler);
Marshall Clow9b454bc2011-08-15 18:06:47 +0000154}
Marshall Clowe2dcb752011-07-20 15:04:39 +0000155
Akira Hatanaka9ef1daa2017-11-28 00:36:29 +0000156// Return the offset of the __cxa_exception header from the start of the
157// allocated buffer. If __cxa_exception's alignment is smaller than the maximum
158// useful alignment for the target machine, padding has to be inserted before
159// the header to ensure the thrown object that follows the header is
160// sufficiently aligned. This happens if _Unwind_exception isn't double-word
161// aligned (on Darwin, for example).
162static size_t get_cxa_exception_offset() {
163 struct S {
164 } __attribute__((aligned));
165
166 // Compute the maximum alignment for the target machine.
167 constexpr size_t alignment = std::alignment_of<S>::value;
168 constexpr size_t excp_size = sizeof(__cxa_exception);
169 constexpr size_t aligned_size =
170 (excp_size + alignment - 1) / alignment * alignment;
171 constexpr size_t offset = aligned_size - excp_size;
172 static_assert((offset == 0 ||
173 std::alignment_of<_Unwind_Exception>::value < alignment),
174 "offset is non-zero only if _Unwind_Exception isn't aligned");
175 return offset;
176}
177
Marshall Clowe2dcb752011-07-20 15:04:39 +0000178extern "C" {
179
180// Allocate a __cxa_exception object, and zero-fill it.
181// Reserve "thrown_size" bytes on the end for the user's exception
182// object. Zero-fill the object. If memory can't be allocated, call
183// std::terminate. Return a pointer to the memory to be used for the
184// user's exception object.
Shoaib Meenaife989a92017-03-01 03:55:57 +0000185void *__cxa_allocate_exception(size_t thrown_size) throw() {
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000186 size_t actual_size = cxa_exception_size_from_exception_thrown_size(thrown_size);
Akira Hatanaka9ef1daa2017-11-28 00:36:29 +0000187
188 // Allocate extra space before the __cxa_exception header to ensure the
189 // start of the thrown object is sufficiently aligned.
190 size_t header_offset = get_cxa_exception_offset();
191 char *raw_buffer =
192 (char *)__aligned_malloc_with_fallback(header_offset + actual_size);
193 if (NULL == raw_buffer)
Marshall Clow9b454bc2011-08-15 18:06:47 +0000194 std::terminate();
Akira Hatanaka9ef1daa2017-11-28 00:36:29 +0000195 __cxa_exception *exception_header =
196 static_cast<__cxa_exception *>((void *)(raw_buffer + header_offset));
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000197 std::memset(exception_header, 0, actual_size);
198 return thrown_object_from_cxa_exception(exception_header);
Marshall Clow9b454bc2011-08-15 18:06:47 +0000199}
Marshall Clowe2dcb752011-07-20 15:04:39 +0000200
201
202// Free a __cxa_exception object allocated with __cxa_allocate_exception.
Shoaib Meenaife989a92017-03-01 03:55:57 +0000203void __cxa_free_exception(void *thrown_object) throw() {
Akira Hatanaka9ef1daa2017-11-28 00:36:29 +0000204 // Compute the size of the padding before the header.
205 size_t header_offset = get_cxa_exception_offset();
206 char *raw_buffer =
207 ((char *)cxa_exception_from_thrown_object(thrown_object)) - header_offset;
208 __aligned_free_with_fallback((void *)raw_buffer);
Marshall Clow9b454bc2011-08-15 18:06:47 +0000209}
Marshall Clowe2dcb752011-07-20 15:04:39 +0000210
211
212// This function shall allocate a __cxa_dependent_exception and
213// return a pointer to it. (Really to the object, not past its' end).
214// Otherwise, it will work like __cxa_allocate_exception.
Howard Hinnant47cb85482012-01-30 16:07:00 +0000215void * __cxa_allocate_dependent_exception () {
Marshall Clow9b454bc2011-08-15 18:06:47 +0000216 size_t actual_size = sizeof(__cxa_dependent_exception);
Eric Fiselierc74a2e12017-03-04 02:04:45 +0000217 void *ptr = __aligned_malloc_with_fallback(actual_size);
Marshall Clow9b454bc2011-08-15 18:06:47 +0000218 if (NULL == ptr)
219 std::terminate();
220 std::memset(ptr, 0, actual_size);
Marshall Clowe2dcb752011-07-20 15:04:39 +0000221 return ptr;
Marshall Clow9b454bc2011-08-15 18:06:47 +0000222}
Marshall Clowe2dcb752011-07-20 15:04:39 +0000223
224
225// This function shall free a dependent_exception.
226// It does not affect the reference count of the primary exception.
Howard Hinnant47cb85482012-01-30 16:07:00 +0000227void __cxa_free_dependent_exception (void * dependent_exception) {
Eric Fiselierc74a2e12017-03-04 02:04:45 +0000228 __aligned_free_with_fallback(dependent_exception);
Marshall Clow9b454bc2011-08-15 18:06:47 +0000229}
Marshall Clowe2dcb752011-07-20 15:04:39 +0000230
Marshall Clow87694492011-08-09 15:09:41 +0000231
232// 2.4.3 Throwing the Exception Object
233/*
234After constructing the exception object with the throw argument value,
235the generated code calls the __cxa_throw runtime library routine. This
236routine never returns.
237
238The __cxa_throw routine will do the following:
239
240* Obtain the __cxa_exception header from the thrown exception object address,
241which can be computed as follows:
242 __cxa_exception *header = ((__cxa_exception *) thrown_exception - 1);
243* Save the current unexpected_handler and terminate_handler in the __cxa_exception header.
244* Save the tinfo and dest arguments in the __cxa_exception header.
245* Set the exception_class field in the unwind header. This is a 64-bit value
246representing the ASCII string "XXXXC++\0", where "XXXX" is a
247vendor-dependent string. That is, for implementations conforming to this
248ABI, the low-order 4 bytes of this 64-bit value will be "C++\0".
249* Increment the uncaught_exception flag.
250* Call _Unwind_RaiseException in the system unwind library, Its argument is the
251pointer to the thrown exception, which __cxa_throw itself received as an argument.
252__Unwind_RaiseException begins the process of stack unwinding, described
253in Section 2.5. In special cases, such as an inability to find a
254handler, _Unwind_RaiseException may return. In that case, __cxa_throw
255will call terminate, assuming that there was no handler for the
256exception.
257*/
Shoaib Meenaife989a92017-03-01 03:55:57 +0000258void
Saleem Abdulrasool12315ed2015-12-04 02:14:58 +0000259__cxa_throw(void *thrown_object, std::type_info *tinfo, void (*dest)(void *)) {
Marshall Clow9b454bc2011-08-15 18:06:47 +0000260 __cxa_eh_globals *globals = __cxa_get_globals();
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000261 __cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
Howard Hinnant6ccae152011-12-08 19:35:18 +0000262
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000263 exception_header->unexpectedHandler = std::get_unexpected();
264 exception_header->terminateHandler = std::get_terminate();
265 exception_header->exceptionType = tinfo;
266 exception_header->exceptionDestructor = dest;
Marshall Clow611a55a2018-10-10 16:18:37 +0000267 setOurExceptionClass(&exception_header->unwindHeader);
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000268 exception_header->referenceCount = 1; // This is a newly allocated exception, no need for thread safety.
Marshall Clow87694492011-08-09 15:09:41 +0000269 globals->uncaughtExceptions += 1; // Not atomically, since globals are thread-local
270
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000271 exception_header->unwindHeader.exception_cleanup = exception_cleanup_func;
Petr Hosek229e0852017-09-13 23:35:07 +0000272
Eric Fiselierc4600cc2017-09-14 22:37:34 +0000273#if __has_feature(address_sanitizer)
Petr Hosek229e0852017-09-13 23:35:07 +0000274 // Inform the ASan runtime that now might be a good time to clean stuff up.
275 __asan_handle_no_return();
276#endif
277
Dan Albert3bd13ca2015-02-05 01:33:15 +0000278#ifdef __USING_SJLJ_EXCEPTIONS__
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000279 _Unwind_SjLj_RaiseException(&exception_header->unwindHeader);
Howard Hinnant6ccae152011-12-08 19:35:18 +0000280#else
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000281 _Unwind_RaiseException(&exception_header->unwindHeader);
Howard Hinnant6ccae152011-12-08 19:35:18 +0000282#endif
Howard Hinnant9aa46842012-01-28 00:34:46 +0000283 // This only happens when there is no handler, or some unexpected unwinding
284 // error happens.
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000285 failed_throw(exception_header);
Marshall Clow9b454bc2011-08-15 18:06:47 +0000286}
Marshall Clow87694492011-08-09 15:09:41 +0000287
288
289// 2.5.3 Exception Handlers
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000290/*
291The adjusted pointer is computed by the personality routine during phase 1
292 and saved in the exception header (either __cxa_exception or
293 __cxa_dependent_exception).
Howard Hinnant47cb85482012-01-30 16:07:00 +0000294
295 Requires: exception is native
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000296*/
Saleem Abdulrasool242d67b2015-12-04 02:14:41 +0000297void *__cxa_get_exception_ptr(void *unwind_exception) throw() {
Ranjeet Singhef6e6722017-03-01 11:42:01 +0000298#if defined(_LIBCXXABI_ARM_EHABI)
Logan Chiendc65ab42014-05-10 00:42:10 +0000299 return reinterpret_cast<void*>(
Dan Albertb98c20c2015-02-05 23:48:06 +0000300 static_cast<_Unwind_Control_Block*>(unwind_exception)->barrier_cache.bitpattern[0]);
Logan Chiendc65ab42014-05-10 00:42:10 +0000301#else
Dan Albertb98c20c2015-02-05 23:48:06 +0000302 return cxa_exception_from_exception_unwind_exception(
303 static_cast<_Unwind_Exception*>(unwind_exception))->adjustedPtr;
Logan Chiendc65ab42014-05-10 00:42:10 +0000304#endif
Marshall Clow9b454bc2011-08-15 18:06:47 +0000305}
Logan Chiendc65ab42014-05-10 00:42:10 +0000306
Ranjeet Singhef6e6722017-03-01 11:42:01 +0000307#if defined(_LIBCXXABI_ARM_EHABI)
Logan Chiendc65ab42014-05-10 00:42:10 +0000308/*
309The routine to be called before the cleanup. This will save __cxa_exception in
310__cxa_eh_globals, so that __cxa_end_cleanup() can recover later.
311*/
Saleem Abdulrasool242d67b2015-12-04 02:14:41 +0000312bool __cxa_begin_cleanup(void *unwind_arg) throw() {
Logan Chiendc65ab42014-05-10 00:42:10 +0000313 _Unwind_Exception* unwind_exception = static_cast<_Unwind_Exception*>(unwind_arg);
314 __cxa_eh_globals* globals = __cxa_get_globals();
315 __cxa_exception* exception_header =
316 cxa_exception_from_exception_unwind_exception(unwind_exception);
317
Marshall Clow611a55a2018-10-10 16:18:37 +0000318 if (__isOurExceptionClass(unwind_exception))
Logan Chiendc65ab42014-05-10 00:42:10 +0000319 {
320 if (0 == exception_header->propagationCount)
321 {
322 exception_header->nextPropagatingException = globals->propagatingExceptions;
323 globals->propagatingExceptions = exception_header;
324 }
325 ++exception_header->propagationCount;
326 }
327 else
328 {
329 // If the propagatingExceptions stack is not empty, since we can't
330 // chain the foreign exception, terminate it.
331 if (NULL != globals->propagatingExceptions)
332 std::terminate();
333 globals->propagatingExceptions = exception_header;
334 }
335 return true;
336}
337
338/*
339The routine to be called after the cleanup has been performed. It will get the
340propagating __cxa_exception from __cxa_eh_globals, and continue the stack
341unwinding with _Unwind_Resume.
342
343According to ARM EHABI 8.4.1, __cxa_end_cleanup() should not clobber any
344register, thus we have to write this function in assembly so that we can save
345{r1, r2, r3}. We don't have to save r0 because it is the return value and the
346first argument to _Unwind_Resume(). In addition, we are saving r4 in order to
347align the stack to 16 bytes, even though it is a callee-save register.
348*/
349__attribute__((used)) static _Unwind_Exception *
350__cxa_end_cleanup_impl()
351{
352 __cxa_eh_globals* globals = __cxa_get_globals();
353 __cxa_exception* exception_header = globals->propagatingExceptions;
354 if (NULL == exception_header)
355 {
356 // It seems that __cxa_begin_cleanup() is not called properly.
357 // We have no choice but terminate the program now.
358 std::terminate();
359 }
360
Marshall Clow611a55a2018-10-10 16:18:37 +0000361 if (__isOurExceptionClass(&exception_header->unwindHeader))
Logan Chiendc65ab42014-05-10 00:42:10 +0000362 {
363 --exception_header->propagationCount;
364 if (0 == exception_header->propagationCount)
365 {
366 globals->propagatingExceptions = exception_header->nextPropagatingException;
367 exception_header->nextPropagatingException = NULL;
368 }
369 }
370 else
371 {
372 globals->propagatingExceptions = NULL;
373 }
374 return &exception_header->unwindHeader;
375}
376
377asm (
Logan Chien338d6de2015-12-22 14:38:30 +0000378 " .pushsection .text.__cxa_end_cleanup,\"ax\",%progbits\n"
Logan Chiendc65ab42014-05-10 00:42:10 +0000379 " .globl __cxa_end_cleanup\n"
380 " .type __cxa_end_cleanup,%function\n"
381 "__cxa_end_cleanup:\n"
382 " push {r1, r2, r3, r4}\n"
383 " bl __cxa_end_cleanup_impl\n"
384 " pop {r1, r2, r3, r4}\n"
385 " bl _Unwind_Resume\n"
386 " bl abort\n"
387 " .popsection"
388);
Ranjeet Singhef6e6722017-03-01 11:42:01 +0000389#endif // defined(_LIBCXXABI_ARM_EHABI)
Marshall Clow87694492011-08-09 15:09:41 +0000390
Marshall Clow87694492011-08-09 15:09:41 +0000391/*
Howard Hinnant47cb85482012-01-30 16:07:00 +0000392This routine can catch foreign or native exceptions. If native, the exception
393can be a primary or dependent variety. This routine may remain blissfully
394ignorant of whether the native exception is primary or dependent.
395
396If the exception is native:
Marshall Clow87694492011-08-09 15:09:41 +0000397* Increment's the exception's handler count.
Howard Hinnant47cb85482012-01-30 16:07:00 +0000398* Push the exception on the stack of currently-caught exceptions if it is not
399 already there (from a rethrow).
Marshall Clow87694492011-08-09 15:09:41 +0000400* Decrements the uncaught_exception count.
Howard Hinnant47cb85482012-01-30 16:07:00 +0000401* Returns the adjusted pointer to the exception object, which is stored in
402 the __cxa_exception by the personality routine.
403
404If the exception is foreign, this means it did not originate from one of throw
405routines. The foreign exception does not necessarily have a __cxa_exception
406header. However we can catch it here with a catch (...), or with a call
407to terminate or unexpected during unwinding.
408* Do not try to increment the exception's handler count, we don't know where
409 it is.
410* Push the exception on the stack of currently-caught exceptions only if the
411 stack is empty. The foreign exception has no way to link to the current
412 top of stack. If the stack is not empty, call terminate. Even with an
413 empty stack, this is hacked in by pushing a pointer to an imaginary
414 __cxa_exception block in front of the foreign exception. It would be better
415 if the __cxa_eh_globals structure had a stack of _Unwind_Exception, but it
416 doesn't. It has a stack of __cxa_exception (which has a next* in it).
417* Do not decrement the uncaught_exception count because we didn't increment it
418 in __cxa_throw (or one of our rethrow functions).
419* If we haven't terminated, assume the exception object is just past the
420 _Unwind_Exception and return a pointer to that.
Marshall Clow87694492011-08-09 15:09:41 +0000421*/
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000422void*
Howard Hinnant47cb85482012-01-30 16:07:00 +0000423__cxa_begin_catch(void* unwind_arg) throw()
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000424{
Howard Hinnant47cb85482012-01-30 16:07:00 +0000425 _Unwind_Exception* unwind_exception = static_cast<_Unwind_Exception*>(unwind_arg);
Marshall Clow611a55a2018-10-10 16:18:37 +0000426 bool native_exception = __isOurExceptionClass(unwind_exception);
Howard Hinnant47cb85482012-01-30 16:07:00 +0000427 __cxa_eh_globals* globals = __cxa_get_globals();
428 // exception_header is a hackish offset from a foreign exception, but it
429 // works as long as we're careful not to try to access any __cxa_exception
430 // parts.
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000431 __cxa_exception* exception_header =
432 cxa_exception_from_exception_unwind_exception
433 (
434 static_cast<_Unwind_Exception*>(unwind_exception)
435 );
Howard Hinnant47cb85482012-01-30 16:07:00 +0000436 if (native_exception)
437 {
438 // Increment the handler count, removing the flag about being rethrown
439 exception_header->handlerCount = exception_header->handlerCount < 0 ?
440 -exception_header->handlerCount + 1 : exception_header->handlerCount + 1;
441 // place the exception on the top of the stack if it's not already
442 // there by a previous rethrow
443 if (exception_header != globals->caughtExceptions)
444 {
445 exception_header->nextException = globals->caughtExceptions;
446 globals->caughtExceptions = exception_header;
447 }
448 globals->uncaughtExceptions -= 1; // Not atomically, since globals are thread-local
Ranjeet Singhef6e6722017-03-01 11:42:01 +0000449#if defined(_LIBCXXABI_ARM_EHABI)
Logan Chiendc65ab42014-05-10 00:42:10 +0000450 return reinterpret_cast<void*>(exception_header->unwindHeader.barrier_cache.bitpattern[0]);
451#else
Howard Hinnant47cb85482012-01-30 16:07:00 +0000452 return exception_header->adjustedPtr;
Logan Chiendc65ab42014-05-10 00:42:10 +0000453#endif
Marshall Clow9b454bc2011-08-15 18:06:47 +0000454 }
Howard Hinnant47cb85482012-01-30 16:07:00 +0000455 // Else this is a foreign exception
456 // If the caughtExceptions stack is not empty, terminate
457 if (globals->caughtExceptions != 0)
458 std::terminate();
459 // Push the foreign exception on to the stack
460 globals->caughtExceptions = exception_header;
461 return unwind_exception + 1;
Marshall Clow9b454bc2011-08-15 18:06:47 +0000462}
Marshall Clow87694492011-08-09 15:09:41 +0000463
464
465/*
466Upon exit for any reason, a handler must call:
467 void __cxa_end_catch ();
468
Howard Hinnant47cb85482012-01-30 16:07:00 +0000469This routine can be called for either a native or foreign exception.
470For a native exception:
Marshall Clow87694492011-08-09 15:09:41 +0000471* Locates the most recently caught exception and decrements its handler count.
472* Removes the exception from the caught exception stack, if the handler count goes to zero.
Howard Hinnant6ccae152011-12-08 19:35:18 +0000473* If the handler count goes down to zero, and the exception was not re-thrown
474 by throw, it locates the primary exception (which may be the same as the one
475 it's handling) and decrements its reference count. If that reference count
476 goes to zero, the function destroys the exception. In any case, if the current
477 exception is a dependent exception, it destroys that.
Howard Hinnant47cb85482012-01-30 16:07:00 +0000478
479For a foreign exception:
480* If it has been rethrown, there is nothing to do.
481* Otherwise delete the exception and pop the catch stack to empty.
Marshall Clow87694492011-08-09 15:09:41 +0000482*/
Shoaib Meenaife989a92017-03-01 03:55:57 +0000483void __cxa_end_catch() {
Nico Weberae543872014-06-25 23:52:07 +0000484 static_assert(sizeof(__cxa_exception) == sizeof(__cxa_dependent_exception),
485 "sizeof(__cxa_exception) must be equal to "
486 "sizeof(__cxa_dependent_exception)");
Saleem Abdulrasoole113b5e2015-11-18 05:33:38 +0000487 static_assert(__builtin_offsetof(__cxa_exception, referenceCount) ==
488 __builtin_offsetof(__cxa_dependent_exception,
489 primaryException),
490 "the layout of __cxa_exception must match the layout of "
491 "__cxa_dependent_exception");
492 static_assert(__builtin_offsetof(__cxa_exception, handlerCount) ==
493 __builtin_offsetof(__cxa_dependent_exception, handlerCount),
494 "the layout of __cxa_exception must match the layout of "
495 "__cxa_dependent_exception");
Howard Hinnant47cb85482012-01-30 16:07:00 +0000496 __cxa_eh_globals* globals = __cxa_get_globals_fast(); // __cxa_get_globals called in __cxa_begin_catch
497 __cxa_exception* exception_header = globals->caughtExceptions;
498 // If we've rethrown a foreign exception, then globals->caughtExceptions
499 // will have been made an empty stack by __cxa_rethrow() and there is
500 // nothing more to be done. Do nothing!
501 if (NULL != exception_header)
502 {
Marshall Clow611a55a2018-10-10 16:18:37 +0000503 bool native_exception = __isOurExceptionClass(&exception_header->unwindHeader);
Howard Hinnant47cb85482012-01-30 16:07:00 +0000504 if (native_exception)
505 {
506 // This is a native exception
507 if (exception_header->handlerCount < 0)
508 {
509 // The exception has been rethrown by __cxa_rethrow, so don't delete it
510 if (0 == incrementHandlerCount(exception_header))
511 {
512 // Remove from the chain of uncaught exceptions
513 globals->caughtExceptions = exception_header->nextException;
514 // but don't destroy
Howard Hinnant6ccae152011-12-08 19:35:18 +0000515 }
Howard Hinnant47cb85482012-01-30 16:07:00 +0000516 // Keep handlerCount negative in case there are nested catch's
517 // that need to be told that this exception is rethrown. Don't
518 // erase this rethrow flag until the exception is recaught.
519 }
520 else
521 {
522 // The native exception has not been rethrown
523 if (0 == decrementHandlerCount(exception_header))
524 {
525 // Remove from the chain of uncaught exceptions
526 globals->caughtExceptions = exception_header->nextException;
527 // Destroy this exception, being careful to distinguish
528 // between dependent and primary exceptions
529 if (isDependentException(&exception_header->unwindHeader))
530 {
531 // Reset exception_header to primaryException and deallocate the dependent exception
532 __cxa_dependent_exception* dep_exception_header =
533 reinterpret_cast<__cxa_dependent_exception*>(exception_header);
534 exception_header =
535 cxa_exception_from_thrown_object(dep_exception_header->primaryException);
536 __cxa_free_dependent_exception(dep_exception_header);
537 }
538 // Destroy the primary exception only if its referenceCount goes to 0
539 // (this decrement must be atomic)
540 __cxa_decrement_exception_refcount(thrown_object_from_cxa_exception(exception_header));
541 }
Marshall Clow9b454bc2011-08-15 18:06:47 +0000542 }
543 }
Howard Hinnant47cb85482012-01-30 16:07:00 +0000544 else
545 {
546 // The foreign exception has not been rethrown. Pop the stack
547 // and delete it. If there are nested catch's and they try
548 // to touch a foreign exception in any way, that is undefined
549 // behavior. They likely can't since the only way to catch
550 // a foreign exception is with catch (...)!
551 _Unwind_DeleteException(&globals->caughtExceptions->unwindHeader);
552 globals->caughtExceptions = 0;
553 }
Marshall Clow87694492011-08-09 15:09:41 +0000554 }
Marshall Clow9b454bc2011-08-15 18:06:47 +0000555}
Marshall Clow87694492011-08-09 15:09:41 +0000556
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000557// Note: exception_header may be masquerading as a __cxa_dependent_exception
558// and that's ok. exceptionType is there too.
Howard Hinnant47cb85482012-01-30 16:07:00 +0000559// However watch out for foreign exceptions. Return null for them.
Shoaib Meenaife989a92017-03-01 03:55:57 +0000560std::type_info *__cxa_current_exception_type() {
Marshall Clow87694492011-08-09 15:09:41 +0000561// get the current exception
Marshall Clow1de4fc02011-12-22 15:45:05 +0000562 __cxa_eh_globals *globals = __cxa_get_globals_fast();
563 if (NULL == globals)
564 return NULL; // If there have never been any exceptions, there are none now.
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000565 __cxa_exception *exception_header = globals->caughtExceptions;
566 if (NULL == exception_header)
Marshall Clow87694492011-08-09 15:09:41 +0000567 return NULL; // No current exception
Marshall Clow611a55a2018-10-10 16:18:37 +0000568 if (!__isOurExceptionClass(&exception_header->unwindHeader))
Howard Hinnant47cb85482012-01-30 16:07:00 +0000569 return NULL;
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000570 return exception_header->exceptionType;
Marshall Clow9b454bc2011-08-15 18:06:47 +0000571}
Marshall Clow87694492011-08-09 15:09:41 +0000572
573// 2.5.4 Rethrowing Exceptions
Howard Hinnant47cb85482012-01-30 16:07:00 +0000574/* This routine can rethrow native or foreign exceptions.
575If the exception is native:
Marshall Clow87694492011-08-09 15:09:41 +0000576* marks the exception object on top of the caughtExceptions stack
577 (in an implementation-defined way) as being rethrown.
578* If the caughtExceptions stack is empty, it calls terminate()
579 (see [C++FDIS] [except.throw], 15.1.8).
Howard Hinnant47cb85482012-01-30 16:07:00 +0000580* It then calls _Unwind_RaiseException which should not return
Howard Hinnant58926c92011-12-12 19:11:42 +0000581 (terminate if it does).
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000582 Note: exception_header may be masquerading as a __cxa_dependent_exception
583 and that's ok.
Marshall Clow87694492011-08-09 15:09:41 +0000584*/
Shoaib Meenaife989a92017-03-01 03:55:57 +0000585void __cxa_rethrow() {
Howard Hinnant47cb85482012-01-30 16:07:00 +0000586 __cxa_eh_globals* globals = __cxa_get_globals();
Howard Hinnant47cb85482012-01-30 16:07:00 +0000587 __cxa_exception* exception_header = globals->caughtExceptions;
588 if (NULL == exception_header)
589 std::terminate(); // throw; called outside of a exception handler
Marshall Clow611a55a2018-10-10 16:18:37 +0000590 bool native_exception = __isOurExceptionClass(&exception_header->unwindHeader);
Howard Hinnant47cb85482012-01-30 16:07:00 +0000591 if (native_exception)
592 {
Howard Hinnant47cb85482012-01-30 16:07:00 +0000593 // Mark the exception as being rethrown (reverse the effects of __cxa_begin_catch)
594 exception_header->handlerCount = -exception_header->handlerCount;
595 globals->uncaughtExceptions += 1;
596 // __cxa_end_catch will remove this exception from the caughtExceptions stack if necessary
597 }
598 else // this is a foreign exception
599 {
600 // The only way to communicate to __cxa_end_catch that we've rethrown
601 // a foreign exception, so don't delete us, is to pop the stack here
602 // which must be empty afterwards. Then __cxa_end_catch will do
603 // nothing
604 globals->caughtExceptions = 0;
605 }
Dan Albert3bd13ca2015-02-05 01:33:15 +0000606#ifdef __USING_SJLJ_EXCEPTIONS__
Howard Hinnant20d6c142012-02-29 22:14:19 +0000607 _Unwind_SjLj_RaiseException(&exception_header->unwindHeader);
Marshall Clow87694492011-08-09 15:09:41 +0000608#else
Howard Hinnant20d6c142012-02-29 22:14:19 +0000609 _Unwind_RaiseException(&exception_header->unwindHeader);
Marshall Clow87694492011-08-09 15:09:41 +0000610#endif
611
Howard Hinnant47cb85482012-01-30 16:07:00 +0000612 // If we get here, some kind of unwinding error has occurred.
613 // There is some weird code generation bug happening with
614 // Apple clang version 4.0 (tags/Apple/clang-418.0.2) (based on LLVM 3.1svn)
615 // If we call failed_throw here. Turns up with -O2 or higher, and -Os.
616 __cxa_begin_catch(&exception_header->unwindHeader);
617 if (native_exception)
618 std::__terminate(exception_header->terminateHandler);
619 // Foreign exception: can't get exception_header->terminateHandler
620 std::terminate();
Marshall Clow9b454bc2011-08-15 18:06:47 +0000621}
Marshall Clow87694492011-08-09 15:09:41 +0000622
Howard Hinnante04f5162011-12-21 23:32:11 +0000623/*
Howard Hinnant47cb85482012-01-30 16:07:00 +0000624 If thrown_object is not null, atomically increment the referenceCount field
625 of the __cxa_exception header associated with the thrown object referred to
626 by thrown_object.
627
628 Requires: If thrown_object is not NULL, it is a native exception.
Howard Hinnante04f5162011-12-21 23:32:11 +0000629*/
Shoaib Meenaife989a92017-03-01 03:55:57 +0000630void
Saleem Abdulrasool12315ed2015-12-04 02:14:58 +0000631__cxa_increment_exception_refcount(void *thrown_object) throw() {
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000632 if (thrown_object != NULL )
Howard Hinnante04f5162011-12-21 23:32:11 +0000633 {
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000634 __cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
Eli Friedman17a47b92018-04-16 22:00:14 +0000635 std::__libcpp_atomic_add(&exception_header->referenceCount, size_t(1));
Howard Hinnante04f5162011-12-21 23:32:11 +0000636 }
637}
638
639/*
Howard Hinnant47cb85482012-01-30 16:07:00 +0000640 If thrown_object is not null, atomically decrement the referenceCount field
641 of the __cxa_exception header associated with the thrown object referred to
642 by thrown_object. If the referenceCount drops to zero, destroy and
643 deallocate the exception.
644
645 Requires: If thrown_object is not NULL, it is a native exception.
Howard Hinnante04f5162011-12-21 23:32:11 +0000646*/
Vlad Tsyrklevichb89e9b52018-04-09 22:11:28 +0000647_LIBCXXABI_NO_CFI
648void __cxa_decrement_exception_refcount(void *thrown_object) throw() {
Howard Hinnante04f5162011-12-21 23:32:11 +0000649 if (thrown_object != NULL )
650 {
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000651 __cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
Eli Friedman17a47b92018-04-16 22:00:14 +0000652 if (std::__libcpp_atomic_add(&exception_header->referenceCount, size_t(-1)) == 0)
Howard Hinnante04f5162011-12-21 23:32:11 +0000653 {
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000654 if (NULL != exception_header->exceptionDestructor)
655 exception_header->exceptionDestructor(thrown_object);
Howard Hinnante04f5162011-12-21 23:32:11 +0000656 __cxa_free_exception(thrown_object);
657 }
658 }
659}
660
661/*
662 Returns a pointer to the thrown object (if any) at the top of the
Howard Hinnantbe2eced2013-02-15 15:48:49 +0000663 caughtExceptions stack. Atomically increment the exception's referenceCount.
Howard Hinnant47cb85482012-01-30 16:07:00 +0000664 If there is no such thrown object or if the thrown object is foreign,
665 returns null.
Marshall Clowd2bab352012-01-04 22:18:10 +0000666
667 We can use __cxa_get_globals_fast here to get the globals because if there have
668 been no exceptions thrown, ever, on this thread, we can return NULL without
669 the need to allocate the exception-handling globals.
Howard Hinnante04f5162011-12-21 23:32:11 +0000670*/
Shoaib Meenaife989a92017-03-01 03:55:57 +0000671void *__cxa_current_primary_exception() throw() {
Howard Hinnante04f5162011-12-21 23:32:11 +0000672// get the current exception
Marshall Clowf83663a2012-01-03 23:26:09 +0000673 __cxa_eh_globals* globals = __cxa_get_globals_fast();
Marshall Clow3e417e72012-01-03 23:10:20 +0000674 if (NULL == globals)
Marshall Clowf3684862012-01-04 14:56:09 +0000675 return NULL; // If there are no globals, there is no exception
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000676 __cxa_exception* exception_header = globals->caughtExceptions;
677 if (NULL == exception_header)
Howard Hinnante04f5162011-12-21 23:32:11 +0000678 return NULL; // No current exception
Marshall Clow611a55a2018-10-10 16:18:37 +0000679 if (!__isOurExceptionClass(&exception_header->unwindHeader))
Howard Hinnant47cb85482012-01-30 16:07:00 +0000680 return NULL; // Can't capture a foreign exception (no way to refcount it)
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000681 if (isDependentException(&exception_header->unwindHeader)) {
682 __cxa_dependent_exception* dep_exception_header =
683 reinterpret_cast<__cxa_dependent_exception*>(exception_header);
684 exception_header = cxa_exception_from_thrown_object(dep_exception_header->primaryException);
Howard Hinnante04f5162011-12-21 23:32:11 +0000685 }
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000686 void* thrown_object = thrown_object_from_cxa_exception(exception_header);
Howard Hinnante04f5162011-12-21 23:32:11 +0000687 __cxa_increment_exception_refcount(thrown_object);
688 return thrown_object;
689}
690
691/*
692 If reason isn't _URC_FOREIGN_EXCEPTION_CAUGHT, then the terminateHandler
693 stored in exc is called. Otherwise the referenceCount stored in the
694 primary exception is decremented, destroying the primary if necessary.
695 Finally the dependent exception is destroyed.
696*/
697static
698void
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000699dependent_exception_cleanup(_Unwind_Reason_Code reason, _Unwind_Exception* unwind_exception)
Howard Hinnante04f5162011-12-21 23:32:11 +0000700{
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000701 __cxa_dependent_exception* dep_exception_header =
702 reinterpret_cast<__cxa_dependent_exception*>(unwind_exception + 1) - 1;
Howard Hinnante04f5162011-12-21 23:32:11 +0000703 if (_URC_FOREIGN_EXCEPTION_CAUGHT != reason)
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000704 std::__terminate(dep_exception_header->terminateHandler);
705 __cxa_decrement_exception_refcount(dep_exception_header->primaryException);
706 __cxa_free_dependent_exception(dep_exception_header);
Howard Hinnante04f5162011-12-21 23:32:11 +0000707}
708
709/*
Howard Hinnantbe2eced2013-02-15 15:48:49 +0000710 If thrown_object is not null, allocate, initialize and throw a dependent
Howard Hinnante04f5162011-12-21 23:32:11 +0000711 exception.
712*/
713void
714__cxa_rethrow_primary_exception(void* thrown_object)
715{
716 if ( thrown_object != NULL )
717 {
Howard Hinnant47cb85482012-01-30 16:07:00 +0000718 // thrown_object guaranteed to be native because
719 // __cxa_current_primary_exception returns NULL for foreign exceptions
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000720 __cxa_exception* exception_header = cxa_exception_from_thrown_object(thrown_object);
721 __cxa_dependent_exception* dep_exception_header =
722 static_cast<__cxa_dependent_exception*>(__cxa_allocate_dependent_exception());
723 dep_exception_header->primaryException = thrown_object;
Howard Hinnante04f5162011-12-21 23:32:11 +0000724 __cxa_increment_exception_refcount(thrown_object);
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000725 dep_exception_header->exceptionType = exception_header->exceptionType;
726 dep_exception_header->unexpectedHandler = std::get_unexpected();
727 dep_exception_header->terminateHandler = std::get_terminate();
728 setDependentExceptionClass(&dep_exception_header->unwindHeader);
Howard Hinnant22f28b22011-12-21 23:48:05 +0000729 __cxa_get_globals()->uncaughtExceptions += 1;
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000730 dep_exception_header->unwindHeader.exception_cleanup = dependent_exception_cleanup;
Dan Albert3bd13ca2015-02-05 01:33:15 +0000731#ifdef __USING_SJLJ_EXCEPTIONS__
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000732 _Unwind_SjLj_RaiseException(&dep_exception_header->unwindHeader);
Howard Hinnante04f5162011-12-21 23:32:11 +0000733#else
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000734 _Unwind_RaiseException(&dep_exception_header->unwindHeader);
Howard Hinnante04f5162011-12-21 23:32:11 +0000735#endif
736 // Some sort of unwinding error. Note that terminate is a handler.
Howard Hinnantafcf7ac2012-01-22 19:14:27 +0000737 __cxa_begin_catch(&dep_exception_header->unwindHeader);
Howard Hinnante04f5162011-12-21 23:32:11 +0000738 }
739 // If we return client will call terminate()
740}
741
Howard Hinnante33b2f52012-01-24 00:01:31 +0000742bool
Marshall Clow604de5c2015-06-02 13:03:17 +0000743__cxa_uncaught_exception() throw() { return __cxa_uncaught_exceptions() != 0; }
744
745unsigned int
746__cxa_uncaught_exceptions() throw()
Howard Hinnante33b2f52012-01-24 00:01:31 +0000747{
Howard Hinnant47cb85482012-01-30 16:07:00 +0000748 // This does not report foreign exceptions in flight
Howard Hinnante33b2f52012-01-24 00:01:31 +0000749 __cxa_eh_globals* globals = __cxa_get_globals_fast();
750 if (globals == 0)
Marshall Clow604de5c2015-06-02 13:03:17 +0000751 return 0;
752 return globals->uncaughtExceptions;
Howard Hinnante33b2f52012-01-24 00:01:31 +0000753}
754
Marshall Clowe2dcb752011-07-20 15:04:39 +0000755} // extern "C"
756
Marshall Clowe2dcb752011-07-20 15:04:39 +0000757} // abi