1 //===-- scudo_utils.h -------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// Header for scudo_utils.cpp.
12 //===----------------------------------------------------------------------===//
14 #ifndef SCUDO_UTILS_H_
15 #define SCUDO_UTILS_H_
19 #include "sanitizer_common/sanitizer_common.h"
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!");
27 memcpy(&dest, &source, sizeof(dest));
31 void NORETURN dieWithMessage(const char *Format, ...);
37 bool testCPUFeature(CPUFeature feature);
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 {
46 const u64 y = State[1];
49 State[1] = x ^ y ^ (x >> 17) ^ (y >> 26);
56 // Software CRC32 functions, to be used when hardware support is not detected.
57 u32 computeSoftwareCRC32(u32 Crc, uptr Data);
59 } // namespace __scudo
61 #endif // SCUDO_UTILS_H_