• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *  * Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 *  * Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in
12 *    the documentation and/or other materials provided with the
13 *    distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include <private/bionic_asm.h>
30
31// DWARF constants.
32#define DW_CFA_def_cfa_expression 0x0f
33#define DW_CFA_expression 0x10
34#define DW_EH_PE_pcrel 0x10
35#define DW_EH_PE_sdata4 0x0b
36#define DW_OP_breg4 0x74
37#define DW_OP_breg7 0x77
38#define DW_OP_deref 0x06
39
40// Offsets into struct ucontext_t of uc_mcontext.gregs[x].
41#define OFFSET_R8 40
42#define OFFSET_R9 48
43#define OFFSET_R10 56
44#define OFFSET_R11 64
45#define OFFSET_R12 72
46#define OFFSET_R13 80
47#define OFFSET_R14 88
48#define OFFSET_R15 96
49#define OFFSET_RDI 104
50#define OFFSET_RSI 112
51#define OFFSET_RBP 120
52#define OFFSET_RSP 160
53#define OFFSET_RBX 128
54#define OFFSET_RDX 136
55#define OFFSET_RAX 144
56#define OFFSET_RCX 152
57#define OFFSET_RIP 168
58
59// Non-standard DWARF constants for the x86-64 registers.
60#define DW_x86_64_RAX 0
61#define DW_x86_64_RDX 1
62#define DW_x86_64_RCX 2
63#define DW_x86_64_RBX 3
64#define DW_x86_64_RSI 4
65#define DW_x86_64_RDI 5
66#define DW_x86_64_RBP 6
67#define DW_x86_64_RSP 7
68#define DW_x86_64_R8 8
69#define DW_x86_64_R9 9
70#define DW_x86_64_R10 10
71#define DW_x86_64_R11 11
72#define DW_x86_64_R12 12
73#define DW_x86_64_R13 13
74#define DW_x86_64_R14 14
75#define DW_x86_64_R15 15
76#define DW_x86_64_RIP 16
77
78#define cfi_signal_frame_start(f) \
79.section .eh_frame,"a",@progbits; \
80.L ## f ## _START_EH_FRAME: \
81  .long 2f - 1f; /* CIE length. */ \
821:.long 0;       /* CIE ID. */ \
83  .byte 1;       /* Version. */ \
84  .string "zRS"; /* Augmentation string. */ \
85  .uleb128 1;    /* Code alignment factor. */ \
86  .sleb128 -8;   /* Data alignment factor. */ \
87  .uleb128 DW_x86_64_RIP;   /* Return address register. */ \
88  .uleb128 1;    /* 1 byte of augmentation data. */ \
89  .byte (DW_EH_PE_pcrel | DW_EH_PE_sdata4); /* FDE encoding. */ \
90  .align 8; \
912: \
92  .long .L ## f ## _END_FDE - .L ## f ## _START_FDE;   /* FDE length. */ \
93.L ## f ## _START_FDE: \
94  .long .L ## f ## _START_FDE - .L ## f ## _START_EH_FRAME; /* CIE location. */ \
95  .long (.L ## f ## _START - 1) - .;                   /* pcrel start address (see FDE encoding above). */ \
96  .long .L ## f ## _END - (.L ## f ## _START - 1);     /* Function this FDE applies to. */ \
97  .uleb128 0;                                          /* FDE augmentation length. */ \
98
99#define cfi_signal_frame_end(f) \
100.L ## f ## _END_FDE: \
101
102#define cfi_def_cfa(offset) \
103  .byte DW_CFA_def_cfa_expression; \
104  .uleb128 2f-1f; \
1051:.byte DW_OP_breg7; \
106  .sleb128 offset; \
107  .byte DW_OP_deref; \
1082: \
109
110#define cfi_offset(reg_number,offset) \
111  .byte DW_CFA_expression; \
112  .uleb128 reg_number; \
113  .uleb128 2f-1f; \
1141:.byte DW_OP_breg7; \
115  .sleb128 offset; \
1162: \
117
118ENTRY_PRIVATE(__restore_rt)
119.L__restore_rt_START:
120  mov $__NR_rt_sigreturn, %rax
121  syscall
122.L__restore_rt_END:
123END(__restore_rt)
124cfi_signal_frame_start(__restore_rt)
125  cfi_def_cfa(OFFSET_RSP)
126  cfi_offset(DW_x86_64_R8, OFFSET_R8)
127  cfi_offset(DW_x86_64_R9, OFFSET_R9)
128  cfi_offset(DW_x86_64_R10, OFFSET_R10)
129  cfi_offset(DW_x86_64_R11, OFFSET_R11)
130  cfi_offset(DW_x86_64_R12, OFFSET_R12)
131  cfi_offset(DW_x86_64_R13, OFFSET_R13)
132  cfi_offset(DW_x86_64_R14, OFFSET_R14)
133  cfi_offset(DW_x86_64_R15, OFFSET_R15)
134  cfi_offset(DW_x86_64_RDI, OFFSET_RDI)
135  cfi_offset(DW_x86_64_RSI, OFFSET_RSI)
136  cfi_offset(DW_x86_64_RBP, OFFSET_RBP)
137  cfi_offset(DW_x86_64_RSP, OFFSET_RSP)
138  cfi_offset(DW_x86_64_RBX, OFFSET_RBX)
139  cfi_offset(DW_x86_64_RDX, OFFSET_RDX)
140  cfi_offset(DW_x86_64_RAX, OFFSET_RAX)
141  cfi_offset(DW_x86_64_RCX, OFFSET_RCX)
142  cfi_offset(DW_x86_64_RIP, OFFSET_RIP)
143cfi_signal_frame_end(__restore_rt)
144