summaryrefslogtreecommitdiff
path: root/lib
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
commitd0dc91869f197d2df69ceaecce0889931e18de67 (patch)
tree65c7caee840541789f2d69a4d46ee418a34bf4a9 /lib
parentdf11061d6df6e7018c34fc23274c40c36db4731a (diff)
tsan: reserve msb in stack depot id's (required for msan)
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@164010 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/sanitizer_common/sanitizer_stackdepot.cc8
-rw-r--r--lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc2
2 files changed, 7 insertions, 3 deletions
diff --git a/lib/sanitizer_common/sanitizer_stackdepot.cc b/lib/sanitizer_common/sanitizer_stackdepot.cc
index 801abc430..6fb3d2dcb 100644
--- a/lib/sanitizer_common/sanitizer_stackdepot.cc
+++ b/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/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc b/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc
index 5ac50eb11..5350c2ab8 100644
--- a/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cc
+++ b/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);
}