Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / unix / sysv / linux / sparc / sparc32 / ____longjmp_chk.S
blob8b5ac7fcebc2438f2dfd6fd205af02ccbeca97f5
1 /* Copyright (C) 2009 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>
21 #define ENV(base,reg) [%base + (reg * 4)]
22 #define ST_FLUSH_WINDOWS 3
23 #define RW_FP [%fp + 0x48]
25 .section .rodata.str1.1,"aMS",@progbits,1
26         .type   longjmp_msg,@object
27 longjmp_msg:
28         .string "longjmp causes uninitialized stack frame"
29         .size   longjmp_msg, .-longjmp_msg
31         .text
32 ENTRY (____longjmp_chk)
33         ld      ENV(o0,JB_SP), %g5
34 #ifdef PTR_DEMANGLE
35         PTR_DEMANGLE (%g5, %g5, %g4)
36 #endif
38         cmp     %sp, %g5
39         bleu    .Lok_norestore
40          nop
42         save    %sp, -80, %sp
43         cfi_remember_state
44         cfi_def_cfa_register(%fp)
45         cfi_window_save
46         cfi_register(%o7, %i7)
48         clr     %o0
49         add     %sp, 64, %o1
50         LOADSYSCALL(sigaltstack)
51         ta      0x10
52         bcs     .Lok
53          ld     [%sp + 64 + 4], %o2
54         andcc   %o2, 0x1, %g0
55         be      .Lfail
56          ld     [%sp + 64 + 0], %o0
58         ld      [%sp + 64 + 8], %o1
59         add     %o0, %o1, %o0
60         sub     %o0, %g5, %o0
61         cmp     %o0, %o1
62         bgeu    .Lok
63          nop
65 .Lfail:
66 #ifdef PIC
67 1:      call    2f
68         sethi   %hi(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7
69 2:      or      %l7, %lo(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7
70         add     %l7, %o7, %l7
71 #endif
72         sethi   %hi(longjmp_msg), %o0
73         or      %o0, %lo(longjmp_msg), %o0
74 #ifdef PIC
75         ld      [%l7 + %o0], %o0
76 #endif
77         call    HIDDEN_JUMPTARGET(__fortify_fail)
78          nop
80 .Lok:
81         restore
82         cfi_restore_state
84 .Lok_norestore:
85         ld      ENV(o0,JB_FP), %g3      /* Cache target FP in register %g3.  */
86 #ifdef PTR_DEMANGLE
87         PTR_DEMANGLE2 (%g3, %g3, %g4)
88 #endif
90         mov %o0, %g1            /* ENV in %g1 */
91         orcc %o1, %g0, %g2      /* VAL in %g2 */
92         be,a 0f                 /* Branch if zero; else skip delay slot.  */
93          mov 1, %g2             /* Delay slot only hit if zero: VAL = 1.  */
96         /*
97          * Do a "flush register windows trap".  The trap handler in the
98          * kernel writes all the register windows to their stack slots, and
99          * marks them all as invalid (needing to be sucked up from the
100          * stack when used).  This ensures that all information needed to
101          * unwind to these callers is in memory, not in the register
102          * windows.
103          */
104         ta      ST_FLUSH_WINDOWS
105 #ifdef PTR_DEMANGLE
106         ld      ENV(g1,JB_PC), %g1 /* Set return PC. */
107         PTR_DEMANGLE2 (%o7, %g1, %g4)
108 #else
109         ld      ENV(g1,JB_PC), %o7 /* Set return PC. */
110 #endif
111         mov     %g5, %fp
112         sub     %fp, 64, %sp    /* Allocate a register frame. */
113         st      %g3, RW_FP      /* Set saved FP on restore below. */
114         retl
115          restore %g2, 0, %o0    /* Restore values from above register frame. */
117 END(____longjmp_chk)