blob: 95b859ea4f285d6c7218c19433e4ad278d80d40d [file] [log] [blame]
Howard Hinnant987afbe2011-12-06 18:01:47 +00001//===------------------------- cxa_exception.hpp --------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnant987afbe2011-12-06 18:01:47 +00006//
7//
8// This file implements the "Exception Handling APIs"
Louis Dionne2b0da3d2019-04-11 16:37:07 +00009// https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html
Howard Hinnant987afbe2011-12-06 18:01:47 +000010//
11//===----------------------------------------------------------------------===//
12
Howard Hinnant4ac72dd2012-03-19 16:20:34 +000013#ifndef _CXA_EXCEPTION_H
14#define _CXA_EXCEPTION_H
15
Marshall Clow1df50ca2011-07-20 14:53:53 +000016#include <exception> // for std::unexpected_handler and std::terminate_handler
Mehdi Amini5a403582017-04-04 05:38:38 +000017#include "cxxabi.h"
Marshall Clow1df50ca2011-07-20 14:53:53 +000018#include "unwind.h"
19
20namespace __cxxabiv1 {
21
Howard Hinnant6830b2a2012-01-24 18:15:20 +000022static const uint64_t kOurExceptionClass = 0x434C4E47432B2B00; // CLNGC++\0
23static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\1
Dan Albertb98c20c2015-02-05 23:48:06 +000024static const uint64_t get_vendor_and_language = 0xFFFFFFFFFFFFFF00; // mask for CLNGC++
25
Marshall Clow611a55a2018-10-10 16:18:37 +000026uint64_t __getExceptionClass (const _Unwind_Exception*);
27void __setExceptionClass ( _Unwind_Exception*, uint64_t);
28bool __isOurExceptionClass(const _Unwind_Exception*);
29
Shoaib Meenaife989a92017-03-01 03:55:57 +000030struct _LIBCXXABI_HIDDEN __cxa_exception {
Ranjeet Singhef6e6722017-03-01 11:42:01 +000031#if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI)
Marshall Clow1df50ca2011-07-20 14:53:53 +000032 // This is a new field to support C++ 0x exception_ptr.
33 // For binary compatibility it is at the start of this
34 // struct which is prepended to the object thrown in
35 // __cxa_allocate_exception.
Logan Chienaacc1c72014-04-12 11:56:41 +000036 size_t referenceCount;
Marshall Clow1df50ca2011-07-20 14:53:53 +000037#endif
Dan Albertb98c20c2015-02-05 23:48:06 +000038
Marshall Clow1df50ca2011-07-20 14:53:53 +000039 // Manage the exception object itself.
Logan Chienaacc1c72014-04-12 11:56:41 +000040 std::type_info *exceptionType;
Dan Albertb98c20c2015-02-05 23:48:06 +000041 void (*exceptionDestructor)(void *);
Logan Chienaacc1c72014-04-12 11:56:41 +000042 std::unexpected_handler unexpectedHandler;
43 std::terminate_handler terminateHandler;
44
45 __cxa_exception *nextException;
46
47 int handlerCount;
48
Ranjeet Singhef6e6722017-03-01 11:42:01 +000049#if defined(_LIBCXXABI_ARM_EHABI)
Logan Chienaacc1c72014-04-12 11:56:41 +000050 __cxa_exception* nextPropagatingException;
51 int propagationCount;
Marshall Clow1df50ca2011-07-20 14:53:53 +000052#else
Logan Chienaacc1c72014-04-12 11:56:41 +000053 int handlerSwitchValue;
54 const unsigned char *actionRecord;
55 const unsigned char *languageSpecificData;
56 void *catchTemp;
57 void *adjustedPtr;
Marshall Clow1df50ca2011-07-20 14:53:53 +000058#endif
59
Ranjeet Singhef6e6722017-03-01 11:42:01 +000060#if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI)
Marshall Clow1df50ca2011-07-20 14:53:53 +000061 // This is a new field to support C++ 0x exception_ptr.
62 // For binary compatibility it is placed where the compiler
63 // previously adding padded to 64-bit align unwindHeader.
Logan Chienaacc1c72014-04-12 11:56:41 +000064 size_t referenceCount;
Marshall Clow1df50ca2011-07-20 14:53:53 +000065#endif
Akira Hatanakac57477b22017-05-13 06:28:17 +000066 _Unwind_Exception unwindHeader;
Logan Chienaacc1c72014-04-12 11:56:41 +000067};
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.
Shoaib Meenaife989a92017-03-01 03:55:57 +000072struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
Ranjeet Singhef6e6722017-03-01 11:42:01 +000073#if defined(__LP64__) || defined(_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
Ranjeet Singhef6e6722017-03-01 11:42:01 +000086#if defined(_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
Ranjeet Singhef6e6722017-03-01 11:42:01 +000097#if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI)
Logan Chienaacc1c72014-04-12 11:56:41 +000098 void* primaryException;
Marshall Clow1df50ca2011-07-20 14:53:53 +000099#endif
Akira Hatanakac57477b22017-05-13 06:28:17 +0000100 _Unwind_Exception unwindHeader;
Logan Chienaacc1c72014-04-12 11:56:41 +0000101};
102
Shoaib Meenaife989a92017-03-01 03:55:57 +0000103struct _LIBCXXABI_HIDDEN __cxa_eh_globals {
Logan Chienaacc1c72014-04-12 11:56:41 +0000104 __cxa_exception * caughtExceptions;
105 unsigned int uncaughtExceptions;
Ranjeet Singhef6e6722017-03-01 11:42:01 +0000106#if defined(_LIBCXXABI_ARM_EHABI)
Logan Chienaacc1c72014-04-12 11:56:41 +0000107 __cxa_exception* propagatingExceptions;
Marshall Clow1df50ca2011-07-20 14:53:53 +0000108#endif
Logan Chienaacc1c72014-04-12 11:56:41 +0000109};
Marshall Clow1df50ca2011-07-20 14:53:53 +0000110
Shoaib Meenaife989a92017-03-01 03:55:57 +0000111extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals ();
112extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals_fast ();
Howard Hinnanteaa65af2012-02-02 20:47:28 +0000113
Shoaib Meenaife989a92017-03-01 03:55:57 +0000114extern "C" _LIBCXXABI_FUNC_VIS void * __cxa_allocate_dependent_exception ();
115extern "C" _LIBCXXABI_FUNC_VIS void __cxa_free_dependent_exception (void * dependent_exception);
Logan Chienaacc1c72014-04-12 11:56:41 +0000116
117} // namespace __cxxabiv1
Howard Hinnant4ac72dd2012-03-19 16:20:34 +0000118
119#endif // _CXA_EXCEPTION_H