diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/v8/src/wasm/module-instantiate.cc | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/v8/src/wasm/module-instantiate.cc')
-rw-r--r-- | chromium/v8/src/wasm/module-instantiate.cc | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/chromium/v8/src/wasm/module-instantiate.cc b/chromium/v8/src/wasm/module-instantiate.cc index 9dfc1e16081..b48c9635880 100644 --- a/chromium/v8/src/wasm/module-instantiate.cc +++ b/chromium/v8/src/wasm/module-instantiate.cc @@ -16,6 +16,7 @@ #include "src/wasm/wasm-import-wrapper-cache.h" #include "src/wasm/wasm-module.h" #include "src/wasm/wasm-objects-inl.h" +#include "src/wasm/wasm-subtyping.h" #define TRACE(...) \ do { \ @@ -196,7 +197,7 @@ class InstanceBuilder { void WriteGlobalValue(const WasmGlobal& global, Handle<WasmGlobalObject> value); - void WriteGlobalAnyRef(const WasmGlobal& global, Handle<Object> value); + void WriteGlobalExternRef(const WasmGlobal& global, Handle<Object> value); void SanitizeImports(); @@ -304,7 +305,8 @@ InstanceBuilder::InstanceBuilder(Isolate* isolate, ErrorThrower* thrower, // Build an instance, in all of its glory. MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { - TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"), "InstanceBuilder::Build"); + TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm.detailed"), + "wasm.InstanceBuilder.Build"); // Check that an imports argument was provided, if the module requires it. // No point in continuing otherwise. if (!module_->import_table.empty() && ffi_.is_null()) { @@ -472,7 +474,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { // iteration below. for (int i = 1; i < table_count; ++i) { const WasmTable& table = module_->tables[i]; - if (table.type == kWasmFuncRef) { + if (table.type.heap_type() == kHeapFunc) { Handle<WasmIndirectFunctionTable> table_obj = WasmIndirectFunctionTable::New(isolate_, table.initial_size); tables->set(i, *table_obj); @@ -524,8 +526,10 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { auto table_object = handle(WasmTableObject::cast(instance->tables().get( elem_segment.table_index)), isolate_); - size_t table_size = table_object->current_length(); - if (!base::IsInBounds(base, elem_segment.entries.size(), table_size)) { + uint32_t table_size = table_object->current_length(); + if (!base::IsInBounds<uint32_t>( + base, static_cast<uint32_t>(elem_segment.entries.size()), + table_size)) { thrower_->LinkError("table initializer is out of bounds"); return {}; } @@ -537,8 +541,8 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { for (const WasmDataSegment& seg : module_->data_segments) { if (!seg.active) continue; uint32_t base = EvalUint32InitExpr(instance, seg.dest_addr); - if (!base::IsInBounds(base, seg.source.length(), - instance->memory_size())) { + if (!base::IsInBounds<uint64_t>(base, seg.source.length(), + instance->memory_size())) { thrower_->LinkError("data segment is out of bounds"); return {}; } @@ -616,8 +620,8 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { } bool InstanceBuilder::ExecuteStartFunction() { - TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"), - "InstanceBuilder::ExecuteStartFunction"); + TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm.detailed"), + "wasm.ExecuteStartFunction"); if (start_function_.is_null()) return true; // No start function. HandleScope scope(isolate_); @@ -730,7 +734,8 @@ void InstanceBuilder::LoadDataSegments(Handle<WasmInstanceObject> instance) { if (size == 0) continue; uint32_t dest_offset = EvalUint32InitExpr(instance, segment.dest_addr); - DCHECK(base::IsInBounds(dest_offset, size, instance->memory_size())); + DCHECK(base::IsInBounds<uint64_t>(dest_offset, size, + instance->memory_size())); byte* dest = instance->memory_start() + dest_offset; const byte* src = wire_bytes.begin() + segment.source.offset(); memcpy(dest, src, size); @@ -741,7 +746,7 @@ void InstanceBuilder::LoadDataSegments(Handle<WasmInstanceObject> instance) { void InstanceBuilder::WriteGlobalValue(const WasmGlobal& global, double num) { TRACE("init [globals_start=%p + %u] = %lf, type = %s\n", raw_buffer_ptr(untagged_globals_, 0), global.offset, num, - global.type.type_name()); + global.type.type_name().c_str()); switch (global.type.kind()) { case ValueType::kI32: WriteLittleEndianValue<int32_t>(GetRawGlobalPtr<int32_t>(global), @@ -767,7 +772,7 @@ void InstanceBuilder::WriteGlobalValue(const WasmGlobal& global, double num) { void InstanceBuilder::WriteGlobalValue(const WasmGlobal& global, int64_t num) { TRACE("init [globals_start=%p + %u] = %" PRId64 ", type = %s\n", raw_buffer_ptr(untagged_globals_, 0), global.offset, num, - global.type.type_name()); + global.type.type_name().c_str()); DCHECK_EQ(kWasmI64, global.type); WriteLittleEndianValue<int64_t>(GetRawGlobalPtr<int64_t>(global), num); } @@ -801,27 +806,25 @@ void InstanceBuilder::WriteGlobalValue(const WasmGlobal& global, TRACE("%lf", num); break; } - case ValueType::kAnyRef: - case ValueType::kFuncRef: - case ValueType::kNullRef: - case ValueType::kExnRef: + case ValueType::kRtt: case ValueType::kRef: - case ValueType::kOptRef: - case ValueType::kEqRef: { - DCHECK_IMPLIES(global.type == kWasmNullRef, value->GetRef()->IsNull()); + case ValueType::kOptRef: { tagged_globals_->set(global.offset, *value->GetRef()); break; } case ValueType::kStmt: case ValueType::kS128: case ValueType::kBottom: + case ValueType::kI8: + case ValueType::kI16: UNREACHABLE(); } - TRACE(", type = %s (from WebAssembly.Global)\n", global.type.type_name()); + TRACE(", type = %s (from WebAssembly.Global)\n", + global.type.type_name().c_str()); } -void InstanceBuilder::WriteGlobalAnyRef(const WasmGlobal& global, - Handle<Object> value) { +void InstanceBuilder::WriteGlobalExternRef(const WasmGlobal& global, + Handle<Object> value) { tagged_globals_->set(global.offset, *value, UPDATE_WRITE_BARRIER); } @@ -1046,7 +1049,7 @@ bool InstanceBuilder::ProcessImportedTable(Handle<WasmInstanceObject> instance, return false; } - if (table.type == kWasmFuncRef && + if (table.type.heap_type() == kHeapFunc && !InitializeImportedIndirectFunctionTable(instance, table_index, import_index, table_object)) { return false; @@ -1113,13 +1116,14 @@ bool InstanceBuilder::ProcessImportedWasmGlobalObject( Handle<WasmInstanceObject> instance, int import_index, Handle<String> module_name, Handle<String> import_name, const WasmGlobal& global, Handle<WasmGlobalObject> global_object) { - if (global_object->is_mutable() != global.mutability) { + if (static_cast<bool>(global_object->is_mutable()) != global.mutability) { ReportLinkError("imported global does not match the expected mutability", import_index, module_name, import_name); return false; } - bool is_sub_type = global_object->type().IsSubTypeOf(global.type); + bool is_sub_type = + IsSubtypeOf(global_object->type(), global.type, instance->module()); bool is_same_type = global_object->type() == global.type; bool valid_type = global.mutability ? is_same_type : is_sub_type; @@ -1132,12 +1136,13 @@ bool InstanceBuilder::ProcessImportedWasmGlobalObject( DCHECK_LT(global.index, module_->num_imported_mutable_globals); Handle<Object> buffer; Address address_or_offset; - if (global.type.IsReferenceType()) { + if (global.type.is_reference_type()) { static_assert(sizeof(global_object->offset()) <= sizeof(Address), "The offset into the globals buffer does not fit into " "the imported_mutable_globals array"); buffer = handle(global_object->tagged_buffer(), isolate_); - // For anyref globals we use a relative offset, not an absolute address. + // For externref globals we use a relative offset, not an absolute + // address. address_or_offset = static_cast<Address>(global_object->offset()); } else { buffer = handle(global_object->untagged_buffer(), isolate_); @@ -1210,8 +1215,8 @@ bool InstanceBuilder::ProcessImportedGlobal(Handle<WasmInstanceObject> instance, return false; } - if (global.type.IsReferenceType()) { - if (global.type == kWasmFuncRef) { + if (global.type.is_reference_type()) { + if (global.type.heap_type() == kHeapFunc) { if (!value->IsNull(isolate_) && !WasmExportedFunction::IsWasmExportedFunction(*value)) { ReportLinkError( @@ -1219,14 +1224,8 @@ bool InstanceBuilder::ProcessImportedGlobal(Handle<WasmInstanceObject> instance, import_index, module_name, import_name); return false; } - } else if (global.type == kWasmNullRef) { - if (!value->IsNull(isolate_)) { - ReportLinkError("imported nullref global must be null", import_index, - module_name, import_name); - return false; - } } - WriteGlobalAnyRef(global, value); + WriteGlobalExternRef(global, value); return true; } @@ -1412,7 +1411,7 @@ void InstanceBuilder::InitGlobals(Handle<WasmInstanceObject> instance) { global.init.val.f64_const); break; case WasmInitExpr::kRefNullConst: - DCHECK(enabled_.has_anyref() || enabled_.has_eh()); + DCHECK(enabled_.has_reftypes() || enabled_.has_eh()); if (global.imported) break; // We already initialized imported globals. tagged_globals_->set(global.offset, @@ -1420,7 +1419,7 @@ void InstanceBuilder::InitGlobals(Handle<WasmInstanceObject> instance) { SKIP_WRITE_BARRIER); break; case WasmInitExpr::kRefFuncConst: { - DCHECK(enabled_.has_anyref()); + DCHECK(enabled_.has_reftypes()); auto function = WasmInstanceObject::GetOrCreateWasmExternalFunction( isolate_, instance, global.init.val.function_index); tagged_globals_->set(global.offset, *function); @@ -1432,8 +1431,8 @@ void InstanceBuilder::InitGlobals(Handle<WasmInstanceObject> instance) { uint32_t old_offset = module_->globals[global.init.val.global_index].offset; TRACE("init [globals+%u] = [globals+%d]\n", global.offset, old_offset); - if (global.type.IsReferenceType()) { - DCHECK(enabled_.has_anyref() || enabled_.has_eh()); + if (global.type.is_reference_type()) { + DCHECK(enabled_.has_reftypes() || enabled_.has_eh()); tagged_globals_->set(new_offset, tagged_globals_->get(old_offset)); } else { size_t size = (global.type == kWasmI64 || global.type == kWasmF64) @@ -1483,7 +1482,7 @@ bool InstanceBuilder::AllocateMemory() { bool InstanceBuilder::NeedsWrappers() const { if (module_->num_exported_functions > 0) return true; for (auto& table : module_->tables) { - if (table.type == kWasmFuncRef) return true; + if (table.type.heap_type() == kHeapFunc) return true; } return false; } @@ -1571,10 +1570,10 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) { if (global.mutability && global.imported) { Handle<FixedArray> buffers_array( instance->imported_mutable_globals_buffers(), isolate_); - if (global.type.IsReferenceType()) { + if (global.type.is_reference_type()) { tagged_buffer = handle( FixedArray::cast(buffers_array->get(global.index)), isolate_); - // For anyref globals we store the relative offset in the + // For externref globals we store the relative offset in the // imported_mutable_globals array instead of an absolute address. Address addr = instance->imported_mutable_globals()[global.index]; DCHECK_LE(addr, static_cast<Address>( @@ -1595,7 +1594,7 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) { offset = static_cast<uint32_t>(global_addr - backing_store); } } else { - if (global.type.IsReferenceType()) { + if (global.type.is_reference_type()) { tagged_buffer = handle(instance->tagged_globals_buffer(), isolate_); } else { untagged_buffer = @@ -1656,7 +1655,7 @@ void InstanceBuilder::InitializeIndirectFunctionTables( for (int i = 0; i < static_cast<int>(module_->tables.size()); ++i) { const WasmTable& table = module_->tables[i]; - if (table.type == kWasmFuncRef) { + if (table.type.heap_type() == kHeapFunc) { WasmInstanceObject::EnsureIndirectFunctionTableWithMinimumSize( instance, i, table.initial_size); } @@ -1672,11 +1671,12 @@ bool LoadElemSegmentImpl(Isolate* isolate, Handle<WasmInstanceObject> instance, // TODO(wasm): Move this functionality into wasm-objects, since it is used // for both instantiation and in the implementation of the table.init // instruction. - if (!base::IsInBounds(dst, count, table_object->current_length()) || - !base::IsInBounds(src, count, - instance->dropped_elem_segments()[segment_index] == 0 - ? elem_segment.entries.size() - : 0)) { + if (!base::IsInBounds<uint64_t>(dst, count, table_object->current_length()) || + !base::IsInBounds<uint64_t>( + src, count, + instance->dropped_elem_segments()[segment_index] == 0 + ? elem_segment.entries.size() + : 0)) { return false; } @@ -1686,7 +1686,7 @@ bool LoadElemSegmentImpl(Isolate* isolate, Handle<WasmInstanceObject> instance, int entry_index = static_cast<int>(dst + i); if (func_index == WasmElemSegment::kNullIndex) { - if (table_object->type() == kWasmFuncRef) { + if (table_object->type().heap_type() == kHeapFunc) { IndirectFunctionTableEntry(instance, table_index, entry_index).clear(); } WasmTableObject::Set(isolate, table_object, entry_index, @@ -1697,15 +1697,15 @@ bool LoadElemSegmentImpl(Isolate* isolate, Handle<WasmInstanceObject> instance, const WasmFunction* function = &module->functions[func_index]; // Update the local dispatch table first if necessary. - if (table_object->type() == kWasmFuncRef) { + if (table_object->type().heap_type() == kHeapFunc) { uint32_t sig_id = module->signature_ids[function->sig_index]; IndirectFunctionTableEntry(instance, table_index, entry_index) .Set(sig_id, instance, func_index); } - // For AnyRef tables, we have to generate the WasmExternalFunction eagerly. - // Later we cannot know if an entry is a placeholder or not. - if (table_object->type() == kWasmAnyRef) { + // For ExternRef tables, we have to generate the WasmExternalFunction + // eagerly. Later we cannot know if an entry is a placeholder or not. + if (table_object->type().heap_type() == kHeapExtern) { Handle<WasmExternalFunction> wasm_external_function = WasmInstanceObject::GetOrCreateWasmExternalFunction(isolate, instance, func_index); @@ -1772,7 +1772,7 @@ void InstanceBuilder::LoadTableSegments(Handle<WasmInstanceObject> instance) { int table_count = static_cast<int>(module_->tables.size()); for (int index = 0; index < table_count; ++index) { - if (module_->tables[index].type == kWasmFuncRef) { + if (module_->tables[index].type.heap_type() == kHeapFunc) { auto table_object = handle( WasmTableObject::cast(instance->tables().get(index)), isolate_); |