]>
Commit | Line | Data |
---|---|---|
d614a753 | 1 | /* Copyright (C) 2001-2020 Free Software Foundation, Inc. |
bcf55240 TS |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
15 | License along with the GNU C Library; if not, see | |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
bcf55240 TS |
17 | |
18 | #include <sysdep.h> | |
19 | #include <jmpbuf-offsets.h> | |
20 | #include <asm-syntax.h> | |
21 | ||
22 | #include <signal-defines.h> | |
23 | /* #include <signal.h> */ | |
24 | #define SS_ONSTACK 1 | |
25 | ||
26 | ||
27 | .section .rodata.str1.1,"aMS",@progbits,1 | |
28 | .type longjmp_msg,@object | |
29 | longjmp_msg: | |
30 | .string "longjmp causes uninitialized stack frame" | |
31 | .size longjmp_msg, .-longjmp_msg | |
32 | ||
33 | ||
34 | #ifdef PIC | |
35 | # define CALL_FAIL movl %ebx, %ecx; /* TODO: what's this mov good for? */ \ | |
36 | cfi_register(%ebx,%ecx); \ | |
37 | LOAD_PIC_REG (bx); \ | |
38 | leal longjmp_msg@GOTOFF(%ebx), %eax; \ | |
1b0bfc69 | 39 | movl %eax, (%esp); \ |
bcf55240 TS |
40 | call HIDDEN_JUMPTARGET(__fortify_fail) |
41 | #else | |
42 | # define CALL_FAIL movl $longjmp_msg, %eax; \ | |
1b0bfc69 | 43 | movl %eax, (%esp); \ |
bcf55240 TS |
44 | call HIDDEN_JUMPTARGET(__fortify_fail) |
45 | #endif | |
46 | ||
47 | ||
48 | .text | |
49 | ENTRY (____longjmp_chk) | |
50 | movl 4(%esp), %ecx /* User's jmp_buf in %ecx. */ | |
51 | ||
52 | /* Save the return address now. */ | |
53 | movl (JB_PC*4)(%ecx), %edx | |
54 | /* Get the stack pointer. */ | |
55 | movl (JB_SP*4)(%ecx), %edi | |
56 | cfi_undefined(%edi) | |
e10bb107 | 57 | #ifdef PTR_DEMANGLE |
bcf55240 TS |
58 | PTR_DEMANGLE (%edx) |
59 | PTR_DEMANGLE (%edi) | |
e10bb107 | 60 | #endif |
bcf55240 TS |
61 | |
62 | cmpl %edi, %esp | |
63 | /* Jumping to a higher-address frame is always allowed. */ | |
64 | jbe .Lok | |
65 | ||
66 | /* Passing here, we're either about to do something invalid, or we're | |
67 | executing on an alternative signal stack. */ | |
68 | ||
69 | /* TODO: need locking? */ | |
70 | /* struct hurd_sigstate * _hurd_self_sigstate (void) */ | |
4d0ac037 | 71 | call HIDDEN_JUMPTARGET(_hurd_self_sigstate) |
bcf55240 TS |
72 | /* TODO: %eax and %eax->sigaltstack are always valid? */ |
73 | ||
74 | testl $SS_ONSTACK, (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_FLAGS__OFFSET)(%eax) | |
75 | /* Fail if SS_ONSTACK is not set. */ | |
76 | jz .Lfail | |
77 | ||
78 | movl (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_SP__OFFSET)(%eax), %ebx | |
79 | addl (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_SIZE__OFFSET)(%eax), %ebx | |
80 | subl %edi, %ebx | |
81 | cmpl (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_SIZE__OFFSET)(%eax), %ebx | |
82 | /* TODO: comment this calculation. */ | |
83 | jae .Lok | |
84 | ||
85 | .Lfail: CALL_FAIL | |
86 | ||
87 | .Lok: /* We add unwind information for the target here. */ | |
88 | cfi_def_cfa(%ecx, 0) | |
89 | cfi_register(%eip, %edx) | |
90 | cfi_register(%esp, %edi) | |
91 | cfi_offset(%ebx, JB_BX*4) | |
92 | cfi_offset(%esi, JB_SI*4) | |
93 | cfi_offset(%edi, JB_DI*4) | |
94 | cfi_offset(%ebp, JB_BP*4) | |
95 | ||
96 | movl 8(%esp), %eax /* Second argument is return value. */ | |
97 | movl %edi, %esp | |
98 | ||
99 | /* Restore registers. */ | |
100 | movl (JB_BX*4)(%ecx), %ebx | |
101 | movl (JB_SI*4)(%ecx), %esi | |
102 | movl (JB_DI*4)(%ecx), %edi | |
103 | movl (JB_BP*4)(%ecx), %ebp | |
104 | cfi_restore(%ebx) | |
105 | cfi_restore(%esi) | |
106 | cfi_restore(%edi) | |
107 | cfi_restore(%ebp) | |
108 | ||
109 | /* Jump to saved PC. */ | |
110 | jmp *%edx | |
111 | END (____longjmp_chk) |