| 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/globals.h" | 11 #include "src/globals.h" |
| 12 #include "src/handles.h" | 12 #include "src/handles.h" |
| 13 #include "src/parsing/preparse-data.h" | 13 #include "src/parsing/preparse-data.h" |
| 14 | 14 |
| 15 #include "src/wasm/managed.h" | 15 #include "src/wasm/managed.h" |
| 16 #include "src/wasm/signature-map.h" | 16 #include "src/wasm/signature-map.h" |
| 17 #include "src/wasm/wasm-opcodes.h" | 17 #include "src/wasm/wasm-opcodes.h" |
| 18 | 18 |
| 19 namespace v8 { | 19 namespace v8 { |
| 20 namespace internal { | 20 namespace internal { |
| 21 | 21 |
| 22 class WasmCompiledModule; | 22 class WasmCompiledModule; |
| 23 class WasmDebugInfo; | 23 class WasmDebugInfo; |
| 24 class WasmModuleObject; | 24 class WasmModuleObject; |
| 25 class WasmInstanceObject; |
| 25 | 26 |
| 26 namespace compiler { | 27 namespace compiler { |
| 27 class CallDescriptor; | 28 class CallDescriptor; |
| 28 class WasmCompilationUnit; | 29 class WasmCompilationUnit; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace wasm { | 32 namespace wasm { |
| 32 class ErrorThrower; | 33 class ErrorThrower; |
| 33 | 34 |
| 34 const size_t kMaxModuleSize = 1024 * 1024 * 1024; | 35 const size_t kMaxModuleSize = 1024 * 1024 * 1024; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 return GetNameOrNull(function->name_offset, function->name_length); | 249 return GetNameOrNull(function->name_offset, function->name_length); |
| 249 } | 250 } |
| 250 | 251 |
| 251 // Checks the given offset range is contained within the module bytes. | 252 // Checks the given offset range is contained within the module bytes. |
| 252 bool BoundsCheck(uint32_t start, uint32_t end) const { | 253 bool BoundsCheck(uint32_t start, uint32_t end) const { |
| 253 size_t size = module_end - module_start; | 254 size_t size = module_end - module_start; |
| 254 return start <= size && end <= size; | 255 return start <= size && end <= size; |
| 255 } | 256 } |
| 256 | 257 |
| 257 // Creates a new instantiation of the module in the given isolate. | 258 // Creates a new instantiation of the module in the given isolate. |
| 258 static MaybeHandle<JSObject> Instantiate(Isolate* isolate, | 259 static MaybeHandle<WasmInstanceObject> Instantiate( |
| 259 ErrorThrower* thrower, | 260 Isolate* isolate, ErrorThrower* thrower, Handle<JSObject> wasm_module, |
| 260 Handle<JSObject> wasm_module, | 261 Handle<JSReceiver> ffi, Handle<JSArrayBuffer> memory); |
| 261 Handle<JSReceiver> ffi, | |
| 262 Handle<JSArrayBuffer> memory); | |
| 263 | 262 |
| 264 MaybeHandle<WasmCompiledModule> CompileFunctions( | 263 MaybeHandle<WasmCompiledModule> CompileFunctions( |
| 265 Isolate* isolate, Handle<Managed<WasmModule>> module_wrapper, | 264 Isolate* isolate, Handle<Managed<WasmModule>> module_wrapper, |
| 266 ErrorThrower* thrower) const; | 265 ErrorThrower* thrower) const; |
| 267 }; | 266 }; |
| 268 | 267 |
| 269 typedef Managed<WasmModule> WasmModuleWrapper; | 268 typedef Managed<WasmModule> WasmModuleWrapper; |
| 270 | 269 |
| 271 // An instantiated WASM module, including memory, function table, etc. | 270 // An instantiated WASM module, including memory, function table, etc. |
| 272 struct WasmInstance { | 271 struct WasmInstance { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 // Return the binary source bytes of a wasm module. | 362 // Return the binary source bytes of a wasm module. |
| 364 Handle<SeqOneByteString> GetWasmBytes(Handle<JSObject> wasm); | 363 Handle<SeqOneByteString> GetWasmBytes(Handle<JSObject> wasm); |
| 365 | 364 |
| 366 // Get the debug info associated with the given wasm object. | 365 // Get the debug info associated with the given wasm object. |
| 367 // If no debug info exists yet, it is created automatically. | 366 // If no debug info exists yet, it is created automatically. |
| 368 Handle<WasmDebugInfo> GetDebugInfo(Handle<JSObject> wasm); | 367 Handle<WasmDebugInfo> GetDebugInfo(Handle<JSObject> wasm); |
| 369 | 368 |
| 370 // Return the number of functions in the given wasm object. | 369 // Return the number of functions in the given wasm object. |
| 371 int GetNumberOfFunctions(Handle<JSObject> wasm); | 370 int GetNumberOfFunctions(Handle<JSObject> wasm); |
| 372 | 371 |
| 373 // Create and export JSFunction | |
| 374 Handle<JSFunction> WrapExportCodeAsJSFunction(Isolate* isolate, | |
| 375 Handle<Code> export_code, | |
| 376 Handle<String> name, | |
| 377 FunctionSig* sig, int func_index, | |
| 378 Handle<JSObject> instance); | |
| 379 | |
| 380 // Check whether the given object represents a WebAssembly.Instance instance. | 372 // Check whether the given object represents a WebAssembly.Instance instance. |
| 381 // This checks the number and type of internal fields, so it's not 100 percent | 373 // This checks the number and type of internal fields, so it's not 100 percent |
| 382 // secure. If it turns out that we need more complete checks, we could add a | 374 // secure. If it turns out that we need more complete checks, we could add a |
| 383 // special marker as internal field, which will definitely never occur anywhere | 375 // special marker as internal field, which will definitely never occur anywhere |
| 384 // else. | 376 // else. |
| 385 bool IsWasmInstance(Object* instance); | 377 bool IsWasmInstance(Object* instance); |
| 386 | 378 |
| 387 // Return the compiled module object for this WASM instance. | 379 // Return the compiled module object for this WASM instance. |
| 388 WasmCompiledModule* GetCompiledModule(Object* wasm_instance); | 380 WasmCompiledModule* GetCompiledModule(Object* wasm_instance); |
| 389 | 381 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 415 int func_index); | 407 int func_index); |
| 416 | 408 |
| 417 // Translate from byte offset in the module to function number and byte offset | 409 // Translate from byte offset in the module to function number and byte offset |
| 418 // within that function, encoded as line and column in the position info. | 410 // within that function, encoded as line and column in the position info. |
| 419 bool GetPositionInfo(Handle<WasmCompiledModule> compiled_module, | 411 bool GetPositionInfo(Handle<WasmCompiledModule> compiled_module, |
| 420 uint32_t position, Script::PositionInfo* info); | 412 uint32_t position, Script::PositionInfo* info); |
| 421 | 413 |
| 422 // Assumed to be called with a code object associated to a wasm module instance. | 414 // Assumed to be called with a code object associated to a wasm module instance. |
| 423 // Intended to be called from runtime functions. | 415 // Intended to be called from runtime functions. |
| 424 // Returns nullptr on failing to get owning instance. | 416 // Returns nullptr on failing to get owning instance. |
| 425 Object* GetOwningWasmInstance(Code* code); | 417 WasmInstanceObject* GetOwningWasmInstance(Code* code); |
| 426 | 418 |
| 427 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, | 419 MaybeHandle<JSArrayBuffer> GetInstanceMemory( |
| 428 Handle<JSObject> instance); | 420 Isolate* isolate, Handle<WasmInstanceObject> instance); |
| 429 | 421 |
| 430 int32_t GetInstanceMemorySize(Isolate* isolate, Handle<JSObject> instance); | 422 int32_t GetInstanceMemorySize(Isolate* isolate, |
| 423 Handle<WasmInstanceObject> instance); |
| 431 | 424 |
| 432 int32_t GrowInstanceMemory(Isolate* isolate, Handle<JSObject> instance, | 425 int32_t GrowInstanceMemory(Isolate* isolate, |
| 433 uint32_t pages); | 426 Handle<WasmInstanceObject> instance, uint32_t pages); |
| 434 | 427 |
| 435 void UpdateDispatchTables(Isolate* isolate, Handle<FixedArray> dispatch_tables, | 428 void UpdateDispatchTables(Isolate* isolate, Handle<FixedArray> dispatch_tables, |
| 436 int index, Handle<JSFunction> js_function); | 429 int index, Handle<JSFunction> js_function); |
| 437 | 430 |
| 438 namespace testing { | 431 namespace testing { |
| 439 | 432 |
| 440 void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> wasm_module, | 433 void ValidateInstancesChain(Isolate* isolate, |
| 434 Handle<WasmModuleObject> module_obj, |
| 441 int instance_count); | 435 int instance_count); |
| 442 void ValidateModuleState(Isolate* isolate, Handle<JSObject> wasm_module); | 436 void ValidateModuleState(Isolate* isolate, Handle<WasmModuleObject> module_obj); |
| 443 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); | 437 void ValidateOrphanedInstance(Isolate* isolate, |
| 438 Handle<WasmInstanceObject> instance); |
| 444 | 439 |
| 445 } // namespace testing | 440 } // namespace testing |
| 446 } // namespace wasm | 441 } // namespace wasm |
| 447 } // namespace internal | 442 } // namespace internal |
| 448 } // namespace v8 | 443 } // namespace v8 |
| 449 | 444 |
| 450 #endif // V8_WASM_MODULE_H_ | 445 #endif // V8_WASM_MODULE_H_ |
| OLD | NEW |