From af5d3028d979f885a786d6fc8d21c1beecd7e3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 6 Nov 2023 19:05:50 -0800 Subject: [PATCH] read shared limits --- tests/gen/assert_shared.0.c | 11 +++++++++++ tests/gen/assert_shared.1.c | 11 +++++++++++ tests/gen/assert_shared.2.c | 11 +++++++++++ tests/gen/assert_shared.3.c | 11 +++++++++++ tests/gen/assert_shared.4.c | 11 +++++++++++ tests/gen/assert_shared.5.c | 11 +++++++++++ tests/gen/assert_shared.6.c | 11 +++++++++++ tests/gen/assert_shared.7.c | 11 +++++++++++ tests/gen/assert_shared.8.c | 11 +++++++++++ tests/gen/shared.0.wasm | Bin 0 -> 14 bytes tests/gen/shared.1.wasm | Bin 0 -> 14 bytes tests/gen/shared.2.wasm | Bin 0 -> 21 bytes tests/gen/shared.3.wasm | Bin 0 -> 21 bytes tests/gen/shared.4.wasm | Bin 0 -> 21 bytes tests/gen/shared.5.wasm | Bin 0 -> 21 bytes tests/gen/shared.6.wasm | Bin 0 -> 21 bytes tests/gen/shared.7.wasm | Bin 0 -> 21 bytes tests/gen/shared.8.wasm | Bin 0 -> 38 bytes tests/gen/shared.json | 11 +++++++++++ tests/main.c | 6 ++++++ tests/shared.wast | 20 ++++++++++++++++++++ w2c2/import.h | 6 ++++-- w2c2/memory.h | 3 ++- w2c2/reader.c | 29 +++++++++++++++++++++++------ w2c2/table.h | 3 ++- 25 files changed, 167 insertions(+), 10 deletions(-) create mode 100644 tests/gen/assert_shared.0.c create mode 100644 tests/gen/assert_shared.1.c create mode 100644 tests/gen/assert_shared.2.c create mode 100644 tests/gen/assert_shared.3.c create mode 100644 tests/gen/assert_shared.4.c create mode 100644 tests/gen/assert_shared.5.c create mode 100644 tests/gen/assert_shared.6.c create mode 100644 tests/gen/assert_shared.7.c create mode 100644 tests/gen/assert_shared.8.c create mode 100644 tests/gen/shared.0.wasm create mode 100644 tests/gen/shared.1.wasm create mode 100644 tests/gen/shared.2.wasm create mode 100644 tests/gen/shared.3.wasm create mode 100644 tests/gen/shared.4.wasm create mode 100644 tests/gen/shared.5.wasm create mode 100644 tests/gen/shared.6.wasm create mode 100644 tests/gen/shared.7.wasm create mode 100644 tests/gen/shared.8.wasm create mode 100644 tests/gen/shared.json create mode 100644 tests/shared.wast diff --git a/tests/gen/assert_shared.0.c b/tests/gen/assert_shared.0.c new file mode 100644 index 00000000..2093d063 --- /dev/null +++ b/tests/gen/assert_shared.0.c @@ -0,0 +1,11 @@ + +#include +#include "w2c2_base.h" +#include "test.h" +#include "test_shared.0.h" + +void test() { + shared0Instance instance; + shared0Instantiate(&instance, resolveTestImports); + printStart("shared.0.wasm"); +} diff --git a/tests/gen/assert_shared.1.c b/tests/gen/assert_shared.1.c new file mode 100644 index 00000000..5b423540 --- /dev/null +++ b/tests/gen/assert_shared.1.c @@ -0,0 +1,11 @@ + +#include +#include "w2c2_base.h" +#include "test.h" +#include "test_shared.1.h" + +void test() { + shared1Instance instance; + shared1Instantiate(&instance, resolveTestImports); + printStart("shared.1.wasm"); +} diff --git a/tests/gen/assert_shared.2.c b/tests/gen/assert_shared.2.c new file mode 100644 index 00000000..0a08a790 --- /dev/null +++ b/tests/gen/assert_shared.2.c @@ -0,0 +1,11 @@ + +#include +#include "w2c2_base.h" +#include "test.h" +#include "test_shared.2.h" + +void test() { + shared2Instance instance; + shared2Instantiate(&instance, resolveTestImports); + printStart("shared.2.wasm"); +} diff --git a/tests/gen/assert_shared.3.c b/tests/gen/assert_shared.3.c new file mode 100644 index 00000000..4c164456 --- /dev/null +++ b/tests/gen/assert_shared.3.c @@ -0,0 +1,11 @@ + +#include +#include "w2c2_base.h" +#include "test.h" +#include "test_shared.3.h" + +void test() { + shared3Instance instance; + shared3Instantiate(&instance, resolveTestImports); + printStart("shared.3.wasm"); +} diff --git a/tests/gen/assert_shared.4.c b/tests/gen/assert_shared.4.c new file mode 100644 index 00000000..dc4c3574 --- /dev/null +++ b/tests/gen/assert_shared.4.c @@ -0,0 +1,11 @@ + +#include +#include "w2c2_base.h" +#include "test.h" +#include "test_shared.4.h" + +void test() { + shared4Instance instance; + shared4Instantiate(&instance, resolveTestImports); + printStart("shared.4.wasm"); +} diff --git a/tests/gen/assert_shared.5.c b/tests/gen/assert_shared.5.c new file mode 100644 index 00000000..68c2de0d --- /dev/null +++ b/tests/gen/assert_shared.5.c @@ -0,0 +1,11 @@ + +#include +#include "w2c2_base.h" +#include "test.h" +#include "test_shared.5.h" + +void test() { + shared5Instance instance; + shared5Instantiate(&instance, resolveTestImports); + printStart("shared.5.wasm"); +} diff --git a/tests/gen/assert_shared.6.c b/tests/gen/assert_shared.6.c new file mode 100644 index 00000000..5905be40 --- /dev/null +++ b/tests/gen/assert_shared.6.c @@ -0,0 +1,11 @@ + +#include +#include "w2c2_base.h" +#include "test.h" +#include "test_shared.6.h" + +void test() { + shared6Instance instance; + shared6Instantiate(&instance, resolveTestImports); + printStart("shared.6.wasm"); +} diff --git a/tests/gen/assert_shared.7.c b/tests/gen/assert_shared.7.c new file mode 100644 index 00000000..804f4742 --- /dev/null +++ b/tests/gen/assert_shared.7.c @@ -0,0 +1,11 @@ + +#include +#include "w2c2_base.h" +#include "test.h" +#include "test_shared.7.h" + +void test() { + shared7Instance instance; + shared7Instantiate(&instance, resolveTestImports); + printStart("shared.7.wasm"); +} diff --git a/tests/gen/assert_shared.8.c b/tests/gen/assert_shared.8.c new file mode 100644 index 00000000..9d456491 --- /dev/null +++ b/tests/gen/assert_shared.8.c @@ -0,0 +1,11 @@ + +#include +#include "w2c2_base.h" +#include "test.h" +#include "test_shared.8.h" + +void test() { + shared8Instance instance; + shared8Instantiate(&instance, resolveTestImports); + printStart("shared.8.wasm"); +} diff --git a/tests/gen/shared.0.wasm b/tests/gen/shared.0.wasm new file mode 100644 index 0000000000000000000000000000000000000000..7a0233b247cd73012dad0810d58ca206e60020f0 GIT binary patch literal 14 VcmZQbEY4+QU|?WnVPs}t000kH0Z;${ literal 0 HcmV?d00001 diff --git a/tests/gen/shared.1.wasm b/tests/gen/shared.1.wasm new file mode 100644 index 0000000000000000000000000000000000000000..63ff5d1daa03fed72b46aa0e89c62b54290f9caa GIT binary patch literal 14 VcmZQbEY4+QU|?WnVPs}x0ss$N0aE|~ literal 0 HcmV?d00001 diff --git a/tests/gen/shared.2.wasm b/tests/gen/shared.2.wasm new file mode 100644 index 0000000000000000000000000000000000000000..638954c4f45cd85181b79d01acc8e2828975b815 GIT binary patch literal 21 ccmZQbEY4+QU|?WnVPs}tWM^e$Ok`pJ02&Sf!Tbuffer, max) == 0) { + static WasmModuleReaderError wasmModuleReaderError = { + wasmModuleReaderInvalidLimitMaximum + }; + *error = &wasmModuleReaderError; + return; + } + *shared = true; break; } default: { @@ -746,9 +761,10 @@ wasmReadMemoryType( WasmModuleReader* reader, U32* min, U32* max, + bool* shared, WasmModuleReaderError** error ) { - wasmReadLimits(reader, min, max, error); + wasmReadLimits(reader, min, max, shared, error); if (*error != NULL) { return; } @@ -770,7 +786,7 @@ wasmReadMemoryImport( import.module = module; import.name = name; - wasmReadMemoryType(reader, &import.min, &import.max, error); + wasmReadMemoryType(reader, &import.min, &import.max, &import.shared, error); if (*error != NULL) { return; } @@ -792,6 +808,7 @@ wasmReadTableType( WasmModuleReader* reader, U32* min, U32* max, + bool* shared, WasmModuleReaderError** error ) { U8 tableType = 0; @@ -808,7 +825,7 @@ wasmReadTableType( return; } - wasmReadLimits(reader, min, max, error); + wasmReadLimits(reader, min, max, shared, error); if (*error != NULL) { return; } @@ -832,7 +849,7 @@ wasmReadTableImport( import.module = module; import.name = name; - wasmReadTableType(reader, &import.min, &import.max, error); + wasmReadTableType(reader, &import.min, &import.max, &import.shared, error); if (*error != NULL) { return; } @@ -1091,7 +1108,7 @@ wasmReadMemorySection( /* Read memories */ for (; memoryIndex < memoryCount; memoryIndex++) { WasmMemory memory = wasmEmptyMemory; - wasmReadMemoryType(reader, &memory.min, &memory.max, error); + wasmReadMemoryType(reader, &memory.min, &memory.max, &memory.shared, error); if (*error != NULL) { return; } @@ -1549,7 +1566,7 @@ wasmReadTableSection( U32 tableIndex = 0; for (; tableIndex < tableCount; tableIndex++) { WasmTable table = wasmEmptyTable; - wasmReadTableType(reader, &table.min, &table.max, error); + wasmReadTableType(reader, &table.min, &table.max, &table.shared, error); if (*error != NULL) { return; } diff --git a/w2c2/table.h b/w2c2/table.h index 882a9115..3775063f 100755 --- a/w2c2/table.h +++ b/w2c2/table.h @@ -10,8 +10,9 @@ static const U8 wasmTableTypeFuncRef = 0x70; typedef struct WasmTable { U32 min; U32 max; + bool shared; } WasmTable; -static const WasmTable wasmEmptyTable = {0, 0}; +static const WasmTable wasmEmptyTable = {0, 0, false}; #endif /* W2C2_TABLE_H */