Upload Tizen:Base source
[external/eglibc.git] / ports / sysdeps / unix / sysv / linux / alpha / ____longjmp_chk.S
1 /* Copyright (C) 1992, 1994, 1997, 2006, 2010 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, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 #include <sysdep.h>
20 #include <jmpbuf-offsets.h>
21
22
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
28
29
30 /* Jump to the position specified by ENV, causing the
31    setjmp call there to return VAL, or 1 if VAL is 0.
32    void __longjmp (__jmp_buf env, int val).  */
33         .text
34         .align  4
35         .globl  ____longjmp_chk
36         .type   ____longjmp_chk, @function
37         .usepv  ____longjmp_chk, std
38
39         cfi_startproc
40 ____longjmp_chk:
41         ldgp    gp, 0(pv)
42 #ifdef PROF
43         .set noat
44         lda     AT, _mcount
45         jsr     AT, (AT), _mcount
46         .set at
47 #endif
48
49         ldq     s2, JB_PC*8(a0)
50         mov     a0, s0
51         ldq     fp, JB_FP*8(a0)
52         mov     a1, s1
53         ldq     s3, JB_SP*8(a0)
54         cmoveq  s1, 1, s1
55
56 #ifdef PTR_DEMANGLE
57         PTR_DEMANGLE(s2, t1)
58         PTR_DEMANGLE2(s3, t1)
59         PTR_DEMANGLE2(fp, t1)
60 #endif
61         cmpule  t0, sp, t1
62         bne     t1, .Lfail
63
64         .align  4
65 .Lok:
66         mov     s0, a0
67         mov     s1, v0
68         mov     s3, t0
69         mov     s2, ra
70         cfi_remember_state
71         cfi_def_cfa(a0, 0)
72         cfi_register(sp, t0)
73         cfi_offset(s0, JB_S0*8)
74         cfi_offset(s1, JB_S1*8)
75         cfi_offset(s2, JB_S2*8)
76         cfi_offset(s3, JB_S3*8)
77         cfi_offset(s4, JB_S4*8)
78         cfi_offset(s5, JB_S5*8)
79         cfi_offset(s3, JB_S3*8)
80         cfi_offset($f2, JB_F2*8)
81         cfi_offset($f3, JB_F3*8)
82         cfi_offset($f4, JB_F4*8)
83         cfi_offset($f5, JB_F5*8)
84         cfi_offset($f6, JB_F6*8)
85         cfi_offset($f7, JB_F7*8)
86         cfi_offset($f8, JB_F8*8)
87         cfi_offset($f9, JB_F9*8)
88         ldq     s0, JB_S0*8(a0)
89         ldq     s1, JB_S1*8(a0)
90         ldq     s2, JB_S2*8(a0)
91         ldq     s3, JB_S3*8(a0)
92         ldq     s4, JB_S4*8(a0)
93         ldq     s5, JB_S5*8(a0)
94         ldt     $f2, JB_F2*8(a0)
95         ldt     $f3, JB_F3*8(a0)
96         ldt     $f4, JB_F4*8(a0)
97         ldt     $f5, JB_F5*8(a0)
98         ldt     $f6, JB_F6*8(a0)
99         ldt     $f7, JB_F7*8(a0)
100         ldt     $f8, JB_F8*8(a0)
101         ldt     $f9, JB_F9*8(a0)
102         mov     t0, sp
103         ret
104
105         .align  4
106 .Lfail:
107         cfi_restore_state
108         lda     v0, __NR_sigaltstack
109         lda     a0, 0
110         lda     a1, -32(sp)
111         lda     sp, -32(sp)
112         cfi_adjust_cfa_offset(32)
113         callsys
114         ldq     t0, 0(sp)       /* ss_sp */
115         ldl     t1, 8(sp)       /* ss_flags */
116         ldq     t2, 16(sp)      /* ss_size */
117         lda     sp, 32(sp)
118         cfi_adjust_cfa_offset(-32)
119
120         /* Without working sigaltstack we cannot perform the test.  */
121         bne     a3, .Lok
122
123         addq    t0, t2, t0      /* t0 = ss_sp + ss_size */
124         subq    t0, s3, t0      /* t0 = (ss_sp + ss_size) - new_sp */
125         cmpule  t2, t0, t0      /* t0 = (t0 >= ss_size) */
126         and     t0, t1, t0      /* t0 = (t0 >= ss_size) & (ss_flags & SS_ONSTACK) */
127         bne     t0, .Lok
128
129         ldah    a0, longjmp_msg(gp)     !gprelhigh
130         lda     a0, longjmp_msg(a0)     !gprellow
131 #ifdef PIC
132         jsr     ra, HIDDEN_JUMPTARGET(__fortify_fail)
133 #else
134         bsr     ra, HIDDEN_JUMPTARGET(__fortify_fail)   !samegp
135 #endif
136         bugchk
137
138         cfi_endproc
139         .size   ____longjmp_chk, .-____longjmp_chk