Skip to content

Commit

Permalink
Fix issue with structure member dereferences
Browse files Browse the repository at this point in the history
Currently, if a structure member is assigned an external pointer
(pointer to kernel address), the pointer to the structure is marked
as external instead of the structure member. This issue affects all
uses of structures with pointers to external addresses. This commit
fixes it by marking the structure member as external.
  • Loading branch information
pchaigno committed May 6, 2018
1 parent be7955b commit c2b87ba
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/cc/frontends/clang/b_frontend_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ class ProbeChecker : public RecursiveASTVisitor<ProbeChecker> {
}
return false;
}
bool VisitMemberExpr(MemberExpr *M) {
if (ptregs_.find(M->getMemberDecl()) != ptregs_.end()) {
needs_probe_ = true;
return false;
}
return true;
}
bool VisitDeclRefExpr(DeclRefExpr *E) {
if (ptregs_.find(E->getDecl()) != ptregs_.end())
needs_probe_ = true;
Expand All @@ -126,6 +133,10 @@ class ProbeSetter : public RecursiveASTVisitor<ProbeSetter> {
ptregs_->insert(E->getDecl());
return true;
}
bool VisitMemberExpr(MemberExpr *M) {
ptregs_->insert(M->getMemberDecl());
return false;
}
private:
set<Decl *> *ptregs_;
};
Expand Down Expand Up @@ -231,11 +242,6 @@ bool ProbeVisitor::VisitUnaryOperator(UnaryOperator *E) {
bool ProbeVisitor::VisitMemberExpr(MemberExpr *E) {
if (memb_visited_.find(E) != memb_visited_.end()) return true;

// Checks to see if the expression references something that needs to be run
// through bpf_probe_read.
if (!ProbeChecker(E, ptregs_).needs_probe())
return true;

Expr *base;
SourceLocation rhs_start, member;
bool found = false;
Expand All @@ -255,6 +261,12 @@ bool ProbeVisitor::VisitMemberExpr(MemberExpr *E) {
error(base->getLocEnd(), "internal error: MemberLoc is invalid while preparing probe rewrite");
return false;
}

// Checks to see if the expression references something that needs to be run
// through bpf_probe_read.
if (!ProbeChecker(base, ptregs_).needs_probe())
return true;

string rhs = rewriter_.getRewrittenText(expansionRange(SourceRange(rhs_start, E->getLocEnd())));
string base_type = base->getType()->getPointeeType().getAsString();
string pre, post;
Expand Down

0 comments on commit c2b87ba

Please sign in to comment.