aboutsummaryrefslogtreecommitdiff
path: root/lib/gwp_asan/random.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-08-20 20:51:06 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-08-20 20:51:06 +0000
commit8f3cadc28cb2bb9e8f9d69eeaaea1f57f2f7b2ab (patch)
tree05a2b6ec297fe6283d9557c791445d1daf88dcd0 /lib/gwp_asan/random.cpp
parent63714eb5809e39666dec2454c354195e76f916ba (diff)
Diffstat (limited to 'lib/gwp_asan/random.cpp')
-rw-r--r--lib/gwp_asan/random.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/gwp_asan/random.cpp b/lib/gwp_asan/random.cpp
new file mode 100644
index 000000000000..90493da7e038
--- /dev/null
+++ b/lib/gwp_asan/random.cpp
@@ -0,0 +1,23 @@
+//===-- random.cpp ----------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#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 =
+ time(nullptr) + GuardedPoolAllocator::getThreadID();
+ RandomState ^= RandomState << 13;
+ RandomState ^= RandomState >> 17;
+ RandomState ^= RandomState << 5;
+ return RandomState;
+}
+} // namespace gwp_asan