* libstdc++-v3/testsuite/util/testsuite_abi.cc (check_version):
        Add CXXABI_TM_1.

        * libstdc++-v3/libsupc++/eh_tm.cc: New file.
        * libstdc++-v3/libsupc++/unwind-cxx.h (__cxa_tm_cleanup): Declare.
        * libstdc++-v3/config/abi/pre/gnu.ver: Export __cxa_tm_cleanup.
        * libstdc++-v3/config/abi/pre/gnu-versioned-namespace.ver: Likewise.
        * libstdc++-v3/libsupc++/Makefile.am (sources): Add eh_tm.cc.
        * libstdc++-v3/libsupc++/Makefile.in: Rebuild.

Index: libstdc++-v3/libsupc++/eh_tm.cc
===================================================================
--- libstdc++-v3/libsupc++/eh_tm.cc     (.../trunk)     (revision 0)
+++ libstdc++-v3/libsupc++/eh_tm.cc (.../branches/transactional-memory) (revision 180773)
@@ -0,0 +1,124 @@
+// -*- C++ -*- Exception handling routines for Transactional Memory.
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of GCC.
+//
+// GCC is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// GCC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+#include <cstdlib>
+#include "unwind-cxx.h"
+
+using namespace __cxxabiv1;
+
+// Free one C++ exception.
+
+static void
+free_any_cxa_exception (_Unwind_Exception *eo)
+{
+  __cxa_refcounted_exception *h
+    = __get_refcounted_exception_header_from_ue (eo);
+
+  if (__is_dependent_exception (eo->exception_class))
+    {
+      __cxa_dependent_exception *dep
+       = __get_dependent_exception_from_ue (eo);
+
+ h = __get_refcounted_exception_header_from_obj (dep->primaryException);
+
+      __cxa_free_dependent_exception (dep);
+    }
+
+  if (__sync_sub_and_fetch (&h->referenceCount, 1) == 0)
+    __cxa_free_exception (h + 1);
+}
+
+// Cleanup exception handling state while rolling back state for
+// a software transactional memory transaction.
+//
+// UNTHROWN_OBJ is non-null if we've called __cxa_allocate_exception
+// but not yet called __cxa_throw for it.
+//
+// CLEANUP_EXC is non-null if we're currently processing a cleanup
+// along an exception path, but we've not caught the exception yet.
+//
+// CAUGHT_COUNT is the nesting depth of __cxa_begin_catch within
+// the transaction; undo as if calling __cxa_end_catch that many times.
+
+extern "C" void
+__cxxabiv1::__cxa_tm_cleanup (void *unthrown_obj,
+                             void *cleanup_exc,
+                             unsigned int caught_count) throw()
+{
+  __cxa_eh_globals *globals = __cxa_get_globals_fast ();
+
+  // Handle a C++ exception not yet thrown.
+  if (unthrown_obj)
+    {
+      globals->uncaughtExceptions -= 1;
+      __cxa_free_exception (unthrown_obj);
+    }
+
+  // Handle an exception not yet caught ie. processing a cleanup
+  // in between the throw and the catch.
+  if (cleanup_exc)
+    {
+      _Unwind_Exception *eo
+       = reinterpret_cast <_Unwind_Exception *>(cleanup_exc);
+      if (__is_gxx_exception_class (eo->exception_class))
+       free_any_cxa_exception (eo);
+      else
+       _Unwind_DeleteException (eo);
+    }
+
+  // Do __cxa_end_catch caught_count times, but don't bother running
+  // the destructors for the objects involved.  All of that is being
+  // undone by the transaction restart.
+  if (caught_count > 0)
+    {
+      __cxa_exception *h = globals->caughtExceptions;
+
+ // Rethrown foreign exceptions are removed from the stack immediately.
+      // We would have freed this exception via THIS_EXC above.
+      if (h == NULL)
+       return;
+
+      do
+       {
+         __cxa_exception *next;
+         _Unwind_Exception *eo = &h->unwindHeader;
+
+         if (__is_gxx_exception_class (eo->exception_class))
+           {
+             next = h->nextException;
+             free_any_cxa_exception (eo);
+           }
+         else
+           {
+             _Unwind_DeleteException (eo);
+             next = 0;
+           }
+
+         h = next;
+       }
+      while (--caught_count);
+
+      globals->caughtExceptions = h;
+    }
+}
Index: libstdc++-v3/libsupc++/Makefile.in
===================================================================
--- libstdc++-v3/libsupc++/Makefile.in  (.../trunk)     (revision 180744)
+++ libstdc++-v3/libsupc++/Makefile.in (.../branches/transactional-memory) (revision 180773)
@@ -95,13 +95,14 @@ am__objects_1 = array_type_info.lo atexi
        del_opnt.lo del_opv.lo del_opvnt.lo dyncast.lo eh_alloc.lo \
        eh_arm.lo eh_aux_runtime.lo eh_call.lo eh_catch.lo \
        eh_exception.lo eh_globals.lo eh_personality.lo eh_ptr.lo \
-       eh_term_handler.lo eh_terminate.lo eh_throw.lo eh_type.lo \
-       eh_unex_handler.lo enum_type_info.lo function_type_info.lo \
-       fundamental_type_info.lo guard.lo guard_error.lo hash_bytes.lo \
-       nested_exception.lo new_handler.lo new_op.lo new_opnt.lo \
-       new_opv.lo new_opvnt.lo pbase_type_info.lo pmem_type_info.lo \
-       pointer_type_info.lo pure.lo si_class_type_info.lo tinfo.lo \
-       tinfo2.lo vec.lo vmi_class_type_info.lo vterminate.lo
+       eh_term_handler.lo eh_terminate.lo eh_tm.lo eh_throw.lo \
+       eh_type.lo eh_unex_handler.lo enum_type_info.lo \
+       function_type_info.lo fundamental_type_info.lo guard.lo \
+       guard_error.lo hash_bytes.lo nested_exception.lo \
+       new_handler.lo new_op.lo new_opnt.lo new_opv.lo new_opvnt.lo \
+       pbase_type_info.lo pmem_type_info.lo pointer_type_info.lo \
+       pure.lo si_class_type_info.lo tinfo.lo tinfo2.lo vec.lo \
+       vmi_class_type_info.lo vterminate.lo
 @GLIBCXX_HOSTED_TRUE@am__objects_2 = cp-demangle.lo
 am_libsupc___la_OBJECTS = $(am__objects_1) $(am__objects_2)
 libsupc___la_OBJECTS = $(am_libsupc___la_OBJECTS)
@@ -375,6 +376,7 @@ sources = \
        eh_ptr.cc \
        eh_term_handler.cc \
        eh_terminate.cc \
+       eh_tm.cc \
        eh_throw.cc \
        eh_type.cc \
        eh_unex_handler.cc \
Index: libstdc++-v3/libsupc++/unwind-cxx.h
===================================================================
--- libstdc++-v3/libsupc++/unwind-cxx.h (.../trunk)     (revision 180744)
+++ libstdc++-v3/libsupc++/unwind-cxx.h (.../branches/transactional-memory) (revision 180773)
@@ -167,6 +167,9 @@ extern "C" bool __cxa_begin_cleanup (_Un
 extern "C" void __cxa_end_cleanup (void);
 #endif

+// Handles cleanup from transactional memory restart.
+extern "C" void __cxa_tm_cleanup (void *, void *, unsigned int) throw();
+
 // Invokes given handler, dying appropriately if the user handler was
 // so inconsiderate as to return.
 extern void __terminate(std::terminate_handler) throw ()
Index: libstdc++-v3/libsupc++/Makefile.am
===================================================================
--- libstdc++-v3/libsupc++/Makefile.am  (.../trunk)     (revision 180744)
+++ libstdc++-v3/libsupc++/Makefile.am (.../branches/transactional-memory) (revision 180773)
@@ -68,6 +68,7 @@ sources = \
        eh_ptr.cc \
        eh_term_handler.cc \
        eh_terminate.cc \
+       eh_tm.cc \
        eh_throw.cc \
        eh_type.cc \
        eh_unex_handler.cc \
Index: libstdc++-v3/testsuite/util/testsuite_abi.cc
===================================================================
--- libstdc++-v3/testsuite/util/testsuite_abi.cc (.../trunk) (revision 180744) +++ libstdc++-v3/testsuite/util/testsuite_abi.cc (.../branches/transactional-memory) (revision 180773)
@@ -203,6 +203,7 @@ check_version(symbol& test, bool added)
       known_versions.push_back("CXXABI_1.3.2");
       known_versions.push_back("CXXABI_1.3.3");
       known_versions.push_back("CXXABI_1.3.4");
+      known_versions.push_back("CXXABI_TM_1");
       known_versions.push_back("CXXABI_1.3.5");
       known_versions.push_back("CXXABI_1.3.6");
       known_versions.push_back("CXXABI_LDBL_1.3");
Index: libstdc++-v3/config/abi/pre/gnu.ver
===================================================================
--- libstdc++-v3/config/abi/pre/gnu.ver (.../trunk)     (revision 180744)
+++ libstdc++-v3/config/abi/pre/gnu.ver (.../branches/transactional-memory) (revision 180773)
@@ -1458,6 +1458,15 @@ CXXABI_1.3.3 {

 } CXXABI_1.3.2;

+# Symbols in the support library (libsupc++) supporting trans-mem.
+CXXABI_TM_1 {
+  global:
+    __cxa_tm_cleanup;
+
+  local:
+    *;
+};
+
 CXXABI_1.3.4 {

     # typeinfo for decimal floating point types
Index: libstdc++-v3/config/abi/pre/gnu-versioned-namespace.ver
===================================================================
--- libstdc++-v3/config/abi/pre/gnu-versioned-namespace.ver (.../trunk) (revision 180744) +++ libstdc++-v3/config/abi/pre/gnu-versioned-namespace.ver (.../branches/transactional-memory) (revision 180773)
@@ -302,3 +302,12 @@ CXXABI_2.0 {
   local:
     *;
 };
+
+# Symbols in the support library (libsupc++) supporting trans-mem.
+CXXABI_TM_1 {
+  global:
+    __cxa_tm_cleanup;
+
+  local:
+    *;
+};

Reply via email to