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