1 | //===--------- Definition of the AddressSanitizer 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 AddressSanitizer class which is a port of the legacy |
10 | // AddressSanitizer pass to use the new PassManager infrastructure. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZER_H |
14 | #define LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZER_H |
15 | |
16 | #include "llvm/IR/PassManager.h" |
17 | #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h" |
18 | |
19 | namespace llvm { |
20 | class Module; |
21 | class raw_ostream; |
22 | |
23 | struct AddressSanitizerOptions { |
24 | bool CompileKernel = false; |
25 | bool Recover = false; |
26 | bool UseAfterScope = false; |
27 | AsanDetectStackUseAfterReturnMode UseAfterReturn = |
28 | AsanDetectStackUseAfterReturnMode::Runtime; |
29 | int InstrumentationWithCallsThreshold = 7000; |
30 | uint32_t MaxInlinePoisoningSize = 64; |
31 | bool InsertVersionCheck = true; |
32 | }; |
33 | |
34 | /// Public interface to the address sanitizer module pass for instrumenting code |
35 | /// to check for various memory errors. |
36 | /// |
37 | /// This adds 'asan.module_ctor' to 'llvm.global_ctors'. This pass may also |
38 | /// run intependently of the function address sanitizer. |
39 | class AddressSanitizerPass : public PassInfoMixin<AddressSanitizerPass> { |
40 | public: |
41 | AddressSanitizerPass(const AddressSanitizerOptions &Options, |
42 | bool UseGlobalGC = true, bool UseOdrIndicator = true, |
43 | AsanDtorKind DestructorKind = AsanDtorKind::Global, |
44 | AsanCtorKind ConstructorKind = AsanCtorKind::Global); |
45 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); |
46 | void printPipeline(raw_ostream &OS, |
47 | function_ref<StringRef(StringRef)> MapClassName2PassName); |
48 | static bool isRequired() { return true; } |
49 | |
50 | private: |
51 | AddressSanitizerOptions Options; |
52 | bool UseGlobalGC; |
53 | bool UseOdrIndicator; |
54 | AsanDtorKind DestructorKind; |
55 | AsanCtorKind ConstructorKind; |
56 | }; |
57 | |
58 | struct ASanAccessInfo { |
59 | const int32_t Packed; |
60 | const uint8_t AccessSizeIndex; |
61 | const bool IsWrite; |
62 | const bool CompileKernel; |
63 | |
64 | explicit ASanAccessInfo(int32_t Packed); |
65 | ASanAccessInfo(bool IsWrite, bool CompileKernel, uint8_t AccessSizeIndex); |
66 | }; |
67 | |
68 | } // namespace llvm |
69 | |
70 | #endif |
71 | |