Use HIDDEN_JUMPTARGET rather than spelling out its effects, for ____longjmp_chk imple...
[glibc.git] / sysdeps / unix / sysv / linux / x86_64 / ____longjmp_chk.S
blobd8cbe06841d441711598fbd56475d9b410b4832d
1 /* Copyright (C) 2001,2004,2005,2006,2009,2010,2011 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
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.
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.
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
19 #include <sysdep.h>
20 #include <jmpbuf-offsets.h>
21 #include <asm-syntax.h>
23         .section .rodata.str1.1,"aMS",@progbits,1
24         .type   longjmp_msg,@object
25 longjmp_msg:
26         .string "longjmp causes uninitialized stack frame"
27         .size   longjmp_msg, .-longjmp_msg
30 //#define __longjmp ____longjmp_chk
32 #ifdef PIC
33 # define CALL_FAIL      subq    $8, %rsp;                                     \
34                         cfi_remember_state;                                   \
35                         cfi_def_cfa_offset(16);                               \
36                         leaq    longjmp_msg(%rip), %rdi;                      \
37                         call    HIDDEN_JUMPTARGET(__fortify_fail);            \
38                         nop;                                                  \
39                         cfi_restore_state
40 #else
41 # define CALL_FAIL      subq    $8, %rsp;                                     \
42                         cfi_remember_state;                                   \
43                         cfi_def_cfa_offset(16);                               \
44                         movq    $longjmp_msg, %rdi;                           \
45                         call    HIDDEN_JUMPTARGET(__fortify_fail);            \
46                         nop;                                                  \
47                         cfi_restore_state
48 #endif
50 /* Jump to the position specified by ENV, causing the
51    setjmp call there to return VAL, or 1 if VAL is 0.
52    void __longjmp (__jmp_buf env, int val).  */
53         .text
54 ENTRY(____longjmp_chk)
55         /* Restore registers.  */
56         movq    (JB_RSP*8)(%rdi), %r8
57         movq    (JB_RBP*8)(%rdi), %r9
58         movq    (JB_PC*8)(%rdi), %rdx
59 #ifdef PTR_DEMANGLE
60         PTR_DEMANGLE (%r8)
61         PTR_DEMANGLE (%r9)
62         PTR_DEMANGLE (%rdx)
63 #endif
65         cmpq    %r8, %rsp
66         jbe     .Lok
68         /* Save function parameters.  */
69         movq    %rdi, %r10
70         cfi_register (%rdi, %r10)
71         movl    %esi, %ebx
72         cfi_register (%rsi, %rbx)
74         xorl    %edi, %edi
75         leaq    -24(%rsp), %rsi
76         movl    $__NR_sigaltstack, %eax
77         syscall
78         /* Without working sigaltstack we cannot perform the test.  */
79         testl   %eax, %eax
80         jne     .Lok2
81         testl   $1, -16(%rsp)
82         jz      .Lfail
84         movq    -24(%rsp), %rax
85         addq    -8(%rsp), %rax
86         subq    %r8, %rax
87         cmpq    -8(%rsp), %rax
88         jae     .Lok2
90 .Lfail: CALL_FAIL
92 .Lok2:  movq    %r10, %rdi
93         cfi_restore (%rdi)
94         movl    %ebx, %esi
95         cfi_restore (%rsi)
97 .Lok:   /* We add unwind information for the target here.  */
98         cfi_def_cfa(%rdi, 0)
99         cfi_register(%rsp,%r8)
100         cfi_register(%rbp,%r9)
101         cfi_register(%rip,%rdx)
102         cfi_offset(%rbx,JB_RBX*8)
103         cfi_offset(%r12,JB_R12*8)
104         cfi_offset(%r13,JB_R13*8)
105         cfi_offset(%r14,JB_R14*8)
106         cfi_offset(%r15,JB_R15*8)
107         movq    (JB_RBX*8)(%rdi), %rbx
108         movq    (JB_R12*8)(%rdi), %r12
109         movq    (JB_R13*8)(%rdi), %r13
110         movq    (JB_R14*8)(%rdi), %r14
111         movq    (JB_R15*8)(%rdi), %r15
112         /* Set return value for setjmp.  */
113         movl    %esi, %eax
114         movq    %r8,%rsp
115         movq    %r9,%rbp
116         jmpq    *%rdx
117 END (____longjmp_chk)