blob: c009db477e5782cde859dbd12d9470599ca9fd4a [file] [log] [blame]
Howard Hinnant987afbe2011-12-06 18:01:47 +00001//===------------------------- cxa_exception.hpp --------------------------===//
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
Howard Hinnant987afbe2011-12-06 18:01:47 +000011//
12//===----------------------------------------------------------------------===//
13
Howard Hinnant4ac72dd2012-03-19 16:20:34 +000014#ifndef _CXA_EXCEPTION_H
15#define _CXA_EXCEPTION_H
16
Marshall Clow1df50ca2011-07-20 14:53:53 +000017#include <exception> // for std::unexpected_handler and std::terminate_handler
Mehdi Amini5a403582017-04-04 05:38:38 +000018#include "cxxabi.h"
Marshall Clow1df50ca2011-07-20 14:53:53 +000019#include "unwind.h"
20
21namespace __cxxabiv1 {
22
Howard Hinnant6830b2a2012-01-24 18:15:20 +000023static const uint64_t kOurExceptionClass = 0x434C4E47432B2B00; // CLNGC++\0
24static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\1
Dan Albertb98c20c2015-02-05 23:48:06 +000025static const uint64_t get_vendor_and_language = 0xFFFFFFFFFFFFFF00; // mask for CLNGC++
26
Shoaib Meenaife989a92017-03-01 03:55:57 +000027struct _LIBCXXABI_HIDDEN __cxa_exception {
Ranjeet Singhef6e6722017-03-01 11:42:01 +000028#if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI)
Marshall Clow1df50ca2011-07-20 14:53:53 +000029 // This is a new field to support C++ 0x exception_ptr.
30 // For binary compatibility it is at the start of this
31 // struct which is prepended to the object thrown in
32 // __cxa_allocate_exception.
Logan Chienaacc1c72014-04-12 11:56:41 +000033 size_t referenceCount;
Marshall Clow1df50ca2011-07-20 14:53:53 +000034#endif
Dan Albertb98c20c2015-02-05 23:48:06 +000035
Marshall Clow1df50ca2011-07-20 14:53:53 +000036 // Manage the exception object itself.
Logan Chienaacc1c72014-04-12 11:56:41 +000037 std::type_info *exceptionType;
Dan Albertb98c20c2015-02-05 23:48:06 +000038 void (*exceptionDestructor)(void *);
Logan Chienaacc1c72014-04-12 11:56:41 +000039 std::unexpected_handler unexpectedHandler;
40 std::terminate_handler terminateHandler;
41
42 __cxa_exception *nextException;
43
44 int handlerCount;
45
Ranjeet Singhef6e6722017-03-01 11:42:01 +000046#if defined(_LIBCXXABI_ARM_EHABI)
Logan Chienaacc1c72014-04-12 11:56:41 +000047 __cxa_exception* nextPropagatingException;
48 int propagationCount;
Marshall Clow1df50ca2011-07-20 14:53:53 +000049#else
Logan Chienaacc1c72014-04-12 11:56:41 +000050 int handlerSwitchValue;
51 const unsigned char *actionRecord;
52 const unsigned char *languageSpecificData;
53 void *catchTemp;
54 void *adjustedPtr;
Marshall Clow1df50ca2011-07-20 14:53:53 +000055#endif
56
Ranjeet Singhef6e6722017-03-01 11:42:01 +000057#if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI)
Marshall Clow1df50ca2011-07-20 14:53:53 +000058 // This is a new field to support C++ 0x exception_ptr.
59 // For binary compatibility it is placed where the compiler
60 // previously adding padded to 64-bit align unwindHeader.
Logan Chienaacc1c72014-04-12 11:56:41 +000061 size_t referenceCount;
Marshall Clow1df50ca2011-07-20 14:53:53 +000062#endif
Logan Chienaacc1c72014-04-12 11:56:41 +000063
64 _Unwind_Exception unwindHeader;
65};
Howard Hinnant6ccae152011-12-08 19:35:18 +000066
67// http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html
Nico Weberae543872014-06-25 23:52:07 +000068// The layout of this structure MUST match the layout of __cxa_exception, with
69// primaryException instead of referenceCount.
Shoaib Meenaife989a92017-03-01 03:55:57 +000070struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
Ranjeet Singhef6e6722017-03-01 11:42:01 +000071#if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI)
Logan Chienaacc1c72014-04-12 11:56:41 +000072 void* primaryException;
Marshall Clow1df50ca2011-07-20 14:53:53 +000073#endif
Dan Albertb98c20c2015-02-05 23:48:06 +000074
Logan Chienaacc1c72014-04-12 11:56:41 +000075 std::type_info *exceptionType;
Dan Albertb98c20c2015-02-05 23:48:06 +000076 void (*exceptionDestructor)(void *);
Logan Chienaacc1c72014-04-12 11:56:41 +000077 std::unexpected_handler unexpectedHandler;
78 std::terminate_handler terminateHandler;
79
80 __cxa_exception *nextException;
81
82 int handlerCount;
Dan Albertb98c20c2015-02-05 23:48:06 +000083
Ranjeet Singhef6e6722017-03-01 11:42:01 +000084#if defined(_LIBCXXABI_ARM_EHABI)
Logan Chienaacc1c72014-04-12 11:56:41 +000085 __cxa_exception* nextPropagatingException;
86 int propagationCount;
Marshall Clow1df50ca2011-07-20 14:53:53 +000087#else
Logan Chienaacc1c72014-04-12 11:56:41 +000088 int handlerSwitchValue;
89 const unsigned char *actionRecord;
90 const unsigned char *languageSpecificData;
91 void * catchTemp;
92 void *adjustedPtr;
Marshall Clow1df50ca2011-07-20 14:53:53 +000093#endif
Dan Albertb98c20c2015-02-05 23:48:06 +000094
Ranjeet Singhef6e6722017-03-01 11:42:01 +000095#if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI)
Logan Chienaacc1c72014-04-12 11:56:41 +000096 void* primaryException;
Marshall Clow1df50ca2011-07-20 14:53:53 +000097#endif
Logan Chienaacc1c72014-04-12 11:56:41 +000098
99 _Unwind_Exception unwindHeader;
100};
101
Shoaib Meenaife989a92017-03-01 03:55:57 +0000102struct _LIBCXXABI_HIDDEN __cxa_eh_globals {
Logan Chienaacc1c72014-04-12 11:56:41 +0000103 __cxa_exception * caughtExceptions;
104 unsigned int uncaughtExceptions;
Ranjeet Singhef6e6722017-03-01 11:42:01 +0000105#if defined(_LIBCXXABI_ARM_EHABI)
Logan Chienaacc1c72014-04-12 11:56:41 +0000106 __cxa_exception* propagatingExceptions;
Marshall Clow1df50ca2011-07-20 14:53:53 +0000107#endif
Logan Chienaacc1c72014-04-12 11:56:41 +0000108};
Marshall Clow1df50ca2011-07-20 14:53:53 +0000109
Shoaib Meenaife989a92017-03-01 03:55:57 +0000110extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals ();
111extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals_fast ();
Howard Hinnanteaa65af2012-02-02 20:47:28 +0000112
Shoaib Meenaife989a92017-03-01 03:55:57 +0000113extern "C" _LIBCXXABI_FUNC_VIS void * __cxa_allocate_dependent_exception ();
114extern "C" _LIBCXXABI_FUNC_VIS void __cxa_free_dependent_exception (void * dependent_exception);
Logan Chienaacc1c72014-04-12 11:56:41 +0000115
116} // namespace __cxxabiv1
Howard Hinnant4ac72dd2012-03-19 16:20:34 +0000117
118#endif // _CXA_EXCEPTION_H