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" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 #define WASM_SECTION_END_SIZE ((size_t)4) | 72 #define WASM_SECTION_END_SIZE ((size_t)4) |
73 #define WASM_SECTION_START_FUNCTION_SIZE ((size_t)6) | 73 #define WASM_SECTION_START_FUNCTION_SIZE ((size_t)6) |
74 #define WASM_SECTION_IMPORT_TABLE_SIZE ((size_t)7) | 74 #define WASM_SECTION_IMPORT_TABLE_SIZE ((size_t)7) |
75 #define WASM_SECTION_EXPORT_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) | 76 #define WASM_SECTION_FUNCTION_SIGNATURES_SIZE ((size_t)9) |
77 #define WASM_SECTION_FUNCTION_BODIES_SIZE ((size_t)5) | 77 #define WASM_SECTION_FUNCTION_BODIES_SIZE ((size_t)5) |
78 #define WASM_SECTION_NAMES_SIZE ((size_t)5) | 78 #define WASM_SECTION_NAMES_SIZE ((size_t)5) |
79 | 79 |
80 class WasmDebugInfo; | 80 class WasmDebugInfo; |
81 | 81 |
82 struct WasmSection { | 82 struct V8_EXPORT_PRIVATE WasmSection { |
83 enum class Code : uint32_t { | 83 enum class Code : uint32_t { |
84 #define F(enumerator, order, string) enumerator, | 84 #define F(enumerator, order, string) enumerator, |
85 FOR_EACH_WASM_SECTION_TYPE(F) | 85 FOR_EACH_WASM_SECTION_TYPE(F) |
86 #undef F | 86 #undef F |
87 Max | 87 Max |
88 }; | 88 }; |
89 static WasmSection::Code begin(); | 89 static WasmSection::Code begin(); |
90 static WasmSection::Code end(); | 90 static WasmSection::Code end(); |
91 static WasmSection::Code next(WasmSection::Code code); | 91 static WasmSection::Code next(WasmSection::Code code); |
92 static const char* getName(Code code); | 92 static const char* getName(Code code); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 return GetNameOrNull(function->name_offset, function->name_length); | 226 return GetNameOrNull(function->name_offset, function->name_length); |
227 } | 227 } |
228 | 228 |
229 // Checks the given offset range is contained within the module bytes. | 229 // Checks the given offset range is contained within the module bytes. |
230 bool BoundsCheck(uint32_t start, uint32_t end) const { | 230 bool BoundsCheck(uint32_t start, uint32_t end) const { |
231 size_t size = module_end - module_start; | 231 size_t size = module_end - module_start; |
232 return start <= size && end <= size; | 232 return start <= size && end <= size; |
233 } | 233 } |
234 | 234 |
235 // Creates a new instantiation of the module in the given isolate. | 235 // Creates a new instantiation of the module in the given isolate. |
236 static MaybeHandle<JSObject> Instantiate(Isolate* isolate, | 236 V8_EXPORT_PRIVATE static MaybeHandle<JSObject> Instantiate( |
237 Handle<JSObject> module_object, | 237 Isolate* isolate, Handle<JSObject> module_object, Handle<JSReceiver> ffi, |
238 Handle<JSReceiver> ffi, | 238 Handle<JSArrayBuffer> memory); |
239 Handle<JSArrayBuffer> memory); | |
240 | 239 |
241 MaybeHandle<FixedArray> CompileFunctions(Isolate* isolate, | 240 MaybeHandle<FixedArray> CompileFunctions(Isolate* isolate, |
242 ErrorThrower* thrower) const; | 241 ErrorThrower* thrower) const; |
243 | 242 |
244 private: | 243 private: |
245 DISALLOW_COPY_AND_ASSIGN(WasmModule); | 244 DISALLOW_COPY_AND_ASSIGN(WasmModule); |
246 }; | 245 }; |
247 | 246 |
248 // An instantiated WASM module, including memory, function table, etc. | 247 // An instantiated WASM module, including memory, function table, etc. |
249 struct WasmModuleInstance { | 248 struct WasmModuleInstance { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 | 394 |
396 // Populates a function table by replacing function indices with handles to | 395 // Populates a function table by replacing function indices with handles to |
397 // the compiled code. | 396 // the compiled code. |
398 void PopulateFunctionTable(Handle<FixedArray> table, uint32_t table_size, | 397 void PopulateFunctionTable(Handle<FixedArray> table, uint32_t table_size, |
399 const std::vector<Handle<Code>>* code_table); | 398 const std::vector<Handle<Code>>* code_table); |
400 | 399 |
401 Handle<JSObject> CreateCompiledModuleObject(Isolate* isolate, | 400 Handle<JSObject> CreateCompiledModuleObject(Isolate* isolate, |
402 Handle<FixedArray> compiled_module, | 401 Handle<FixedArray> compiled_module, |
403 ModuleOrigin origin); | 402 ModuleOrigin origin); |
404 | 403 |
405 MaybeHandle<JSObject> CreateModuleObjectFromBytes(Isolate* isolate, | 404 V8_EXPORT_PRIVATE MaybeHandle<JSObject> CreateModuleObjectFromBytes( |
406 const byte* start, | 405 Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower, |
407 const byte* end, | 406 ModuleOrigin origin); |
408 ErrorThrower* thrower, | |
409 ModuleOrigin origin); | |
410 | 407 |
411 // Assumed to be called with a code object associated to a wasm module instance. | 408 // Assumed to be called with a code object associated to a wasm module instance. |
412 // Intended to be called from runtime functions. | 409 // Intended to be called from runtime functions. |
413 // Returns undefined if the runtime support was not setup, nullptr if the | 410 // Returns undefined if the runtime support was not setup, nullptr if the |
414 // instance | 411 // instance |
415 // was collected, or the instance object owning the Code object | 412 // was collected, or the instance object owning the Code object |
416 Object* GetOwningWasmInstance(Object* undefined, Code* code); | 413 Object* GetOwningWasmInstance(Object* undefined, Code* code); |
417 | 414 |
418 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, | 415 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, |
419 Handle<JSObject> instance); | 416 Handle<JSObject> instance); |
420 void SetInstanceMemory(Handle<JSObject> instance, JSArrayBuffer* buffer); | 417 void SetInstanceMemory(Handle<JSObject> instance, JSArrayBuffer* buffer); |
421 | 418 |
422 namespace testing { | 419 namespace testing { |
423 | 420 |
424 void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> module_obj, | 421 void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> module_obj, |
425 int instance_count); | 422 int instance_count); |
426 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); | 423 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); |
427 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); | 424 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); |
428 | 425 |
429 } // namespace testing | 426 } // namespace testing |
430 } // namespace wasm | 427 } // namespace wasm |
431 } // namespace internal | 428 } // namespace internal |
432 } // namespace v8 | 429 } // namespace v8 |
433 | 430 |
434 #endif // V8_WASM_MODULE_H_ | 431 #endif // V8_WASM_MODULE_H_ |
OLD | NEW |