Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 14 | pmbaty | 1 | //===--------- Definition of the HWAddressSanitizer class -------*- C++ -*-===// |
| 2 | // |
||
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
||
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
||
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
||
| 6 | // |
||
| 7 | //===----------------------------------------------------------------------===// |
||
| 8 | // |
||
| 9 | // This file declares the Hardware AddressSanitizer class which is a port of the |
||
| 10 | // legacy HWAddressSanitizer pass to use the new PassManager infrastructure. |
||
| 11 | // |
||
| 12 | //===----------------------------------------------------------------------===// |
||
| 13 | #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_HWADDRESSSANITIZER_H |
||
| 14 | #define LLVM_TRANSFORMS_INSTRUMENTATION_HWADDRESSSANITIZER_H |
||
| 15 | |||
| 16 | #include "llvm/ADT/STLFunctionalExtras.h" |
||
| 17 | #include "llvm/IR/PassManager.h" |
||
| 18 | |||
| 19 | namespace llvm { |
||
| 20 | class Module; |
||
| 21 | class StringRef; |
||
| 22 | class raw_ostream; |
||
| 23 | |||
| 24 | struct HWAddressSanitizerOptions { |
||
| 25 | HWAddressSanitizerOptions() |
||
| 26 | : HWAddressSanitizerOptions(false, false, false){}; |
||
| 27 | HWAddressSanitizerOptions(bool CompileKernel, bool Recover, |
||
| 28 | bool DisableOptimization) |
||
| 29 | : CompileKernel(CompileKernel), Recover(Recover), |
||
| 30 | DisableOptimization(DisableOptimization){}; |
||
| 31 | bool CompileKernel; |
||
| 32 | bool Recover; |
||
| 33 | bool DisableOptimization; |
||
| 34 | }; |
||
| 35 | |||
| 36 | /// This is a public interface to the hardware address sanitizer pass for |
||
| 37 | /// instrumenting code to check for various memory errors at runtime, similar to |
||
| 38 | /// AddressSanitizer but based on partial hardware assistance. |
||
| 39 | class HWAddressSanitizerPass : public PassInfoMixin<HWAddressSanitizerPass> { |
||
| 40 | public: |
||
| 41 | explicit HWAddressSanitizerPass(HWAddressSanitizerOptions Options) |
||
| 42 | : Options(Options){}; |
||
| 43 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); |
||
| 44 | static bool isRequired() { return true; } |
||
| 45 | void printPipeline(raw_ostream &OS, |
||
| 46 | function_ref<StringRef(StringRef)> MapClassName2PassName); |
||
| 47 | |||
| 48 | private: |
||
| 49 | HWAddressSanitizerOptions Options; |
||
| 50 | }; |
||
| 51 | |||
| 52 | namespace HWASanAccessInfo { |
||
| 53 | |||
| 54 | // Bit field positions for the accessinfo parameter to |
||
| 55 | // llvm.hwasan.check.memaccess. Shared between the pass and the backend. Bits |
||
| 56 | // 0-15 are also used by the runtime. |
||
| 57 | enum { |
||
| 58 | AccessSizeShift = 0, // 4 bits |
||
| 59 | IsWriteShift = 4, |
||
| 60 | RecoverShift = 5, |
||
| 61 | MatchAllShift = 16, // 8 bits |
||
| 62 | HasMatchAllShift = 24, |
||
| 63 | CompileKernelShift = 25, |
||
| 64 | }; |
||
| 65 | |||
| 66 | enum { RuntimeMask = 0xffff }; |
||
| 67 | |||
| 68 | } // namespace HWASanAccessInfo |
||
| 69 | |||
| 70 | } // namespace llvm |
||
| 71 | |||
| 72 | #endif |