cctest-utils.h 1.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// 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
16 17
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("mov %%rsp, %0" : "=g"(sp_addr))
18
#elif V8_HOST_ARCH_IA32
19 20
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("mov %%esp, %0" : "=g"(sp_addr))
21
#elif V8_HOST_ARCH_ARM
22 23
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("str sp, %0" : "=g"(sp_addr))
24
#elif V8_HOST_ARCH_ARM64
25 26
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("mov x16, sp; str x16, %0" : "=g"(sp_addr))
27
#elif V8_HOST_ARCH_MIPS
28 29
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("sw $sp, %0" : "=g"(sp_addr))
30
#elif V8_HOST_ARCH_MIPS64
31 32
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("sd $sp, %0" : "=g"(sp_addr))
33
#elif defined(__s390x__) || defined(_ARCH_S390X)
34 35
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("stg %%r15, %0" : "=m"(sp_addr))
36
#elif defined(__s390__) || defined(_ARCH_S390)
37 38
#define GET_STACK_POINTER_TO(sp_addr) \
  __asm__ __volatile__("st 15, %0" : "=m"(sp_addr))
39
#elif defined(__PPC64__) || defined(_ARCH_PPC64)
40
#define GET_STACK_POINTER_TO(sp_addr) \
41
  __asm__ __volatile__("std 1, %0" : "=m"(sp_addr))
42
#elif defined(__PPC__) || defined(_ARCH_PPC)
43
#define GET_STACK_POINTER_TO(sp_addr) \
44
  __asm__ __volatile__("stw 1, %0" : "=m"(sp_addr))
45 46 47
#else
#error Host architecture was not detected as supported by v8
#endif
48 49 50 51 52 53

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);
54 55 56 57 58 59 60
  return sp_addr;
}

#endif  // V8_CC_GNU

}  // namespace internal
}  // namespace v8