HWAddressSanitizer.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--------- Definition of the HWAddressSanitizer class -------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file declares the Hardware AddressSanitizer class which is a port of the
  15. // legacy HWAddressSanitizer pass to use the new PassManager infrastructure.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_HWADDRESSSANITIZER_H
  19. #define LLVM_TRANSFORMS_INSTRUMENTATION_HWADDRESSSANITIZER_H
  20. #include "llvm/IR/Function.h"
  21. #include "llvm/IR/PassManager.h"
  22. #include "llvm/Pass.h"
  23. namespace llvm {
  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. /// This is a public interface to the hardware address sanitizer pass for
  36. /// instrumenting code to check for various memory errors at runtime, similar to
  37. /// AddressSanitizer but based on partial hardware assistance.
  38. class HWAddressSanitizerPass : public PassInfoMixin<HWAddressSanitizerPass> {
  39. public:
  40. explicit HWAddressSanitizerPass(HWAddressSanitizerOptions Options)
  41. : Options(Options){};
  42. PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
  43. static bool isRequired() { return true; }
  44. void printPipeline(raw_ostream &OS,
  45. function_ref<StringRef(StringRef)> MapClassName2PassName);
  46. private:
  47. HWAddressSanitizerOptions Options;
  48. };
  49. FunctionPass *
  50. createHWAddressSanitizerLegacyPassPass(bool CompileKernel = false,
  51. bool Recover = false,
  52. bool DisableOptimization = false);
  53. namespace HWASanAccessInfo {
  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. enum { RuntimeMask = 0xffff };
  66. } // namespace HWASanAccessInfo
  67. } // namespace llvm
  68. #endif
  69. #ifdef __GNUC__
  70. #pragma GCC diagnostic pop
  71. #endif