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