summaryrefslogtreecommitdiff
path: root/lib/asan/asan_allocator.h
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2012-12-10 14:19:15 +0000
committerKostya Serebryany <kcc@google.com>2012-12-10 14:19:15 +0000
commit2679f1904dc5d5eb2ce82014116764c5f5131a2b (patch)
treeb6c4bd9d324811c68ddb78c9db2010b3832b1ac6 /lib/asan/asan_allocator.h
parent8b0a7ce34660ef5b02d21dddb7d45d502539e9fd (diff)
[asan] move FakeStack into a separate file
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@169734 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/asan/asan_allocator.h')
-rw-r--r--lib/asan/asan_allocator.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/asan/asan_allocator.h b/lib/asan/asan_allocator.h
index 803aa2392..1e936c305 100644
--- a/lib/asan/asan_allocator.h
+++ b/lib/asan/asan_allocator.h
@@ -181,5 +181,40 @@ uptr asan_mz_size(const void *ptr);
void asan_mz_force_lock();
void asan_mz_force_unlock();
+// Log2 and RoundUpToPowerOfTwo should be inlined for performance.
+
+static inline uptr Log2(uptr x) {
+ CHECK(IsPowerOfTwo(x));
+#if !defined(_WIN32) || defined(__clang__)
+ return __builtin_ctzl(x);
+#elif defined(_WIN64)
+ unsigned long ret; // NOLINT
+ _BitScanForward64(&ret, x);
+ return ret;
+#else
+ unsigned long ret; // NOLINT
+ _BitScanForward(&ret, x);
+ return ret;
+#endif
+}
+
+static inline uptr RoundUpToPowerOfTwo(uptr size) {
+ CHECK(size);
+ if (IsPowerOfTwo(size)) return size;
+
+ unsigned long up; // NOLINT
+#if !defined(_WIN32) || defined(__clang__)
+ up = SANITIZER_WORDSIZE - 1 - __builtin_clzl(size);
+#elif defined(_WIN64)
+ _BitScanReverse64(&up, size);
+#else
+ _BitScanReverse(&up, size);
+#endif
+ CHECK(size < (1ULL << (up + 1)));
+ CHECK(size > (1ULL << up));
+ return 1UL << (up + 1);
+}
+
+
} // namespace __asan
#endif // ASAN_ALLOCATOR_H