1 // -*- C++ -*- Manage the thread-local exception globals.
2 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009
3 // Free Software Foundation, Inc.
5 // This file is part of GCC.
7 // GCC is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3, or (at your option)
12 // GCC is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
26 #include <bits/c++config.h>
30 #include "unwind-cxx.h"
31 #include "bits/gthr.h"
37 // In a freestanding environment, these functions may not be
38 // available -- but for now, we assume that they are.
39 extern "C" void *malloc (std::size_t);
40 extern "C" void free(void *);
43 using namespace __cxxabiv1
;
49 abi::__cxa_eh_globals
*
52 static __thread
abi::__cxa_eh_globals global
;
55 } // anonymous namespace
57 extern "C" __cxa_eh_globals
*
58 __cxxabiv1::__cxa_get_globals_fast() throw()
59 { return get_global(); }
61 extern "C" __cxa_eh_globals
*
62 __cxxabiv1::__cxa_get_globals() throw()
63 { return get_global(); }
68 // Single-threaded fallback buffer.
69 static __cxa_eh_globals eh_globals
;
74 eh_globals_dtor(void* ptr
)
78 __cxa_eh_globals
* g
= reinterpret_cast<__cxa_eh_globals
*>(ptr
);
79 __cxa_exception
* exn
= g
->caughtExceptions
;
80 __cxa_exception
* next
;
83 next
= exn
->nextException
;
84 _Unwind_DeleteException(&exn
->unwindHeader
);
91 struct __eh_globals_init
93 __gthread_key_t _M_key
;
96 __eh_globals_init() : _M_init(false)
98 if (__gthread_active_p())
99 _M_init
= __gthread_key_create(&_M_key
, eh_globals_dtor
) == 0;
105 __gthread_key_delete(_M_key
);
110 static __eh_globals_init init
;
112 extern "C" __cxa_eh_globals
*
113 __cxxabiv1::__cxa_get_globals_fast() throw()
117 g
= static_cast<__cxa_eh_globals
*>(__gthread_getspecific(init
._M_key
));
123 extern "C" __cxa_eh_globals
*
124 __cxxabiv1::__cxa_get_globals() throw()
129 g
= static_cast<__cxa_eh_globals
*>(__gthread_getspecific(init
._M_key
));
132 void* v
= malloc(sizeof(__cxa_eh_globals
));
133 if (v
== 0 || __gthread_setspecific(init
._M_key
, v
) != 0)
135 g
= static_cast<__cxa_eh_globals
*>(v
);
136 g
->caughtExceptions
= 0;
137 g
->uncaughtExceptions
= 0;
138 #ifdef __ARM_EABI_UNWINDER__
139 g
->propagatingExceptions
= 0;
150 extern "C" __cxa_eh_globals
*
151 __cxxabiv1::__cxa_get_globals_fast() throw()
152 { return &eh_globals
; }
154 extern "C" __cxa_eh_globals
*
155 __cxxabiv1::__cxa_get_globals() throw()
156 { return &eh_globals
; }