]>
Commit | Line | Data |
---|---|---|
d4697bc9 | 1 | /* Copyright (C) 2001-2014 Free Software Foundation, Inc. |
da97dfdc UD |
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 | |
59ba27a6 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ | |
da97dfdc UD |
17 | |
18 | #include <sysdep.h> | |
19 | #include <jmpbuf-offsets.h> | |
20 | #include <asm-syntax.h> | |
8422c9a5 | 21 | #include <stap-probe.h> |
da97dfdc UD |
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; \ | |
b402e91a | 36 | call HIDDEN_JUMPTARGET(__fortify_fail) |
da97dfdc UD |
37 | #else |
38 | # define CALL_FAIL movl $longjmp_msg, %eax; \ | |
b402e91a | 39 | call HIDDEN_JUMPTARGET(__fortify_fail) |
da97dfdc UD |
40 | #endif |
41 | ||
da97dfdc UD |
42 | |
43 | .text | |
44 | ENTRY (____longjmp_chk) | |
45 | movl 4(%esp), %ecx /* User's jmp_buf in %ecx. */ | |
46 | ||
47 | /* Save the return address now. */ | |
48 | movl (JB_PC*4)(%ecx), %edx | |
49 | /* Get the stack pointer. */ | |
50 | movl (JB_SP*4)(%ecx), %edi | |
51 | cfi_undefined(%edi) | |
52 | PTR_DEMANGLE (%edx) | |
53 | PTR_DEMANGLE (%edi) | |
54 | ||
da97dfdc UD |
55 | cmpl %edi, %esp |
56 | jbe .Lok | |
57 | ||
58 | subl $12, %esp | |
59 | cfi_adjust_cfa_offset(12) | |
60 | xorl %ebx, %ebx | |
61 | movl %esp, %ecx | |
62 | movl $__NR_sigaltstack, %eax | |
63 | ENTER_KERNEL | |
e4143e7a UD |
64 | /* Without working sigaltstack we cannot perform the test. */ |
65 | test %eax, %eax | |
66 | jne .Lok2 | |
67 | testl $1, 4(%esp) | |
68 | jz .Lfail | |
69 | ||
70 | movl (%esp), %eax | |
71 | addl 8(%esp), %eax | |
72 | subl %edi, %eax | |
73 | cmpl 8(%esp), %eax | |
74 | jae .Lok2 | |
75 | ||
76 | .Lfail: CALL_FAIL | |
77 | ||
78 | .Lok2: addl $12, %esp | |
da97dfdc | 79 | cfi_adjust_cfa_offset(-12) |
e4143e7a UD |
80 | movl 4(%esp), %ecx |
81 | ||
8422c9a5 RM |
82 | .Lok: |
83 | LIBC_PROBE (longjmp, 3, 4@%ecx, -4@8(%esp), 4@%edx) | |
84 | /* We add unwind information for the target here. */ | |
da97dfdc UD |
85 | cfi_def_cfa(%ecx, 0) |
86 | cfi_register(%eip, %edx) | |
87 | cfi_register(%esp, %edi) | |
88 | cfi_offset(%ebx, JB_BX*4) | |
89 | cfi_offset(%esi, JB_SI*4) | |
90 | cfi_offset(%edi, JB_DI*4) | |
91 | cfi_offset(%ebp, JB_BP*4) | |
92 | ||
e4143e7a UD |
93 | movl 8(%esp), %eax /* Second argument is return value. */ |
94 | movl %edi, %esp | |
da97dfdc | 95 | |
57dbdb9f | 96 | /* Restore registers. */ |
e4143e7a | 97 | movl (JB_BX*4)(%ecx), %ebx |
da97dfdc UD |
98 | movl (JB_SI*4)(%ecx), %esi |
99 | movl (JB_DI*4)(%ecx), %edi | |
100 | movl (JB_BP*4)(%ecx), %ebp | |
101 | cfi_restore(%ebx) | |
102 | cfi_restore(%esi) | |
103 | cfi_restore(%edi) | |
104 | cfi_restore(%ebp) | |
105 | ||
106 | /* Jump to saved PC. */ | |
8422c9a5 | 107 | LIBC_PROBE (longjmp_target, 3, 4@%ecx, -4@%eax, 4@%edx) |
57dbdb9f | 108 | jmp *%edx |
da97dfdc | 109 | END (____longjmp_chk) |