summaryrefslogtreecommitdiff
path: root/runtime/GCCLibraries/crtend/Exception.cpp
blob: 156b714cb1a2c4e490524407bd3a5eb3d53c8894 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//===- Exception.cpp - Generic language-independent exceptions ------------===//
//
// This file defines the the shared data structures used by all language
// specific exception handling runtime libraries.
//
//===----------------------------------------------------------------------===//

#include "Exception.h"
#include <cassert>

// Thread local state for exception handling.  FIXME: This should really be made
// thread-local!

// UncaughtExceptionStack - The stack of exceptions currently being thrown.
static llvm_exception *UncaughtExceptionStack = 0;

// __llvm_eh_has_uncaught_exception - This is used to implement
// std::uncaught_exception.
//
bool __llvm_eh_has_uncaught_exception() throw() {
  return UncaughtExceptionStack != 0;
}

// __llvm_eh_current_uncaught_exception - This function checks to see if the
// current uncaught exception is of the specified language type.  If so, it
// returns a pointer to the exception area data.
//
void *__llvm_eh_current_uncaught_exception_type(unsigned HandlerType) throw() {
  assert(UncaughtExceptionStack && "No uncaught exception!");
  if (UncaughtExceptionStack->ExceptionType == HandlerType)
    return UncaughtExceptionStack+1;
  return 0;
}

// __llvm_eh_add_uncaught_exception - This adds the specified exception to the
// top of the uncaught exception stack.  The exception should not already be on
// the stack!
void __llvm_eh_add_uncaught_exception(llvm_exception *E) throw() {
  E->Next = UncaughtExceptionStack;
  UncaughtExceptionStack = E;
}


// __llvm_eh_get_uncaught_exception - Returns the current uncaught exception.
// There must be an uncaught exception for this to work!
llvm_exception *__llvm_eh_get_uncaught_exception() throw() {
  assert(UncaughtExceptionStack && "There are no uncaught exceptions!?!?");
  return UncaughtExceptionStack;
}

// __llvm_eh_pop_from_uncaught_stack - Remove the current uncaught exception
// from the top of the stack.
llvm_exception *__llvm_eh_pop_from_uncaught_stack() throw() {
  llvm_exception *E = __llvm_eh_get_uncaught_exception();
  UncaughtExceptionStack = E->Next;
  return E;
}