blob: d4ac290122dc07ab85ebae85fd66ffd03179afbd [file] [log] [blame]
Reid Spencer8b2e1412006-11-17 03:32:33 +00001//===- Exception.cpp - Generic language-independent exceptions ------------===//
2//
3// This file defines the the shared data structures used by all language
4// specific exception handling runtime libraries.
5//
6//===----------------------------------------------------------------------===//
7
8#include "Exception.h"
9
10// Thread local state for exception handling. FIXME: This should really be made
11// thread-local!
12
13// UncaughtExceptionStack - The stack of exceptions currently being thrown.
14static llvm_exception *UncaughtExceptionStack = 0;
15
16// __llvm_eh_has_uncaught_exception - This is used to implement
17// std::uncaught_exception.
18//
19bool __llvm_eh_has_uncaught_exception() throw() {
20 return UncaughtExceptionStack != 0;
21}
22
23// __llvm_eh_current_uncaught_exception - This function checks to see if the
24// current uncaught exception is of the specified language type. If so, it
25// returns a pointer to the exception area data.
26//
27void *__llvm_eh_current_uncaught_exception_type(unsigned HandlerType) throw() {
28 if (UncaughtExceptionStack->ExceptionType == HandlerType)
29 return UncaughtExceptionStack+1;
30 return 0;
31}
32
33// __llvm_eh_add_uncaught_exception - This adds the specified exception to the
34// top of the uncaught exception stack. The exception should not already be on
35// the stack!
36void __llvm_eh_add_uncaught_exception(llvm_exception *E) throw() {
37 E->Next = UncaughtExceptionStack;
38 UncaughtExceptionStack = E;
39}
40
41
42// __llvm_eh_get_uncaught_exception - Returns the current uncaught exception.
43// There must be an uncaught exception for this to work!
44llvm_exception *__llvm_eh_get_uncaught_exception() throw() {
45 return UncaughtExceptionStack;
46}
47
48// __llvm_eh_pop_from_uncaught_stack - Remove the current uncaught exception
49// from the top of the stack.
50llvm_exception *__llvm_eh_pop_from_uncaught_stack() throw() {
51 llvm_exception *E = __llvm_eh_get_uncaught_exception();
52 UncaughtExceptionStack = E->Next;
53 return E;
54}