diff --git a/runtime/vm/compiler/stub_code_compiler_arm.cc b/runtime/vm/compiler/stub_code_compiler_arm.cc index a7afdc82000..ed369f1efce 100644 --- a/runtime/vm/compiler/stub_code_compiler_arm.cc +++ b/runtime/vm/compiler/stub_code_compiler_arm.cc @@ -2973,12 +2973,6 @@ void StubCodeCompiler::GenerateSubtypeNTestCacheStub(Assembler* assembler, }); } -// Return the current stack pointer address, used to do stack alignment checks. -void StubCodeCompiler::GenerateGetCStackPointerStub() { - __ mov(R0, Operand(SP)); - __ Ret(); -} - // Jump to a frame on the call stack. // LR: return address. // R0: program_counter. diff --git a/runtime/vm/compiler/stub_code_compiler_arm64.cc b/runtime/vm/compiler/stub_code_compiler_arm64.cc index 975cddda4a3..6f723752bb3 100644 --- a/runtime/vm/compiler/stub_code_compiler_arm64.cc +++ b/runtime/vm/compiler/stub_code_compiler_arm64.cc @@ -3353,11 +3353,6 @@ void StubCodeCompiler::GenerateSubtypeNTestCacheStub(Assembler* assembler, }); } -void StubCodeCompiler::GenerateGetCStackPointerStub() { - __ mov(R0, CSP); - __ ret(); -} - // Jump to a frame on the call stack. // LR: return address. // R0: program_counter. diff --git a/runtime/vm/compiler/stub_code_compiler_ia32.cc b/runtime/vm/compiler/stub_code_compiler_ia32.cc index 61b8ea77164..83a2f1ea7d0 100644 --- a/runtime/vm/compiler/stub_code_compiler_ia32.cc +++ b/runtime/vm/compiler/stub_code_compiler_ia32.cc @@ -2891,14 +2891,6 @@ void StubCodeCompiler::GenerateSubtypeNTestCacheStub(Assembler* assembler, __ ret(); } -// Return the current stack pointer address, used to do stack alignment checks. -// TOS + 0: return address -// Result in EAX. -void StubCodeCompiler::GenerateGetCStackPointerStub() { - __ leal(EAX, Address(ESP, target::kWordSize)); - __ ret(); -} - // Jump to a frame on the call stack. // TOS + 0: return address // TOS + 1: program_counter diff --git a/runtime/vm/compiler/stub_code_compiler_riscv.cc b/runtime/vm/compiler/stub_code_compiler_riscv.cc index d8ad381f73d..654789f61f5 100644 --- a/runtime/vm/compiler/stub_code_compiler_riscv.cc +++ b/runtime/vm/compiler/stub_code_compiler_riscv.cc @@ -2868,11 +2868,6 @@ void StubCodeCompiler::GenerateSubtypeNTestCacheStub(Assembler* assembler, }); } -void StubCodeCompiler::GenerateGetCStackPointerStub() { - __ mv(A0, SP); - __ ret(); -} - // Jump to a frame on the call stack. // RA: return address. // A0: program_counter. diff --git a/runtime/vm/compiler/stub_code_compiler_x64.cc b/runtime/vm/compiler/stub_code_compiler_x64.cc index 0d3a1bee795..2cc44fea877 100644 --- a/runtime/vm/compiler/stub_code_compiler_x64.cc +++ b/runtime/vm/compiler/stub_code_compiler_x64.cc @@ -3315,15 +3315,6 @@ void StubCodeCompiler::GenerateSubtypeNTestCacheStub(Assembler* assembler, }); } -// Return the current stack pointer address, used to stack alignment -// checks. -// TOS + 0: return address -// Result in RAX. -void StubCodeCompiler::GenerateGetCStackPointerStub() { - __ leaq(RAX, Address(RSP, target::kWordSize)); - __ ret(); -} - // Jump to a frame on the call stack. // TOS + 0: return address // Arg1: program counter diff --git a/runtime/vm/native_arguments.h b/runtime/vm/native_arguments.h index 41b5d18d32d..5ced9ba6871 100644 --- a/runtime/vm/native_arguments.h +++ b/runtime/vm/native_arguments.h @@ -35,10 +35,8 @@ class Thread; #else #define CHECK_STACK_ALIGNMENT \ { \ - uword (*func)() = reinterpret_cast( \ - StubCode::GetCStackPointer().EntryPoint()); \ - uword current_sp = func(); \ - ASSERT(Utils::IsAligned(current_sp, OS::ActivationFrameAlignment())); \ + ASSERT(Utils::IsAligned(OSThread::GetCurrentStackPointer(), \ + OS::ActivationFrameAlignment())); \ } #endif diff --git a/runtime/vm/os_thread.cc b/runtime/vm/os_thread.cc index 0b0c480d117..e4f057e9bec 100644 --- a/runtime/vm/os_thread.cc +++ b/runtime/vm/os_thread.cc @@ -140,9 +140,15 @@ void OSThread::SetName(const char* name) { DART_NOINLINE uword OSThread::GetCurrentStackPointer() { #ifdef _MSC_VER - return reinterpret_cast(_AddressOfReturnAddress()); + return reinterpret_cast(_AddressOfReturnAddress()) + kWordSize; #elif __GNUC__ +#if defined(HOST_ARCH_RISCV32) || defined(HOST_ARCH_RISCV64) + // RISC-V has unusual choice of FP as SP at entry (i.e., DWARF CFA). return reinterpret_cast(__builtin_frame_address(0)); +#else + // Usually FP is address of saved FP, two slots from SP at entry. + return reinterpret_cast(__builtin_frame_address(0)) + 2 * kWordSize; +#endif #else #error Unimplemented #endif diff --git a/runtime/vm/stub_code_list.h b/runtime/vm/stub_code_list.h index a2e3814be19..9625918343c 100644 --- a/runtime/vm/stub_code_list.h +++ b/runtime/vm/stub_code_list.h @@ -29,7 +29,6 @@ namespace dart { // List of stubs created in the VM isolate, these stubs are shared by different // isolates running in this dart process. #define VM_STUB_CODE_LIST(V) \ - V(GetCStackPointer) \ V(JumpToFrame) \ V(RunExceptionHandler) \ V(RunExceptionHandlerUnbox) \