blob: 6e68f985389f9eda7360ea2d1c0727e73d828c7d [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
18#include <cxxabi.h>
19#include "unwind.h"
20
21namespace __cxxabiv1 {
22
Howard Hinnanteaa65af2012-02-02 20:47:28 +000023#pragma GCC visibility push(hidden)
24
Howard Hinnant6830b2a2012-01-24 18:15:20 +000025static const uint64_t kOurExceptionClass = 0x434C4E47432B2B00; // CLNGC++\0
26static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\1
Dan Albertb98c20c2015-02-05 23:48:06 +000027static const uint64_t get_vendor_and_language = 0xFFFFFFFFFFFFFF00; // mask for CLNGC++
28
29struct __cxa_exception {
Dan Albert3be4efa2015-02-05 02:44:50 +000030#if defined(__LP64__) || LIBCXXABI_ARM_EHABI
Marshall Clow1df50ca2011-07-20 14:53:53 +000031 // This is a new field to support C++ 0x exception_ptr.
32 // For binary compatibility it is at the start of this
33 // struct which is prepended to the object thrown in
34 // __cxa_allocate_exception.
Logan Chienaacc1c72014-04-12 11:56:41 +000035 size_t referenceCount;
Marshall Clow1df50ca2011-07-20 14:53:53 +000036#endif
Dan Albertb98c20c2015-02-05 23:48:06 +000037
Marshall Clow1df50ca2011-07-20 14:53:53 +000038 // Manage the exception object itself.
Logan Chienaacc1c72014-04-12 11:56:41 +000039 std::type_info *exceptionType;
Dan Albertb98c20c2015-02-05 23:48:06 +000040 void (*exceptionDestructor)(void *);
Logan Chienaacc1c72014-04-12 11:56:41 +000041 std::unexpected_handler unexpectedHandler;
42 std::terminate_handler terminateHandler;
43
44 __cxa_exception *nextException;
45
46 int handlerCount;
47
Logan Chiendc65ab42014-05-10 00:42:10 +000048#if LIBCXXABI_ARM_EHABI
Logan Chienaacc1c72014-04-12 11:56:41 +000049 __cxa_exception* nextPropagatingException;
50 int propagationCount;
Marshall Clow1df50ca2011-07-20 14:53:53 +000051#else
Logan Chienaacc1c72014-04-12 11:56:41 +000052 int handlerSwitchValue;
53 const unsigned char *actionRecord;
54 const unsigned char *languageSpecificData;
55 void *catchTemp;
56 void *adjustedPtr;
Marshall Clow1df50ca2011-07-20 14:53:53 +000057#endif
58
Dan Albert3be4efa2015-02-05 02:44:50 +000059#if !defined(__LP64__) && !LIBCXXABI_ARM_EHABI
Marshall Clow1df50ca2011-07-20 14:53:53 +000060 // This is a new field to support C++ 0x exception_ptr.
61 // For binary compatibility it is placed where the compiler
62 // previously adding padded to 64-bit align unwindHeader.
Logan Chienaacc1c72014-04-12 11:56:41 +000063 size_t referenceCount;
Marshall Clow1df50ca2011-07-20 14:53:53 +000064#endif
Logan Chienaacc1c72014-04-12 11:56:41 +000065
66 _Unwind_Exception unwindHeader;
67};
Howard Hinnant6ccae152011-12-08 19:35:18 +000068
69// http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html
Nico Weberae543872014-06-25 23:52:07 +000070// The layout of this structure MUST match the layout of __cxa_exception, with
71// primaryException instead of referenceCount.
Logan Chienaacc1c72014-04-12 11:56:41 +000072struct __cxa_dependent_exception {
Dan Albert3be4efa2015-02-05 02:44:50 +000073#if defined(__LP64__) || LIBCXXABI_ARM_EHABI
Logan Chienaacc1c72014-04-12 11:56:41 +000074 void* primaryException;
Marshall Clow1df50ca2011-07-20 14:53:53 +000075#endif
Dan Albertb98c20c2015-02-05 23:48:06 +000076
Logan Chienaacc1c72014-04-12 11:56:41 +000077 std::type_info *exceptionType;
Dan Albertb98c20c2015-02-05 23:48:06 +000078 void (*exceptionDestructor)(void *);
Logan Chienaacc1c72014-04-12 11:56:41 +000079 std::unexpected_handler unexpectedHandler;
80 std::terminate_handler terminateHandler;
81
82 __cxa_exception *nextException;
83
84 int handlerCount;
Dan Albertb98c20c2015-02-05 23:48:06 +000085
Logan Chiendc65ab42014-05-10 00:42:10 +000086#if LIBCXXABI_ARM_EHABI
Logan Chienaacc1c72014-04-12 11:56:41 +000087 __cxa_exception* nextPropagatingException;
88 int propagationCount;
Marshall Clow1df50ca2011-07-20 14:53:53 +000089#else
Logan Chienaacc1c72014-04-12 11:56:41 +000090 int handlerSwitchValue;
91 const unsigned char *actionRecord;
92 const unsigned char *languageSpecificData;
93 void * catchTemp;
94 void *adjustedPtr;
Marshall Clow1df50ca2011-07-20 14:53:53 +000095#endif
Dan Albertb98c20c2015-02-05 23:48:06 +000096
Dan Albert3be4efa2015-02-05 02:44:50 +000097#if !defined(__LP64__) && !LIBCXXABI_ARM_EHABI
Logan Chienaacc1c72014-04-12 11:56:41 +000098 void* primaryException;
Marshall Clow1df50ca2011-07-20 14:53:53 +000099#endif
Logan Chienaacc1c72014-04-12 11:56:41 +0000100
101 _Unwind_Exception unwindHeader;
102};
103
104struct __cxa_eh_globals {
105 __cxa_exception * caughtExceptions;
106 unsigned int uncaughtExceptions;
Logan Chiendc65ab42014-05-10 00:42:10 +0000107#if LIBCXXABI_ARM_EHABI
Logan Chienaacc1c72014-04-12 11:56:41 +0000108 __cxa_exception* propagatingExceptions;
Marshall Clow1df50ca2011-07-20 14:53:53 +0000109#endif
Logan Chienaacc1c72014-04-12 11:56:41 +0000110};
Marshall Clow1df50ca2011-07-20 14:53:53 +0000111
Howard Hinnanteaa65af2012-02-02 20:47:28 +0000112#pragma GCC visibility pop
113#pragma GCC visibility push(default)
114
Logan Chienaacc1c72014-04-12 11:56:41 +0000115extern "C" __cxa_eh_globals * __cxa_get_globals ();
116extern "C" __cxa_eh_globals * __cxa_get_globals_fast ();
Marshall Clow1df50ca2011-07-20 14:53:53 +0000117
Logan Chienaacc1c72014-04-12 11:56:41 +0000118extern "C" void * __cxa_allocate_dependent_exception ();
119extern "C" void __cxa_free_dependent_exception (void * dependent_exception);
Marshall Clow1df50ca2011-07-20 14:53:53 +0000120
Howard Hinnanteaa65af2012-02-02 20:47:28 +0000121#pragma GCC visibility pop
Logan Chienaacc1c72014-04-12 11:56:41 +0000122
123} // namespace __cxxabiv1
Howard Hinnant4ac72dd2012-03-19 16:20:34 +0000124
125#endif // _CXA_EXCEPTION_H