]>
Commit | Line | Data |
---|---|---|
5e2eebc8 ST |
1 | /* DWARF2 EH unwinding support for GNU Hurd: x86. |
2 | Copyright (C) 2020 Free Software Foundation, Inc. | |
3 | Contributed by Samuel Thibault <samuel.thibault@gnu.org> | |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GCC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | Under Section 7 of GPL version 3, you are granted additional | |
18 | permissions described in the GCC Runtime Library Exception, version | |
19 | 3.1, as published by the Free Software Foundation. | |
20 | ||
21 | You should have received a copy of the GNU General Public License and | |
22 | a copy of the GCC Runtime Library Exception along with this program; | |
23 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
24 | <http://www.gnu.org/licenses/>. */ | |
25 | ||
26 | /* Do code reading to identify a signal frame, and set the frame | |
27 | state data appropriately. See unwind-dw2.c for the structs. */ | |
28 | ||
29 | #ifndef inhibit_libc | |
30 | ||
31 | #include <signal.h> | |
32 | ||
33 | #define MD_FALLBACK_FRAME_STATE_FOR x86_gnu_fallback_frame_state | |
34 | ||
35 | static _Unwind_Reason_Code | |
36 | x86_gnu_fallback_frame_state | |
37 | (struct _Unwind_Context *context, _Unwind_FrameState *fs) | |
38 | { | |
39 | struct handler_args { | |
40 | int signo; | |
41 | int sigcode; | |
42 | struct sigcontext *scp; | |
43 | } *handler_args; | |
44 | struct sigcontext *scp; | |
45 | unsigned long usp; | |
46 | ||
47 | /* | |
48 | * i386 sigtramp frame we are looking for follows. | |
49 | * (see glibc/sysdeps/mach/hurd/i386/trampoline.c assembly) | |
50 | * | |
51 | * rpc_wait_trampoline: | |
52 | * 0: b8 e7 ff ff ff mov $-25,%eax mach_msg_trap | |
53 | * 5: 9a 00 00 00 00 07 00 lcall $7,$0 | |
54 | * 12: 89 01 movl %eax, (%ecx) | |
55 | * 14: 89 dc movl %ebx, %esp switch to signal stack | |
56 | * | |
57 | * trampoline: | |
58 | * 16: ff d2 call *%edx call the handler function | |
59 | * RA HERE | |
60 | * 18: 83 c4 0c addl $12, %esp pop its args | |
61 | * 21: c3 ret return to sigreturn | |
62 | * | |
63 | * firewall: | |
64 | * 22: f4 hlt | |
65 | */ | |
66 | ||
67 | if (!( *(unsigned int *)(context->ra ) == 0xc30cc483 | |
68 | && *(unsigned char *)(context->ra + 4) == 0xf4 | |
69 | ||
70 | && *(unsigned int *)(context->ra - 4) == 0xd2ffdc89 | |
71 | && *(unsigned int *)(context->ra - 8) == 0x01890007 | |
72 | && *(unsigned int *)(context->ra - 12) == 0x00000000 | |
73 | && *(unsigned int *)(context->ra - 16) == 0x9affffff | |
74 | && *(unsigned short *)(context->ra - 18) == 0xe7b8)) | |
75 | return _URC_END_OF_STACK; | |
76 | ||
77 | handler_args = context->cfa; | |
78 | scp = handler_args->scp; | |
79 | usp = scp->sc_uesp; | |
80 | ||
81 | fs->regs.cfa_how = CFA_REG_OFFSET; | |
82 | fs->regs.cfa_reg = 4; | |
83 | fs->regs.cfa_offset = usp - (unsigned long) context->cfa; | |
84 | ||
85 | fs->regs.reg[0].how = REG_SAVED_OFFSET; | |
86 | fs->regs.reg[0].loc.offset = (unsigned long)&scp->sc_eax - usp; | |
87 | fs->regs.reg[1].how = REG_SAVED_OFFSET; | |
88 | fs->regs.reg[1].loc.offset = (unsigned long)&scp->sc_ecx - usp; | |
89 | fs->regs.reg[2].how = REG_SAVED_OFFSET; | |
90 | fs->regs.reg[2].loc.offset = (unsigned long)&scp->sc_edx - usp; | |
91 | fs->regs.reg[3].how = REG_SAVED_OFFSET; | |
92 | fs->regs.reg[3].loc.offset = (unsigned long)&scp->sc_ebx - usp; | |
93 | fs->regs.reg[5].how = REG_SAVED_OFFSET; | |
94 | fs->regs.reg[5].loc.offset = (unsigned long)&scp->sc_ebp - usp; | |
95 | fs->regs.reg[6].how = REG_SAVED_OFFSET; | |
96 | fs->regs.reg[6].loc.offset = (unsigned long)&scp->sc_esi - usp; | |
97 | fs->regs.reg[7].how = REG_SAVED_OFFSET; | |
98 | fs->regs.reg[7].loc.offset = (unsigned long)&scp->sc_edi - usp; | |
99 | fs->regs.reg[8].how = REG_SAVED_OFFSET; | |
100 | fs->regs.reg[8].loc.offset = (unsigned long)&scp->sc_eip - usp; | |
101 | fs->retaddr_column = 8; | |
102 | fs->signal_frame = 1; | |
103 | ||
104 | return _URC_NO_REASON; | |
105 | } | |
106 | ||
107 | #endif /* ifndef inhibit_libc */ |