OSDN Git Service

Support sun symbol versioning in libitm
[pf3gnuchains/gcc-fork.git] / libitm / eh_cpp.cc
1 /* Copyright (C) 2009, 2011 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 #ifdef __osf__ /* Really: !HAVE_WEAKDEF  */
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 #endif
49
50 }
51
52
53 void *
54 _ITM_cxa_allocate_exception (size_t size)
55 {
56   void *r = __cxa_allocate_exception (size);
57   gtm_thr()->cxa_unthrown = r;
58   return r;
59 }
60
61 void
62 _ITM_cxa_throw (void *obj, void *tinfo, void *dest)
63 {
64   gtm_thr()->cxa_unthrown = NULL;
65   __cxa_throw (obj, tinfo, dest);
66 }
67
68 void *
69 _ITM_cxa_begin_catch (void *exc_ptr)
70 {
71   gtm_thr()->cxa_catch_count++;
72   return __cxa_begin_catch (exc_ptr);
73 }
74
75 void
76 _ITM_cxa_end_catch (void)
77 {
78   gtm_thr()->cxa_catch_count--;
79   __cxa_end_catch ();
80 }
81
82 void
83 GTM::gtm_thread::revert_cpp_exceptions (gtm_transaction_cp *cp)
84 {
85   if (cp)
86     {
87       // If rolling back a nested transaction, only clean up unthrown
88       // exceptions since the last checkpoint. Always reset eh_in_flight
89       // because it just contains the argument provided to
90       // _ITM_commitTransactionEH
91       void *unthrown =
92           (cxa_unthrown != cp->cxa_unthrown ? cxa_unthrown : NULL);
93       assert (cxa_catch_count >= cp->cxa_catch_count);
94       uint32_t catch_count = cxa_catch_count - cp->cxa_catch_count;
95       if (unthrown || catch_count)
96         {
97           __cxa_tm_cleanup (unthrown, this->eh_in_flight, catch_count);
98           cxa_catch_count = cp->cxa_catch_count;
99           cxa_unthrown = cp->cxa_unthrown;
100           this->eh_in_flight = NULL;
101         }
102     }
103   else
104     {
105       // Both cxa_catch_count and cxa_unthrown are maximal because EH regions
106       // and transactions are properly nested.
107       if (this->cxa_unthrown || this->cxa_catch_count)
108         {
109           __cxa_tm_cleanup (this->cxa_unthrown, this->eh_in_flight,
110               this->cxa_catch_count);
111           this->cxa_catch_count = 0;
112           this->cxa_unthrown = NULL;
113           this->eh_in_flight = NULL;
114         }
115     }
116 }