2020-10-13 15:44:09 +00:00
|
|
|
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "src/base/build_config.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
#ifdef V8_CC_GNU
|
|
|
|
|
|
|
|
#if V8_HOST_ARCH_X64
|
2020-10-14 09:16:11 +00:00
|
|
|
#define GET_STACK_POINTER_TO(sp_addr) \
|
|
|
|
__asm__ __volatile__("mov %%rsp, %0" : "=g"(sp_addr))
|
2020-10-13 15:44:09 +00:00
|
|
|
#elif V8_HOST_ARCH_IA32
|
2020-10-14 09:16:11 +00:00
|
|
|
#define GET_STACK_POINTER_TO(sp_addr) \
|
|
|
|
__asm__ __volatile__("mov %%esp, %0" : "=g"(sp_addr))
|
2020-10-13 15:44:09 +00:00
|
|
|
#elif V8_HOST_ARCH_ARM
|
2020-10-14 09:16:11 +00:00
|
|
|
#define GET_STACK_POINTER_TO(sp_addr) \
|
|
|
|
__asm__ __volatile__("str sp, %0" : "=g"(sp_addr))
|
2020-10-13 15:44:09 +00:00
|
|
|
#elif V8_HOST_ARCH_ARM64
|
2020-10-14 09:16:11 +00:00
|
|
|
#define GET_STACK_POINTER_TO(sp_addr) \
|
|
|
|
__asm__ __volatile__("mov x16, sp; str x16, %0" : "=g"(sp_addr))
|
2020-10-13 15:44:09 +00:00
|
|
|
#elif V8_HOST_ARCH_MIPS
|
2020-10-14 09:16:11 +00:00
|
|
|
#define GET_STACK_POINTER_TO(sp_addr) \
|
|
|
|
__asm__ __volatile__("sw $sp, %0" : "=g"(sp_addr))
|
2020-10-13 15:44:09 +00:00
|
|
|
#elif V8_HOST_ARCH_MIPS64
|
2020-10-14 09:16:11 +00:00
|
|
|
#define GET_STACK_POINTER_TO(sp_addr) \
|
|
|
|
__asm__ __volatile__("sd $sp, %0" : "=g"(sp_addr))
|
2020-10-13 15:44:09 +00:00
|
|
|
#elif defined(__s390x__) || defined(_ARCH_S390X)
|
2020-10-14 09:16:11 +00:00
|
|
|
#define GET_STACK_POINTER_TO(sp_addr) \
|
|
|
|
__asm__ __volatile__("stg %%r15, %0" : "=m"(sp_addr))
|
2020-10-13 15:44:09 +00:00
|
|
|
#elif defined(__s390__) || defined(_ARCH_S390)
|
2020-10-14 09:16:11 +00:00
|
|
|
#define GET_STACK_POINTER_TO(sp_addr) \
|
|
|
|
__asm__ __volatile__("st 15, %0" : "=m"(sp_addr))
|
2020-10-13 15:44:09 +00:00
|
|
|
#elif defined(__PPC64__) || defined(_ARCH_PPC64)
|
2020-10-14 09:16:11 +00:00
|
|
|
#define GET_STACK_POINTER_TO(sp_addr) \
|
2020-10-15 15:10:21 +00:00
|
|
|
__asm__ __volatile__("std 1, %0" : "=m"(sp_addr))
|
2020-10-13 15:44:09 +00:00
|
|
|
#elif defined(__PPC__) || defined(_ARCH_PPC)
|
2020-10-14 09:16:11 +00:00
|
|
|
#define GET_STACK_POINTER_TO(sp_addr) \
|
2020-10-15 15:10:21 +00:00
|
|
|
__asm__ __volatile__("stw 1, %0" : "=m"(sp_addr))
|
2020-10-13 15:44:09 +00:00
|
|
|
#else
|
|
|
|
#error Host architecture was not detected as supported by v8
|
|
|
|
#endif
|
2020-10-14 09:16:11 +00:00
|
|
|
|
|
|
|
DISABLE_ASAN inline uintptr_t GetStackPointer() {
|
|
|
|
// MSAN doesn't seem to treat initializing stores in inline assembly as such,
|
|
|
|
// so we initialize this value here.
|
|
|
|
uintptr_t sp_addr = 0;
|
|
|
|
GET_STACK_POINTER_TO(sp_addr);
|
2020-10-13 15:44:09 +00:00
|
|
|
return sp_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // V8_CC_GNU
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|