]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/i386/____longjmp_chk.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / ____longjmp_chk.S
1 /* Copyright (C) 2001-2018 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 <http://www.gnu.org/licenses/>. */
17
18 #include <sysdep.h>
19 #include <jmpbuf-offsets.h>
20 #include <asm-syntax.h>
21 #include <stap-probe.h>
22
23
24 .section .rodata.str1.1,"aMS",@progbits,1
25 .type longjmp_msg,@object
26 longjmp_msg:
27 .string "longjmp causes uninitialized stack frame"
28 .size longjmp_msg, .-longjmp_msg
29
30
31 #ifdef PIC
32 # define CALL_FAIL movl %ebx, %ecx; \
33 cfi_register(%ebx,%ecx); \
34 LOAD_PIC_REG (bx); \
35 leal longjmp_msg@GOTOFF(%ebx), %eax; \
36 movl %eax, (%esp); \
37 call HIDDEN_JUMPTARGET(__fortify_fail)
38 #else
39 # define CALL_FAIL movl $longjmp_msg, %eax; \
40 movl %eax, (%esp); \
41 call HIDDEN_JUMPTARGET(__fortify_fail)
42 #endif
43
44
45 .text
46 ENTRY (____longjmp_chk)
47 movl 4(%esp), %ecx /* User's jmp_buf in %ecx. */
48
49 /* Save the return address now. */
50 movl (JB_PC*4)(%ecx), %edx
51 /* Get the stack pointer. */
52 movl (JB_SP*4)(%ecx), %edi
53 cfi_undefined(%edi)
54 PTR_DEMANGLE (%edx)
55 PTR_DEMANGLE (%edi)
56
57 cmpl %edi, %esp
58 jbe .Lok
59
60 subl $12, %esp
61 cfi_adjust_cfa_offset(12)
62 xorl %ebx, %ebx
63 movl %esp, %ecx
64 movl $__NR_sigaltstack, %eax
65 ENTER_KERNEL
66 /* Without working sigaltstack we cannot perform the test. */
67 test %eax, %eax
68 jne .Lok2
69 testl $1, 4(%esp)
70 jz .Lfail
71
72 movl (%esp), %eax
73 addl 8(%esp), %eax
74 subl %edi, %eax
75 cmpl 8(%esp), %eax
76 jae .Lok2
77
78 .Lfail: CALL_FAIL
79
80 .Lok2: addl $12, %esp
81 cfi_adjust_cfa_offset(-12)
82 movl 4(%esp), %ecx
83
84 .Lok:
85 LIBC_PROBE (longjmp, 3, 4@%ecx, -4@8(%esp), 4@%edx)
86 /* We add unwind information for the target here. */
87 cfi_def_cfa(%ecx, 0)
88 cfi_register(%eip, %edx)
89 cfi_register(%esp, %edi)
90 cfi_offset(%ebx, JB_BX*4)
91 cfi_offset(%esi, JB_SI*4)
92 cfi_offset(%edi, JB_DI*4)
93 cfi_offset(%ebp, JB_BP*4)
94
95 movl 8(%esp), %eax /* Second argument is return value. */
96 movl %edi, %esp
97
98 /* Restore registers. */
99 movl (JB_BX*4)(%ecx), %ebx
100 movl (JB_SI*4)(%ecx), %esi
101 movl (JB_DI*4)(%ecx), %edi
102 movl (JB_BP*4)(%ecx), %ebp
103 cfi_restore(%ebx)
104 cfi_restore(%esi)
105 cfi_restore(%edi)
106 cfi_restore(%ebp)
107
108 /* Jump to saved PC. */
109 LIBC_PROBE (longjmp_target, 3, 4@%ecx, -4@%eax, 4@%edx)
110 jmp *%edx
111 END (____longjmp_chk)