]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/mach/hurd/i386/____longjmp_chk.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / mach / hurd / i386 / ____longjmp_chk.S
1 /* Copyright (C) 2001-2017 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
22 #include <signal-defines.h>
23 /* #include <signal.h> */
24 #define SS_ONSTACK 1
25
26
27 .section .rodata.str1.1,"aMS",@progbits,1
28 .type longjmp_msg,@object
29 longjmp_msg:
30 .string "longjmp causes uninitialized stack frame"
31 .size longjmp_msg, .-longjmp_msg
32
33
34 #ifdef PIC
35 # define CALL_FAIL movl %ebx, %ecx; /* TODO: what's this mov good for? */ \
36 cfi_register(%ebx,%ecx); \
37 LOAD_PIC_REG (bx); \
38 leal longjmp_msg@GOTOFF(%ebx), %eax; \
39 call HIDDEN_JUMPTARGET(__fortify_fail)
40 #else
41 # define CALL_FAIL movl $longjmp_msg, %eax; \
42 call HIDDEN_JUMPTARGET(__fortify_fail)
43 #endif
44
45
46 .text
47 ENTRY (____longjmp_chk)
48 movl 4(%esp), %ecx /* User's jmp_buf in %ecx. */
49
50 /* Save the return address now. */
51 movl (JB_PC*4)(%ecx), %edx
52 /* Get the stack pointer. */
53 movl (JB_SP*4)(%ecx), %edi
54 cfi_undefined(%edi)
55 #ifdef PTR_DEMANGLE
56 PTR_DEMANGLE (%edx)
57 PTR_DEMANGLE (%edi)
58 #endif
59
60 cmpl %edi, %esp
61 /* Jumping to a higher-address frame is always allowed. */
62 jbe .Lok
63
64 /* Passing here, we're either about to do something invalid, or we're
65 executing on an alternative signal stack. */
66
67 /* TODO: need locking? */
68 /* struct hurd_sigstate * _hurd_self_sigstate (void) */
69 #ifdef PIC
70 call 1f
71 1: popl %ebx
72 addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
73 #endif
74 call JUMPTARGET(_hurd_self_sigstate)
75 /* TODO: %eax and %eax->sigaltstack are always valid? */
76
77 testl $SS_ONSTACK, (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_FLAGS__OFFSET)(%eax)
78 /* Fail if SS_ONSTACK is not set. */
79 jz .Lfail
80
81 movl (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_SP__OFFSET)(%eax), %ebx
82 addl (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_SIZE__OFFSET)(%eax), %ebx
83 subl %edi, %ebx
84 cmpl (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_SIZE__OFFSET)(%eax), %ebx
85 /* TODO: comment this calculation. */
86 jae .Lok
87
88 .Lfail: CALL_FAIL
89
90 .Lok: /* We add unwind information for the target here. */
91 cfi_def_cfa(%ecx, 0)
92 cfi_register(%eip, %edx)
93 cfi_register(%esp, %edi)
94 cfi_offset(%ebx, JB_BX*4)
95 cfi_offset(%esi, JB_SI*4)
96 cfi_offset(%edi, JB_DI*4)
97 cfi_offset(%ebp, JB_BP*4)
98
99 movl 8(%esp), %eax /* Second argument is return value. */
100 movl %edi, %esp
101
102 /* Restore registers. */
103 movl (JB_BX*4)(%ecx), %ebx
104 movl (JB_SI*4)(%ecx), %esi
105 movl (JB_DI*4)(%ecx), %edi
106 movl (JB_BP*4)(%ecx), %ebp
107 cfi_restore(%ebx)
108 cfi_restore(%esi)
109 cfi_restore(%edi)
110 cfi_restore(%ebp)
111
112 /* Jump to saved PC. */
113 jmp *%edx
114 END (____longjmp_chk)