cctest-utils.h 2.24 KB
Newer Older
1 2 3 4 5 6 7
// 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"
8
#include "src/base/sanitizer/asan.h"
9 10 11 12 13 14 15 16
#include "test/cctest/cctest.h"

namespace v8 {
namespace internal {

#ifdef V8_CC_GNU

#if V8_HOST_ARCH_X64
17 18
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("mov %%rsp, %0" : "=g"(sp_addr))
19
#elif V8_HOST_ARCH_IA32
20 21
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("mov %%esp, %0" : "=g"(sp_addr))
22
#elif V8_HOST_ARCH_ARM
23 24
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("str sp, %0" : "=g"(sp_addr))
25
#elif V8_HOST_ARCH_ARM64
26 27
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("mov x16, sp; str x16, %0" : "=g"(sp_addr))
28
#elif V8_HOST_ARCH_MIPS
29 30
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("sw $sp, %0" : "=g"(sp_addr))
31
#elif V8_HOST_ARCH_MIPS64
32 33
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("sd $sp, %0" : "=g"(sp_addr))
34
#elif defined(__s390x__) || defined(_ARCH_S390X)
35 36
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("stg %%r15, %0" : "=m"(sp_addr))
37
#elif defined(__s390__) || defined(_ARCH_S390)
38 39
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("st 15, %0" : "=m"(sp_addr))
40
#elif defined(__PPC64__) || defined(_ARCH_PPC64)
41
#define GET_STACK_POINTER_TO(sp_addr) \
42
  __asm__ __volatile__("std 1, %0" : "=m"(sp_addr))
43
#elif defined(__PPC__) || defined(_ARCH_PPC)
44
#define GET_STACK_POINTER_TO(sp_addr) \
45
  __asm__ __volatile__("stw 1, %0" : "=m"(sp_addr))
46
#elif V8_TARGET_ARCH_RISCV64 || V8_TARGET_ARCH_RISCV32
Brice Dobry's avatar
Brice Dobry committed
47 48
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("add %0, sp, x0" : "=r"(sp_addr))
49 50 51
#elif V8_HOST_ARCH_LOONG64
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("st.d $sp, %0" : "=m"(sp_addr))
52 53 54
#else
#error Host architecture was not detected as supported by v8
#endif
55 56 57 58 59 60

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);
61 62 63 64 65 66 67
  return sp_addr;
}

#endif  // V8_CC_GNU

}  // namespace internal
}  // namespace v8