| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_WASM_MODULE_H_ | 5 #ifndef V8_WASM_MODULE_H_ |
| 6 #define V8_WASM_MODULE_H_ | 6 #define V8_WASM_MODULE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "src/api.h" | 10 #include "src/api.h" |
| 11 #include "src/handles.h" | 11 #include "src/handles.h" |
| 12 #include "src/parsing/preparse-data.h" | 12 #include "src/parsing/preparse-data.h" |
| 13 | 13 |
| 14 #include "src/wasm/wasm-opcodes.h" | 14 #include "src/wasm/wasm-opcodes.h" |
| 15 #include "src/wasm/wasm-result.h" | 15 #include "src/wasm/wasm-result.h" |
| 16 | 16 |
| 17 namespace v8 { | 17 namespace v8 { |
| 18 namespace internal { | 18 namespace internal { |
| 19 | 19 |
| 20 namespace compiler { | 20 namespace compiler { |
| 21 class CallDescriptor; | 21 class CallDescriptor; |
| 22 class WasmCompilationUnit; | 22 class WasmCompilationUnit; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace wasm { | 25 namespace wasm { |
| 26 const size_t kMaxModuleSize = 1024 * 1024 * 1024; | 26 const size_t kMaxModuleSize = 1024 * 1024 * 1024; |
| 27 const size_t kMaxFunctionSize = 128 * 1024; | 27 const size_t kMaxFunctionSize = 128 * 1024; |
| 28 const size_t kMaxStringSize = 256; | 28 const size_t kMaxStringSize = 256; |
| 29 const uint32_t kWasmMagic = 0x6d736100; | 29 const uint32_t kWasmMagic = 0x6d736100; |
| 30 const uint32_t kWasmVersion = 0x0b; | 30 const uint32_t kWasmVersion = 0x0c; |
| 31 |
| 31 const uint8_t kWasmFunctionTypeForm = 0x40; | 32 const uint8_t kWasmFunctionTypeForm = 0x40; |
| 33 const uint8_t kWasmAnyFunctionTypeForm = 0x20; |
| 32 | 34 |
| 33 // WebAssembly sections are named as strings in the binary format, but | 35 enum WasmSectionCode { |
| 34 // internally V8 uses an enum to handle them. | 36 kUnknownSectionCode = 0, // code for unknown sections |
| 35 // | 37 kTypeSectionCode = 1, // Function signature declarations |
| 36 // Entries have the form F(enumerator, string). | 38 kImportSectionCode = 2, // Import declarations |
| 37 #define FOR_EACH_WASM_SECTION_TYPE(F) \ | 39 kFunctionSectionCode = 3, // Function declarations |
| 38 F(Signatures, 1, "type") \ | 40 kTableSectionCode = 4, // Indirect function table and other tables |
| 39 F(ImportTable, 2, "import") \ | 41 kMemorySectionCode = 5, // Memory attributes |
| 40 F(FunctionSignatures, 3, "function") \ | 42 kGlobalSectionCode = 6, // Global declarations |
| 41 F(FunctionTable, 4, "table") \ | 43 kExportSectionCode = 7, // Exports |
| 42 F(Memory, 5, "memory") \ | 44 kStartSectionCode = 8, // Start function declaration |
| 43 F(ExportTable, 6, "export") \ | 45 kElementSectionCode = 9, // Elements section |
| 44 F(StartFunction, 7, "start") \ | 46 kCodeSectionCode = 10, // Function code |
| 45 F(FunctionBodies, 8, "code") \ | 47 kDataSectionCode = 11, // Data segments |
| 46 F(DataSegments, 9, "data") \ | 48 kNameSectionCode = 12, // Name section (encoded as a string) |
| 47 F(Names, 10, "name") \ | 49 }; |
| 48 F(Globals, 0, "global") \ | |
| 49 F(End, 0, "end") | |
| 50 | 50 |
| 51 // Contants for the above section types: {LEB128 length, characters...}. | 51 inline bool IsValidSectionCode(uint8_t byte) { |
| 52 #define WASM_SECTION_MEMORY 6, 'm', 'e', 'm', 'o', 'r', 'y' | 52 return kTypeSectionCode <= byte && byte <= kDataSectionCode; |
| 53 #define WASM_SECTION_SIGNATURES 4, 't', 'y', 'p', 'e' | 53 } |
| 54 #define WASM_SECTION_GLOBALS 6, 'g', 'l', 'o', 'b', 'a', 'l' | |
| 55 #define WASM_SECTION_DATA_SEGMENTS 4, 'd', 'a', 't', 'a' | |
| 56 #define WASM_SECTION_FUNCTION_TABLE 5, 't', 'a', 'b', 'l', 'e' | |
| 57 #define WASM_SECTION_END 3, 'e', 'n', 'd' | |
| 58 #define WASM_SECTION_START_FUNCTION 5, 's', 't', 'a', 'r', 't' | |
| 59 #define WASM_SECTION_IMPORT_TABLE 6, 'i', 'm', 'p', 'o', 'r', 't' | |
| 60 #define WASM_SECTION_EXPORT_TABLE 6, 'e', 'x', 'p', 'o', 'r', 't' | |
| 61 #define WASM_SECTION_FUNCTION_SIGNATURES \ | |
| 62 8, 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n' | |
| 63 #define WASM_SECTION_FUNCTION_BODIES 4, 'c', 'o', 'd', 'e' | |
| 64 #define WASM_SECTION_NAMES 4, 'n', 'a', 'm', 'e' | |
| 65 | 54 |
| 66 // Constants for the above section headers' size (LEB128 + characters). | 55 const char* SectionName(WasmSectionCode code); |
| 67 #define WASM_SECTION_MEMORY_SIZE ((size_t)7) | |
| 68 #define WASM_SECTION_SIGNATURES_SIZE ((size_t)5) | |
| 69 #define WASM_SECTION_GLOBALS_SIZE ((size_t)7) | |
| 70 #define WASM_SECTION_DATA_SEGMENTS_SIZE ((size_t)5) | |
| 71 #define WASM_SECTION_FUNCTION_TABLE_SIZE ((size_t)6) | |
| 72 #define WASM_SECTION_END_SIZE ((size_t)4) | |
| 73 #define WASM_SECTION_START_FUNCTION_SIZE ((size_t)6) | |
| 74 #define WASM_SECTION_IMPORT_TABLE_SIZE ((size_t)7) | |
| 75 #define WASM_SECTION_EXPORT_TABLE_SIZE ((size_t)7) | |
| 76 #define WASM_SECTION_FUNCTION_SIGNATURES_SIZE ((size_t)9) | |
| 77 #define WASM_SECTION_FUNCTION_BODIES_SIZE ((size_t)5) | |
| 78 #define WASM_SECTION_NAMES_SIZE ((size_t)5) | |
| 79 | 56 |
| 80 class WasmDebugInfo; | 57 class WasmDebugInfo; |
| 81 | 58 |
| 82 struct V8_EXPORT_PRIVATE WasmSection { | 59 // Constants for fixed-size elements within a module. |
| 83 enum class Code : uint32_t { | 60 static const uint32_t kMaxReturnCount = 1; |
| 84 #define F(enumerator, order, string) enumerator, | 61 static const uint8_t kResizableMaximumFlag = 1; |
| 85 FOR_EACH_WASM_SECTION_TYPE(F) | 62 static const int32_t kInvalidFunctionIndex = -1; |
| 86 #undef F | 63 |
| 87 Max | 64 enum WasmExternalKind { |
| 88 }; | 65 kExternalFunction = 0, |
| 89 static WasmSection::Code begin(); | 66 kExternalTable = 1, |
| 90 static WasmSection::Code end(); | 67 kExternalMemory = 2, |
| 91 static WasmSection::Code next(WasmSection::Code code); | 68 kExternalGlobal = 3 |
| 92 static const char* getName(Code code); | |
| 93 static int getOrder(Code code); | |
| 94 static size_t getNameLength(Code code); | |
| 95 static WasmSection::Code lookup(const byte* string, uint32_t length); | |
| 96 }; | 69 }; |
| 97 | 70 |
| 98 enum WasmFunctionDeclBit { | 71 // Representation of an initializer expression. |
| 99 kDeclFunctionName = 0x01, | 72 struct WasmInitExpr { |
| 100 kDeclFunctionExport = 0x08 | 73 enum WasmInitKind { |
| 74 kNone, |
| 75 kGlobalIndex, |
| 76 kI32Const, |
| 77 kI64Const, |
| 78 kF32Const, |
| 79 kF64Const |
| 80 } kind; |
| 81 |
| 82 union { |
| 83 int32_t i32_const; |
| 84 int64_t i64_const; |
| 85 float f32_const; |
| 86 double f64_const; |
| 87 uint32_t global_index; |
| 88 } val; |
| 101 }; | 89 }; |
| 102 | 90 |
| 103 // Constants for fixed-size elements within a module. | 91 #define NO_INIT \ |
| 104 static const size_t kDeclMemorySize = 3; | 92 { \ |
| 105 static const size_t kDeclDataSegmentSize = 13; | 93 WasmInitExpr::kNone, { 0u } \ |
| 106 | 94 } |
| 107 static const uint32_t kMaxReturnCount = 1; | |
| 108 | 95 |
| 109 // Static representation of a WASM function. | 96 // Static representation of a WASM function. |
| 110 struct WasmFunction { | 97 struct WasmFunction { |
| 111 FunctionSig* sig; // signature of the function. | 98 FunctionSig* sig; // signature of the function. |
| 112 uint32_t func_index; // index into the function table. | 99 uint32_t func_index; // index into the function table. |
| 113 uint32_t sig_index; // index into the signature table. | 100 uint32_t sig_index; // index into the signature table. |
| 114 uint32_t name_offset; // offset in the module bytes of the name, if any. | 101 uint32_t name_offset; // offset in the module bytes of the name, if any. |
| 115 uint32_t name_length; // length in bytes of the name. | 102 uint32_t name_length; // length in bytes of the name. |
| 116 uint32_t code_start_offset; // offset in the module bytes of code start. | 103 uint32_t code_start_offset; // offset in the module bytes of code start. |
| 117 uint32_t code_end_offset; // offset in the module bytes of code end. | 104 uint32_t code_end_offset; // offset in the module bytes of code end. |
| 118 }; | 105 bool imported; |
| 119 | 106 bool exported; |
| 120 // Static representation of an imported WASM function. | |
| 121 struct WasmImport { | |
| 122 FunctionSig* sig; // signature of the function. | |
| 123 uint32_t sig_index; // index into the signature table. | |
| 124 uint32_t module_name_offset; // offset in module bytes of the module name. | |
| 125 uint32_t module_name_length; // length in bytes of the module name. | |
| 126 uint32_t function_name_offset; // offset in module bytes of the import name. | |
| 127 uint32_t function_name_length; // length in bytes of the import name. | |
| 128 }; | |
| 129 | |
| 130 // Static representation of an exported WASM function. | |
| 131 struct WasmExport { | |
| 132 uint32_t func_index; // index into the function table. | |
| 133 uint32_t name_offset; // offset in module bytes of the name to export. | |
| 134 uint32_t name_length; // length in bytes of the exported name. | |
| 135 }; | 107 }; |
| 136 | 108 |
| 137 // Static representation of a wasm global variable. | 109 // Static representation of a wasm global variable. |
| 138 struct WasmGlobal { | 110 struct WasmGlobal { |
| 139 uint32_t name_offset; // offset in the module bytes of the name, if any. | |
| 140 uint32_t name_length; // length in bytes of the global name. | |
| 141 LocalType type; // type of the global. | 111 LocalType type; // type of the global. |
| 142 uint32_t offset; // offset from beginning of globals area. | 112 bool mutability; // {true} if mutable. |
| 143 bool exported; // true if this global is exported. | 113 WasmInitExpr init; // the initialization expression of the global. |
| 114 uint32_t offset; // offset into global memory. |
| 115 bool imported; // true if imported. |
| 116 bool exported; // true if exported. |
| 144 }; | 117 }; |
| 145 | 118 |
| 146 // Static representation of a wasm data segment. | 119 // Static representation of a wasm data segment. |
| 147 struct WasmDataSegment { | 120 struct WasmDataSegment { |
| 148 uint32_t dest_addr; // destination memory address of the data. | 121 WasmInitExpr dest_addr; // destination memory address of the data. |
| 149 uint32_t source_offset; // start offset in the module bytes. | 122 uint32_t source_offset; // start offset in the module bytes. |
| 150 uint32_t source_size; // end offset in the module bytes. | 123 uint32_t source_size; // end offset in the module bytes. |
| 151 bool init; // true if loaded upon instantiation. | |
| 152 }; | 124 }; |
| 153 | 125 |
| 154 // Static representation of a wasm indirect call table. | 126 // Static representation of a wasm indirect call table. |
| 155 struct WasmIndirectFunctionTable { | 127 struct WasmIndirectFunctionTable { |
| 156 uint32_t size; // initial table size. | 128 uint32_t size; // initial table size. |
| 157 uint32_t max_size; // maximum table size. | 129 uint32_t max_size; // maximum table size. |
| 158 std::vector<uint16_t> values; // function table. | 130 std::vector<int32_t> values; // function table, -1 indicating invalid. |
| 131 bool imported; // true if imported. |
| 132 bool exported; // true if exported. |
| 133 }; |
| 134 |
| 135 // Static representation of how to initialize a table. |
| 136 struct WasmTableInit { |
| 137 uint32_t table_index; |
| 138 WasmInitExpr offset; |
| 139 std::vector<uint32_t> entries; |
| 140 }; |
| 141 |
| 142 // Static representation of a WASM import. |
| 143 struct WasmImport { |
| 144 uint32_t module_name_length; // length in bytes of the module name. |
| 145 uint32_t module_name_offset; // offset in module bytes of the module name. |
| 146 uint32_t field_name_length; // length in bytes of the import name. |
| 147 uint32_t field_name_offset; // offset in module bytes of the import name. |
| 148 WasmExternalKind kind; // kind of the import. |
| 149 uint32_t index; // index into the respective space. |
| 150 }; |
| 151 |
| 152 // Static representation of a WASM export. |
| 153 struct WasmExport { |
| 154 uint32_t name_length; // length in bytes of the exported name. |
| 155 uint32_t name_offset; // offset in module bytes of the name to export. |
| 156 WasmExternalKind kind; // kind of the export. |
| 157 uint32_t index; // index into the respective space. |
| 159 }; | 158 }; |
| 160 | 159 |
| 161 enum ModuleOrigin { kWasmOrigin, kAsmJsOrigin }; | 160 enum ModuleOrigin { kWasmOrigin, kAsmJsOrigin }; |
| 162 | 161 |
| 163 // Static representation of a module. | 162 // Static representation of a module. |
| 164 struct WasmModule { | 163 struct WasmModule { |
| 165 static const uint32_t kPageSize = 0x10000; // Page size, 64kb. | 164 static const uint32_t kPageSize = 0x10000; // Page size, 64kb. |
| 165 static const uint32_t kMaxLegalPages = 65536; // Maximum legal pages |
| 166 static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb | 166 static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb |
| 167 static const uint32_t kMaxMemPages = 16384; // Maximum memory size = 1gb | 167 static const uint32_t kMaxMemPages = 16384; // Maximum memory size = 1gb |
| 168 | 168 |
| 169 const byte* module_start; // starting address for the module bytes. | 169 const byte* module_start; // starting address for the module bytes. |
| 170 const byte* module_end; // end address for the module bytes. | 170 const byte* module_end; // end address for the module bytes. |
| 171 uint32_t min_mem_pages; // minimum size of the memory in 64k pages. | 171 uint32_t min_mem_pages; // minimum size of the memory in 64k pages. |
| 172 uint32_t max_mem_pages; // maximum size of the memory in 64k pages. | 172 uint32_t max_mem_pages; // maximum size of the memory in 64k pages. |
| 173 bool mem_export; // true if the memory is exported. | 173 bool mem_export; // true if the memory is exported. |
| 174 bool mem_external; // true if the memory is external. | |
| 175 // TODO(wasm): reconcile start function index being an int with | 174 // TODO(wasm): reconcile start function index being an int with |
| 176 // the fact that we index on uint32_t, so we may technically not be | 175 // the fact that we index on uint32_t, so we may technically not be |
| 177 // able to represent some start_function_index -es. | 176 // able to represent some start_function_index -es. |
| 178 int start_function_index; // start function, if any. | 177 int start_function_index; // start function, if any. |
| 179 ModuleOrigin origin; // origin of the module | 178 ModuleOrigin origin; // origin of the module |
| 180 | 179 |
| 181 std::vector<WasmGlobal> globals; // globals in this module. | 180 std::vector<WasmGlobal> globals; // globals in this module. |
| 182 uint32_t globals_size; // size of globals table. | 181 uint32_t globals_size; // size of globals table. |
| 182 uint32_t num_imported_functions; // number of imported functions. |
| 183 uint32_t num_declared_functions; // number of declared functions. |
| 184 uint32_t num_exported_functions; // number of exported functions. |
| 183 std::vector<FunctionSig*> signatures; // signatures in this module. | 185 std::vector<FunctionSig*> signatures; // signatures in this module. |
| 184 std::vector<WasmFunction> functions; // functions in this module. | 186 std::vector<WasmFunction> functions; // functions in this module. |
| 185 std::vector<WasmDataSegment> data_segments; // data segments in this module. | 187 std::vector<WasmDataSegment> data_segments; // data segments in this module. |
| 186 std::vector<WasmIndirectFunctionTable> function_tables; // function tables. | 188 std::vector<WasmIndirectFunctionTable> function_tables; // function tables. |
| 187 std::vector<WasmImport> import_table; // import table. | 189 std::vector<WasmImport> import_table; // import table. |
| 188 std::vector<WasmExport> export_table; // export table. | 190 std::vector<WasmExport> export_table; // export table. |
| 191 std::vector<WasmTableInit> table_inits; // initializations of tables |
| 189 // We store the semaphore here to extend its lifetime. In <libc-2.21, which we | 192 // We store the semaphore here to extend its lifetime. In <libc-2.21, which we |
| 190 // use on the try bots, semaphore::Wait() can return while some compilation | 193 // use on the try bots, semaphore::Wait() can return while some compilation |
| 191 // tasks are still executing semaphore::Signal(). If the semaphore is cleaned | 194 // tasks are still executing semaphore::Signal(). If the semaphore is cleaned |
| 192 // up right after semaphore::Wait() returns, then this can cause an | 195 // up right after semaphore::Wait() returns, then this can cause an |
| 193 // invalid-semaphore error in the compilation tasks. | 196 // invalid-semaphore error in the compilation tasks. |
| 194 // TODO(wasm): Move this semaphore back to CompileInParallel when the try bots | 197 // TODO(wasm): Move this semaphore back to CompileInParallel when the try bots |
| 195 // switch to libc-2.21 or higher. | 198 // switch to libc-2.21 or higher. |
| 196 std::unique_ptr<base::Semaphore> pending_tasks; | 199 std::unique_ptr<base::Semaphore> pending_tasks; |
| 197 | 200 |
| 198 WasmModule() : WasmModule(nullptr) {} | 201 WasmModule() : WasmModule(nullptr) {} |
| (...skipping 28 matching lines...) Expand all Loading... |
| 227 } | 230 } |
| 228 | 231 |
| 229 // Checks the given offset range is contained within the module bytes. | 232 // Checks the given offset range is contained within the module bytes. |
| 230 bool BoundsCheck(uint32_t start, uint32_t end) const { | 233 bool BoundsCheck(uint32_t start, uint32_t end) const { |
| 231 size_t size = module_end - module_start; | 234 size_t size = module_end - module_start; |
| 232 return start <= size && end <= size; | 235 return start <= size && end <= size; |
| 233 } | 236 } |
| 234 | 237 |
| 235 // Creates a new instantiation of the module in the given isolate. | 238 // Creates a new instantiation of the module in the given isolate. |
| 236 V8_EXPORT_PRIVATE static MaybeHandle<JSObject> Instantiate( | 239 V8_EXPORT_PRIVATE static MaybeHandle<JSObject> Instantiate( |
| 237 Isolate* isolate, Handle<JSObject> module_object, Handle<JSReceiver> ffi, | 240 Isolate* isolate, ErrorThrower* thrower, Handle<JSObject> module_object, |
| 238 Handle<JSArrayBuffer> memory); | 241 Handle<JSReceiver> ffi, Handle<JSArrayBuffer> memory); |
| 239 | 242 |
| 240 MaybeHandle<FixedArray> CompileFunctions(Isolate* isolate, | 243 MaybeHandle<FixedArray> CompileFunctions(Isolate* isolate, |
| 241 ErrorThrower* thrower) const; | 244 ErrorThrower* thrower) const; |
| 242 | 245 |
| 243 private: | 246 private: |
| 244 DISALLOW_COPY_AND_ASSIGN(WasmModule); | 247 DISALLOW_COPY_AND_ASSIGN(WasmModule); |
| 245 }; | 248 }; |
| 246 | 249 |
| 247 // An instantiated WASM module, including memory, function table, etc. | 250 // An instantiated WASM module, including memory, function table, etc. |
| 248 struct WasmModuleInstance { | 251 struct WasmModuleInstance { |
| 249 const WasmModule* module; // static representation of the module. | 252 const WasmModule* module; // static representation of the module. |
| 250 // -- Heap allocated -------------------------------------------------------- | 253 // -- Heap allocated -------------------------------------------------------- |
| 251 Handle<JSObject> js_object; // JavaScript module object. | 254 Handle<JSObject> js_object; // JavaScript module object. |
| 252 Handle<Context> context; // JavaScript native context. | 255 Handle<Context> context; // JavaScript native context. |
| 253 Handle<JSArrayBuffer> mem_buffer; // Handle to array buffer of memory. | 256 Handle<JSArrayBuffer> mem_buffer; // Handle to array buffer of memory. |
| 254 Handle<JSArrayBuffer> globals_buffer; // Handle to array buffer of globals. | 257 Handle<JSArrayBuffer> globals_buffer; // Handle to array buffer of globals. |
| 255 std::vector<Handle<FixedArray>> function_tables; // indirect function tables. | 258 std::vector<Handle<FixedArray>> function_tables; // indirect function tables. |
| 256 std::vector<Handle<Code>> function_code; // code objects for each function. | 259 std::vector<Handle<Code>> function_code; // code objects for each function. |
| 257 std::vector<Handle<Code>> import_code; // code objects for each import. | |
| 258 // -- raw memory ------------------------------------------------------------ | 260 // -- raw memory ------------------------------------------------------------ |
| 259 byte* mem_start; // start of linear memory. | 261 byte* mem_start; // start of linear memory. |
| 260 uint32_t mem_size; // size of the linear memory. | 262 uint32_t mem_size; // size of the linear memory. |
| 261 // -- raw globals ----------------------------------------------------------- | 263 // -- raw globals ----------------------------------------------------------- |
| 262 byte* globals_start; // start of the globals area. | 264 byte* globals_start; // start of the globals area. |
| 263 | 265 |
| 264 explicit WasmModuleInstance(const WasmModule* m) | 266 explicit WasmModuleInstance(const WasmModule* m) |
| 265 : module(m), | 267 : module(m), |
| 266 function_tables(m->function_tables.size()), | 268 function_tables(m->function_tables.size()), |
| 267 function_code(m->functions.size()), | 269 function_code(m->functions.size()), |
| 268 import_code(m->import_table.size()), | |
| 269 mem_start(nullptr), | 270 mem_start(nullptr), |
| 270 mem_size(0), | 271 mem_size(0), |
| 271 globals_start(nullptr) {} | 272 globals_start(nullptr) {} |
| 272 }; | 273 }; |
| 273 | 274 |
| 274 // Interface provided to the decoder/graph builder which contains only | 275 // Interface provided to the decoder/graph builder which contains only |
| 275 // minimal information about the globals, functions, and function tables. | 276 // minimal information about the globals, functions, and function tables. |
| 276 struct ModuleEnv { | 277 struct ModuleEnv { |
| 277 const WasmModule* module; | 278 const WasmModule* module; |
| 278 WasmModuleInstance* instance; | 279 WasmModuleInstance* instance; |
| 279 ModuleOrigin origin; | 280 ModuleOrigin origin; |
| 280 // TODO(mtrofin): remove this once we introduce WASM_DIRECT_CALL | |
| 281 // reloc infos. | |
| 282 std::vector<Handle<Code>> placeholders; | |
| 283 | 281 |
| 284 bool IsValidGlobal(uint32_t index) const { | 282 bool IsValidGlobal(uint32_t index) const { |
| 285 return module && index < module->globals.size(); | 283 return module && index < module->globals.size(); |
| 286 } | 284 } |
| 287 bool IsValidFunction(uint32_t index) const { | 285 bool IsValidFunction(uint32_t index) const { |
| 288 return module && index < module->functions.size(); | 286 return module && index < module->functions.size(); |
| 289 } | 287 } |
| 290 bool IsValidSignature(uint32_t index) const { | 288 bool IsValidSignature(uint32_t index) const { |
| 291 return module && index < module->signatures.size(); | 289 return module && index < module->signatures.size(); |
| 292 } | 290 } |
| 293 bool IsValidImport(uint32_t index) const { | |
| 294 return module && index < module->import_table.size(); | |
| 295 } | |
| 296 bool IsValidTable(uint32_t index) const { | 291 bool IsValidTable(uint32_t index) const { |
| 297 return module && index < module->function_tables.size(); | 292 return module && index < module->function_tables.size(); |
| 298 } | 293 } |
| 299 LocalType GetGlobalType(uint32_t index) { | 294 LocalType GetGlobalType(uint32_t index) { |
| 300 DCHECK(IsValidGlobal(index)); | 295 DCHECK(IsValidGlobal(index)); |
| 301 return module->globals[index].type; | 296 return module->globals[index].type; |
| 302 } | 297 } |
| 303 FunctionSig* GetFunctionSignature(uint32_t index) { | 298 FunctionSig* GetFunctionSignature(uint32_t index) { |
| 304 DCHECK(IsValidFunction(index)); | 299 DCHECK(IsValidFunction(index)); |
| 305 return module->functions[index].sig; | 300 return module->functions[index].sig; |
| 306 } | 301 } |
| 307 FunctionSig* GetImportSignature(uint32_t index) { | |
| 308 DCHECK(IsValidImport(index)); | |
| 309 return module->import_table[index].sig; | |
| 310 } | |
| 311 FunctionSig* GetSignature(uint32_t index) { | 302 FunctionSig* GetSignature(uint32_t index) { |
| 312 DCHECK(IsValidSignature(index)); | 303 DCHECK(IsValidSignature(index)); |
| 313 return module->signatures[index]; | 304 return module->signatures[index]; |
| 314 } | 305 } |
| 315 const WasmIndirectFunctionTable* GetTable(uint32_t index) const { | 306 const WasmIndirectFunctionTable* GetTable(uint32_t index) const { |
| 316 DCHECK(IsValidTable(index)); | 307 DCHECK(IsValidTable(index)); |
| 317 return &module->function_tables[index]; | 308 return &module->function_tables[index]; |
| 318 } | 309 } |
| 319 | 310 |
| 320 bool asm_js() { return origin == kAsmJsOrigin; } | 311 bool asm_js() { return origin == kAsmJsOrigin; } |
| 321 | 312 |
| 322 Handle<Code> GetCodeOrPlaceholder(uint32_t index) const; | 313 Handle<Code> GetFunctionCode(uint32_t index) { |
| 323 Handle<Code> GetImportCode(uint32_t index); | 314 DCHECK_NOT_NULL(instance); |
| 315 return instance->function_code[index]; |
| 316 } |
| 324 | 317 |
| 325 static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone, | 318 static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone, |
| 326 FunctionSig* sig); | 319 FunctionSig* sig); |
| 327 static compiler::CallDescriptor* GetI32WasmCallDescriptor( | 320 static compiler::CallDescriptor* GetI32WasmCallDescriptor( |
| 328 Zone* zone, compiler::CallDescriptor* descriptor); | 321 Zone* zone, compiler::CallDescriptor* descriptor); |
| 329 compiler::CallDescriptor* GetCallDescriptor(Zone* zone, uint32_t index); | 322 compiler::CallDescriptor* GetCallDescriptor(Zone* zone, uint32_t index); |
| 330 }; | 323 }; |
| 331 | 324 |
| 332 // A helper for printing out the names of functions. | 325 // A helper for printing out the names of functions. |
| 333 struct WasmFunctionName { | 326 struct WasmFunctionName { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 const std::vector<Handle<Code>>* code_table); | 391 const std::vector<Handle<Code>>* code_table); |
| 399 | 392 |
| 400 Handle<JSObject> CreateCompiledModuleObject(Isolate* isolate, | 393 Handle<JSObject> CreateCompiledModuleObject(Isolate* isolate, |
| 401 Handle<FixedArray> compiled_module, | 394 Handle<FixedArray> compiled_module, |
| 402 ModuleOrigin origin); | 395 ModuleOrigin origin); |
| 403 | 396 |
| 404 V8_EXPORT_PRIVATE MaybeHandle<JSObject> CreateModuleObjectFromBytes( | 397 V8_EXPORT_PRIVATE MaybeHandle<JSObject> CreateModuleObjectFromBytes( |
| 405 Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower, | 398 Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower, |
| 406 ModuleOrigin origin); | 399 ModuleOrigin origin); |
| 407 | 400 |
| 401 // Get the number of imported functions for a WASM instance. |
| 402 uint32_t GetNumImportedFunctions(Handle<JSObject> wasm_object); |
| 403 |
| 408 // Assumed to be called with a code object associated to a wasm module instance. | 404 // Assumed to be called with a code object associated to a wasm module instance. |
| 409 // Intended to be called from runtime functions. | 405 // Intended to be called from runtime functions. |
| 410 // Returns undefined if the runtime support was not setup, nullptr if the | 406 // Returns undefined if the runtime support was not setup, nullptr if the |
| 411 // instance | 407 // instance |
| 412 // was collected, or the instance object owning the Code object | 408 // was collected, or the instance object owning the Code object |
| 413 Object* GetOwningWasmInstance(Object* undefined, Code* code); | 409 Object* GetOwningWasmInstance(Object* undefined, Code* code); |
| 414 | 410 |
| 415 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, | 411 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, |
| 416 Handle<JSObject> instance); | 412 Handle<JSObject> instance); |
| 417 void SetInstanceMemory(Handle<JSObject> instance, JSArrayBuffer* buffer); | 413 void SetInstanceMemory(Handle<JSObject> instance, JSArrayBuffer* buffer); |
| 418 | 414 |
| 419 namespace testing { | 415 namespace testing { |
| 420 | 416 |
| 421 void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> module_obj, | 417 void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> module_obj, |
| 422 int instance_count); | 418 int instance_count); |
| 423 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); | 419 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); |
| 424 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); | 420 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); |
| 425 | 421 |
| 426 } // namespace testing | 422 } // namespace testing |
| 427 } // namespace wasm | 423 } // namespace wasm |
| 428 } // namespace internal | 424 } // namespace internal |
| 429 } // namespace v8 | 425 } // namespace v8 |
| 430 | 426 |
| 431 #endif // V8_WASM_MODULE_H_ | 427 #endif // V8_WASM_MODULE_H_ |
| OLD | NEW |