| OLD | NEW |
| 1 //===- subzero/src/IceASanInstrumentation.h - AddressSanitizer --*- C++ -*-===// | 1 //===- subzero/src/IceASanInstrumentation.h - AddressSanitizer --*- C++ -*-===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 /// | 9 /// |
| 10 /// \file | 10 /// \file |
| 11 /// \brief Declares the AddressSanitizer instrumentation class. | 11 /// \brief Declares the AddressSanitizer instrumentation class. |
| 12 /// | 12 /// |
| 13 /// This class is responsible for inserting redzones around global and stack | 13 /// This class is responsible for inserting redzones around global and stack |
| 14 /// variables, inserting code responsible for poisoning those redzones, and | 14 /// variables, inserting code responsible for poisoning those redzones, and |
| 15 /// performing any other instrumentation necessary to implement | 15 /// performing any other instrumentation necessary to implement |
| 16 /// AddressSanitizer. | 16 /// AddressSanitizer. |
| 17 /// | 17 /// |
| 18 //===----------------------------------------------------------------------===// | 18 //===----------------------------------------------------------------------===// |
| 19 | 19 |
| 20 #ifndef SUBZERO_SRC_ICEASANINSTRUMENTATION_H | 20 #ifndef SUBZERO_SRC_ICEASANINSTRUMENTATION_H |
| 21 #define SUBZERO_SRC_ICEASANINSTRUMENTATION_H | 21 #define SUBZERO_SRC_ICEASANINSTRUMENTATION_H |
| 22 | 22 |
| 23 #include "IceGlobalInits.h" | 23 #include "IceGlobalInits.h" |
| 24 #include "IceInstrumentation.h" | 24 #include "IceInstrumentation.h" |
| 25 | 25 |
| 26 namespace Ice { | 26 namespace Ice { |
| 27 | 27 |
| 28 using VarSizeMap = std::unordered_map<Operand *, SizeT>; | 28 using VarSizeMap = std::unordered_map<Operand *, SizeT>; |
| 29 using GlobalSizeMap = std::unordered_map<GlobalString, SizeT>; |
| 29 | 30 |
| 30 class ASanInstrumentation : public Instrumentation { | 31 class ASanInstrumentation : public Instrumentation { |
| 31 ASanInstrumentation() = delete; | 32 ASanInstrumentation() = delete; |
| 32 ASanInstrumentation(const ASanInstrumentation &) = delete; | 33 ASanInstrumentation(const ASanInstrumentation &) = delete; |
| 33 ASanInstrumentation &operator=(const ASanInstrumentation &) = delete; | 34 ASanInstrumentation &operator=(const ASanInstrumentation &) = delete; |
| 34 | 35 |
| 35 public: | 36 public: |
| 36 ASanInstrumentation(GlobalContext *Ctx) : Instrumentation(Ctx), RzNum(0) { | 37 ASanInstrumentation(GlobalContext *Ctx) : Instrumentation(Ctx), RzNum(0) { |
| 37 ICE_TLS_INIT_FIELD(LocalVars); | 38 ICE_TLS_INIT_FIELD(LocalVars); |
| 38 ICE_TLS_INIT_FIELD(LocalDtors); | 39 ICE_TLS_INIT_FIELD(LocalDtors); |
| 39 } | 40 } |
| 40 void instrumentGlobals(VariableDeclarationList &Globals) override; | 41 void instrumentGlobals(VariableDeclarationList &Globals) override; |
| 41 | 42 |
| 42 private: | 43 private: |
| 43 std::string nextRzName(); | 44 std::string nextRzName(); |
| 45 bool isOkGlobalAccess(Operand *Op, SizeT Size); |
| 44 bool isInstrumentable(Cfg *Func) override; | 46 bool isInstrumentable(Cfg *Func) override; |
| 45 void instrumentFuncStart(LoweringContext &Context) override; | 47 void instrumentFuncStart(LoweringContext &Context) override; |
| 46 void instrumentCall(LoweringContext &Context, InstCall *Instr) override; | 48 void instrumentCall(LoweringContext &Context, InstCall *Instr) override; |
| 47 void instrumentRet(LoweringContext &Context, InstRet *Instr) override; | 49 void instrumentRet(LoweringContext &Context, InstRet *Instr) override; |
| 48 void instrumentLoad(LoweringContext &Context, InstLoad *Instr) override; | 50 void instrumentLoad(LoweringContext &Context, InstLoad *Instr) override; |
| 49 void instrumentStore(LoweringContext &Context, InstStore *Instr) override; | 51 void instrumentStore(LoweringContext &Context, InstStore *Instr) override; |
| 50 void instrumentAccess(LoweringContext &Context, Operand *Op, SizeT Size, | 52 void instrumentAccess(LoweringContext &Context, Operand *Op, SizeT Size, |
| 51 Constant *AccessFunc); | 53 Constant *AccessFunc); |
| 52 void instrumentStart(Cfg *Func) override; | 54 void instrumentStart(Cfg *Func) override; |
| 53 void finishFunc(Cfg *Func) override; | 55 void finishFunc(Cfg *Func) override; |
| 54 ICE_TLS_DECLARE_FIELD(VarSizeMap *, LocalVars); | 56 ICE_TLS_DECLARE_FIELD(VarSizeMap *, LocalVars); |
| 55 ICE_TLS_DECLARE_FIELD(std::vector<InstCall *> *, LocalDtors); | 57 ICE_TLS_DECLARE_FIELD(std::vector<InstCall *> *, LocalDtors); |
| 58 GlobalSizeMap GlobalSizes; |
| 56 std::atomic<uint32_t> RzNum; | 59 std::atomic<uint32_t> RzNum; |
| 57 bool DidProcessGlobals = false; | 60 bool DidProcessGlobals = false; |
| 58 SizeT RzGlobalsNum = 0; | 61 SizeT RzGlobalsNum = 0; |
| 59 std::mutex GlobalsMutex; | 62 std::mutex GlobalsMutex; |
| 60 }; | 63 }; |
| 61 } // end of namespace Ice | 64 } // end of namespace Ice |
| 62 | 65 |
| 63 #endif // SUBZERO_SRC_ICEASANINSTRUMENTATION_H | 66 #endif // SUBZERO_SRC_ICEASANINSTRUMENTATION_H |
| OLD | NEW |