Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: src/IceASanInstrumentation.cpp

Issue 2086593002: Inserted local redzones. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Made RzNum atomic Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/IceASanInstrumentation.h ('k') | src/IceInstrumentation.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceASanInstrumentation.cpp - ASan ------------*- C++ -*-===// 1 //===- subzero/src/IceASanInstrumentation.cpp - ASan ------------*- 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 Implements the AddressSanitizer instrumentation class. 11 /// \brief Implements the AddressSanitizer instrumentation class.
12 /// 12 ///
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 14
15 #include "IceASanInstrumentation.h" 15 #include "IceASanInstrumentation.h"
16 16
17 #include "IceBuildDefs.h" 17 #include "IceBuildDefs.h"
18 #include "IceCfg.h"
18 #include "IceCfgNode.h" 19 #include "IceCfgNode.h"
19 #include "IceGlobalInits.h" 20 #include "IceGlobalInits.h"
20 #include "IceInst.h" 21 #include "IceInst.h"
21 #include "IceTargetLowering.h" 22 #include "IceTargetLowering.h"
22 #include "IceTypes.h" 23 #include "IceTypes.h"
23 24
24 #include <sstream> 25 #include <sstream>
25 #include <unordered_map> 26 #include <unordered_map>
26 27
27 namespace Ice { 28 namespace Ice {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 Rz->addInitializer( 116 Rz->addInitializer(
116 VariableDeclaration::ZeroInitializer::create(List, RzSize)); 117 VariableDeclaration::ZeroInitializer::create(List, RzSize));
117 } 118 }
118 Rz->setIsConstant(Global->getIsConstant()); 119 Rz->setIsConstant(Global->getIsConstant());
119 RzArray->addInitializer(VariableDeclaration::RelocInitializer::create( 120 RzArray->addInitializer(VariableDeclaration::RelocInitializer::create(
120 List, Rz, RelocOffsetArray(0))); 121 List, Rz, RelocOffsetArray(0)));
121 ++RzArraySize; 122 ++RzArraySize;
122 return Rz; 123 return Rz;
123 } 124 }
124 125
126 // Check for an alloca signaling the presence of local variables and add a
127 // redzone if it is found
128 void ASanInstrumentation::instrumentFuncStart(LoweringContext &Context) {
129 auto *FirstAlloca = llvm::dyn_cast<InstAlloca>(Context.getCur());
130 if (FirstAlloca == nullptr)
131 return;
132
133 constexpr SizeT Alignment = 4;
134 InstAlloca *RzAlloca = createLocalRz(Context, RzSize, Alignment);
135
136 // insert before the current instruction
137 InstList::iterator Next = Context.getNext();
138 Context.setInsertPoint(Context.getCur());
139 Context.insert(RzAlloca);
140 Context.setNext(Next);
141 }
142
143 void ASanInstrumentation::instrumentAlloca(LoweringContext &Context,
144 InstAlloca *Instr) {
145 auto *VarSizeOp = llvm::dyn_cast<ConstantInteger32>(Instr->getSizeInBytes());
146 SizeT VarSize = (VarSizeOp == nullptr) ? RzSize : VarSizeOp->getValue();
147 SizeT Padding = Utils::OffsetToAlignment(VarSize, RzSize);
148 constexpr SizeT Alignment = 1;
149 InstAlloca *Rz = createLocalRz(Context, RzSize + Padding, Alignment);
150 Context.insert(Rz);
151 }
152
153 InstAlloca *ASanInstrumentation::createLocalRz(LoweringContext &Context,
154 SizeT Size, SizeT Alignment) {
155 Cfg *Func = Context.getNode()->getCfg();
156 Variable *Rz = Func->makeVariable(IceType_i32);
157 Rz->setName(Func, nextRzName());
158 auto *ByteCount = ConstantInteger32::create(Ctx, IceType_i32, Size);
159 auto *RzAlloca = InstAlloca::create(Func, Rz, ByteCount, Alignment);
160 return RzAlloca;
161 }
162
125 void ASanInstrumentation::instrumentCall(LoweringContext &Context, 163 void ASanInstrumentation::instrumentCall(LoweringContext &Context,
126 InstCall *Instr) { 164 InstCall *Instr) {
127 auto *CallTarget = 165 auto *CallTarget =
128 llvm::dyn_cast<ConstantRelocatable>(Instr->getCallTarget()); 166 llvm::dyn_cast<ConstantRelocatable>(Instr->getCallTarget());
129 if (CallTarget == nullptr) 167 if (CallTarget == nullptr)
130 return; 168 return;
131 169
132 std::string TargetName = CallTarget->getName().toStringOrEmpty(); 170 std::string TargetName = CallTarget->getName().toStringOrEmpty();
133 auto Subst = FuncSubstitutions.find(TargetName); 171 auto Subst = FuncSubstitutions.find(TargetName);
134 if (Subst == FuncSubstitutions.end()) 172 if (Subst == FuncSubstitutions.end())
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 Constant *ShadowMemInit = 218 Constant *ShadowMemInit =
181 Ctx->getConstantExternSym(Ctx->getGlobalString("__asan_init")); 219 Ctx->getConstantExternSym(Ctx->getGlobalString("__asan_init"));
182 constexpr SizeT NumArgs = 0; 220 constexpr SizeT NumArgs = 0;
183 constexpr Variable *Void = nullptr; 221 constexpr Variable *Void = nullptr;
184 constexpr bool NoTailCall = false; 222 constexpr bool NoTailCall = false;
185 auto *Call = InstCall::create(Func, NumArgs, Void, ShadowMemInit, NoTailCall); 223 auto *Call = InstCall::create(Func, NumArgs, Void, ShadowMemInit, NoTailCall);
186 Func->getEntryNode()->getInsts().push_front(Call); 224 Func->getEntryNode()->getInsts().push_front(Call);
187 } 225 }
188 226
189 } // end of namespace Ice 227 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceASanInstrumentation.h ('k') | src/IceInstrumentation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698