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

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

Issue 2691993004: [wasm] Introduce WasmStackGuard builtin (Closed)
Patch Set: 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
« BUILD.gn ('K') | « src/runtime/runtime.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/assembler.h" 8 #include "src/assembler.h"
9 #include "src/compiler/wasm-compiler.h" 9 #include "src/compiler/wasm-compiler.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
11 #include "src/debug/debug.h" 11 #include "src/debug/debug.h"
12 #include "src/factory.h" 12 #include "src/factory.h"
13 #include "src/frames-inl.h" 13 #include "src/frames-inl.h"
14 #include "src/objects-inl.h" 14 #include "src/objects-inl.h"
15 #include "src/runtime/runtime.h"
15 #include "src/v8memory.h" 16 #include "src/v8memory.h"
16 #include "src/wasm/wasm-module.h" 17 #include "src/wasm/wasm-module.h"
17 #include "src/wasm/wasm-objects.h" 18 #include "src/wasm/wasm-objects.h"
18 #include "src/wasm/wasm-opcodes.h" 19 #include "src/wasm/wasm-opcodes.h"
19 20
20 namespace v8 { 21 namespace v8 {
21 namespace internal { 22 namespace internal {
22 23
23 namespace { 24 namespace {
24 Handle<WasmInstanceObject> GetWasmInstanceOnStackTop(Isolate* isolate) { 25 WasmInstanceObject* GetWasmInstanceOnStackTop(Isolate* isolate) {
25 DisallowHeapAllocation no_allocation; 26 DisallowHeapAllocation no_allocation;
26 const Address entry = Isolate::c_entry_fp(isolate->thread_local_top()); 27 const Address entry = Isolate::c_entry_fp(isolate->thread_local_top());
27 Address pc = 28 Address pc =
28 Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset); 29 Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset);
29 Code* code = isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; 30 Code* code = isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code;
30 DCHECK_EQ(Code::WASM_FUNCTION, code->kind()); 31 DCHECK_EQ(Code::WASM_FUNCTION, code->kind());
31 WasmInstanceObject* owning_instance = wasm::GetOwningWasmInstance(code); 32 WasmInstanceObject* owning_instance = wasm::GetOwningWasmInstance(code);
32 CHECK_NOT_NULL(owning_instance); 33 CHECK_NOT_NULL(owning_instance);
33 return handle(owning_instance, isolate); 34 return owning_instance;
34 } 35 }
35 } // namespace 36 } // namespace
36 37
37 RUNTIME_FUNCTION(Runtime_WasmMemorySize) { 38 RUNTIME_FUNCTION(Runtime_WasmMemorySize) {
38 HandleScope scope(isolate); 39 HandleScope scope(isolate);
39 DCHECK_EQ(0, args.length()); 40 DCHECK_EQ(0, args.length());
40 41
41 Handle<WasmInstanceObject> instance = GetWasmInstanceOnStackTop(isolate); 42 Handle<WasmInstanceObject> instance(GetWasmInstanceOnStackTop(isolate),
43 isolate);
42 return *isolate->factory()->NewNumberFromInt( 44 return *isolate->factory()->NewNumberFromInt(
43 wasm::GetInstanceMemorySize(isolate, instance)); 45 wasm::GetInstanceMemorySize(isolate, instance));
44 } 46 }
45 47
46 RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { 48 RUNTIME_FUNCTION(Runtime_WasmGrowMemory) {
47 HandleScope scope(isolate); 49 HandleScope scope(isolate);
48 DCHECK_EQ(1, args.length()); 50 DCHECK_EQ(1, args.length());
49 CONVERT_UINT32_ARG_CHECKED(delta_pages, 0); 51 CONVERT_UINT32_ARG_CHECKED(delta_pages, 0);
50 Handle<WasmInstanceObject> instance = GetWasmInstanceOnStackTop(isolate); 52 Handle<WasmInstanceObject> instance(GetWasmInstanceOnStackTop(isolate),
53 isolate);
51 return *isolate->factory()->NewNumberFromInt( 54 return *isolate->factory()->NewNumberFromInt(
52 wasm::GrowMemory(isolate, instance, delta_pages)); 55 wasm::GrowMemory(isolate, instance, delta_pages));
53 } 56 }
54 57
55 Object* ThrowRuntimeError(Isolate* isolate, int message_id, int byte_offset, 58 Object* ThrowRuntimeError(Isolate* isolate, int message_id, int byte_offset,
56 bool patch_source_position) { 59 bool patch_source_position) {
57 HandleScope scope(isolate); 60 HandleScope scope(isolate);
58 DCHECK_NULL(isolate->context()); 61 DCHECK_NULL(isolate->context());
59 StackFrameIterator it(isolate); 62 StackFrameIterator it(isolate);
60 it.Advance(); 63 it.Advance();
61 CHECK(it.frame()->is_wasm_compiled()); 64 CHECK(it.frame()->is_wasm_compiled());
62 isolate->set_context(*WasmCompiledFrame::cast(it.frame()) 65 isolate->set_context(*WasmCompiledFrame::cast(it.frame())
63 ->wasm_instance() 66 ->wasm_instance()
64 ->compiled_module() 67 ->compiled_module()
ahaas 2017/02/14 14:45:38 Could you use GetWasmInstanceOnStackTop(isolate) h
65 ->native_context()); 68 ->native_context());
66 Handle<Object> error_obj = isolate->factory()->NewWasmRuntimeError( 69 Handle<Object> error_obj = isolate->factory()->NewWasmRuntimeError(
67 static_cast<MessageTemplate::Template>(message_id)); 70 static_cast<MessageTemplate::Template>(message_id));
68 71
69 if (!patch_source_position) { 72 if (!patch_source_position) {
70 return isolate->Throw(*error_obj); 73 return isolate->Throw(*error_obj);
71 } 74 }
72 75
73 // For wasm traps, the byte offset (a.k.a source position) can not be 76 // For wasm traps, the byte offset (a.k.a source position) can not be
74 // determined from relocation info, since the explicit checks for traps 77 // determined from relocation info, since the explicit checks for traps
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 DCHECK_EQ(1, args.length()); 157 DCHECK_EQ(1, args.length());
155 Object* exception = args[0]; 158 Object* exception = args[0];
156 // The unwinder will only deliver exceptions to wasm if the exception is a 159 // The unwinder will only deliver exceptions to wasm if the exception is a
157 // Number or a Smi (which we have just converted to a Number.) This logic 160 // Number or a Smi (which we have just converted to a Number.) This logic
158 // lives in Isolate::is_catchable_by_wasm(Object*). 161 // lives in Isolate::is_catchable_by_wasm(Object*).
159 CHECK(exception->IsNumber()); 162 CHECK(exception->IsNumber());
160 return exception; 163 return exception;
161 } 164 }
162 165
163 RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) { 166 RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
164 DCHECK(args.length() == 3); 167 DCHECK_EQ(3, args.length());
165 HandleScope scope(isolate); 168 HandleScope scope(isolate);
166 CONVERT_ARG_HANDLE_CHECKED(JSObject, instance_obj, 0); 169 CONVERT_ARG_HANDLE_CHECKED(JSObject, instance_obj, 0);
167 CONVERT_NUMBER_CHECKED(int32_t, func_index, Int32, args[1]); 170 CONVERT_NUMBER_CHECKED(int32_t, func_index, Int32, args[1]);
168 CONVERT_ARG_HANDLE_CHECKED(Object, arg_buffer_obj, 2); 171 CONVERT_ARG_HANDLE_CHECKED(Object, arg_buffer_obj, 2);
169 CHECK(WasmInstanceObject::IsWasmInstanceObject(*instance_obj)); 172 CHECK(WasmInstanceObject::IsWasmInstanceObject(*instance_obj));
170 Handle<WasmInstanceObject> instance = 173 Handle<WasmInstanceObject> instance =
171 Handle<WasmInstanceObject>::cast(instance_obj); 174 Handle<WasmInstanceObject>::cast(instance_obj);
172 175
173 // The arg buffer is the raw pointer to the caller's stack. It looks like a 176 // The arg buffer is the raw pointer to the caller's stack. It looks like a
174 // Smi (lowest bit not set, as checked by IsSmi), but is no valid Smi. We just 177 // Smi (lowest bit not set, as checked by IsSmi), but is no valid Smi. We just
175 // cast it back to the raw pointer. 178 // cast it back to the raw pointer.
176 CHECK(!arg_buffer_obj->IsHeapObject()); 179 CHECK(!arg_buffer_obj->IsHeapObject());
177 CHECK(arg_buffer_obj->IsSmi()); 180 CHECK(arg_buffer_obj->IsSmi());
178 uint8_t* arg_buffer = reinterpret_cast<uint8_t*>(*arg_buffer_obj); 181 uint8_t* arg_buffer = reinterpret_cast<uint8_t*>(*arg_buffer_obj);
179 182
180 // Set the current isolate's context, saving the previous one. 183 // Set the current isolate's context.
181 SaveContext save(isolate);
182 isolate->set_context(*instance->compiled_module()->native_context()); 184 isolate->set_context(*instance->compiled_module()->native_context());
ahaas 2017/02/14 14:45:38 nit: Can you add a DCHECK_NULL(isolate->context())
Clemens Hammacher 2017/02/14 17:23:14 Done.
183 185
184 instance->debug_info()->RunInterpreter(func_index, arg_buffer); 186 instance->debug_info()->RunInterpreter(func_index, arg_buffer);
185 return isolate->heap()->undefined_value(); 187 return isolate->heap()->undefined_value();
186 } 188 }
187 189
190 RUNTIME_FUNCTION(Runtime_WasmStackGuard) {
191 SealHandleScope shs(isolate);
192 DCHECK_EQ(0, args.length());
193
194 // Set the current isolate's context.
195 WasmInstanceObject* instance = GetWasmInstanceOnStackTop(isolate);
196 isolate->set_context(instance->compiled_module()->ptr_to_native_context());
ahaas 2017/02/14 14:45:38 nit: Can you add a DCHECK_NULL(isolate->context())
Clemens Hammacher 2017/02/14 17:23:14 Done.
197
198 // Check if this is a real stack overflow.
199 StackLimitCheck check(isolate);
200 if (check.JsHasOverflowed()) return isolate->StackOverflow();
201
202 return isolate->stack_guard()->HandleInterrupts();
203 }
204
188 } // namespace internal 205 } // namespace internal
189 } // namespace v8 206 } // namespace v8
OLDNEW
« BUILD.gn ('K') | « src/runtime/runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698