1 | /* Copyright (C) 2001-2024 Free Software Foundation, Inc. |
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 |
16 | <https://www.gnu.org/licenses/>. */ |
17 | |
18 | #include <sysdep.h> |
19 | #include <pointer_guard.h> |
20 | #include <jmpbuf-offsets.h> |
21 | #include <asm-syntax.h> |
22 | #include <stap-probe.h> |
23 | |
24 | |
25 | .section .rodata.str1.1,"aMS" ,@progbits,1 |
26 | .type longjmp_msg,@object |
27 | longjmp_msg: |
28 | .string "longjmp causes uninitialized stack frame" |
29 | .size longjmp_msg, .-longjmp_msg |
30 | |
31 | |
32 | #ifdef PIC |
33 | # define CALL_FAIL movl %ebx, %ecx; \ |
34 | cfi_register(%ebx,%ecx); \ |
35 | LOAD_PIC_REG (bx); \ |
36 | leal longjmp_msg@GOTOFF(%ebx), %eax; \ |
37 | movl %eax, (%esp); \ |
38 | call HIDDEN_JUMPTARGET(__fortify_fail) |
39 | #else |
40 | # define CALL_FAIL movl $longjmp_msg, %eax; \ |
41 | movl %eax, (%esp); \ |
42 | call HIDDEN_JUMPTARGET(__fortify_fail) |
43 | #endif |
44 | |
45 | |
46 | .text |
47 | ENTRY (____longjmp_chk) |
48 | movl 4(%esp), %ecx /* User's jmp_buf in %ecx. */ |
49 | |
50 | /* Save the return address now. */ |
51 | movl (JB_PC*4)(%ecx), %edx |
52 | /* Get the stack pointer. */ |
53 | movl (JB_SP*4)(%ecx), %edi |
54 | cfi_undefined(%edi) |
55 | PTR_DEMANGLE (%edx) |
56 | PTR_DEMANGLE (%edi) |
57 | |
58 | cmpl %edi, %esp |
59 | jbe .Lok |
60 | |
61 | subl $12, %esp |
62 | cfi_adjust_cfa_offset(12) |
63 | xorl %ebx, %ebx |
64 | movl %esp, %ecx |
65 | movl $__NR_sigaltstack, %eax |
66 | ENTER_KERNEL |
67 | /* Without working sigaltstack we cannot perform the test. */ |
68 | test %eax, %eax |
69 | jne .Lok2 |
70 | testl $1, 4(%esp) |
71 | jz .Lfail |
72 | |
73 | movl (%esp), %eax |
74 | addl 8(%esp), %eax |
75 | subl %edi, %eax |
76 | cmpl 8(%esp), %eax |
77 | jae .Lok2 |
78 | |
79 | .Lfail: CALL_FAIL |
80 | |
81 | .Lok2: addl $12, %esp |
82 | cfi_adjust_cfa_offset(-12) |
83 | movl 4(%esp), %ecx |
84 | |
85 | .Lok: |
86 | LIBC_PROBE (longjmp, 3, 4@%ecx, -4@8(%esp), 4@%edx) |
87 | /* 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 | LIBC_PROBE (longjmp_target, 3, 4@%ecx, -4@%eax, 4@%edx) |
111 | jmp *%edx |
112 | END (____longjmp_chk) |
113 | |