llvm-faultinjector / fault-injector Goto Github PK
View Code? Open in Web Editor NEWFault Injector for LLVM based on LLFI project.
Fault Injector for LLVM based on LLFI project.
static void insertDetermineLogicForRawFaultInjection(Module &M, Function &F, Instruction *I, Instruction *T, std::mt19937& R) {
// Create XOR setter and xor operand resetter
// ENTRY:
// %xor_marker = alloca i32, align 4
// store i32 (0~31 random number), %xor_marker, align 4
// CORE:
// %t = xor %target, %xor_marker
// store i32 0, %xor_marker
// pick random bits
std::uniform_int_distribution<std::mt19937::result_type> dist(0, 31);
int loc = dist(R);
IntegerType *type = Type::getInt32Ty(M.getContext());
AllocaInst *xor_marker =
new AllocaInst(type, M.getDataLayout().getProgramAddressSpace(),
"xor_marker", &*F.getEntryBlock().begin());
//Value *num = ConstantInt::get(type, loc, true);
//new StoreInst(num, xor_marker, &*++F.getEntryBlock().begin());
//new CallInst()
CallInst *CI = CallInst::Create(M.getOrInsertFunction("__faultinject_xor_marker_caller",
FunctionType::get(type, false)), "",
&*++F.getEntryBlock().begin());
new StoreInst(CI, xor_marker, &*++F.getEntryBlock().begin());
// Create xor and resetter
Value *num_zero = ConstantInt::get(type, 0, true);
StoreInst *resetter = new StoreInst(num_zero, xor_marker, I->getNextNode());
LoadInst *val = new LoadInst(xor_marker, "xor_val", resetter);
BinaryOperator *fi = BinaryOperator::CreateXor(I, val, "rfi", val->getNextNode());
/*for (int i = 0; i < I->getNumOperands(); i++)
if (I->getOperand(i) == T)
I->setOperand(i, fi);*/
std::list<User *> inst_uses;
for (Value::user_iterator user_it = I->user_begin();
user_it != I->user_end(); ++user_it) {
User *user = *user_it;
if (user != I && user != fi) inst_uses.push_back(user);
}
for (std::list<User *>::iterator use_it = inst_uses.begin();
use_it != inst_uses.end(); ++use_it) {
User *user = *use_it;
user->replaceUsesOfWith(I, fi);
}
F.print(errs());
}
#include <stdio.h>
| 2
.. (up a dir) | 3 extern void __marking_faultinject_ptr(int*);
</llvm-7.0.1.src/build/bin/ | 4
a.c | 5 int main(int argc, char argv[]) {
a.ll | 6 int a,b;
a.out | 7 __marking_faultinject_ptr(&b);
b.c | 8 for (a = 0; a < argc; a++)
b.ll | 9 {
bubble.c | 10 b+=a;
c.ll | 11 }
llvm-lit* | 12 printf("%d", b);
llvm-tblgen* | 13 }
opt* |~
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.