diff options
author | Mitch Phillips <mitchphillips@outlook.com> | 2019-07-16 20:06:17 +0000 |
---|---|---|
committer | Mitch Phillips <mitchphillips@outlook.com> | 2019-07-16 20:06:17 +0000 |
commit | 48b8bfb2cb3a469471678ad2613ea30566a374dd (patch) | |
tree | 231a9ffc75484a96ef720d451cfac8976844a517 /lib/gwp_asan | |
parent | 882efe25584f52e5e5bfa57da68f9235e4d84b3e (diff) | |
download | compiler-rt-48b8bfb2cb3a469471678ad2613ea30566a374dd.tar.gz |
[GWP-ASan] Add thread ID to PRNG seed.
Summary:
Adds thread ID to PRNG seed for increased entropy. In particular, this allows
multiple runs in quick succession that will have different PRNG seeds, allowing
for better demos/testing.
Reviewers: kcc
Reviewed By: kcc
Subscribers: kubamracek, #sanitizers, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D64453
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@366253 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/gwp_asan')
-rw-r--r-- | lib/gwp_asan/guarded_pool_allocator.h | 8 | ||||
-rw-r--r-- | lib/gwp_asan/random.cpp | 4 |
2 files changed, 7 insertions, 5 deletions
diff --git a/lib/gwp_asan/guarded_pool_allocator.h b/lib/gwp_asan/guarded_pool_allocator.h index 400d50c0b..28a41110f 100644 --- a/lib/gwp_asan/guarded_pool_allocator.h +++ b/lib/gwp_asan/guarded_pool_allocator.h @@ -132,6 +132,10 @@ public: // occur. static void reportError(uintptr_t AccessPtr, Error E = Error::UNKNOWN); + // Get the current thread ID, or kInvalidThreadID if failure. Note: This + // implementation is platform-specific. + static uint64_t getThreadID(); + private: static constexpr size_t kInvalidSlotID = SIZE_MAX; @@ -146,10 +150,6 @@ private: void markReadWrite(void *Ptr, size_t Size) const; void markInaccessible(void *Ptr, size_t Size) const; - // Get the current thread ID, or kInvalidThreadID if failure. Note: This - // implementation is platform-specific. - static uint64_t getThreadID(); - // Get the page size from the platform-specific implementation. Only needs to // be called once, and the result should be cached in PageSize in this class. static size_t getPlatformPageSize(); diff --git a/lib/gwp_asan/random.cpp b/lib/gwp_asan/random.cpp index 67f4a22ef..90493da7e 100644 --- a/lib/gwp_asan/random.cpp +++ b/lib/gwp_asan/random.cpp @@ -7,12 +7,14 @@ //===----------------------------------------------------------------------===// #include "gwp_asan/random.h" +#include "gwp_asan/guarded_pool_allocator.h" #include <time.h> namespace gwp_asan { uint32_t getRandomUnsigned32() { - thread_local uint32_t RandomState = static_cast<uint64_t>(time(nullptr)); + thread_local uint32_t RandomState = + time(nullptr) + GuardedPoolAllocator::getThreadID(); RandomState ^= RandomState << 13; RandomState ^= RandomState >> 17; RandomState ^= RandomState << 5; |