Skip to content

Commit

Permalink
[Truffle] Use the top-level IsTaintNode and TaintNode.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Mar 3, 2015
1 parent 2c2bc0f commit f8acad8
Showing 1 changed file with 20 additions and 8 deletions.
Expand Up @@ -12,13 +12,19 @@

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.KernelNodes;
import org.jruby.truffle.nodes.core.KernelNodesFactory;
import org.jruby.truffle.nodes.objects.IsTaintedNode;
import org.jruby.truffle.nodes.objects.IsTaintedNodeFactory;
import org.jruby.truffle.nodes.objects.TaintNode;
import org.jruby.truffle.nodes.objects.TaintNodeFactory;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;

public class TaintResultNode extends RubyNode {

Expand All @@ -27,15 +33,15 @@ public class TaintResultNode extends RubyNode {
private final ConditionProfile taintProfile = ConditionProfile.createBinaryProfile();

@Child private RubyNode method;
@Child private KernelNodes.KernelIsTaintedNode isTaintedNode;
@Child private KernelNodes.KernelTaintNode taintNode;
@Child private IsTaintedNode isTaintedNode;
@Child private TaintNode taintNode;

public TaintResultNode(RubyContext context, SourceSection sourceSection, boolean needSelf, int taintSourceIndex, RubyNode method) {
super(context, sourceSection);
this.needsSelf = needSelf;
this.taintSourceIndex = taintSourceIndex;
this.method = method;
this.isTaintedNode = KernelNodesFactory.KernelIsTaintedNodeFactory.create(context, sourceSection, new RubyNode[]{});
this.isTaintedNode = IsTaintedNodeFactory.create(context, sourceSection, null);
}

public TaintResultNode(TaintResultNode prev) {
Expand All @@ -48,22 +54,28 @@ public TaintResultNode(TaintResultNode prev) {

@Override
public Object execute(VirtualFrame frame) {
final Object result = method.execute(frame);
final RubyBasicObject result;

try {
result = method.executeRubyBasicObject(frame);
} catch (UnexpectedResultException e) {
throw new UnsupportedOperationException(e);
}

if (result != getContext().getCoreLibrary().getNilObject()) {
final Object taintSource;
final RubyBasicObject taintSource;

if (needsSelf && taintSourceIndex == 0) {
taintSource = RubyArguments.getSelf(frame.getArguments());
taintSource = (RubyBasicObject) RubyArguments.getSelf(frame.getArguments());
} else {
final int adjustedIndex = needsSelf ? taintSourceIndex - 1 : taintSourceIndex;
taintSource = RubyArguments.getUserArgument(frame.getArguments(), adjustedIndex);
taintSource = (RubyBasicObject) RubyArguments.getUserArgument(frame.getArguments(), adjustedIndex);
}

if (taintProfile.profile(isTaintedNode.isTainted(taintSource))) {
if (taintNode == null) {
CompilerDirectives.transferToInterpreter();
taintNode = insert(KernelNodesFactory.KernelTaintNodeFactory.create(getContext(), getSourceSection(), new RubyNode[]{}));
taintNode = insert(TaintNodeFactory.create(getContext(), getSourceSection(), null));
}

taintNode.taint(result);
Expand Down

0 comments on commit f8acad8

Please sign in to comment.