Serban Constantinescu | e210488 | 2013-09-26 11:37:10 +0100 | [diff] [blame] | 1 | /* |
Elliott Hughes | 7dc2b7b | 2014-09-10 15:20:40 -0700 | [diff] [blame] | 2 | * Copyright (C) 2014 The Android Open Source Project |
Elliott Hughes | 54a7494 | 2014-01-03 16:40:37 -0800 | [diff] [blame] | 3 | * All rights reserved. |
Serban Constantinescu | e210488 | 2013-09-26 11:37:10 +0100 | [diff] [blame] | 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 | |
Elliott Hughes | 851e68a | 2014-02-19 16:53:20 -0800 | [diff] [blame] | 29 | #include <private/bionic_asm.h> |
Ryan Prichard | fd8d687 | 2020-04-17 19:46:51 -0700 | [diff] [blame] | 30 | #include <private/bionic_asm_dwarf_exprs.h> |
Pavel Chupin | 8eb8c39 | 2014-09-26 16:02:09 +0400 | [diff] [blame] | 31 | |
| 32 | // Offsets into struct sigcontext. |
| 33 | #define OFFSET_EDI 16 |
| 34 | #define OFFSET_ESI 20 |
| 35 | #define OFFSET_EBP 24 |
| 36 | #define OFFSET_ESP 28 |
| 37 | #define OFFSET_EBX 32 |
| 38 | #define OFFSET_EDX 36 |
| 39 | #define OFFSET_ECX 40 |
| 40 | #define OFFSET_EAX 44 |
| 41 | #define OFFSET_EIP 56 |
| 42 | |
| 43 | // Non-standard DWARF constants for the x86 registers. |
| 44 | #define DW_x86_REG_EAX 0 |
| 45 | #define DW_x86_REG_ECX 1 |
| 46 | #define DW_x86_REG_EDX 2 |
| 47 | #define DW_x86_REG_EBX 3 |
Ryan Prichard | fd8d687 | 2020-04-17 19:46:51 -0700 | [diff] [blame] | 48 | #define DW_x86_REG_ESP 4 |
Pavel Chupin | 8eb8c39 | 2014-09-26 16:02:09 +0400 | [diff] [blame] | 49 | #define DW_x86_REG_EBP 5 |
| 50 | #define DW_x86_REG_ESI 6 |
| 51 | #define DW_x86_REG_EDI 7 |
| 52 | #define DW_x86_REG_EIP 8 |
| 53 | |
Ryan Prichard | fd8d687 | 2020-04-17 19:46:51 -0700 | [diff] [blame] | 54 | #define RESTORE_GPR(reg, extra_offset) \ |
| 55 | m_cfi_breg_offset DW_x86_REG_ ## reg, \ |
| 56 | DW_x86_REG_ESP, \ |
| 57 | (OFFSET_ ## reg + (extra_offset)); |
Pavel Chupin | 8eb8c39 | 2014-09-26 16:02:09 +0400 | [diff] [blame] | 58 | |
Ryan Prichard | fd8d687 | 2020-04-17 19:46:51 -0700 | [diff] [blame] | 59 | // Restoring ESP is unnecessary as the unwinder simply uses the CFA value. |
| 60 | #define RESTORE_GPRS(extra_offset) \ |
| 61 | m_cfi_def_cfa_deref DW_x86_REG_ESP, (OFFSET_ESP + (extra_offset)); \ |
| 62 | RESTORE_GPR(EDI, extra_offset) \ |
| 63 | RESTORE_GPR(ESI, extra_offset) \ |
| 64 | RESTORE_GPR(EBP, extra_offset) \ |
| 65 | RESTORE_GPR(EBX, extra_offset) \ |
| 66 | RESTORE_GPR(EDX, extra_offset) \ |
| 67 | RESTORE_GPR(ECX, extra_offset) \ |
| 68 | RESTORE_GPR(EAX, extra_offset) \ |
| 69 | RESTORE_GPR(EIP, extra_offset) \ |
Pavel Chupin | 8eb8c39 | 2014-09-26 16:02:09 +0400 | [diff] [blame] | 70 | |
Ryan Prichard | fd8d687 | 2020-04-17 19:46:51 -0700 | [diff] [blame] | 71 | .text |
Pavel Chupin | 8eb8c39 | 2014-09-26 16:02:09 +0400 | [diff] [blame] | 72 | |
Ryan Prichard | fd8d687 | 2020-04-17 19:46:51 -0700 | [diff] [blame] | 73 | .cfi_startproc |
| 74 | .cfi_signal_frame |
| 75 | RESTORE_GPRS(4) |
| 76 | nop // See comment in libc/arch-x86_64/bionic/__restore_rt.S about this nop. |
| 77 | ENTRY_PRIVATE_NO_DWARF(__restore) |
Elliott Hughes | 7dc2b7b | 2014-09-10 15:20:40 -0700 | [diff] [blame] | 78 | popl %eax |
Ryan Prichard | fd8d687 | 2020-04-17 19:46:51 -0700 | [diff] [blame] | 79 | RESTORE_GPRS(0) |
Elliott Hughes | 7dc2b7b | 2014-09-10 15:20:40 -0700 | [diff] [blame] | 80 | movl $__NR_sigreturn, %eax |
| 81 | int $0x80 |
| 82 | END(__restore) |
Pavel Chupin | 8eb8c39 | 2014-09-26 16:02:09 +0400 | [diff] [blame] | 83 | |
Ryan Prichard | fd8d687 | 2020-04-17 19:46:51 -0700 | [diff] [blame] | 84 | .cfi_startproc |
| 85 | .cfi_signal_frame |
| 86 | RESTORE_GPRS(160) |
| 87 | nop // See comment in libc/arch-x86_64/bionic/__restore_rt.S about this nop. |
| 88 | ENTRY_PRIVATE_NO_DWARF(__restore_rt) |
Pavel Chupin | 8eb8c39 | 2014-09-26 16:02:09 +0400 | [diff] [blame] | 89 | movl $__NR_rt_sigreturn, %eax |
| 90 | int $0x80 |
Pavel Chupin | 8eb8c39 | 2014-09-26 16:02:09 +0400 | [diff] [blame] | 91 | END(__restore_rt) |