| Index: src/runtime/runtime-wasm.cc
|
| diff --git a/src/runtime/runtime-wasm.cc b/src/runtime/runtime-wasm.cc
|
| index 3ed63879add0dd24a128c273ff0075f92070f276..61ba1f7a3d1b868d501c24e4037198cd1b55f8c5 100644
|
| --- a/src/runtime/runtime-wasm.cc
|
| +++ b/src/runtime/runtime-wasm.cc
|
| @@ -21,7 +21,7 @@ namespace v8 {
|
| namespace internal {
|
|
|
| namespace {
|
| -Handle<WasmInstanceObject> GetWasmInstanceOnStackTop(Isolate* isolate) {
|
| +WasmInstanceObject* GetWasmInstanceOnStackTop(Isolate* isolate) {
|
| DisallowHeapAllocation no_allocation;
|
| const Address entry = Isolate::c_entry_fp(isolate->thread_local_top());
|
| Address pc =
|
| @@ -30,7 +30,12 @@ Handle<WasmInstanceObject> GetWasmInstanceOnStackTop(Isolate* isolate) {
|
| DCHECK_EQ(Code::WASM_FUNCTION, code->kind());
|
| WasmInstanceObject* owning_instance = wasm::GetOwningWasmInstance(code);
|
| CHECK_NOT_NULL(owning_instance);
|
| - return handle(owning_instance, isolate);
|
| + return owning_instance;
|
| +}
|
| +Context* GetWasmContextOnStackTop(Isolate* isolate) {
|
| + return GetWasmInstanceOnStackTop(isolate)
|
| + ->compiled_module()
|
| + ->ptr_to_native_context();
|
| }
|
| } // namespace
|
|
|
| @@ -38,7 +43,8 @@ RUNTIME_FUNCTION(Runtime_WasmMemorySize) {
|
| HandleScope scope(isolate);
|
| DCHECK_EQ(0, args.length());
|
|
|
| - Handle<WasmInstanceObject> instance = GetWasmInstanceOnStackTop(isolate);
|
| + Handle<WasmInstanceObject> instance(GetWasmInstanceOnStackTop(isolate),
|
| + isolate);
|
| return *isolate->factory()->NewNumberFromInt(
|
| wasm::GetInstanceMemorySize(isolate, instance));
|
| }
|
| @@ -47,7 +53,8 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) {
|
| HandleScope scope(isolate);
|
| DCHECK_EQ(1, args.length());
|
| CONVERT_UINT32_ARG_CHECKED(delta_pages, 0);
|
| - Handle<WasmInstanceObject> instance = GetWasmInstanceOnStackTop(isolate);
|
| + Handle<WasmInstanceObject> instance(GetWasmInstanceOnStackTop(isolate),
|
| + isolate);
|
| return *isolate->factory()->NewNumberFromInt(
|
| wasm::GrowMemory(isolate, instance, delta_pages));
|
| }
|
| @@ -56,13 +63,7 @@ Object* ThrowRuntimeError(Isolate* isolate, int message_id, int byte_offset,
|
| bool patch_source_position) {
|
| HandleScope scope(isolate);
|
| DCHECK_NULL(isolate->context());
|
| - StackFrameIterator it(isolate);
|
| - it.Advance();
|
| - CHECK(it.frame()->is_wasm_compiled());
|
| - isolate->set_context(*WasmCompiledFrame::cast(it.frame())
|
| - ->wasm_instance()
|
| - ->compiled_module()
|
| - ->native_context());
|
| + isolate->set_context(GetWasmContextOnStackTop(isolate));
|
| Handle<Object> error_obj = isolate->factory()->NewWasmRuntimeError(
|
| static_cast<MessageTemplate::Template>(message_id));
|
|
|
| @@ -161,7 +162,7 @@ RUNTIME_FUNCTION(Runtime_WasmGetCaughtExceptionValue) {
|
| }
|
|
|
| RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
|
| - DCHECK(args.length() == 3);
|
| + DCHECK_EQ(3, args.length());
|
| HandleScope scope(isolate);
|
| CONVERT_ARG_HANDLE_CHECKED(JSObject, instance_obj, 0);
|
| CONVERT_NUMBER_CHECKED(int32_t, func_index, Int32, args[1]);
|
| @@ -177,13 +178,27 @@ RUNTIME_FUNCTION(Runtime_WasmRunInterpreter) {
|
| CHECK(arg_buffer_obj->IsSmi());
|
| uint8_t* arg_buffer = reinterpret_cast<uint8_t*>(*arg_buffer_obj);
|
|
|
| - // Set the current isolate's context, saving the previous one.
|
| - SaveContext save(isolate);
|
| - isolate->set_context(*instance->compiled_module()->native_context());
|
| + DCHECK_EQ(isolate->context(),
|
| + instance->compiled_module()->ptr_to_native_context());
|
|
|
| instance->debug_info()->RunInterpreter(func_index, arg_buffer);
|
| return isolate->heap()->undefined_value();
|
| }
|
|
|
| +RUNTIME_FUNCTION(Runtime_WasmStackGuard) {
|
| + SealHandleScope shs(isolate);
|
| + DCHECK_EQ(0, args.length());
|
| +
|
| + // Set the current isolate's context.
|
| + DCHECK_NULL(isolate->context());
|
| + isolate->set_context(GetWasmContextOnStackTop(isolate));
|
| +
|
| + // Check if this is a real stack overflow.
|
| + StackLimitCheck check(isolate);
|
| + if (check.JsHasOverflowed()) return isolate->StackOverflow();
|
| +
|
| + return isolate->stack_guard()->HandleInterrupts();
|
| +}
|
| +
|
| } // namespace internal
|
| } // namespace v8
|
|
|