Skip to content

Commit 40d4a65

Browse files
committed
Add methods with taintOS
1 parent 0eb3ce6 commit 40d4a65

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-5
lines changed

lib/Core/Memory.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -814,3 +814,64 @@ void ObjectStage::print() const {
814814
llvm::errs() << "\t\t[" << un->index << "] = " << un->value << "\n";
815815
}
816816
}
817+
818+
/***/
819+
820+
void ObjectStage::reset(ref<Expr> newDefault) {
821+
knownSymbolics->reset(std::move(newDefault));
822+
unflushedMask->reset(false);
823+
updates = UpdateList(nullptr, nullptr);
824+
}
825+
826+
void ObjectStage::reset(ref<Expr> updateForDefault, bool isAdd) {
827+
ref<Expr> oldDefault = knownSymbolics->defaultV();
828+
ref<Expr> newDefault =
829+
isAdd ? OrExpr::create(oldDefault, updateForDefault)
830+
: AndExpr::create(oldDefault, NotExpr::create(updateForDefault));
831+
knownSymbolics->reset(std::move(newDefault));
832+
unflushedMask->reset(false);
833+
updates = UpdateList(nullptr, nullptr);
834+
}
835+
836+
ref<Expr> ObjectStage::combineAll() const {
837+
ref<Expr> result = knownSymbolics->defaultV();
838+
for (auto [index, value] : knownSymbolics->storage()) {
839+
result = OrExpr::create(result, value);
840+
}
841+
for (const auto *un = updates.head.get(); un; un = un->next.get()) {
842+
result = OrExpr::create(result, un->value);
843+
}
844+
return result;
845+
}
846+
847+
void ObjectStage::updateAll(ref<Expr> updateExpr, bool isAdd) {
848+
std::vector<std::pair<size_t, ref<Expr>>> newKnownSymbolics;
849+
for (auto [index, value] : knownSymbolics->storage()) {
850+
ref<Expr> newValue =
851+
isAdd ? OrExpr::create(value, updateExpr)
852+
: AndExpr::create(value, NotExpr::create(updateExpr));
853+
newKnownSymbolics.emplace_back(index, value);
854+
}
855+
856+
ref<Expr> oldDefault = knownSymbolics->defaultV();
857+
ref<Expr> newDefault =
858+
isAdd ? OrExpr::create(oldDefault, updateExpr)
859+
: AndExpr::create(oldDefault, NotExpr::create(updateExpr));
860+
knownSymbolics->reset(std::move(newDefault));
861+
862+
for (auto [index, value] : newKnownSymbolics) {
863+
knownSymbolics->store(index, value);
864+
}
865+
866+
std::vector<std::pair<ref<Expr>, ref<Expr>>> newUpdates;
867+
for (auto *un = updates.head.get(); un; un = un->next.get()) {
868+
ref<Expr> newValue =
869+
isAdd ? OrExpr::create(un->value, updateExpr)
870+
: AndExpr::create(un->value, NotExpr::create(updateExpr));
871+
newUpdates.emplace_back(un->index, newValue);
872+
}
873+
updates = UpdateList(nullptr, nullptr);
874+
for (auto [index, value] : newUpdates) {
875+
updates.extend(index, value);
876+
}
877+
}

lib/Core/Memory.h

+15-5
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,11 @@ class ObjectStage {
267267
}
268268
void initializeToZero();
269269

270-
void reset(ref<Expr> newDefault) {
271-
knownSymbolics->reset(std::move(newDefault));
272-
unflushedMask->reset(false);
273-
}
270+
void reset(ref<Expr> newDefault);
271+
void reset(ref<Expr> updateForDefault, bool isAdd);
272+
273+
ref<Expr> combineAll() const;
274+
void updateAll(ref<Expr> updateExpr, bool isAdd);
274275

275276
private:
276277
const UpdateList &getUpdates() const;
@@ -359,7 +360,11 @@ class ObjectState {
359360

360361
KType *getDynamicType() const;
361362

362-
void resetTaint(ref<Expr> newTaint) { taintOS.reset(std::move(newTaint)); }
363+
ref<Expr> readTaint() const { return taintOS.combineAll(); }
364+
void updateTaint(ref<Expr> updateForTaint, bool isAdd) {
365+
// resetTaint(updateForTaint, isAdd);
366+
taintOS.updateAll(updateForTaint, isAdd);
367+
}
363368

364369
private:
365370
ref<Expr> read8(ref<Expr> offset) const;
@@ -368,6 +373,11 @@ class ObjectState {
368373
ref<Expr> readTaint8(ref<Expr> offset) const;
369374
void write8(unsigned offset, ref<Expr> value);
370375
void write8(ref<Expr> offset, ref<Expr> value);
376+
377+
void resetTaint(ref<Expr> newTaint) { taintOS.reset(std::move(newTaint)); }
378+
void resetTaint(ref<Expr> updateForTaint, bool isAdd) {
379+
taintOS.reset(std::move(updateForTaint), isAdd);
380+
}
371381
};
372382

373383
} // namespace klee

0 commit comments

Comments
 (0)