summaryrefslogtreecommitdiff
path: root/lib/gwp_asan
diff options
context:
space:
mode:
authorMitch Phillips <mitchphillips@outlook.com>2019-05-14 21:43:11 +0000
committerMitch Phillips <mitchphillips@outlook.com>2019-05-14 21:43:11 +0000
commit3c2213e37c81e7f0f016d4ea16756f7754e466b5 (patch)
treef9fd6642d6f82b455a2b8ef131c9c953a0e6e58f /lib/gwp_asan
parent67a5399a1d97fcd87e6075b50c9a32f59190e344 (diff)
downloadcompiler-rt-3c2213e37c81e7f0f016d4ea16756f7754e466b5.tar.gz
[GWP-ASan] Initial build files, implementation of PRNG [1].
Summary: See D60593 for further information. This patch slices off the PRNG implementation and the initial build files for GWP-ASan. Reviewers: vlad.tsyrklevich, morehouse, vitalybuka Reviewed By: morehouse Subscribers: srhines, kubamracek, mgorny, #sanitizers, llvm-commits, cryptoad, eugenis Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D61867 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@360710 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/gwp_asan')
-rw-r--r--lib/gwp_asan/CMakeLists.txt36
-rw-r--r--lib/gwp_asan/random.cpp21
-rw-r--r--lib/gwp_asan/random.h20
3 files changed, 77 insertions, 0 deletions
diff --git a/lib/gwp_asan/CMakeLists.txt b/lib/gwp_asan/CMakeLists.txt
new file mode 100644
index 000000000..b8ab64dd2
--- /dev/null
+++ b/lib/gwp_asan/CMakeLists.txt
@@ -0,0 +1,36 @@
+add_compiler_rt_component(gwp_asan)
+
+include_directories(..)
+
+set(GWP_ASAN_SOURCES
+ random.cpp
+)
+
+set(GWP_ASAN_HEADERS
+ random.h
+)
+
+# Disable RTTI and exception support, as we want these libraries to be
+# C-compatible. Regular C source files can be linked against the generated
+# GwpAsan libraries using the Clang C compiler.
+set(GWP_ASAN_CFLAGS -fno-rtti -fno-exceptions)
+
+if (COMPILER_RT_HAS_GWP_ASAN)
+ foreach(arch ${GWP_ASAN_SUPPORTED_ARCH})
+ add_compiler_rt_runtime(
+ clang_rt.gwp_asan
+ STATIC
+ ARCHS ${arch}
+ SOURCES ${GWP_ASAN_SOURCES}
+ ADDITIONAL_HEADERS ${GWP_ASAN_HEADERS}
+ CFLAGS ${GWP_ASAN_CFLAGS}
+ PARENT_TARGET gwp_asan
+ )
+ endforeach()
+
+ add_compiler_rt_object_libraries(RTGwpAsan
+ ARCHS ${GWP_ASAN_SUPPORTED_ARCH}
+ SOURCES ${GWP_ASAN_SOURCES}
+ ADDITIONAL_HEADERS ${GWP_ASAN_HEADERS}
+ CFLAGS ${GWP_ASAN_CFLAGS})
+endif()
diff --git a/lib/gwp_asan/random.cpp b/lib/gwp_asan/random.cpp
new file mode 100644
index 000000000..625973c48
--- /dev/null
+++ b/lib/gwp_asan/random.cpp
@@ -0,0 +1,21 @@
+//===-- 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 <ctime>
+
+namespace gwp_asan {
+uint32_t getRandomUnsigned32() {
+ thread_local uint32_t RandomState = static_cast<uint64_t>(time(nullptr));
+ RandomState ^= RandomState << 13;
+ RandomState ^= RandomState >> 17;
+ RandomState ^= RandomState << 5;
+ return RandomState;
+}
+} // namespace gwp_asan
diff --git a/lib/gwp_asan/random.h b/lib/gwp_asan/random.h
new file mode 100644
index 000000000..a71f3e59c
--- /dev/null
+++ b/lib/gwp_asan/random.h
@@ -0,0 +1,20 @@
+//===-- random.h ------------------------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef GWP_ASAN_RANDOM_H_
+#define GWP_ASAN_RANDOM_H_
+
+#include <cstdint>
+
+namespace gwp_asan {
+// xorshift (32-bit output), extremely fast PRNG that uses arithmetic operations
+// only. Seeded using walltime.
+uint32_t getRandomUnsigned32();
+} // namespace gwp_asan
+
+#endif // GWP_ASAN_RANDOM_H_