annotate libstdc++-v3/libsupc++/eh_tm.cc @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // -*- C++ -*- Exception handling routines for Transactional Memory.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 // Copyright (C) 2009-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 //
kono
parents:
diff changeset
4 // This file is part of GCC.
kono
parents:
diff changeset
5 //
kono
parents:
diff changeset
6 // GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
7 // it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
8 // the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 // any later version.
kono
parents:
diff changeset
10 //
kono
parents:
diff changeset
11 // GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
14 // GNU General Public License for more details.
kono
parents:
diff changeset
15 //
kono
parents:
diff changeset
16 // Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 // permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 // 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 // You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 // a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 // <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include <cstdlib>
kono
parents:
diff changeset
26 #include "unwind-cxx.h"
kono
parents:
diff changeset
27 #include "eh_atomics.h"
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 using namespace __cxxabiv1;
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 // Free one C++ exception.
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 static void
kono
parents:
diff changeset
34 free_any_cxa_exception (_Unwind_Exception *eo)
kono
parents:
diff changeset
35 {
kono
parents:
diff changeset
36 __cxa_refcounted_exception *h
kono
parents:
diff changeset
37 = __get_refcounted_exception_header_from_ue (eo);
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 if (__is_dependent_exception (eo->exception_class))
kono
parents:
diff changeset
40 {
kono
parents:
diff changeset
41 __cxa_dependent_exception *dep
kono
parents:
diff changeset
42 = __get_dependent_exception_from_ue (eo);
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 h = __get_refcounted_exception_header_from_obj (dep->primaryException);
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 __cxa_free_dependent_exception (dep);
kono
parents:
diff changeset
47 }
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 if (__gnu_cxx::__eh_atomic_dec (&h->referenceCount))
kono
parents:
diff changeset
50 __cxa_free_exception (h + 1);
kono
parents:
diff changeset
51 }
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 // Cleanup exception handling state while rolling back state for
kono
parents:
diff changeset
54 // a software transactional memory transaction.
kono
parents:
diff changeset
55 //
kono
parents:
diff changeset
56 // UNTHROWN_OBJ is non-null if we've called __cxa_allocate_exception
kono
parents:
diff changeset
57 // but not yet called __cxa_throw for it.
kono
parents:
diff changeset
58 //
kono
parents:
diff changeset
59 // CLEANUP_EXC is non-null if we're currently processing a cleanup
kono
parents:
diff changeset
60 // along an exception path, but we've not caught the exception yet.
kono
parents:
diff changeset
61 //
kono
parents:
diff changeset
62 // CAUGHT_COUNT is the nesting depth of __cxa_begin_catch within
kono
parents:
diff changeset
63 // the transaction; undo as if calling __cxa_end_catch that many times.
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 extern "C" void
kono
parents:
diff changeset
66 __cxxabiv1::__cxa_tm_cleanup (void *unthrown_obj,
kono
parents:
diff changeset
67 void *cleanup_exc,
kono
parents:
diff changeset
68 unsigned int caught_count) throw()
kono
parents:
diff changeset
69 {
kono
parents:
diff changeset
70 __cxa_eh_globals *globals = __cxa_get_globals_fast ();
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 // Handle a C++ exception not yet thrown.
kono
parents:
diff changeset
73 if (unthrown_obj)
kono
parents:
diff changeset
74 {
kono
parents:
diff changeset
75 globals->uncaughtExceptions -= 1;
kono
parents:
diff changeset
76 __cxa_free_exception (unthrown_obj);
kono
parents:
diff changeset
77 }
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 // Handle an exception not yet caught ie. processing a cleanup
kono
parents:
diff changeset
80 // in between the throw and the catch.
kono
parents:
diff changeset
81 if (cleanup_exc)
kono
parents:
diff changeset
82 {
kono
parents:
diff changeset
83 _Unwind_Exception *eo
kono
parents:
diff changeset
84 = reinterpret_cast <_Unwind_Exception *>(cleanup_exc);
kono
parents:
diff changeset
85 if (__is_gxx_exception_class (eo->exception_class))
kono
parents:
diff changeset
86 free_any_cxa_exception (eo);
kono
parents:
diff changeset
87 else
kono
parents:
diff changeset
88 _Unwind_DeleteException (eo);
kono
parents:
diff changeset
89 }
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 // Do __cxa_end_catch caught_count times, but don't bother running
kono
parents:
diff changeset
92 // the destructors for the objects involved. All of that is being
kono
parents:
diff changeset
93 // undone by the transaction restart.
kono
parents:
diff changeset
94 if (caught_count > 0)
kono
parents:
diff changeset
95 {
kono
parents:
diff changeset
96 __cxa_exception *h = globals->caughtExceptions;
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 // Rethrown foreign exceptions are removed from the stack immediately.
kono
parents:
diff changeset
99 // We would have freed this exception via THIS_EXC above.
kono
parents:
diff changeset
100 if (h == NULL)
kono
parents:
diff changeset
101 return;
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 do
kono
parents:
diff changeset
104 {
kono
parents:
diff changeset
105 __cxa_exception *next;
kono
parents:
diff changeset
106 _Unwind_Exception *eo = &h->unwindHeader;
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 if (__is_gxx_exception_class (eo->exception_class))
kono
parents:
diff changeset
109 {
kono
parents:
diff changeset
110 next = h->nextException;
kono
parents:
diff changeset
111 free_any_cxa_exception (eo);
kono
parents:
diff changeset
112 }
kono
parents:
diff changeset
113 else
kono
parents:
diff changeset
114 {
kono
parents:
diff changeset
115 _Unwind_DeleteException (eo);
kono
parents:
diff changeset
116 next = 0;
kono
parents:
diff changeset
117 }
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 h = next;
kono
parents:
diff changeset
120 }
kono
parents:
diff changeset
121 while (--caught_count);
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 globals->caughtExceptions = h;
kono
parents:
diff changeset
124 }
kono
parents:
diff changeset
125 }