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 <sigaltstack-offsets.h> |
19 | |
20 | .section .rodata.str1.1,"aMS" ,@progbits,1 |
21 | .type longjmp_msg,@object |
22 | longjmp_msg: |
23 | .string "longjmp causes uninitialized stack frame" |
24 | .size longjmp_msg, .-longjmp_msg |
25 | |
26 | #ifdef PIC |
27 | # define LOAD_MSG lea longjmp_msg(%rip), %RDI_LP |
28 | #else |
29 | # define LOAD_MSG mov $longjmp_msg, %RDI_LP |
30 | #endif |
31 | |
32 | #define CHECK_INVALID_LONGJMP \ |
33 | cmp %R8_LP, %RSP_LP; \ |
34 | jbe .Lok; \ |
35 | /* Save function parameters. */ \ |
36 | movq %rdi, %r10; \ |
37 | cfi_register (%rdi, %r10); \ |
38 | movl %esi, %ebx; \ |
39 | cfi_register (%rsi, %rbx); \ |
40 | xorl %edi, %edi; \ |
41 | lea -sizeSS(%rsp), %RSI_LP; \ |
42 | movl $__NR_sigaltstack, %eax; \ |
43 | syscall; \ |
44 | /* Without working sigaltstack we cannot perform the test. */ \ |
45 | testl %eax, %eax; \ |
46 | jne .Lok2; \ |
47 | testl $1, (-sizeSS + oSS_FLAGS)(%rsp); \ |
48 | jz .Lfail; \ |
49 | mov (-sizeSS + oSS_SP)(%rsp), %RAX_LP; \ |
50 | add (-sizeSS + oSS_SIZE)(%rsp), %RAX_LP; \ |
51 | sub %R8_LP, %RAX_LP; \ |
52 | cmp (-sizeSS + oSS_SIZE)(%rsp), %RAX_LP; \ |
53 | jae .Lok2; \ |
54 | .Lfail: \ |
55 | sub $8, %RSP_LP; \ |
56 | cfi_remember_state; \ |
57 | cfi_def_cfa_offset(16); \ |
58 | LOAD_MSG; \ |
59 | call HIDDEN_JUMPTARGET(__fortify_fail); \ |
60 | cfi_restore_state; \ |
61 | .p2align 3, 5; \ |
62 | .Lok2: \ |
63 | movq %r10, %rdi; \ |
64 | cfi_restore (%rdi); \ |
65 | movl %ebx, %esi; \ |
66 | cfi_restore (%rsi); \ |
67 | .Lok: |
68 | |
69 | #define __longjmp ____longjmp_chk |
70 | #include <__longjmp.S> |
71 | |