rust: Implement TARGET_RUST_OS_INFO for *-*-darwin*
[official-gcc.git] / libsanitizer / hwasan / hwasan_registers.h
blob48a140ffc9236def3e09dbe25b1402479b53d3f3
1 //===-- hwasan_registers.h --------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This describes the register state retrieved by hwasan when error reporting.
11 //===----------------------------------------------------------------------===//
13 #ifndef HWASAN_REGISTERS_H
14 #define HWASAN_REGISTERS_H
16 #include "sanitizer_common/sanitizer_common.h"
17 #include "sanitizer_common/sanitizer_platform.h"
19 #if defined(__aarch64__)
21 # define CAN_GET_REGISTERS 1
23 struct Registers {
24 uptr x[32];
27 __attribute__((always_inline, unused)) static Registers GetRegisters() {
28 Registers regs;
29 __asm__ volatile(
30 "stp x0, x1, [%1, #(8 * 0)]\n"
31 "stp x2, x3, [%1, #(8 * 2)]\n"
32 "stp x4, x5, [%1, #(8 * 4)]\n"
33 "stp x6, x7, [%1, #(8 * 6)]\n"
34 "stp x8, x9, [%1, #(8 * 8)]\n"
35 "stp x10, x11, [%1, #(8 * 10)]\n"
36 "stp x12, x13, [%1, #(8 * 12)]\n"
37 "stp x14, x15, [%1, #(8 * 14)]\n"
38 "stp x16, x17, [%1, #(8 * 16)]\n"
39 "stp x18, x19, [%1, #(8 * 18)]\n"
40 "stp x20, x21, [%1, #(8 * 20)]\n"
41 "stp x22, x23, [%1, #(8 * 22)]\n"
42 "stp x24, x25, [%1, #(8 * 24)]\n"
43 "stp x26, x27, [%1, #(8 * 26)]\n"
44 "stp x28, x29, [%1, #(8 * 28)]\n"
45 : "=m"(regs)
46 : "r"(regs.x));
47 regs.x[30] = reinterpret_cast<uintptr_t>(__builtin_return_address(0));
48 regs.x[31] = reinterpret_cast<uintptr_t>(__builtin_frame_address(0));
49 return regs;
52 #else
53 # define CAN_GET_REGISTERS 0
54 #endif
56 #endif // HWASAN_REGISTERS_H