From: bdemsky Date: Thu, 17 Mar 2011 07:42:02 +0000 (+0000) Subject: more changes...do node-based taints...taint edges...change taintset... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=269bf79b3f73ea3ab963eea045ead60e34f6ca94;p=IRC.git more changes...do node-based taints...taint edges...change taintset... --- diff --git a/Robust/src/Analysis/Disjoint/Taint.java b/Robust/src/Analysis/Disjoint/Taint.java index a6a38e9a..44abdb4d 100644 --- a/Robust/src/Analysis/Disjoint/Taint.java +++ b/Robust/src/Analysis/Disjoint/Taint.java @@ -55,7 +55,11 @@ public class Taint extends Canonical { // callee to that context protected ExistPredSet preds; - + public Taint reTaint(FlatNode fn) { + Taint out=new Taint(sese, stallSite, var, allocSite, fn, preds); + out = (Taint) Canonical.makeCanonical( out ); + return out; + } public static Taint factory( FlatSESEEnterNode sese, TempDescriptor insetVar, diff --git a/Robust/src/Analysis/Disjoint/TaintSet.java b/Robust/src/Analysis/Disjoint/TaintSet.java index 697ae815..b0750343 100644 --- a/Robust/src/Analysis/Disjoint/TaintSet.java +++ b/Robust/src/Analysis/Disjoint/TaintSet.java @@ -32,6 +32,26 @@ public class TaintSet extends Canonical { protected HashSet taints; + public static TaintSet factory(HashSet taints) { + TaintSet out = new TaintSet(taints); + out = (TaintSet) Canonical.makeCanonical( out ); + return out; + } + + public TaintSet reTaint(FlatNode fn) { + HashSet taintset=new HashSet(); + for(Taint t:taints) { + if (t.getWhereDefined()!=fn) { + t=t.reTaint(fn); + } + taintset.add(t); + } + + TaintSet out=new TaintSet(taintset); + out = (TaintSet) Canonical.makeCanonical( out ); + return out; + } + public static TaintSet factory() { TaintSet out = new TaintSet(); out = (TaintSet) Canonical.makeCanonical( out ); @@ -88,6 +108,10 @@ public class TaintSet extends Canonical { taints = new HashSet(); } + protected TaintSet(HashSet taints) { + this.taints = taints; + } + public Set getTaints() { return taints; } diff --git a/Robust/src/Analysis/Pointer/Delta.java b/Robust/src/Analysis/Pointer/Delta.java index c02cc6c5..283161cc 100644 --- a/Robust/src/Analysis/Pointer/Delta.java +++ b/Robust/src/Analysis/Pointer/Delta.java @@ -189,14 +189,14 @@ public class Delta { if (!heapedgeadd.containsKey(e.src)) heapedgeadd.put(e.src, new MySet(e)); else - heapedgeadd.get(e.src).add(e); + Edge.mergeEdgeInto(heapedgeadd.get(e.src), e); } public void addVarEdge(Edge e) { if (!varedgeadd.containsKey(e.srcvar)) varedgeadd.put(e.srcvar, new MySet(e)); else - varedgeadd.get(e.srcvar).add(e); + Edge.mergeEdgeInto(varedgeadd.get(e.srcvar), e); } public void removeEdges(MySet eset) { diff --git a/Robust/src/Analysis/Pointer/Edge.java b/Robust/src/Analysis/Pointer/Edge.java index 35b7187e..ee5bba80 100644 --- a/Robust/src/Analysis/Pointer/Edge.java +++ b/Robust/src/Analysis/Pointer/Edge.java @@ -103,12 +103,27 @@ public class Edge { return false; } - public Edge changeSrcVar(TempDescriptor tmp) { + public Edge changeSrcVar(TempDescriptor tmp, TaintSet taintset) { Edge e=new Edge(); e.fd=fd; e.srcvar=srcvar; e.dst=dst; e.statuspredicate=NEW; + if (taints==null) + e.taints=taintset; + else if (taintset==null) + e.taints=taints; + else + e.taints=taints.merge(taintset); + return e; + } + + public Edge changeSrc(FieldDescriptor newfd, AllocNode srcnode) { + Edge e=new Edge(); + e.fd=newfd; + e.src=srcnode; + e.dst=dst; + e.statuspredicate=NEW; if (taints!=null) e.taints=taints; return e; @@ -202,4 +217,12 @@ public class Edge { orig.add(e); } } + + public static void mergeEdgeInto(MySet orig, Edge e) { + if (orig.contains(e)) { + Edge old=orig.get(e); + e=e.merge(old); + } + orig.add(e); + } } \ No newline at end of file diff --git a/Robust/src/Analysis/Pointer/GraphManip.java b/Robust/src/Analysis/Pointer/GraphManip.java index 9ee46a88..f025061d 100644 --- a/Robust/src/Analysis/Pointer/GraphManip.java +++ b/Robust/src/Analysis/Pointer/GraphManip.java @@ -3,6 +3,7 @@ import IR.Flat.*; import IR.*; import Analysis.Pointer.AllocFactory.AllocNode; import java.util.*; +import Analysis.Disjoint.TaintSet; public class GraphManip { static MySet genEdges(TempDescriptor tmp, HashSet dstSet) { @@ -16,7 +17,7 @@ public class GraphManip { static MySet genEdges(TempDescriptor tmp, MySet dstSet) { MySet edgeset=new MySet(); for(Edge e:dstSet) { - edgeset.add(e.changeSrcVar(tmp)); + edgeset.add(e.changeSrcVar(tmp, null)); } return edgeset; } @@ -31,6 +32,16 @@ public class GraphManip { return edgeset; } + static MySet genEdges(HashSet srcSet, FieldDescriptor fd, MySet dstSet) { + MySet edgeset=new MySet(); + for(AllocNode srcnode:srcSet) { + for(Edge dstedge:dstSet) { + edgeset.add(dstedge.changeSrc(fd, srcnode)); + } + } + return edgeset; + } + static MySet getDiffEdges(Delta delta, TempDescriptor tmp) { MySet edges=new MySet(); MySet removeedges=delta.varedgeremove.get(tmp); @@ -208,13 +219,16 @@ public class GraphManip { return edgeset; } - static MySet dereference(Graph graph, Delta delta, TempDescriptor dst, MySet srcEdges, FieldDescriptor fd) { + static MySet dereference(Graph graph, Delta delta, TempDescriptor dst, MySet srcEdges, FieldDescriptor fd, FlatNode fn) { MySet edgeset=new MySet(); for(Edge edge:srcEdges) { + TaintSet ts=edge.getTaints(); + if (ts!=null) + ts=ts.reTaint(fn); MySet removeedges=delta.heapedgeremove.get(edge.dst); for(Edge e:graph.getEdges(edge.dst)) { if (e.fd==fd&&(removeedges==null||!removeedges.contains(e))) { - e=e.changeSrcVar(dst); + e=e.changeSrcVar(dst, ts); if (!edgeset.contains(e)) edgeset.add(e); else { @@ -227,7 +241,7 @@ public class GraphManip { if (delta.heapedgeadd.containsKey(edge.dst)) for(Edge e:delta.heapedgeadd.get(edge.dst)) { if (e.fd==fd) { - e=e.changeSrcVar(dst); + e=e.changeSrcVar(dst, ts); if (!edgeset.contains(e)) edgeset.add(e); else { @@ -241,14 +255,17 @@ public class GraphManip { return edgeset; } - static MySet diffDereference(Delta delta, TempDescriptor dst, MySet srcEdges, FieldDescriptor fd) { + static MySet diffDereference(Delta delta, TempDescriptor dst, MySet srcEdges, FieldDescriptor fd, FlatNode fn) { MySet edgeset=new MySet(); for(Edge edge:srcEdges) { + TaintSet ts=edge.getTaints(); + if (ts!=null) + ts=ts.reTaint(fn); MySet removeedges=delta.heapedgeremove.get(edge.dst); if (delta.baseheapedge.containsKey(edge.dst)) { for(Edge e:delta.baseheapedge.get(edge.dst)) { if (e.fd==fd&&(removeedges==null||!removeedges.contains(e))) { - e=e.changeSrcVar(dst); + e=e.changeSrcVar(dst, ts); if (!edgeset.contains(e)) edgeset.add(e); else { @@ -262,7 +279,7 @@ public class GraphManip { if (delta.heapedgeadd.containsKey(edge.dst)) for(Edge e:delta.heapedgeadd.get(edge.dst)) { if (e.fd==fd) { - e=e.changeSrcVar(dst); + e=e.changeSrcVar(dst, ts); if (!edgeset.contains(e)) edgeset.add(e); else { diff --git a/Robust/src/Analysis/Pointer/Pointer.java b/Robust/src/Analysis/Pointer/Pointer.java index cca1f978..03d4825c 100644 --- a/Robust/src/Analysis/Pointer/Pointer.java +++ b/Robust/src/Analysis/Pointer/Pointer.java @@ -1185,7 +1185,7 @@ public class Pointer { else graph.nodeMap.put(node, new MySet()); } - graph.nodeMap.get(node).addAll(edgestoadd); + Edge.mergeEdgesInto(graph.nodeMap.get(node),edgestoadd); if (genbackwards) { for(Edge eadd:edgestoadd) { if (!graph.backMap.containsKey(eadd.dst)) @@ -1216,7 +1216,7 @@ public class Pointer { TempDescriptor tmp=e.getKey(); MySet edgestoadd=e.getValue(); if (graph.varMap.containsKey(tmp)) { - graph.varMap.get(tmp).addAll(edgestoadd); + Edge.mergeEdgesInto(graph.varMap.get(tmp), edgestoadd); } else graph.varMap.put(tmp, (MySet) edgestoadd.clone()); if (genbackwards) { @@ -1260,9 +1260,9 @@ public class Pointer { return delta; if (delta.getInit()) { - HashSet srcNodes=GraphManip.getNodes(graph, delta, src); + MySet srcEdges=GraphManip.getEdges(graph, delta, src); HashSet dstNodes=GraphManip.getNodes(graph, delta, dst); - MySet edgesToAdd=GraphManip.genEdges(dstNodes, fd, srcNodes); + MySet edgesToAdd=GraphManip.genEdges(dstNodes, fd, srcEdges); MySet edgesToRemove=null; if (dstNodes.size()==1&&!dstNodes.iterator().next().isSummary()&&fd!=null) { /* Can do a strong update */ @@ -1276,8 +1276,8 @@ public class Pointer { } else { /* First look at new sources */ MySet edgesToAdd=new MySet(); - HashSet newSrcNodes=GraphManip.getDiffNodes(delta, src); - HashSet srcNodes=GraphManip.getNodes(graph, delta, src); + MySet newSrcEdges=GraphManip.getDiffEdges(delta, src); + MySet srcEdges=GraphManip.getEdges(graph, delta, src); HashSet dstNodes=GraphManip.getNodes(graph, delta, dst); HashSet newDstNodes=GraphManip.getDiffNodes(delta, dst); @@ -1294,7 +1294,7 @@ public class Pointer { edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd); graph.strongUpdateSet.addAll(edgesToRemove); } - edgesToAdd.addAll(GraphManip.genEdges(newDstNodes, fd, srcNodes)); + Edge.mergeEdgesInto(edgesToAdd, GraphManip.genEdges(newDstNodes, fd, srcEdges)); } //Kill new edges @@ -1308,7 +1308,7 @@ public class Pointer { } //Next look at new destinations - edgesToAdd.addAll(GraphManip.genEdges(dstNodes, fd, newSrcNodes)); + Edge.mergeEdgesInto(edgesToAdd, GraphManip.genEdges(dstNodes, fd, newSrcEdges)); /* Update diff */ updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove); @@ -1381,17 +1381,17 @@ public class Pointer { return delta; if (delta.getInit()) { MySet srcedges=GraphManip.getEdges(graph, delta, src); - MySet edgesToAdd=GraphManip.dereference(graph, delta, dst, srcedges, fd); + MySet edgesToAdd=GraphManip.dereference(graph, delta, dst, srcedges, fd, node); MySet edgesToRemove=GraphManip.getEdges(graph, delta, dst); updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove); applyDiffs(graph, delta); } else { /* First compute new objects we read fields of */ MySet allsrcedges=GraphManip.getEdges(graph, delta, src); - MySet edgesToAdd=GraphManip.diffDereference(delta, dst, allsrcedges, fd); + MySet edgesToAdd=GraphManip.diffDereference(delta, dst, allsrcedges, fd, node); /* Next compute new targets of fields */ MySet newsrcedges=GraphManip.getDiffEdges(delta, src); - MySet newfdedges=GraphManip.dereference(graph, delta, dst, newsrcedges, fd); + MySet newfdedges=GraphManip.dereference(graph, delta, dst, newsrcedges, fd, node); /* Compute the union, and then the set of edges */ Edge.mergeEdgesInto(edgesToAdd, newfdedges); @@ -1759,6 +1759,13 @@ public class Pointer { //We have a new edge diffedges.add(e); dstedges.add(e); + } else { + Edge origedge=dstedges.get(e); + if (!origedge.subsumes(e)) { + Edge mergededge=origedge.merge(e); + diffedges.add(mergededge); + dstedges.add(mergededge); + } } } //Done with edge set...