1 //===--------- Definition of the HWAddressSanitizer class -------*- 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 // This file declares the Hardware AddressSanitizer class which is a port of the
11 // legacy HWAddressSanitizer pass to use the new PassManager infrastructure.
12 //
13 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_HWADDRESSSANITIZER_H
15 #define LLVM_TRANSFORMS_INSTRUMENTATION_HWADDRESSSANITIZER_H
16 
17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/PassManager.h"
19 
20 namespace llvm {
21 
22 /// This is a public interface to the hardware address sanitizer pass for
23 /// instrumenting code to check for various memory errors at runtime, similar to
24 /// AddressSanitizer but based on partial hardware assistance.
25 class HWAddressSanitizerPass : public PassInfoMixin<HWAddressSanitizerPass> {
26 public:
27   explicit HWAddressSanitizerPass(bool CompileKernel = false,
28                                   bool Recover = false,
29                                   bool DisableOptimization = false);
30   PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
isRequired()31   static bool isRequired() { return true; }
32 
33 private:
34   bool CompileKernel;
35   bool Recover;
36   bool DisableOptimization;
37 };
38 
39 FunctionPass *
40 createHWAddressSanitizerLegacyPassPass(bool CompileKernel = false,
41                                        bool Recover = false,
42                                        bool DisableOptimization = false);
43 
44 namespace HWASanAccessInfo {
45 
46 // Bit field positions for the accessinfo parameter to
47 // llvm.hwasan.check.memaccess. Shared between the pass and the backend. Bits
48 // 0-15 are also used by the runtime.
49 enum {
50   AccessSizeShift = 0, // 4 bits
51   IsWriteShift = 4,
52   RecoverShift = 5,
53   MatchAllShift = 16, // 8 bits
54   HasMatchAllShift = 24,
55   CompileKernelShift = 25,
56 };
57 
58 enum { RuntimeMask = 0xffff };
59 
60 } // namespace HWASanAccessInfo
61 
62 } // namespace llvm
63 
64 #endif
65