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