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

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

Issue 2371833007: [wasm] Initial signal handler (Closed)
Patch Set: Make sure guard pages get set up when resizing from 0 to more than 0 Created 3 years, 9 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 | « src/v8.gyp ('k') | test/cctest/cctest.cc » ('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"
11 #include "src/compiler/wasm-compiler.h" 11 #include "src/compiler/wasm-compiler.h"
12 #include "src/debug/interface-types.h" 12 #include "src/debug/interface-types.h"
13 #include "src/objects.h" 13 #include "src/objects.h"
14 #include "src/property-descriptor.h" 14 #include "src/property-descriptor.h"
15 #include "src/simulator.h" 15 #include "src/simulator.h"
16 #include "src/snapshot/snapshot.h" 16 #include "src/snapshot/snapshot.h"
17 #include "src/trap-handler/trap-handler.h"
17 #include "src/v8.h" 18 #include "src/v8.h"
18 19
19 #include "src/asmjs/asm-wasm-builder.h" 20 #include "src/asmjs/asm-wasm-builder.h"
20 #include "src/wasm/function-body-decoder.h" 21 #include "src/wasm/function-body-decoder.h"
21 #include "src/wasm/module-decoder.h" 22 #include "src/wasm/module-decoder.h"
22 #include "src/wasm/wasm-code-specialization.h" 23 #include "src/wasm/wasm-code-specialization.h"
23 #include "src/wasm/wasm-js.h" 24 #include "src/wasm/wasm-js.h"
24 #include "src/wasm/wasm-limits.h" 25 #include "src/wasm/wasm-limits.h"
25 #include "src/wasm/wasm-module.h" 26 #include "src/wasm/wasm-module.h"
26 #include "src/wasm/wasm-objects.h" 27 #include "src/wasm/wasm-objects.h"
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 WasmInstanceObject* owner = reinterpret_cast<WasmInstanceObject*>(*p); 665 WasmInstanceObject* owner = reinterpret_cast<WasmInstanceObject*>(*p);
665 Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate()); 666 Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate());
666 // If a link to shared memory instances exists, update the list of memory 667 // If a link to shared memory instances exists, update the list of memory
667 // instances before the instance is destroyed. 668 // instances before the instance is destroyed.
668 if (owner->has_instance_wrapper()) MemoryInstanceFinalizer(isolate, owner); 669 if (owner->has_instance_wrapper()) MemoryInstanceFinalizer(isolate, owner);
669 WasmCompiledModule* compiled_module = owner->compiled_module(); 670 WasmCompiledModule* compiled_module = owner->compiled_module();
670 TRACE("Finalizing %d {\n", compiled_module->instance_id()); 671 TRACE("Finalizing %d {\n", compiled_module->instance_id());
671 DCHECK(compiled_module->has_weak_wasm_module()); 672 DCHECK(compiled_module->has_weak_wasm_module());
672 WeakCell* weak_wasm_module = compiled_module->ptr_to_weak_wasm_module(); 673 WeakCell* weak_wasm_module = compiled_module->ptr_to_weak_wasm_module();
673 674
675 if (trap_handler::UseTrapHandler()) {
676 Handle<FixedArray> code_table = compiled_module->code_table();
677 for (int i = 0; i < code_table->length(); ++i) {
678 Handle<Code> code = code_table->GetValueChecked<Code>(isolate, i);
679 int index = code->trap_handler_index()->value();
680 if (index >= 0) {
681 trap_handler::ReleaseHandlerData(index);
682 code->set_trap_handler_index(Smi::FromInt(-1));
683 }
684 }
685 }
686
674 // weak_wasm_module may have been cleared, meaning the module object 687 // weak_wasm_module may have been cleared, meaning the module object
675 // was GC-ed. In that case, there won't be any new instances created, 688 // was GC-ed. In that case, there won't be any new instances created,
676 // and we don't need to maintain the links between instances. 689 // and we don't need to maintain the links between instances.
677 if (!weak_wasm_module->cleared()) { 690 if (!weak_wasm_module->cleared()) {
678 JSObject* wasm_module = JSObject::cast(weak_wasm_module->value()); 691 JSObject* wasm_module = JSObject::cast(weak_wasm_module->value());
679 WasmCompiledModule* current_template = 692 WasmCompiledModule* current_template =
680 WasmCompiledModule::cast(wasm_module->GetInternalField(0)); 693 WasmCompiledModule::cast(wasm_module->GetInternalField(0));
681 694
682 TRACE("chain before {\n"); 695 TRACE("chain before {\n");
683 TRACE_CHAIN(current_template); 696 TRACE_CHAIN(current_template);
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 { 1236 {
1224 code_specialization.RelocateDirectCalls(instance); 1237 code_specialization.RelocateDirectCalls(instance);
1225 code_specialization.ApplyToWholeInstance(*instance, SKIP_ICACHE_FLUSH); 1238 code_specialization.ApplyToWholeInstance(*instance, SKIP_ICACHE_FLUSH);
1226 } 1239 }
1227 1240
1228 FlushICache(isolate_, code_table); 1241 FlushICache(isolate_, code_table);
1229 1242
1230 //-------------------------------------------------------------------------- 1243 //--------------------------------------------------------------------------
1231 // Unpack and notify signal handler of protected instructions. 1244 // Unpack and notify signal handler of protected instructions.
1232 //-------------------------------------------------------------------------- 1245 //--------------------------------------------------------------------------
1233 if (FLAG_wasm_trap_handler) { 1246 if (trap_handler::UseTrapHandler()) {
1234 for (int i = 0; i < code_table->length(); ++i) { 1247 for (int i = 0; i < code_table->length(); ++i) {
1235 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i); 1248 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i);
1236 1249
1237 if (code->kind() != Code::WASM_FUNCTION) { 1250 if (code->kind() != Code::WASM_FUNCTION) {
1238 continue; 1251 continue;
1239 } 1252 }
1240 1253
1241 const intptr_t base = reinterpret_cast<intptr_t>(code->entry()); 1254 const intptr_t base = reinterpret_cast<intptr_t>(code->entry());
1242 1255
1243 Zone zone(isolate_->allocator(), "Wasm Module"); 1256 Zone zone(isolate_->allocator(), "Wasm Module");
1244 ZoneVector<trap_handler::ProtectedInstructionData> unpacked(&zone); 1257 ZoneVector<trap_handler::ProtectedInstructionData> unpacked(&zone);
1245 const int mode_mask = 1258 const int mode_mask =
1246 RelocInfo::ModeMask(RelocInfo::WASM_PROTECTED_INSTRUCTION_LANDING); 1259 RelocInfo::ModeMask(RelocInfo::WASM_PROTECTED_INSTRUCTION_LANDING);
1247 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) { 1260 for (RelocIterator it(*code, mode_mask); !it.done(); it.next()) {
1248 trap_handler::ProtectedInstructionData data; 1261 trap_handler::ProtectedInstructionData data;
1249 data.instr_offset = it.rinfo()->data(); 1262 data.instr_offset = it.rinfo()->data();
1250 data.landing_offset = 1263 data.landing_offset =
1251 reinterpret_cast<intptr_t>(it.rinfo()->pc()) - base; 1264 reinterpret_cast<intptr_t>(it.rinfo()->pc()) - base;
1252 unpacked.emplace_back(data); 1265 unpacked.emplace_back(data);
1253 } 1266 }
1254 // TODO(eholk): Register the protected instruction information once the 1267 if (unpacked.size() > 0) {
1255 // trap handler is in place. 1268 int size = code->CodeSize();
1269 const int index =
1270 RegisterHandlerData(reinterpret_cast<void*>(base), size,
1271 unpacked.size(), &unpacked[0]);
1272 // TODO(eholk): if index is negative, fail.
1273 DCHECK(index >= 0);
1274 code->set_trap_handler_index(Smi::FromInt(index));
1275 }
1256 } 1276 }
1257 } 1277 }
1258 1278
1259 //-------------------------------------------------------------------------- 1279 //--------------------------------------------------------------------------
1260 // Set up and link the new instance. 1280 // Set up and link the new instance.
1261 //-------------------------------------------------------------------------- 1281 //--------------------------------------------------------------------------
1262 { 1282 {
1263 Handle<Object> global_handle = 1283 Handle<Object> global_handle =
1264 isolate_->global_handles()->Create(*instance); 1284 isolate_->global_handles()->Create(*instance);
1265 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_); 1285 Handle<WeakCell> link_to_clone = factory->NewWeakCell(compiled_module_);
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
2146 std::numeric_limits<uint32_t>::max()); 2166 std::numeric_limits<uint32_t>::max());
2147 uint32_t new_size = old_size + pages * WasmModule::kPageSize; 2167 uint32_t new_size = old_size + pages * WasmModule::kPageSize;
2148 if (new_size <= old_size || max_pages * WasmModule::kPageSize < new_size || 2168 if (new_size <= old_size || max_pages * WasmModule::kPageSize < new_size ||
2149 FLAG_wasm_max_mem_pages * WasmModule::kPageSize < new_size) { 2169 FLAG_wasm_max_mem_pages * WasmModule::kPageSize < new_size) {
2150 return Handle<JSArrayBuffer>::null(); 2170 return Handle<JSArrayBuffer>::null();
2151 } 2171 }
2152 2172
2153 // TODO(gdeepti): Change the protection here instead of allocating a new 2173 // TODO(gdeepti): Change the protection here instead of allocating a new
2154 // buffer before guard regions are turned on, see issue #5886. 2174 // buffer before guard regions are turned on, see issue #5886.
2155 const bool enable_guard_regions = 2175 const bool enable_guard_regions =
2156 !old_buffer.is_null() && old_buffer->has_guard_region(); 2176 (old_buffer.is_null() && EnableGuardRegions()) ||
2177 (!old_buffer.is_null() && old_buffer->has_guard_region());
2157 Handle<JSArrayBuffer> new_buffer = 2178 Handle<JSArrayBuffer> new_buffer =
2158 NewArrayBuffer(isolate, new_size, enable_guard_regions); 2179 NewArrayBuffer(isolate, new_size, enable_guard_regions);
2159 if (new_buffer.is_null()) return new_buffer; 2180 if (new_buffer.is_null()) return new_buffer;
2160 Address new_mem_start = static_cast<Address>(new_buffer->backing_store()); 2181 Address new_mem_start = static_cast<Address>(new_buffer->backing_store());
2161 if (old_size != 0) { 2182 if (old_size != 0) {
2162 memcpy(new_mem_start, old_mem_start, old_size); 2183 memcpy(new_mem_start, old_mem_start, old_size);
2163 } 2184 }
2164 return new_buffer; 2185 return new_buffer;
2165 } 2186 }
2166 2187
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
2721 Handle<String> module_property_name = 2742 Handle<String> module_property_name =
2722 isolate->factory()->InternalizeUtf8String("module"); 2743 isolate->factory()->InternalizeUtf8String("module");
2723 Handle<String> instance_property_name = 2744 Handle<String> instance_property_name =
2724 isolate->factory()->InternalizeUtf8String("instance"); 2745 isolate->factory()->InternalizeUtf8String("instance");
2725 JSObject::AddProperty(ret, module_property_name, module, NONE); 2746 JSObject::AddProperty(ret, module_property_name, module, NONE);
2726 JSObject::AddProperty(ret, instance_property_name, 2747 JSObject::AddProperty(ret, instance_property_name,
2727 instance_object.ToHandleChecked(), NONE); 2748 instance_object.ToHandleChecked(), NONE);
2728 2749
2729 ResolvePromise(isolate, promise, ret); 2750 ResolvePromise(isolate, promise, ret);
2730 } 2751 }
OLDNEW
« no previous file with comments | « src/v8.gyp ('k') | test/cctest/cctest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698