summaryrefslogtreecommitdiffstats
path: root/compiler-rt
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2012-09-17 03:14:15 +0000
committerDmitry Vyukov <dvyukov@google.com>2012-09-17 03:14:15 +0000
commit4d743f5346546e2972ee41e033ddfdaeaf14e929 (patch)
treea638b3cf8b3f9cb8b0d19b08e0a632be4f9e8d41 /compiler-rt
parent7fdbd2820e7a1efc93c9e72a5a98fc9c29ade836 (diff)
downloadbcm5719-llvm-4d743f5346546e2972ee41e033ddfdaeaf14e929.tar.gz
bcm5719-llvm-4d743f5346546e2972ee41e033ddfdaeaf14e929.zip
tsan: reserve msb in stack depot id's (required for msan)
llvm-svn: 164010
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc8
-rw-r--r--compiler-rt/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc2
2 files changed, 7 insertions, 3 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc
index 801abc430ab..6fb3d2dcbb6 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc
@@ -13,14 +13,15 @@
#include "sanitizer_stackdepot.h"
#include "sanitizer_common.h"
+#include "sanitizer_internal_defs.h"
#include "sanitizer_mutex.h"
#include "sanitizer_atomic.h"
namespace __sanitizer {
const int kTabSize = 1024 * 1024; // Hash table size.
-const int kPartBits = 10;
-const int kPartShift = sizeof(u32) * 8 - kPartBits;
+const int kPartBits = 8;
+const int kPartShift = sizeof(u32) * 8 - kPartBits - 1;
const int kPartCount = 1 << kPartBits; // Number of subparts in the table.
const int kPartSize = kTabSize / kPartCount;
const int kMaxId = 1 << kPartShift;
@@ -157,6 +158,8 @@ u32 StackDepotPut(const uptr *stack, uptr size) {
id = atomic_fetch_add(&depot.seq[part], 1, memory_order_relaxed) + 1;
CHECK_LT(id, kMaxId);
id |= part << kPartShift;
+ CHECK_NE(id, 0);
+ CHECK_EQ(id & (1u << 31), 0);
s = allocDesc(size);
s->id = id;
s->hash = h;
@@ -170,6 +173,7 @@ u32 StackDepotPut(const uptr *stack, uptr size) {
const uptr *StackDepotGet(u32 id, uptr *size) {
if (id == 0)
return 0;
+ CHECK_EQ(id & (1u << 31), 0);
// High kPartBits contain part id, so we need to scan at most kPartSize lists.
uptr part = id >> kPartShift;
for (int i = 0; i != kPartSize; i++) {
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc
index 5ac50eb1145..5350c2ab8db 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc
@@ -29,7 +29,7 @@ TEST(SanitizerCommon, StackDepotBasic) {
TEST(SanitizerCommon, StackDepotAbsent) {
uptr sz1 = 0;
- const uptr *sp1 = StackDepotGet(-10, &sz1);
+ const uptr *sp1 = StackDepotGet((1 << 30) - 1, &sz1);
EXPECT_EQ(sp1, (uptr*)0);
}
OpenPOWER on IntegriCloud