HWAddressSanitizer.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/ADT/STLFunctionalExtras.h"
  21. #include "llvm/IR/PassManager.h"
  22. namespace llvm {
  23. class Module;
  24. class StringRef;
  25. class raw_ostream;
  26. struct HWAddressSanitizerOptions {
  27. HWAddressSanitizerOptions()
  28. : HWAddressSanitizerOptions(false, false, false){};
  29. HWAddressSanitizerOptions(bool CompileKernel, bool Recover,
  30. bool DisableOptimization)
  31. : CompileKernel(CompileKernel), Recover(Recover),
  32. DisableOptimization(DisableOptimization){};
  33. bool CompileKernel;
  34. bool Recover;
  35. bool DisableOptimization;
  36. };
  37. /// This is a public interface to the hardware address sanitizer pass for
  38. /// instrumenting code to check for various memory errors at runtime, similar to
  39. /// AddressSanitizer but based on partial hardware assistance.
  40. class HWAddressSanitizerPass : public PassInfoMixin<HWAddressSanitizerPass> {
  41. public:
  42. explicit HWAddressSanitizerPass(HWAddressSanitizerOptions Options)
  43. : Options(Options){};
  44. PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
  45. static bool isRequired() { return true; }
  46. void printPipeline(raw_ostream &OS,
  47. function_ref<StringRef(StringRef)> MapClassName2PassName);
  48. private:
  49. HWAddressSanitizerOptions Options;
  50. };
  51. namespace HWASanAccessInfo {
  52. // Bit field positions for the accessinfo parameter to
  53. // llvm.hwasan.check.memaccess. Shared between the pass and the backend. Bits
  54. // 0-15 are also used by the runtime.
  55. enum {
  56. AccessSizeShift = 0, // 4 bits
  57. IsWriteShift = 4,
  58. RecoverShift = 5,
  59. MatchAllShift = 16, // 8 bits
  60. HasMatchAllShift = 24,
  61. CompileKernelShift = 25,
  62. };
  63. enum { RuntimeMask = 0xffff };
  64. } // namespace HWASanAccessInfo
  65. } // namespace llvm
  66. #endif
  67. #ifdef __GNUC__
  68. #pragma GCC diagnostic pop
  69. #endif