Commit d62914f6 authored by rossberg's avatar rossberg Committed by Commit bot

[wasm] check that there is at most 1 table

R=titzer@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2643783002
Cr-Commit-Position: refs/heads/master@{#42465}
parent c69a40fc
...@@ -304,6 +304,7 @@ class ModuleDecoder : public Decoder { ...@@ -304,6 +304,7 @@ class ModuleDecoder : public Decoder {
} }
case kExternalTable: { case kExternalTable: {
// ===== Imported table ========================================== // ===== Imported table ==========================================
if (!AddTable(module)) break;
import->index = import->index =
static_cast<uint32_t>(module->function_tables.size()); static_cast<uint32_t>(module->function_tables.size());
module->function_tables.push_back({0, 0, false, module->function_tables.push_back({0, 0, false,
...@@ -319,11 +320,11 @@ class ModuleDecoder : public Decoder { ...@@ -319,11 +320,11 @@ class ModuleDecoder : public Decoder {
} }
case kExternalMemory: { case kExternalMemory: {
// ===== Imported memory ========================================= // ===== Imported memory =========================================
if (!AddMemory(module)) break;
consume_resizable_limits( consume_resizable_limits(
"memory", "pages", kV8MaxWasmMemoryPages, "memory", "pages", kV8MaxWasmMemoryPages,
&module->min_mem_pages, &module->has_max_mem, &module->min_mem_pages, &module->has_max_mem,
kSpecMaxWasmMemoryPages, &module->max_mem_pages); kSpecMaxWasmMemoryPages, &module->max_mem_pages);
SetHasMemory(module);
break; break;
} }
case kExternalGlobal: { case kExternalGlobal: {
...@@ -373,12 +374,11 @@ class ModuleDecoder : public Decoder { ...@@ -373,12 +374,11 @@ class ModuleDecoder : public Decoder {
// ===== Table section =================================================== // ===== Table section ===================================================
if (section_iter.section_code() == kTableSectionCode) { if (section_iter.section_code() == kTableSectionCode) {
uint32_t table_count = consume_count("table count", kV8MaxWasmTables); uint32_t table_count = consume_count("table count", kV8MaxWasmTables);
if (module->function_tables.size() < 1) {
module->function_tables.push_back({0, 0, false, std::vector<int32_t>(),
false, false, SignatureMap()});
}
for (uint32_t i = 0; ok() && i < table_count; i++) { for (uint32_t i = 0; ok() && i < table_count; i++) {
if (!AddTable(module)) break;
module->function_tables.push_back({0, 0, false, std::vector<int32_t>(),
false, false, SignatureMap()});
WasmIndirectFunctionTable* table = &module->function_tables.back(); WasmIndirectFunctionTable* table = &module->function_tables.back();
expect_u8("table type", kWasmAnyFunctionTypeForm); expect_u8("table type", kWasmAnyFunctionTypeForm);
consume_resizable_limits( consume_resizable_limits(
...@@ -393,12 +393,12 @@ class ModuleDecoder : public Decoder { ...@@ -393,12 +393,12 @@ class ModuleDecoder : public Decoder {
uint32_t memory_count = consume_count("memory count", kV8MaxWasmMemories); uint32_t memory_count = consume_count("memory count", kV8MaxWasmMemories);
for (uint32_t i = 0; ok() && i < memory_count; i++) { for (uint32_t i = 0; ok() && i < memory_count; i++) {
if (!AddMemory(module)) break;
consume_resizable_limits("memory", "pages", kV8MaxWasmMemoryPages, consume_resizable_limits("memory", "pages", kV8MaxWasmMemoryPages,
&module->min_mem_pages, &module->has_max_mem, &module->min_mem_pages, &module->has_max_mem,
kSpecMaxWasmMemoryPages, kSpecMaxWasmMemoryPages,
&module->max_mem_pages); &module->max_mem_pages);
} }
SetHasMemory(module);
section_iter.advance(); section_iter.advance();
} }
...@@ -683,11 +683,22 @@ class ModuleDecoder : public Decoder { ...@@ -683,11 +683,22 @@ class ModuleDecoder : public Decoder {
uint32_t off(const byte* ptr) { return static_cast<uint32_t>(ptr - start_); } uint32_t off(const byte* ptr) { return static_cast<uint32_t>(ptr - start_); }
void SetHasMemory(WasmModule* module) { bool AddTable(WasmModule* module) {
if (module->function_tables.size() > 0) {
error("At most one table is supported");
return false;
} else {
return true;
}
}
bool AddMemory(WasmModule* module) {
if (module->has_memory) { if (module->has_memory) {
error("At most one memory object is supported"); error("At most one memory is supported");
return false;
} else { } else {
module->has_memory = true; module->has_memory = true;
return true;
} }
} }
......
...@@ -319,9 +319,8 @@ function js_div(a, b) { return (a / b) | 0; } ...@@ -319,9 +319,8 @@ function js_div(a, b) { return (a / b) | 0; }
kExprCallIndirect, sig_index2, kTableZero]) // -- kExprCallIndirect, sig_index2, kTableZero]) // --
.exportAs("main"); .exportAs("main");
builder.setFunctionTableLength(kTableSize);
builder.addFunctionTableInit(1, false, [f2.index]);
builder.addImportedTable("z", "table", kTableSize, kTableSize); builder.addImportedTable("z", "table", kTableSize, kTableSize);
builder.addFunctionTableInit(1, false, [f2.index], true);
var m2 = new WebAssembly.Module(builder.toBuffer()); var m2 = new WebAssembly.Module(builder.toBuffer());
......
...@@ -227,12 +227,12 @@ class WasmModuleBuilder { ...@@ -227,12 +227,12 @@ class WasmModuleBuilder {
this.exports.push({name: name, kind: kExternalMemory, index: 0}); this.exports.push({name: name, kind: kExternalMemory, index: 0});
} }
addFunctionTableInit(base, is_global, array) { addFunctionTableInit(base, is_global, array, is_import = false) {
this.function_table_inits.push({base: base, is_global: is_global, this.function_table_inits.push({base: base, is_global: is_global,
array: array}); array: array});
if (!is_global) { if (!is_global) {
var length = base + array.length; var length = base + array.length;
if (length > this.function_table_length) { if (length > this.function_table_length && !is_import) {
this.function_table_length = length; this.function_table_length = length;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment