Skip to content

Commit

Permalink
* Fixed hard-coded use of edu/columbia/cs/psl/phosphor/runtime/Runtim…
Browse files Browse the repository at this point in the history
…eJDKInternalUnsafePropagator

* Renamed edu/columbia/cs/psl/phosphor/runtime/RuntimeJDKInternalUnsafePropagator to JdkUnsafeMasker
  • Loading branch information
katherine-hough committed Nov 29, 2023
1 parent 82e03dc commit 452df9b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package edu.columbia.cs.psl.phosphor.agent;

import edu.columbia.cs.psl.phosphor.runtime.mask.JdkUnsafeMasker;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;

Expand All @@ -18,7 +20,7 @@ public byte[] patch(String name, byte[] content) {
name = name.replace(".class", "");
if (ConfigurationEmbeddingCV.isApplicable(name)) {
return PhosphorPatcher.apply(content, ConfigurationEmbeddingCV::new);
} else if (name.equals("edu/columbia/cs/psl/phosphor/runtime/RuntimeJDKInternalUnsafePropagator")) {
} else if (name.equals(Type.getInternalName(JdkUnsafeMasker.class))) {
return PhosphorPatcher.apply(content, cv -> new UnsafePatchingCV(cv, patchUnsafeNames));
} else if (JdkUnsafeAdapterPatchingCV.isApplicable(name, patchUnsafeNames)) {
return PhosphorPatcher.apply(content, JdkUnsafeAdapterPatchingCV::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import edu.columbia.cs.psl.phosphor.instrumenter.LocalVariableManager;
import edu.columbia.cs.psl.phosphor.mask.MaskRegistry.MaskInfo;
import edu.columbia.cs.psl.phosphor.runtime.*;
import edu.columbia.cs.psl.phosphor.runtime.mask.RuntimeJDKInternalUnsafePropagator;
import edu.columbia.cs.psl.phosphor.runtime.mask.JdkUnsafeMasker;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
Expand Down Expand Up @@ -102,7 +102,7 @@ private void maskUnsafe(
} else if (shouldPatchUnsafe(name, descWithoutStackFrame)) {
name = name.replace("Object", "Reference");
desc = "(L" + owner + ";" + desc.substring(1);
owner = Type.getInternalName(RuntimeJDKInternalUnsafePropagator.class);
owner = Type.getInternalName(JdkUnsafeMasker.class);
super.visitMethodInsn(Opcodes.INVOKESTATIC, owner, name, desc, false);
} else {
super.visitMethodInsn(opcode, owner, name, desc, isInterface);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public void putDoubleVolatile(Object o, long offset, double x) {

@Override
public void putOrderedObject(Object o, long offset, Object x) {
unsafe.putObjectRelease(o, offset, x);
unsafe.putObjectVolatile(o, offset, x);
}

@Override
Expand All @@ -292,11 +292,11 @@ public boolean compareAndSwapLong(Object o, long offset, long expected, long x)

@Override
public void putOrderedInt(Object o, long offset, int x) {
unsafe.putIntRelease(o, offset, x);
unsafe.putIntVolatile(o, offset, x);
}

@Override
public void putOrderedLong(Object o, long offset, long x) {
unsafe.putLongRelease(o, offset, x);
unsafe.putLongVolatile(o, offset, x);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@

/* Ensures that calls methods in UnsafeProxy that set or retrieve the value of a field of a Java heap object set and
* retrieve both the original field and its associated taint field if it has one. */
public class RuntimeJDKInternalUnsafePropagator {

private RuntimeJDKInternalUnsafePropagator() {
// Prevents this class from being instantiated
}

public class JdkUnsafeMasker {
/* Used to disambiguate between a static field of a given type and an instance field of java.lang.Class */
static long LAST_INSTANCE_OFFSET_JAVA_LANG_CLASS = UnsafeProxy.INVALID_FIELD_OFFSET;

Expand Down Expand Up @@ -206,6 +201,7 @@ public static void copyMemory(UnsafeProxy unsafe, long srcAddress, long destAddr
unsafe.copyMemory(srcAddress, destAddress, length);
}

@SuppressWarnings("unused")
public static void copySwapMemory(UnsafeProxy unsafe, Object srcBase, long srcOffset, Object destBase,
long destOffset, long bytes, long elemSize, PhosphorStackFrame stackFrame) {
if (srcBase instanceof TaggedArray) {
Expand All @@ -217,6 +213,7 @@ public static void copySwapMemory(UnsafeProxy unsafe, Object srcBase, long srcOf
unsafe.copySwapMemory(srcBase, srcOffset, destBase, destOffset, bytes, elemSize);
}

@SuppressWarnings("unused")
public static void copySwapMemory(UnsafeProxy unsafe, long srcAddress, long destAddress, long bytes, long elemSize, PhosphorStackFrame stackFrame) {
unsafe.copySwapMemory(srcAddress, destAddress, bytes, elemSize);
}
Expand Down Expand Up @@ -1392,7 +1389,7 @@ public static Object getReference(UnsafeProxy unsafe, Object obj, long offset, P
if (pair != null && pair.wrappedFieldOffset != UnsafeProxy.INVALID_FIELD_OFFSET) {
offset = pair.wrappedFieldOffset;
}
getTag(unsafe, obj, offset, phosphorStackFrame, RuntimeJDKInternalUnsafePropagator.SpecialAccessPolicy.NONE);
getTag(unsafe, obj, offset, phosphorStackFrame, SpecialAccessPolicy.NONE);
return unsafe.getReference(obj, offset);
}
}
Expand Down Expand Up @@ -1564,5 +1561,4 @@ public static void putDoubleRelease(UnsafeProxy unsafe, Object o, long offset, d
public static void putBooleanRelease(UnsafeProxy unsafe, Object o, long offset, boolean x, PhosphorStackFrame phosphorStackFrame) {
putBooleanVolatile(unsafe, o, offset, x, phosphorStackFrame);
}

}

0 comments on commit 452df9b

Please sign in to comment.