blob: 2b128aa803f13fbc5e40f470571759a4bc7f0c0c [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"
10// http://www.codesourcery.com/public/cxx-abi/abi-eh.html
11//
12//===----------------------------------------------------------------------===//
13
Marshall Clow1df50ca2011-07-20 14:53:53 +000014#include <exception> // for std::unexpected_handler and std::terminate_handler
15#include <cxxabi.h>
16#include "unwind.h"
17
18namespace __cxxabiv1 {
19
Howard Hinnant6830b2a2012-01-24 18:15:20 +000020static const uint64_t kOurExceptionClass = 0x434C4E47432B2B00; // CLNGC++\0
21static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\1
Howard Hinnant8aa78512012-02-01 18:15:15 +000022static const uint64_t get_vendor_and_language = 0xFFFFFFFFFFFFFF00; // mask for CLNGC++
Howard Hinnant6830b2a2012-01-24 18:15:20 +000023
Marshall Clow1df50ca2011-07-20 14:53:53 +000024 struct __cxa_exception {
25#if __LP64__
26 // This is a new field to support C++ 0x exception_ptr.
27 // For binary compatibility it is at the start of this
28 // struct which is prepended to the object thrown in
29 // __cxa_allocate_exception.
30 size_t referenceCount;
31#endif
32
33 // Manage the exception object itself.
34 std::type_info *exceptionType;
35 void (*exceptionDestructor)(void *);
36 std::unexpected_handler unexpectedHandler;
37 std::terminate_handler terminateHandler;
38
39 __cxa_exception *nextException;
40
41 int handlerCount;
42
43#ifdef __ARM_EABI_UNWINDER__
44 __cxa_exception* nextPropagatingException;
45 int propagationCount;
46#else
47 int handlerSwitchValue;
48 const unsigned char *actionRecord;
49 const unsigned char *languageSpecificData;
50 void *catchTemp;
51 void *adjustedPtr;
52#endif
53
54#if !__LP64__
55 // This is a new field to support C++ 0x exception_ptr.
56 // For binary compatibility it is placed where the compiler
57 // previously adding padded to 64-bit align unwindHeader.
58 size_t referenceCount;
59#endif
60
61 _Unwind_Exception unwindHeader;
62 };
Howard Hinnant6ccae152011-12-08 19:35:18 +000063
64// http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html
Marshall Clow1df50ca2011-07-20 14:53:53 +000065
66 struct __cxa_dependent_exception {
67#if __LP64__
68 void* primaryException;
69#endif
70
Marshall Clow1df50ca2011-07-20 14:53:53 +000071 std::type_info *exceptionType;
72 void (*exceptionDestructor)(void *);
Marshall Clow1df50ca2011-07-20 14:53:53 +000073 std::unexpected_handler unexpectedHandler;
74 std::terminate_handler terminateHandler;
75
76 __cxa_exception *nextException;
77
78 int handlerCount;
79
80#ifdef __ARM_EABI_UNWINDER__
81 __cxa_exception* nextPropagatingException;
82 int propagationCount;
83#else
84 int handlerSwitchValue;
85 const unsigned char *actionRecord;
86 const unsigned char *languageSpecificData;
87 void * catchTemp;
88 void *adjustedPtr;
89#endif
90
91#if !__LP64__
92 void* primaryException;
93#endif
94
95 _Unwind_Exception unwindHeader;
96 };
97
98 struct __cxa_eh_globals {
99 __cxa_exception * caughtExceptions;
100 unsigned int uncaughtExceptions;
101#ifdef __ARM_EABI_UNWINDER__
102 __cxa_exception* propagatingExceptions;
103#endif
104 };
105
Howard Hinnant47cb85482012-01-30 16:07:00 +0000106 extern "C" __cxa_eh_globals * __cxa_get_globals ();
107 extern "C" __cxa_eh_globals * __cxa_get_globals_fast ();
Marshall Clow1df50ca2011-07-20 14:53:53 +0000108
Howard Hinnant47cb85482012-01-30 16:07:00 +0000109 extern "C" void * __cxa_allocate_dependent_exception ();
110 extern "C" void __cxa_free_dependent_exception (void * dependent_exception);
Marshall Clow1df50ca2011-07-20 14:53:53 +0000111
112}