| 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 "src/api.h" | 8 #include "src/api.h" |
| 9 #include "src/handles.h" | 9 #include "src/handles.h" |
| 10 #include "src/wasm/wasm-opcodes.h" | 10 #include "src/wasm/wasm-opcodes.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 205 |
| 206 // Checks the given offset range is contained within the module bytes. | 206 // Checks the given offset range is contained within the module bytes. |
| 207 bool BoundsCheck(uint32_t start, uint32_t end) const { | 207 bool BoundsCheck(uint32_t start, uint32_t end) const { |
| 208 size_t size = module_end - module_start; | 208 size_t size = module_end - module_start; |
| 209 return start <= size && end <= size; | 209 return start <= size && end <= size; |
| 210 } | 210 } |
| 211 | 211 |
| 212 // Creates a new instantiation of the module in the given isolate. | 212 // Creates a new instantiation of the module in the given isolate. |
| 213 MaybeHandle<JSObject> Instantiate(Isolate* isolate, Handle<JSReceiver> ffi, | 213 MaybeHandle<JSObject> Instantiate(Isolate* isolate, Handle<JSReceiver> ffi, |
| 214 Handle<JSArrayBuffer> memory) const; | 214 Handle<JSArrayBuffer> memory) const; |
| 215 |
| 216 Handle<FixedArray> CompileFunctions(Isolate* isolate) const; |
| 215 }; | 217 }; |
| 216 | 218 |
| 217 // An instantiated WASM module, including memory, function table, etc. | 219 // An instantiated WASM module, including memory, function table, etc. |
| 218 struct WasmModuleInstance { | 220 struct WasmModuleInstance { |
| 219 const WasmModule* module; // static representation of the module. | 221 const WasmModule* module; // static representation of the module. |
| 220 // -- Heap allocated -------------------------------------------------------- | 222 // -- Heap allocated -------------------------------------------------------- |
| 221 Handle<JSObject> js_object; // JavaScript module object. | 223 Handle<JSObject> js_object; // JavaScript module object. |
| 222 Handle<Context> context; // JavaScript native context. | 224 Handle<Context> context; // JavaScript native context. |
| 223 Handle<JSArrayBuffer> mem_buffer; // Handle to array buffer of memory. | 225 Handle<JSArrayBuffer> mem_buffer; // Handle to array buffer of memory. |
| 224 Handle<JSArrayBuffer> globals_buffer; // Handle to array buffer of globals. | 226 Handle<JSArrayBuffer> globals_buffer; // Handle to array buffer of globals. |
| 225 Handle<FixedArray> function_table; // indirect function table. | 227 Handle<FixedArray> function_table; // indirect function table. |
| 226 std::vector<Handle<Code>> function_code; // code objects for each function. | 228 std::vector<Handle<Code>> function_code; // code objects for each function. |
| 227 std::vector<Handle<Code>> import_code; // code objects for each import. | 229 std::vector<Handle<Code>> import_code; // code objects for each import. |
| 228 // -- raw memory ------------------------------------------------------------ | 230 // -- raw memory ------------------------------------------------------------ |
| 229 byte* mem_start; // start of linear memory. | 231 byte* mem_start; // start of linear memory. |
| 230 uint32_t mem_size; // size of the linear memory. | 232 uint32_t mem_size; // size of the linear memory. |
| 231 // -- raw globals ----------------------------------------------------------- | 233 // -- raw globals ----------------------------------------------------------- |
| 232 byte* globals_start; // start of the globals area. | 234 byte* globals_start; // start of the globals area. |
| 233 | 235 |
| 234 explicit WasmModuleInstance(const WasmModule* m) | 236 explicit WasmModuleInstance(const WasmModule* m) |
| 235 : module(m), | 237 : module(m), |
| 236 function_code(m->functions.size()), | 238 function_code(m->functions.size()), |
| 239 import_code(m->import_table.size()), |
| 237 mem_start(nullptr), | 240 mem_start(nullptr), |
| 238 mem_size(0), | 241 mem_size(0), |
| 239 globals_start(nullptr) {} | 242 globals_start(nullptr) {} |
| 240 }; | 243 }; |
| 241 | 244 |
| 242 // forward declaration. | |
| 243 class WasmLinker; | |
| 244 | |
| 245 // Interface provided to the decoder/graph builder which contains only | 245 // Interface provided to the decoder/graph builder which contains only |
| 246 // minimal information about the globals, functions, and function tables. | 246 // minimal information about the globals, functions, and function tables. |
| 247 struct ModuleEnv { | 247 struct ModuleEnv { |
| 248 const WasmModule* module; | 248 const WasmModule* module; |
| 249 WasmModuleInstance* instance; | 249 WasmModuleInstance* instance; |
| 250 WasmLinker* linker; | |
| 251 ModuleOrigin origin; | 250 ModuleOrigin origin; |
| 251 // TODO(mtrofin): remove this once we introduce WASM_DIRECT_CALL |
| 252 // reloc infos. |
| 253 std::vector<Handle<Code>> placeholders; |
| 252 | 254 |
| 253 bool IsValidGlobal(uint32_t index) { | 255 bool IsValidGlobal(uint32_t index) { |
| 254 return module && index < module->globals.size(); | 256 return module && index < module->globals.size(); |
| 255 } | 257 } |
| 256 bool IsValidFunction(uint32_t index) const { | 258 bool IsValidFunction(uint32_t index) const { |
| 257 return module && index < module->functions.size(); | 259 return module && index < module->functions.size(); |
| 258 } | 260 } |
| 259 bool IsValidSignature(uint32_t index) { | 261 bool IsValidSignature(uint32_t index) { |
| 260 return module && index < module->signatures.size(); | 262 return module && index < module->signatures.size(); |
| 261 } | 263 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 // secure. If it turns out that we need more complete checks, we could add a | 347 // secure. If it turns out that we need more complete checks, we could add a |
| 346 // special marker as internal field, which will definitely never occur anywhere | 348 // special marker as internal field, which will definitely never occur anywhere |
| 347 // else. | 349 // else. |
| 348 bool IsWasmObject(Object* object); | 350 bool IsWasmObject(Object* object); |
| 349 | 351 |
| 350 } // namespace wasm | 352 } // namespace wasm |
| 351 } // namespace internal | 353 } // namespace internal |
| 352 } // namespace v8 | 354 } // namespace v8 |
| 353 | 355 |
| 354 #endif // V8_WASM_MODULE_H_ | 356 #endif // V8_WASM_MODULE_H_ |
| OLD | NEW |