]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
Use R*_LP, sizeSS, oSS_FLAGS, oSS_SP and oSS_SIZE
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / x86_64 / ____longjmp_chk.S
CommitLineData
e451d22b 1/* Copyright (C) 2001,2004,2005,2006,2009,2010,2011 Free Software Foundation, Inc.
98b1e6c8
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/>. */
98b1e6c8
UD
17
18#include <sysdep.h>
19#include <jmpbuf-offsets.h>
20#include <asm-syntax.h>
21
85736dc7
L
22#include <sigaltstack-offsets.h>
23
98b1e6c8
UD
24 .section .rodata.str1.1,"aMS",@progbits,1
25 .type longjmp_msg,@object
26longjmp_msg:
27 .string "longjmp causes uninitialized stack frame"
28 .size longjmp_msg, .-longjmp_msg
29
30
31//#define __longjmp ____longjmp_chk
32
33#ifdef PIC
85736dc7 34# define CALL_FAIL sub $8, %RSP_LP; \
e451d22b
AS
35 cfi_remember_state; \
36 cfi_def_cfa_offset(16); \
85736dc7 37 lea longjmp_msg(%rip), %RDI_LP; \
b402e91a 38 call HIDDEN_JUMPTARGET(__fortify_fail); \
e451d22b
AS
39 nop; \
40 cfi_restore_state
98b1e6c8 41#else
85736dc7 42# define CALL_FAIL sub $8, %RSP_LP; \
e451d22b
AS
43 cfi_remember_state; \
44 cfi_def_cfa_offset(16); \
85736dc7 45 mov $longjmp_msg, %RDI_LP; \
b402e91a 46 call HIDDEN_JUMPTARGET(__fortify_fail); \
e451d22b
AS
47 nop; \
48 cfi_restore_state
98b1e6c8
UD
49#endif
50
98b1e6c8
UD
51/* Jump to the position specified by ENV, causing the
52 setjmp call there to return VAL, or 1 if VAL is 0.
53 void __longjmp (__jmp_buf env, int val). */
54 .text
55ENTRY(____longjmp_chk)
56 /* Restore registers. */
85736dc7 57 mov (JB_RSP*8)(%rdi), %R8_LP
c044aa75 58 movq (JB_RBP*8)(%rdi), %r9
85736dc7 59 mov (JB_PC*8)(%rdi), %RDX_LP
98b1e6c8 60#ifdef PTR_DEMANGLE
85736dc7 61 PTR_DEMANGLE (%R8_LP)
98b1e6c8 62 PTR_DEMANGLE (%r9)
85736dc7 63 PTR_DEMANGLE (%RDX_LP)
98b1e6c8
UD
64#endif
65
85736dc7 66 cmp %R8_LP, %RSP_LP
e4143e7a
UD
67 jbe .Lok
68
98b1e6c8
UD
69 /* Save function parameters. */
70 movq %rdi, %r10
c044aa75
CLT
71 cfi_register (%rdi, %r10)
72 movl %esi, %ebx
73 cfi_register (%rsi, %rbx)
98b1e6c8 74
98b1e6c8 75 xorl %edi, %edi
85736dc7 76 lea -sizeSS(%rsp), %RSI_LP
98b1e6c8
UD
77 movl $__NR_sigaltstack, %eax
78 syscall
e4143e7a 79 /* Without working sigaltstack we cannot perform the test. */
98b1e6c8 80 testl %eax, %eax
e4143e7a 81 jne .Lok2
85736dc7 82 testl $1, (-sizeSS + oSS_FLAGS)(%rsp)
e4143e7a 83 jz .Lfail
98b1e6c8 84
85736dc7
L
85 mov (-sizeSS + oSS_SP)(%rsp), %RAX_LP
86 add (-sizeSS + oSS_SIZE)(%rsp), %RAX_LP
87 sub %R8_LP, %RAX_LP
88 cmp (-sizeSS + oSS_SIZE)(%rsp), %RAX_LP
e4143e7a
UD
89 jae .Lok2
90
91.Lfail: CALL_FAIL
92
93.Lok2: movq %r10, %rdi
c044aa75
CLT
94 cfi_restore (%rdi)
95 movl %ebx, %esi
96 cfi_restore (%rsi)
e4143e7a
UD
97
98.Lok: /* We add unwind information for the target here. */
99 cfi_def_cfa(%rdi, 0)
98b1e6c8
UD
100 cfi_register(%rsp,%r8)
101 cfi_register(%rbp,%r9)
102 cfi_register(%rip,%rdx)
103 cfi_offset(%rbx,JB_RBX*8)
104 cfi_offset(%r12,JB_R12*8)
105 cfi_offset(%r13,JB_R13*8)
106 cfi_offset(%r14,JB_R14*8)
107 cfi_offset(%r15,JB_R15*8)
c044aa75
CLT
108 movq (JB_RBX*8)(%rdi), %rbx
109 movq (JB_R12*8)(%rdi), %r12
110 movq (JB_R13*8)(%rdi), %r13
111 movq (JB_R14*8)(%rdi), %r14
112 movq (JB_R15*8)(%rdi), %r15
98b1e6c8 113 /* Set return value for setjmp. */
e4143e7a 114 movl %esi, %eax
85736dc7 115 mov %R8_LP, %RSP_LP
e4143e7a 116 movq %r9,%rbp
98b1e6c8 117 jmpq *%rdx
9663bb3e 118END (____longjmp_chk)