1 //===- c++-exception.h - C++ Specific exception Handling --------*- C++ -*-===//
3 // This file defines the data structures and API used by the C++ exception
4 // handling runtime library.
6 //===----------------------------------------------------------------------===//
8 #ifndef CXX_EXCEPTION_H
9 #define CXX_EXCEPTION_H
11 #include "exception.h"
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.
19 const std::type_info *TypeInfo;
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.
25 void (*ExceptionObjectDestructor)(void *);
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.
32 void (*UnexpectedHandler)();
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.
39 void (*TerminateHandler)();
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.
45 llvm_exception BaseException;
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;
53 // Interface to the C++ standard library to get to the terminate and unexpected
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));
61 // The current installed user handlers.
62 extern std::terminate_handler __terminate_handler;
63 extern std::unexpected_handler __unexpected_handler;
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();
72 void __llvm_cxxeh_call_terminate() throw() __attribute__((noreturn));
73 void * __llvm_cxxeh_current_uncaught_exception_isa(void *Ty)
75 void *__llvm_cxxeh_begin_catch() throw();
76 void *__llvm_cxxeh_begin_catch_if_isa(void *CatchType) throw();
77 void __llvm_cxxeh_end_catch() /* might throw */;
78 void __llvm_cxxeh_rethrow() throw();
79 void __llvm_cxxeh_check_eh_spec(void *Info, ...);