1 |
737 |
jeremybenn |
/* Copyright (C) 2009, 2011, 2012 Free Software Foundation, Inc.
|
2 |
|
|
Contributed by Richard Henderson <rth@redhat.com>.
|
3 |
|
|
|
4 |
|
|
This file is part of the GNU Transactional Memory Library (libitm).
|
5 |
|
|
|
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.
|
10 |
|
|
|
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.
|
15 |
|
|
|
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.
|
19 |
|
|
|
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/>. */
|
24 |
|
|
|
25 |
|
|
#include "libitm_i.h"
|
26 |
|
|
|
27 |
|
|
using namespace GTM;
|
28 |
|
|
|
29 |
|
|
/* Everything from libstdc++ is weak, to avoid requiring that library
|
30 |
|
|
to be linked into plain C applications using libitm.so. */
|
31 |
|
|
|
32 |
|
|
#define WEAK __attribute__((weak))
|
33 |
|
|
|
34 |
|
|
extern "C" {
|
35 |
|
|
|
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;
|
41 |
|
|
|
42 |
|
|
#if !defined (HAVE_ELF_STYLE_WEAKREF) && !defined (__MACH__)
|
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 NULL; }
|
47 |
|
|
void __cxa_tm_cleanup (void *, void *, unsigned int) { return; }
|
48 |
|
|
void _Unwind_DeleteException (_Unwind_Exception *) { return; }
|
49 |
|
|
#endif /* HAVE_ELF_STYLE_WEAKREF */
|
50 |
|
|
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
void *
|
55 |
|
|
_ITM_cxa_allocate_exception (size_t size)
|
56 |
|
|
{
|
57 |
|
|
void *r = __cxa_allocate_exception (size);
|
58 |
|
|
gtm_thr()->cxa_unthrown = r;
|
59 |
|
|
return r;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
void
|
63 |
|
|
_ITM_cxa_throw (void *obj, void *tinfo, void *dest)
|
64 |
|
|
{
|
65 |
|
|
gtm_thr()->cxa_unthrown = NULL;
|
66 |
|
|
__cxa_throw (obj, tinfo, dest);
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
void *
|
70 |
|
|
_ITM_cxa_begin_catch (void *exc_ptr)
|
71 |
|
|
{
|
72 |
|
|
gtm_thr()->cxa_catch_count++;
|
73 |
|
|
return __cxa_begin_catch (exc_ptr);
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
void
|
77 |
|
|
_ITM_cxa_end_catch (void)
|
78 |
|
|
{
|
79 |
|
|
gtm_thr()->cxa_catch_count--;
|
80 |
|
|
__cxa_end_catch ();
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
void
|
84 |
|
|
GTM::gtm_thread::revert_cpp_exceptions (gtm_transaction_cp *cp)
|
85 |
|
|
{
|
86 |
|
|
if (cp)
|
87 |
|
|
{
|
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)
|
97 |
|
|
{
|
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;
|
102 |
|
|
}
|
103 |
|
|
}
|
104 |
|
|
else
|
105 |
|
|
{
|
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)
|
109 |
|
|
{
|
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;
|
115 |
|
|
}
|
116 |
|
|
}
|
117 |
|
|
}
|