81a7639d95236aa89a02ebf0a157178e82c5ab78
[oota-llvm.git] / runtime / GCCLibraries / crtend / C++-Exception.h
1 //===- c++-exception.h - C++ Specific exception Handling --------*- C++ -*-===//
2 //
3 // This file defines the data structures and API used by the C++ exception
4 // handling runtime library.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef CXX_EXCEPTION_H
9 #define CXX_EXCEPTION_H
10
11 #include "exception.h"
12 #include <typeinfo>
13 #include <cassert>
14
15 struct llvm_cxx_exception {
16   /* TypeInfo - A pointer to the C++ std::type_info object for this exception
17    * class.  This is required because the class may not be polymorphic.
18    */
19   const std::type_info *TypeInfo;
20
21   /* ExceptionObjectDestructor - A pointer to the function which destroys the
22    * object represented by this exception.  This is required because the class
23    * may not be polymorphic.  This may be null if there is no cleanup required.
24    */
25   void (*ExceptionObjectDestructor)(void *);
26
27   /* UnexpectedHandler - This contains a pointer to the "unexpected" handler
28    * which may be registered by the user program with set_unexpected.  Calls to
29    * unexpected which are a result of an exception throw are supposed to use the
30    * value of the handler at the time of the throw, not the currently set value.
31    */
32   void (*UnexpectedHandler)();
33
34   /* TerminateHandler - This contains a pointer to the "terminate" handler which
35    * may be registered by the user program with set_terminate.  Calls to
36    * unexpected which are a result of an exception throw are supposed to use the
37    * value of the handler at the time of the throw, not the currently set value.
38    */
39   void (*TerminateHandler)();
40
41   /* BaseException - The language independent portion of the exception state.
42    * This is at the end of the record so that we can add additional members to
43    * this structure without breaking binary compatibility.
44    */
45   llvm_exception BaseException;
46 };
47
48 inline llvm_cxx_exception *get_cxx_exception(llvm_exception *E) throw() {
49   assert(E->ExceptionType == CXXException && "Not a C++ exception?");
50   return (llvm_cxx_exception*)(E+1)-1;
51 }
52
53 // Interface to the C++ standard library to get to the terminate and unexpected
54 // handler stuff.
55 namespace __cxxabiv1 {
56   // Invokes given handler, dying appropriately if the user handler was
57   // so inconsiderate as to return.
58   extern void __terminate(std::terminate_handler) __attribute__((noreturn));
59   extern void __unexpected(std::unexpected_handler) __attribute__((noreturn));
60   
61   // The current installed user handlers.
62   extern std::terminate_handler __terminate_handler;
63   extern std::unexpected_handler __unexpected_handler;
64 }
65
66 extern "C" {
67   void *__llvm_cxxeh_allocate_exception(unsigned NumBytes) throw();
68   void __llvm_cxxeh_free_exception(void *ObjectPtr) throw();
69   void __llvm_cxxeh_throw(void *ObjectPtr, void *TypeInfoPtr,
70                           void (*DtorPtr)(void*)) throw();
71
72   void * __llvm_cxxeh_current_uncaught_exception_isa(void *Ty)
73     throw();
74   void *__llvm_cxxeh_begin_catch() throw();
75   void *__llvm_cxxeh_begin_catch_if_isa(void *CatchType) throw();
76   void __llvm_cxxeh_end_catch() /* might throw */;
77   void __llvm_cxxeh_rethrow() throw();
78   void __llvm_cxxeh_check_eh_spec(void *Info, ...);
79 }
80
81 #endif