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