Commit c2b87ba2 authored by Paul Chaignon's avatar Paul Chaignon

Fix issue with structure member dereferences

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.
parent be7955b7
......@@ -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;
......@@ -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_;
};
......@@ -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;
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment