a
Opened this issue · 1 comments
rollrat commented
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());
}
rollrat commented
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, CI->getNextNode());
// 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());
}