1 // Copyright 2019 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "src/execution/thread-local-top.h" 6 #include "src/execution/isolate.h" 7 #include "src/execution/simulator.h" 8 #include "src/trap-handler/trap-handler.h" 9 10 namespace v8 { 11 namespace internal { 12 Clear()13void ThreadLocalTop::Clear() { 14 try_catch_handler_ = nullptr; 15 isolate_ = nullptr; 16 context_ = Context(); 17 thread_id_ = ThreadId(); 18 pending_handler_entrypoint_ = kNullAddress; 19 pending_handler_constant_pool_ = kNullAddress; 20 pending_handler_fp_ = kNullAddress; 21 pending_handler_sp_ = kNullAddress; 22 num_frames_above_pending_handler_ = 0; 23 last_api_entry_ = kNullAddress; 24 pending_message_ = Object(); 25 rethrowing_message_ = false; 26 external_caught_exception_ = false; 27 c_entry_fp_ = kNullAddress; 28 handler_ = kNullAddress; 29 c_function_ = kNullAddress; 30 simulator_ = nullptr; 31 js_entry_sp_ = kNullAddress; 32 external_callback_scope_ = nullptr; 33 current_vm_state_ = EXTERNAL; 34 current_embedder_state_ = nullptr; 35 failed_access_check_callback_ = nullptr; 36 thread_in_wasm_flag_address_ = kNullAddress; 37 #ifdef V8_ENABLE_CONSERVATIVE_STACK_SCANNING 38 stack_ = ::heap::base::Stack(nullptr); 39 #endif 40 } 41 Initialize(Isolate * isolate)42void ThreadLocalTop::Initialize(Isolate* isolate) { 43 Clear(); 44 isolate_ = isolate; 45 thread_id_ = ThreadId::Current(); 46 #if V8_ENABLE_WEBASSEMBLY 47 thread_in_wasm_flag_address_ = reinterpret_cast<Address>( 48 trap_handler::GetThreadInWasmThreadLocalAddress()); 49 #endif // V8_ENABLE_WEBASSEMBLY 50 #ifdef USE_SIMULATOR 51 simulator_ = Simulator::current(isolate); 52 #endif 53 54 #ifdef V8_ENABLE_CONSERVATIVE_STACK_SCANNING 55 stack_ = ::heap::base::Stack(base::Stack::GetStackStart()); 56 #endif 57 } 58 Free()59void ThreadLocalTop::Free() {} 60 61 #if defined(USE_SIMULATOR) StoreCurrentStackPosition()62void ThreadLocalTop::StoreCurrentStackPosition() { 63 last_api_entry_ = simulator_->get_sp(); 64 } 65 #elif defined(V8_USE_ADDRESS_SANITIZER) StoreCurrentStackPosition()66void ThreadLocalTop::StoreCurrentStackPosition() { 67 last_api_entry_ = reinterpret_cast<Address>(GetCurrentStackPosition()); 68 } 69 #endif 70 71 } // namespace internal 72 } // namespace v8 73