Add C++11 header <cuchar>.
[official-gcc.git] / libitm / eh_cpp.cc
bloba86dbf164ddcf1b11bc88fed78851dc90f3d37c4
1 /* Copyright (C) 2009-2015 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@redhat.com>.
4 This file is part of the GNU Transactional Memory Library (libitm).
6 Libitm is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 #include "libitm_i.h"
27 using namespace GTM;
29 /* Everything from libstdc++ is weak, to avoid requiring that library
30 to be linked into plain C applications using libitm.so. */
32 #define WEAK __attribute__((weak))
34 extern "C" {
36 extern void *__cxa_allocate_exception (size_t) WEAK;
37 extern void __cxa_throw (void *, void *, void *) WEAK;
38 extern void *__cxa_begin_catch (void *) WEAK;
39 extern void __cxa_end_catch (void) WEAK;
40 extern void __cxa_tm_cleanup (void *, void *, unsigned int) WEAK;
42 #if !defined (HAVE_ELF_STYLE_WEAKREF)
43 void *__cxa_allocate_exception (size_t) { return NULL; }
44 void __cxa_throw (void *, void *, void *) { return; }
45 void *__cxa_begin_catch (void *) { return NULL; }
46 void __cxa_end_catch (void) { return; }
47 void __cxa_tm_cleanup (void *, void *, unsigned int) { return; }
48 void _Unwind_DeleteException (_Unwind_Exception *) { return; }
49 #endif /* HAVE_ELF_STYLE_WEAKREF */
54 void *
55 _ITM_cxa_allocate_exception (size_t size)
57 void *r = __cxa_allocate_exception (size);
58 gtm_thr()->cxa_unthrown = r;
59 return r;
62 void
63 _ITM_cxa_throw (void *obj, void *tinfo, void *dest)
65 gtm_thr()->cxa_unthrown = NULL;
66 __cxa_throw (obj, tinfo, dest);
69 void *
70 _ITM_cxa_begin_catch (void *exc_ptr)
72 gtm_thr()->cxa_catch_count++;
73 return __cxa_begin_catch (exc_ptr);
76 void
77 _ITM_cxa_end_catch (void)
79 gtm_thr()->cxa_catch_count--;
80 __cxa_end_catch ();
83 void
84 GTM::gtm_thread::revert_cpp_exceptions (gtm_transaction_cp *cp)
86 if (cp)
88 // If rolling back a nested transaction, only clean up unthrown
89 // exceptions since the last checkpoint. Always reset eh_in_flight
90 // because it just contains the argument provided to
91 // _ITM_commitTransactionEH
92 void *unthrown =
93 (cxa_unthrown != cp->cxa_unthrown ? cxa_unthrown : NULL);
94 assert (cxa_catch_count >= cp->cxa_catch_count);
95 uint32_t catch_count = cxa_catch_count - cp->cxa_catch_count;
96 if (unthrown || catch_count)
98 __cxa_tm_cleanup (unthrown, this->eh_in_flight, catch_count);
99 cxa_catch_count = cp->cxa_catch_count;
100 cxa_unthrown = cp->cxa_unthrown;
101 this->eh_in_flight = NULL;
104 else
106 // Both cxa_catch_count and cxa_unthrown are maximal because EH regions
107 // and transactions are properly nested.
108 if (this->cxa_unthrown || this->cxa_catch_count)
110 __cxa_tm_cleanup (this->cxa_unthrown, this->eh_in_flight,
111 this->cxa_catch_count);
112 this->cxa_catch_count = 0;
113 this->cxa_unthrown = NULL;
114 this->eh_in_flight = NULL;