Move remaining files out of nptl/sysdeps/unix/sysv/linux/x86/.
[glibc.git] / sysdeps / unix / sysv / linux / sh / ____longjmp_chk.S
blobb276466f53f345b1666211ba727789e05f167454
1 /* Copyright (C) 2009-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>
20 #include <sigaltstack-offsets.h>
22         .section .rodata.str1.1,"aMS",@progbits,1
23         .type   longjmp_msg,@object
24 longjmp_msg:
25         .string "longjmp causes uninitialized stack frame"
26         .size   longjmp_msg, .-longjmp_msg
27         .text
29 #define __longjmp ____longjmp_chk
31 #ifdef PIC
32 # define CALL_FAIL \
33         mov.l   .Lfail, r1;                             \
34         mov.l   .Lstr, r4;                              \
35         mov.l   r12, @-r15;                             \
36         cfi_remember_state;                             \
37         cfi_adjust_cfa_offset (4);                      \
38         cfi_rel_offset (r12, 0);                        \
39         mova    .Lgot, r0;                              \
40         mov.l   .Lgot, r12;                             \
41         add     r0, r12;                                \
42         sts.l   pr, @-r15;                              \
43         cfi_adjust_cfa_offset (4);                      \
44         cfi_rel_offset (pr, 0);                         \
45         bsrf    r1;                                     \
46          add    r12, r4;                                \
47 .Lfail0:                                                \
48         /* Unreachable.  */                             \
49         .align  2;                                      \
50 .Lgot:                                                  \
51         .long   _GLOBAL_OFFSET_TABLE_;                  \
52 .Lstr:                                                  \
53         .long   longjmp_msg@GOTOFF;                     \
54 .Lfail:                                                 \
55         .long   __GI___fortify_fail@PLT-(.Lfail0-.);    \
56         cfi_restore_state;
57 #else
58 # define CALL_FAIL \
59         mov.l   .Lfail, r1;                             \
60         mov.l   .Lstr, r4;                              \
61         sts.l   pr, @-r15;                              \
62         cfi_remember_state;                             \
63         cfi_adjust_cfa_offset (4);                      \
64         cfi_rel_offset (pr, 0);                         \
65         jsr     @r1;                                    \
66          nop;                                           \
67         /* Unreachable.  */                             \
68         .align  2;                                      \
69 .Lstr:                                                  \
70         .long   longjmp_msg;                            \
71 .Lfail:                                                 \
72         .long   __fortify_fail;                         \
73         cfi_restore_state;
74 #endif
76 #define CHECK_SP(reg) \
77         /* Jumping to a higher-address frame is always allowed.  */     \
78         cmp/hs  r15, reg;                                               \
79         bt      .Lok;                                                   \
80                                                                         \
81         mov.l   r0, @-r15; /* The return value is already in here.  */  \
82         cfi_adjust_cfa_offset (4);                                      \
83         mov.l   r1, @-r15; /* PTR_DEMANGLE helper.  */                  \
84         cfi_adjust_cfa_offset (4);                                      \
85         mov.l   r2, @-r15; /* The new SP value is already in here.  */  \
86         cfi_adjust_cfa_offset (4);                                      \
87         mov.l   r4, @-r15; /* We'll still need this one.  */            \
88         cfi_adjust_cfa_offset (4);                                      \
89         add     #-sizeSS, r15;                                          \
90         cfi_adjust_cfa_offset (sizeSS);                                 \
91         mov     #0, r4;                                                 \
92         mov     r15, r5;                                                \
93         DO_CALL (sigaltstack, 2);                                       \
94         /* Without working sigaltstack we cannot perform the test.  */  \
95         tst     r0, r0;                                                 \
96         bf      .Lok2;                                                  \
97         mov.l   @(oSS_FLAGS, r15), r0;                                  \
98         tst     #SS_ONSTACK, r0;                                        \
99         bt      .Lcall_fail;                                            \
100         mov.l   @(oSS_SIZE, r15), r2;                                   \
101         mov.l   @(oSS_SP, r15), r1;                                     \
102         add     r2, r1;                                                 \
103         sub     r8, r1;                                                 \
104         cmp/hi  r1, r2;                                                 \
105         bf      .Lok2;                                                  \
106 .Lcall_fail:                                                            \
107         CALL_FAIL                                                       \
108                                                                         \
109 .Lok2:                                                                  \
110         add     #sizeSS, r15;                                           \
111         cfi_adjust_cfa_offset (-sizeSS);                                \
112         mov.l   @r15+, r4;                                              \
113         cfi_adjust_cfa_offset (-4);                                     \
114         mov.l   @r15+, r2;                                              \
115         cfi_adjust_cfa_offset (-4);                                     \
116         mov.l   @r15+, r1;                                              \
117         cfi_adjust_cfa_offset (-4);                                     \
118         mov.l   @r15+, r0;                                              \
119         cfi_adjust_cfa_offset (-4);                                     \
120 .Lok:
122 #include <__longjmp.S>