Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/wasm/wasm-module.cc

Issue 2653533003: [wasm] Do not patch memory references in imported functions. (Closed)
Patch Set: ]This patch should apply Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/wasm/wasm-objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <memory> 5 #include <memory>
6 6
7 #include "src/assembler-inl.h" 7 #include "src/assembler-inl.h"
8 #include "src/base/adapters.h" 8 #include "src/base/adapters.h"
9 #include "src/base/atomic-utils.h" 9 #include "src/base/atomic-utils.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 is_external = true; 113 is_external = true;
114 return memory; 114 return memory;
115 } else { 115 } else {
116 void* memory = isolate->array_buffer_allocator()->Allocate(size); 116 void* memory = isolate->array_buffer_allocator()->Allocate(size);
117 return memory; 117 return memory;
118 } 118 }
119 } 119 }
120 120
121 void RelocateMemoryReferencesInCode(Handle<FixedArray> code_table, 121 void RelocateMemoryReferencesInCode(Handle<FixedArray> code_table,
122 uint32_t num_imported_functions,
122 Address old_start, Address start, 123 Address old_start, Address start,
123 uint32_t prev_size, uint32_t new_size) { 124 uint32_t prev_size, uint32_t new_size) {
124 for (int i = 0; i < code_table->length(); ++i) { 125 for (int i = static_cast<int>(num_imported_functions);
126 i < code_table->length(); ++i) {
125 DCHECK(code_table->get(i)->IsCode()); 127 DCHECK(code_table->get(i)->IsCode());
126 Handle<Code> code = Handle<Code>(Code::cast(code_table->get(i))); 128 Handle<Code> code = Handle<Code>(Code::cast(code_table->get(i)));
127 AllowDeferredHandleDereference embedding_raw_address; 129 AllowDeferredHandleDereference embedding_raw_address;
128 int mask = (1 << RelocInfo::WASM_MEMORY_REFERENCE) | 130 int mask = (1 << RelocInfo::WASM_MEMORY_REFERENCE) |
129 (1 << RelocInfo::WASM_MEMORY_SIZE_REFERENCE); 131 (1 << RelocInfo::WASM_MEMORY_SIZE_REFERENCE);
130 for (RelocIterator it(*code, mask); !it.done(); it.next()) { 132 for (RelocIterator it(*code, mask); !it.done(); it.next()) {
131 it.rinfo()->update_wasm_memory_reference(old_start, start, prev_size, 133 it.rinfo()->update_wasm_memory_reference(old_start, start, prev_size,
132 new_size); 134 new_size);
133 } 135 }
134 } 136 }
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_SIZE_REFERENCE) | 559 RelocInfo::ModeMask(RelocInfo::WASM_MEMORY_SIZE_REFERENCE) |
558 RelocInfo::ModeMask(RelocInfo::WASM_GLOBAL_REFERENCE) | 560 RelocInfo::ModeMask(RelocInfo::WASM_GLOBAL_REFERENCE) |
559 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); 561 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
560 562
561 // Patch code to update memory references, global references, and function 563 // Patch code to update memory references, global references, and function
562 // table references. 564 // table references.
563 Object* fct_obj = compiled_module->ptr_to_code_table(); 565 Object* fct_obj = compiled_module->ptr_to_code_table();
564 if (fct_obj != nullptr && fct_obj != undefined && 566 if (fct_obj != nullptr && fct_obj != undefined &&
565 (old_mem_size > 0 || globals_start != nullptr || function_tables)) { 567 (old_mem_size > 0 || globals_start != nullptr || function_tables)) {
566 FixedArray* functions = FixedArray::cast(fct_obj); 568 FixedArray* functions = FixedArray::cast(fct_obj);
567 for (int i = 0; i < functions->length(); ++i) { 569 for (int i = compiled_module->num_imported_functions();
570 i < functions->length(); ++i) {
568 Code* code = Code::cast(functions->get(i)); 571 Code* code = Code::cast(functions->get(i));
569 bool changed = false; 572 bool changed = false;
570 for (RelocIterator it(code, mode_mask); !it.done(); it.next()) { 573 for (RelocIterator it(code, mode_mask); !it.done(); it.next()) {
571 RelocInfo::Mode mode = it.rinfo()->rmode(); 574 RelocInfo::Mode mode = it.rinfo()->rmode();
572 if (RelocInfo::IsWasmMemoryReference(mode) || 575 if (RelocInfo::IsWasmMemoryReference(mode) ||
573 RelocInfo::IsWasmMemorySizeReference(mode)) { 576 RelocInfo::IsWasmMemorySizeReference(mode)) {
574 it.rinfo()->update_wasm_memory_reference( 577 it.rinfo()->update_wasm_memory_reference(
575 old_mem_address, nullptr, old_mem_size, default_mem_size); 578 old_mem_address, nullptr, old_mem_size, default_mem_size);
576 changed = true; 579 changed = true;
577 } else if (RelocInfo::IsWasmGlobalReference(mode)) { 580 } else if (RelocInfo::IsWasmGlobalReference(mode)) {
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 986
984 Handle<WasmSharedModuleData> shared = WasmSharedModuleData::New( 987 Handle<WasmSharedModuleData> shared = WasmSharedModuleData::New(
985 isolate, module_wrapper, Handle<SeqOneByteString>::cast(module_bytes), 988 isolate, module_wrapper, Handle<SeqOneByteString>::cast(module_bytes),
986 script, asm_js_offset_table); 989 script, asm_js_offset_table);
987 990
988 // Create the compiled module object, and populate with compiled functions 991 // Create the compiled module object, and populate with compiled functions
989 // and information needed at instantiation time. This object needs to be 992 // and information needed at instantiation time. This object needs to be
990 // serializable. Instantiation may occur off a deserialized version of this 993 // serializable. Instantiation may occur off a deserialized version of this
991 // object. 994 // object.
992 Handle<WasmCompiledModule> ret = WasmCompiledModule::New(isolate, shared); 995 Handle<WasmCompiledModule> ret = WasmCompiledModule::New(isolate, shared);
996 ret->set_num_imported_functions(num_imported_functions);
993 ret->set_code_table(code_table); 997 ret->set_code_table(code_table);
994 ret->set_min_mem_pages(min_mem_pages); 998 ret->set_min_mem_pages(min_mem_pages);
995 ret->set_max_mem_pages(max_mem_pages); 999 ret->set_max_mem_pages(max_mem_pages);
996 if (function_table_count > 0) { 1000 if (function_table_count > 0) {
997 ret->set_function_tables(function_tables); 1001 ret->set_function_tables(function_tables);
998 ret->set_signature_tables(signature_tables); 1002 ret->set_signature_tables(signature_tables);
999 ret->set_empty_function_tables(function_tables); 1003 ret->set_empty_function_tables(function_tables);
1000 } 1004 }
1001 1005
1002 // If we created a wasm script, finish it now and make it public to the 1006 // If we created a wasm script, finish it now and make it public to the
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 uint32_t mem_size = 1340 uint32_t mem_size =
1337 static_cast<uint32_t>(memory_->byte_length()->Number()); 1341 static_cast<uint32_t>(memory_->byte_length()->Number());
1338 LoadDataSegments(mem_start, mem_size); 1342 LoadDataSegments(mem_start, mem_size);
1339 1343
1340 uint32_t old_mem_size = compiled_module_->mem_size(); 1344 uint32_t old_mem_size = compiled_module_->mem_size();
1341 Address old_mem_start = 1345 Address old_mem_start =
1342 compiled_module_->has_memory() 1346 compiled_module_->has_memory()
1343 ? static_cast<Address>( 1347 ? static_cast<Address>(
1344 compiled_module_->memory()->backing_store()) 1348 compiled_module_->memory()->backing_store())
1345 : nullptr; 1349 : nullptr;
1346 RelocateMemoryReferencesInCode(code_table, old_mem_start, mem_start, 1350 RelocateMemoryReferencesInCode(
1347 old_mem_size, mem_size); 1351 code_table, module_->num_imported_functions, old_mem_start, mem_start,
1352 old_mem_size, mem_size);
1348 compiled_module_->set_memory(memory_); 1353 compiled_module_->set_memory(memory_);
1349 } 1354 }
1350 1355
1351 //-------------------------------------------------------------------------- 1356 //--------------------------------------------------------------------------
1352 // Set up the runtime support for the new instance. 1357 // Set up the runtime support for the new instance.
1353 //-------------------------------------------------------------------------- 1358 //--------------------------------------------------------------------------
1354 Handle<WeakCell> weak_link = factory->NewWeakCell(instance); 1359 Handle<WeakCell> weak_link = factory->NewWeakCell(instance);
1355 1360
1356 for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs; 1361 for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs;
1357 i < code_table->length(); ++i) { 1362 i < code_table->length(); ++i) {
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after
2373 void UncheckedUpdateInstanceMemory(Isolate* isolate, 2378 void UncheckedUpdateInstanceMemory(Isolate* isolate,
2374 Handle<WasmInstanceObject> instance, 2379 Handle<WasmInstanceObject> instance,
2375 Address old_mem_start, uint32_t old_size) { 2380 Address old_mem_start, uint32_t old_size) {
2376 DCHECK(instance->has_memory_buffer()); 2381 DCHECK(instance->has_memory_buffer());
2377 Handle<JSArrayBuffer> new_buffer(instance->memory_buffer()); 2382 Handle<JSArrayBuffer> new_buffer(instance->memory_buffer());
2378 uint32_t new_size = new_buffer->byte_length()->Number(); 2383 uint32_t new_size = new_buffer->byte_length()->Number();
2379 DCHECK(new_size <= std::numeric_limits<uint32_t>::max()); 2384 DCHECK(new_size <= std::numeric_limits<uint32_t>::max());
2380 Address new_mem_start = static_cast<Address>(new_buffer->backing_store()); 2385 Address new_mem_start = static_cast<Address>(new_buffer->backing_store());
2381 DCHECK_NOT_NULL(new_mem_start); 2386 DCHECK_NOT_NULL(new_mem_start);
2382 Handle<FixedArray> code_table = instance->compiled_module()->code_table(); 2387 Handle<FixedArray> code_table = instance->compiled_module()->code_table();
2383 RelocateMemoryReferencesInCode(code_table, old_mem_start, new_mem_start, 2388 RelocateMemoryReferencesInCode(
2384 old_size, new_size); 2389 code_table, instance->compiled_module()->module()->num_imported_functions,
2390 old_mem_start, new_mem_start, old_size, new_size);
2385 } 2391 }
2386 2392
2387 int32_t wasm::GrowWebAssemblyMemory(Isolate* isolate, 2393 int32_t wasm::GrowWebAssemblyMemory(Isolate* isolate,
2388 Handle<WasmMemoryObject> receiver, 2394 Handle<WasmMemoryObject> receiver,
2389 uint32_t pages) { 2395 uint32_t pages) {
2390 DCHECK(WasmJs::IsWasmMemoryObject(isolate, receiver)); 2396 DCHECK(WasmJs::IsWasmMemoryObject(isolate, receiver));
2391 Handle<WasmMemoryObject> memory_object = 2397 Handle<WasmMemoryObject> memory_object =
2392 handle(WasmMemoryObject::cast(*receiver)); 2398 handle(WasmMemoryObject::cast(*receiver));
2393 MaybeHandle<JSArrayBuffer> memory_buffer = handle(memory_object->buffer()); 2399 MaybeHandle<JSArrayBuffer> memory_buffer = handle(memory_object->buffer());
2394 Handle<JSArrayBuffer> old_buffer; 2400 Handle<JSArrayBuffer> old_buffer;
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
2684 2690
2685 JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(), 2691 JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(),
2686 NONE); 2692 NONE);
2687 JSObject::AddProperty(entry, kind_string, export_kind, NONE); 2693 JSObject::AddProperty(entry, kind_string, export_kind, NONE);
2688 2694
2689 storage->set(index, *entry); 2695 storage->set(index, *entry);
2690 } 2696 }
2691 2697
2692 return array_object; 2698 return array_object;
2693 } 2699 }
OLDNEW
« no previous file with comments | « no previous file | src/wasm/wasm-objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698