C/Wasm: fix heap corruption when GC hits on initializing stack trace of exception

This commit is contained in:
Alexey Andreev 2019-10-28 13:59:03 +03:00
parent 4f9567561c
commit 6ed00f1af2
2 changed files with 8 additions and 8 deletions

View File

@ -22,7 +22,6 @@ import org.teavm.classlib.java.util.TArrays;
import org.teavm.interop.Remove;
import org.teavm.interop.Rename;
import org.teavm.interop.Superclass;
import org.teavm.interop.Unmanaged;
import org.teavm.runtime.ExceptionHandling;
@Superclass("java.lang.Object")
@ -104,16 +103,11 @@ public class TThrowable extends RuntimeException {
@Override
public Throwable fillInStackTrace() {
if (PlatformDetector.isLowLevel()) {
stackTrace = fillInStackTraceLowLevel();
stackTrace = (TStackTraceElement[]) (Object) ExceptionHandling.fillStackTrace();
}
return this;
}
@Unmanaged
private static TStackTraceElement[] fillInStackTraceLowLevel() {
return (TStackTraceElement[]) (Object) ExceptionHandling.fillStackTrace();
}
@Rename("getMessage")
public String getMessage0() {
return message;

View File

@ -67,6 +67,8 @@ import org.teavm.runtime.ExceptionHandling;
import org.teavm.runtime.ShadowStack;
public class ExceptionHandlingShadowStackContributor {
private static final MethodReference FILL_STACK_TRACE = new MethodReference(ExceptionHandling.class,
"fillStackTrace", StackTraceElement[].class);
private Characteristics characteristics;
private List<CallSiteDescriptor> callSites;
private BasicBlock defaultExceptionHandler;
@ -281,7 +283,11 @@ public class ExceptionHandlingShadowStackContributor {
|| insn instanceof NullCheckInstruction || insn instanceof BoundCheckInstruction) {
return true;
} else if (insn instanceof InvokeInstruction) {
return isManagedMethodCall(characteristics, ((InvokeInstruction) insn).getMethod());
MethodReference method = ((InvokeInstruction) insn).getMethod();
if (method.equals(FILL_STACK_TRACE)) {
return true;
}
return isManagedMethodCall(characteristics, method);
}
return false;
}