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

Unified Diff: src/IceASanInstrumentation.cpp

Issue 2086593002: Inserted local redzones. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: src/IceASanInstrumentation.cpp
diff --git a/src/IceASanInstrumentation.cpp b/src/IceASanInstrumentation.cpp
index 9bd95553902304a10b4922519657a916f1244799..d182b128bc5ec4ed77260c5ee7eae64a65bf6144 100644
--- a/src/IceASanInstrumentation.cpp
+++ b/src/IceASanInstrumentation.cpp
@@ -15,6 +15,7 @@
#include "IceASanInstrumentation.h"
#include "IceBuildDefs.h"
+#include "IceCfg.h"
#include "IceCfgNode.h"
#include "IceGlobalInits.h"
#include "IceInst.h"
@@ -95,7 +96,7 @@ void ASanInstrumentation::instrumentGlobals(VariableDeclarationList &Globals) {
}
}
}
-
+// TODO(tlively): Make this thread safe
std::string ASanInstrumentation::nextRzName() {
std::stringstream Name;
Name << RzPrefix << RzNum++;
@@ -122,6 +123,47 @@ ASanInstrumentation::createRz(VariableDeclarationList *List,
return Rz;
}
+// Check for an alloca signaling the presence of local variables and add a
+// redzone if it is found
+void ASanInstrumentation::instrumentFuncStart(LoweringContext &Context) {
+ auto *FirstAlloca = llvm::dyn_cast<InstAlloca>(Context.getCur());
+ if (FirstAlloca == nullptr)
+ return;
+
+ constexpr SizeT Alignment = 4;
+ InstAlloca *RzAlloca = createLocalRz(Context, RzSize, Alignment);
+
+ // insert before the current instruction
+ InstList::iterator Next = Context.getNext();
+ Context.setInsertPoint(Context.getCur());
+ Context.insert(RzAlloca);
+ Context.setNext(Next);
+}
+
+void ASanInstrumentation::instrumentAlloca(LoweringContext &Context,
+ InstAlloca *Instr) {
+ auto *VarSizeOp = llvm::dyn_cast<ConstantInteger32>(Instr->getSizeInBytes());
+ SizeT VarSize = (VarSizeOp == nullptr) ? RzSize : VarSizeOp->getValue();
+ SizeT Padding = (VarSize % RzSize) ? RzSize - VarSize % RzSize : 0;
Jim Stichnoth 2016/06/20 19:44:41 Can you use Utils::OffsetToAlignment() here?
tlively 2016/06/20 22:19:33 Done.
+ constexpr SizeT Alignment = 1;
+ InstAlloca *Rz = createLocalRz(Context, RzSize + Padding, Alignment);
+ Context.insert(Rz);
+}
+
+InstAlloca *ASanInstrumentation::createLocalRz(LoweringContext &Context,
+ SizeT Size, SizeT Alignment) {
+ Cfg *Func = Context.getNode()->getCfg();
+ Variable *Rz = Func->makeVariable(IceType_i32);
+ Rz->setName(Func, nextRzName());
+ // TODO(tlively): Make this unnecessary
Jim Stichnoth 2016/06/20 19:44:41 I'm not sure what the exact problem is here. Is i
tlively 2016/06/20 22:19:33 I'll just get rid of this now. It will be unnecess
+ Rz->setIgnoreLiveness();
+
+ auto *ByteCount = ConstantInteger32::create(Ctx, IceType_i32, Size);
+ auto *RzAlloca = InstAlloca::create(Func, Rz, ByteCount, Alignment);
+
+ return RzAlloca;
+}
+
void ASanInstrumentation::instrumentCall(LoweringContext &Context,
InstCall *Instr) {
auto *CallTarget =

Powered by Google App Engine
This is Rietveld 408576698