Skip to content

Commit

Permalink
change SymbolicExpression::cs from a static to a class member to elim…
Browse files Browse the repository at this point in the history
…inate data races

prior to this change, data races occurred on "static SymbolicExpression::cs"
when two threads used it concurrently, with each thread reading and writing
the variable.
  • Loading branch information
John Mellor-Crummey committed Jan 5, 2018
1 parent f5d95d7 commit d16b53d
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion parseAPI/src/BoundFactCalculator.C
Expand Up @@ -457,7 +457,7 @@ void BoundFactsCalculator::CalcTransferFunction(Node::Ptr curNode, BoundFact *ne
// In other cases, if the AbsRegion represents a register,
// the generator is not set.
if (ar.generator() != NULL)
outAST = SymbolicExpression::SimplifyAnAST(
outAST = se.SimplifyAnAST(
RoseAST::create(ROSEOperation(ROSEOperation::derefOp, ar.size()), ar.generator()),
SymbolicExpression::PCValue(node->assign()->addr(),
insn.size(),
Expand Down
3 changes: 1 addition & 2 deletions parseAPI/src/IndirectASTVisitor.C
Expand Up @@ -3,14 +3,13 @@
#include "debug_parse.h"
#include "CodeObject.h"
#include <algorithm>
#include "SymbolicExpression.h"
using namespace Dyninst::ParseAPI;

AST::Ptr SimplifyVisitor::visit(DataflowAPI::RoseAST *ast) {
unsigned totalChildren = ast->numChildren();
for (unsigned i = 0 ; i < totalChildren; ++i) {
ast->child(i)->accept(this);
ast->setChild(i, SymbolicExpression::SimplifyRoot(ast->child(i), addr, keepMultiOne));
ast->setChild(i, se.SimplifyRoot(ast->child(i), addr, keepMultiOne));
}
return AST::Ptr();
}
Expand Down
4 changes: 3 additions & 1 deletion parseAPI/src/IndirectASTVisitor.h
Expand Up @@ -7,6 +7,7 @@
#include "SymEval.h"
#include "CodeSource.h"
#include "BoundFactData.h"
#include "SymbolicExpression.h"

using namespace std;
using namespace Dyninst;
Expand All @@ -25,10 +26,11 @@ using namespace Dyninst::DataflowAPI;
class SimplifyVisitor: public ASTVisitor {
Address addr;
bool keepMultiOne;
SymbolicExpression &se;
public:
using ASTVisitor::visit;
virtual ASTPtr visit(DataflowAPI::RoseAST *ast);
SimplifyVisitor(Address a, bool k): addr(a), keepMultiOne(k) {}
SimplifyVisitor(Address a, bool k, SymbolicExpression &sym): addr(a), keepMultiOne(k), se(sym) {}
};


Expand Down
2 changes: 1 addition & 1 deletion parseAPI/src/JumpTableFormatPred.C
Expand Up @@ -267,7 +267,7 @@ bool JumpTableFormatPred::modifyCurrentFrame(Slicer::SliceFrame &frame, Graph::P
}
JumpTableFormatVisitor jtfv(block);
assert(jumpTarget);
jumpTarget = SymbolicExpression::SimplifyAnAST(jumpTarget, 0, true);
jumpTarget = se.SimplifyAnAST(jumpTarget, 0, true);
parsing_printf("Check expression %s\n", jumpTarget->format().c_str());
jumpTarget->accept(&jtfv);
if (jtfv.findIncorrectFormat) {
Expand Down
2 changes: 1 addition & 1 deletion parseAPI/src/JumpTableIndexPred.C
Expand Up @@ -286,7 +286,7 @@ bool JumpTableIndexPred::MatchReadAST(Assignment::Ptr a) {
pair<AST::Ptr, bool> expandRet = se.ExpandAssignment(a);
if (!expandRet.second || expandRet.first == NULL) return false;
if (a->out().generator() == NULL) return false;
AST::Ptr write = SymbolicExpression::SimplifyAnAST(RoseAST::create(ROSEOperation(ROSEOperation::derefOp, a->out().size()), a->out().generator()),
AST::Ptr write = se.SimplifyAnAST(RoseAST::create(ROSEOperation(ROSEOperation::derefOp, a->out().size()), a->out().generator()),
SymbolicExpression::PCValue(a->addr(),
a->insn().size(),
a->block()->obj()->cs()->getArch()));
Expand Down
4 changes: 1 addition & 3 deletions parseAPI/src/SymbolicExpression.C
Expand Up @@ -11,8 +11,6 @@ using namespace Dyninst;
using namespace Dyninst::ParseAPI;
using namespace Dyninst::DataflowAPI;

CodeSource* SymbolicExpression::cs = NULL;

bool SymbolicExpression::ReadMemory(Address addr, uint64_t &v, int ) {
int addressWidth = cs->getAddressWidth();
if (addressWidth == 4) {
Expand Down Expand Up @@ -272,7 +270,7 @@ AST::Ptr SymbolicExpression::SimplifyRoot(AST::Ptr ast, Address addr, bool keepM


AST::Ptr SymbolicExpression::SimplifyAnAST(AST::Ptr ast, Address addr, bool keepMultiOne) {
SimplifyVisitor sv(addr, keepMultiOne);
SimplifyVisitor sv(addr, keepMultiOne, *this);
ast->accept(&sv);
return SimplifyRoot(ast, addr, keepMultiOne);
}
Expand Down
8 changes: 4 additions & 4 deletions parseAPI/src/SymbolicExpression.h
Expand Up @@ -15,13 +15,13 @@ class SymbolicExpression {

public:

static AST::Ptr SimplifyRoot(AST::Ptr ast, Address addr, bool keepMultiOne = false);
static AST::Ptr SimplifyAnAST(AST::Ptr ast, Address addr, bool keepMultiOne = false);
AST::Ptr SimplifyRoot(AST::Ptr ast, Address addr, bool keepMultiOne = false);
AST::Ptr SimplifyAnAST(AST::Ptr ast, Address addr, bool keepMultiOne = false);
static AST::Ptr SubstituteAnAST(AST::Ptr ast, const std::map<AST::Ptr, AST::Ptr>& aliasMap);
static AST::Ptr DeepCopyAnAST(AST::Ptr ast);
static bool ContainAnAST(AST::Ptr root, AST::Ptr check);
static bool ReadMemory(Address addr, uint64_t &val, int size);
static ParseAPI::CodeSource* cs;
bool ReadMemory(Address addr, uint64_t &val, int size);
ParseAPI::CodeSource* cs;
std::pair<AST::Ptr, bool> ExpandAssignment(Assignment::Ptr, bool keepMultiOne = false);

//On x86 and x86-64, the value of PC is post-instruction,
Expand Down

0 comments on commit d16b53d

Please sign in to comment.