// Copyright 2015 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "src/wasm/wasm-objects.h" #include "src/base/iterator.h" #include "src/base/vector.h" #include "src/codegen/assembler-inl.h" #include "src/codegen/code-factory.h" #include "src/compiler/wasm-compiler.h" #include "src/debug/debug-interface.h" #include "src/logging/counters.h" #include "src/objects/debug-objects-inl.h" #include "src/objects/managed-inl.h" #include "src/objects/objects-inl.h" #include "src/objects/shared-function-info.h" #include "src/objects/struct-inl.h" #include "src/trap-handler/trap-handler.h" #include "src/utils/utils.h" #include "src/wasm/code-space-access.h" #include "src/wasm/jump-table-assembler.h" #include "src/wasm/module-compiler.h" #include "src/wasm/module-decoder.h" #include "src/wasm/module-instantiate.h" #include "src/wasm/value-type.h" #include "src/wasm/wasm-code-manager.h" #include "src/wasm/wasm-engine.h" #include "src/wasm/wasm-limits.h" #include "src/wasm/wasm-module.h" #include "src/wasm/wasm-objects-inl.h" #include "src/wasm/wasm-subtyping.h" #include "src/wasm/wasm-value.h" #define TRACE_IFT(...) \ do { \ if (false) PrintF(__VA_ARGS__); \ } while (false) namespace v8 { namespace internal { // Import a few often used types from the wasm namespace. using WasmFunction = wasm::WasmFunction; using WasmModule = wasm::WasmModule; namespace { // Manages the natively-allocated memory for a WasmInstanceObject. Since // an instance finalizer is not guaranteed to run upon isolate shutdown, // we must use a Managed to guarantee // it is freed. class WasmInstanceNativeAllocations { public: WasmInstanceNativeAllocations(Handle instance, size_t num_imported_functions, size_t num_imported_mutable_globals, size_t num_data_segments, size_t num_elem_segments) : imported_function_targets_(new Address[num_imported_functions]), imported_mutable_globals_(new Address[num_imported_mutable_globals]), data_segment_starts_(new Address[num_data_segments]), data_segment_sizes_(new uint32_t[num_data_segments]), dropped_elem_segments_(new uint8_t[num_elem_segments]) { instance->set_imported_function_targets(imported_function_targets_.get()); instance->set_imported_mutable_globals(imported_mutable_globals_.get()); instance->set_data_segment_starts(data_segment_starts_.get()); instance->set_data_segment_sizes(data_segment_sizes_.get()); instance->set_dropped_elem_segments(dropped_elem_segments_.get()); } private: const std::unique_ptr imported_function_targets_; const std::unique_ptr imported_mutable_globals_; const std::unique_ptr data_segment_starts_; const std::unique_ptr data_segment_sizes_; const std::unique_ptr dropped_elem_segments_; }; size_t EstimateNativeAllocationsSize(const WasmModule* module) { size_t estimate = sizeof(WasmInstanceNativeAllocations) + (1 * kSystemPointerSize * module->num_imported_mutable_globals) + (2 * kSystemPointerSize * module->num_imported_functions) + ((kSystemPointerSize + sizeof(uint32_t) + sizeof(uint8_t)) * module->num_declared_data_segments); return estimate; } enum DispatchTableElements : int { kDispatchTableInstanceOffset, kDispatchTableIndexOffset, // Marker: kDispatchTableNumElements }; } // namespace // static Handle WasmModuleObject::New( Isolate* isolate, std::shared_ptr native_module, Handle