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

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

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

Powered by Google App Engine
This is Rietveld 408576698