Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / mach / hurd / i386 / ____longjmp_chk.S
blob666465e9e9bc99a73ed510a204cd5baabc58550f
1 /* Copyright (C) 2001-2014 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, see
16    <http://www.gnu.org/licenses/>.  */
18 #include <sysdep.h>
19 #include <jmpbuf-offsets.h>
20 #include <asm-syntax.h>
22 #include <signal-defines.h>
23 /* #include <signal.h> */
24 #define SS_ONSTACK 1
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
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
46         .text
47 ENTRY (____longjmp_chk)
48         movl    4(%esp), %ecx   /* User's jmp_buf in %ecx.  */
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
60         cmpl    %edi, %esp
61         /* Jumping to a higher-address frame is always allowed.  */
62         jbe     .Lok
64         /* Passing here, we're either about to do something invalid, or we're
65         executing on an alternative signal stack.  */
67         /* TODO: need locking?  */
68         /* struct hurd_sigstate * _hurd_self_sigstate (void) */
69         call    _hurd_self_sigstate
70         /* TODO: %eax and %eax->sigaltstack are always valid?  */
72         testl   $SS_ONSTACK, (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_FLAGS__OFFSET)(%eax)
73         /* Fail if SS_ONSTACK is not set.  */
74         jz      .Lfail
76         movl    (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_SP__OFFSET)(%eax), %ebx
77         addl    (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_SIZE__OFFSET)(%eax), %ebx
78         subl    %edi, %ebx
79         cmpl    (HURD_SIGSTATE__SIGALTSTACK__OFFSET + SIGALTSTACK__SS_SIZE__OFFSET)(%eax), %ebx
80         /* TODO: comment this calculation.  */
81         jae     .Lok
83 .Lfail: CALL_FAIL
85 .Lok:   /* We add unwind information for the target here.  */
86         cfi_def_cfa(%ecx, 0)
87         cfi_register(%eip, %edx)
88         cfi_register(%esp, %edi)
89         cfi_offset(%ebx, JB_BX*4)
90         cfi_offset(%esi, JB_SI*4)
91         cfi_offset(%edi, JB_DI*4)
92         cfi_offset(%ebp, JB_BP*4)
94         movl    8(%esp), %eax   /* Second argument is return value.  */
95         movl    %edi, %esp
97         /* Restore registers.  */
98         movl    (JB_BX*4)(%ecx), %ebx
99         movl    (JB_SI*4)(%ecx), %esi
100         movl    (JB_DI*4)(%ecx), %edi
101         movl    (JB_BP*4)(%ecx), %ebp
102         cfi_restore(%ebx)
103         cfi_restore(%esi)
104         cfi_restore(%edi)
105         cfi_restore(%ebp)
107         /* Jump to saved PC.  */
108         jmp     *%edx
109 END (____longjmp_chk)