Fix bugs in Wasi support. Fix GC issue in Wasm

This commit is contained in:
Alexey Andreev 2022-11-11 20:59:09 +01:00
parent 1b6acc9eb1
commit d9fb2bc159
5 changed files with 10 additions and 10 deletions

View File

@ -69,7 +69,6 @@ public final class WasmHeap {
public static void initHeap(Address start, int minHeap, int maxHeap, int stackSize, int bufferSize) { public static void initHeap(Address start, int minHeap, int maxHeap, int stackSize, int bufferSize) {
initHeapTrace(maxHeap); initHeapTrace(maxHeap);
buffer = start;
buffer = WasmRuntime.align(start, 16); buffer = WasmRuntime.align(start, 16);
WasmHeap.bufferSize = bufferSize; WasmHeap.bufferSize = bufferSize;
stack = WasmRuntime.align(buffer.add(bufferSize), 16); stack = WasmRuntime.align(buffer.add(bufferSize), 16);

View File

@ -112,8 +112,8 @@ public class WasiSupport {
if (errno != ERRNO_SUCCESS) { if (errno != ERRNO_SUCCESS) {
throw new RuntimeException("Could not get command line arguments"); throw new RuntimeException("Could not get command line arguments");
} }
int argvSize = (int) sizesReceiver.value; int argvSize = sizesReceiver.value;
int argvBufSize = (int) bufferSizeReceiver.value; int argvBufSize = bufferSizeReceiver.value;
int[] argvOffsets = new int[argvSize]; int[] argvOffsets = new int[argvSize];
byte[] argvBuffer = new byte[argvBufSize]; byte[] argvBuffer = new byte[argvBufSize];

View File

@ -60,10 +60,11 @@ public class Characteristics {
public boolean isResource(String className) { public boolean isResource(String className) {
byte result = isResource.getOrDefault(className, (byte) -1); byte result = isResource.getOrDefault(className, (byte) -1);
if (result < 0) { if (result < 0) {
if (className.equals("org/teavm/platform/metadata/Resource")) { if (className.equals("org.teavm.platform.metadata.Resource")) {
result = 1; result = 1;
} else { } else {
ClassReader cls = classSource.get(className); ClassReader cls = classSource.get(className);
result = 0;
if (cls != null) { if (cls != null) {
if (cls.getParent() != null) { if (cls.getParent() != null) {
result = isResource(cls.getParent()) ? (byte) 1 : 0; result = isResource(cls.getParent()) ? (byte) 1 : 0;

View File

@ -141,19 +141,19 @@ public final class ExceptionHandling {
@Unmanaged @Unmanaged
public static void throwClassCastException() { public static void throwClassCastException() {
throw new ClassCastException(); throwException(new ClassCastException());
} }
@Unmanaged @Unmanaged
@Export(name = "teavm_throwNullPointerException") @Export(name = "teavm_throwNullPointerException")
public static void throwNullPointerException() { public static void throwNullPointerException() {
throw new NullPointerException(); throwException(new NullPointerException());
} }
@Unmanaged @Unmanaged
@Export(name = "teavm_throwArrayIndexOutOfBoundsException") @Export(name = "teavm_throwArrayIndexOutOfBoundsException")
public static void throwArrayIndexOutOfBoundsException() { public static void throwArrayIndexOutOfBoundsException() {
throw new ArrayIndexOutOfBoundsException(); throwException(new ArrayIndexOutOfBoundsException());
} }
@Unmanaged @Unmanaged

View File

@ -92,7 +92,7 @@ int32_t wasi_snapshot_preview1_args_sizes_get(int32_t argv_size, int32_t argv_bu
int32_t bufferSize = 0; int32_t bufferSize = 0;
for (int i = 0; i < wasm_args; ++i) { for (int i = 0; i < wasm_args; ++i) {
bufferSize += (int32_t) strlen(wasm_argv[i]); bufferSize += (int32_t) strlen(wasm_argv[i]) + 1;
} }
*argvBufferSizePtr = bufferSize; *argvBufferSizePtr = bufferSize;
return 0; return 0;
@ -103,8 +103,8 @@ int32_t wasi_snapshot_preview1_args_get(int32_t sizes_ptr, int32_t args_ptr) {
char* argsPtr = (char*) (wasm_heap + args_ptr); char* argsPtr = (char*) (wasm_heap + args_ptr);
int offset = 0; int offset = 0;
for (int i = 0; i < wasm_args; ++i) { for (int i = 0; i < wasm_args; ++i) {
sizesPtr[i] = (int32_t) offset; sizesPtr[i] = (int32_t) offset + args_ptr;
int len = strlen(wasm_argv[i]); int len = strlen(wasm_argv[i]) + 1;
memcpy(argsPtr + offset, wasm_argv[i], len); memcpy(argsPtr + offset, wasm_argv[i], len);
offset += len; offset += len;
} }