summaryrefslogtreecommitdiff
path: root/libitm/local.cc
diff options
context:
space:
mode:
authortorvald <torvald@138bc75d-0d04-0410-961f-82ee72b054a4>2012-01-13 23:45:06 +0000
committertorvald <torvald@138bc75d-0d04-0410-961f-82ee72b054a4>2012-01-13 23:45:06 +0000
commit16cd83025fa0a794e4beec3647be492f08fe2d72 (patch)
tree8ed0df69ae3d1543fa4811e7cb7e72a8d99333b5 /libitm/local.cc
parentad76fe700e7812977c64513fd552a701571b3e3f (diff)
libitm: Filter out undo writes that overlap with the libitm stack.
PR libitm/51855 * config/generic/tls.h (GTM::mask_stack_top): New. (GTM::mask_stack_bottom): Declare. * config/generic/tls.c (GTM::mask_stack_bottom): New. * local.cc (gtm_undolog::rollback): Filter out any updates that overlap the libitm stack. Add current transaction as parameter. * libitm_i.h (GTM::gtm_undolog::rollback): Adapt. * beginend.cc (GTM::gtm_thread::rollback): Adapt. * testsuite/libitm.c/stackundo.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@183172 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libitm/local.cc')
-rw-r--r--libitm/local.cc27
1 files changed, 23 insertions, 4 deletions
diff --git a/libitm/local.cc b/libitm/local.cc
index 39b6da3a5d20..5645a12bab89 100644
--- a/libitm/local.cc
+++ b/libitm/local.cc
@@ -26,11 +26,20 @@
namespace GTM HIDDEN {
-
-void
-gtm_undolog::rollback (size_t until_size)
+// This function needs to be noinline because we need to prevent that it gets
+// inlined into another function that calls further functions. This could
+// break our assumption that we only call memcpy and thus only need to
+// additionally protect the memcpy stack (see the hack in mask_stack_bottom()).
+// Even if that isn't an issue because those other calls don't happen during
+// copying, we still need mask_stack_bottom() to be called "close" to the
+// memcpy in terms of stack frames, so just ensure that for now using the
+// noinline.
+void __attribute__((noinline))
+gtm_undolog::rollback (gtm_thread* tx, size_t until_size)
{
size_t i, n = undolog.size();
+ void *top = mask_stack_top(tx);
+ void *bot = mask_stack_bottom(tx);
if (n > 0)
{
@@ -40,7 +49,17 @@ gtm_undolog::rollback (size_t until_size)
size_t len = undolog[i];
size_t words = (len + sizeof(gtm_word) - 1) / sizeof(gtm_word);
i -= words;
- __builtin_memcpy (ptr, &undolog[i], len);
+ // Filter out any updates that overlap the libitm stack. We don't
+ // bother filtering out just the overlapping bytes because we don't
+ // merge writes and thus any overlapping write is either bogus or
+ // would restore data on stack frames that are not in use anymore.
+ // FIXME The memcpy can/will end up as another call but we
+ // calculated BOT based on the current function. Can we inline or
+ // reimplement this without too much trouble due to unaligned calls
+ // and still have good performance, so that we can remove the hack
+ // in mask_stack_bottom()?
+ if (likely(ptr > top || (uint8_t*)ptr + len <= bot))
+ __builtin_memcpy (ptr, &undolog[i], len);
}
}
}