]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/scudo/scudo_utils.h
Update the GNU DTS file from Linux 4.11
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / scudo / scudo_utils.h
1 //===-- scudo_utils.h -------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// Header for scudo_utils.cpp.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #ifndef SCUDO_UTILS_H_
15 #define SCUDO_UTILS_H_
16
17 #include <string.h>
18
19 #include "sanitizer_common/sanitizer_common.h"
20
21 namespace __scudo {
22
23 template <class Dest, class Source>
24 inline Dest bit_cast(const Source& source) {
25   static_assert(sizeof(Dest) == sizeof(Source), "Sizes are not equal!");
26   Dest dest;
27   memcpy(&dest, &source, sizeof(dest));
28   return dest;
29 }
30
31 void NORETURN dieWithMessage(const char *Format, ...);
32
33 enum CPUFeature {
34   CRC32CPUFeature = 0,
35   MaxCPUFeature,
36 };
37 bool testCPUFeature(CPUFeature feature);
38
39 // Tiny PRNG based on https://en.wikipedia.org/wiki/Xorshift#xorshift.2B
40 // The state (128 bits) will be stored in thread local storage.
41 struct Xorshift128Plus {
42  public:
43   Xorshift128Plus();
44   u64 Next() {
45     u64 x = State[0];
46     const u64 y = State[1];
47     State[0] = y;
48     x ^= x << 23;
49     State[1] = x ^ y ^ (x >> 17) ^ (y >> 26);
50     return State[1] + y;
51   }
52  private:
53   u64 State[2];
54 };
55
56 // Software CRC32 functions, to be used when hardware support is not detected.
57 u32 computeSoftwareCRC32(u32 Crc, uptr Data);
58
59 }  // namespace __scudo
60
61 #endif  // SCUDO_UTILS_H_