]>
Commit | Line | Data |
---|---|---|
a0902db9 DM |
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 | ||
45 | clr %o0 | |
46 | add %sp, 64, %o1 | |
47 | set __NR_sigaltstack, %g1 | |
48 | ta 0x10 | |
49 | bcs .Lok | |
50 | ld [%sp + 64 + 4], %o2 | |
51 | andcc %o2, 0x1, %g0 | |
52 | be .Lfail | |
53 | ld [%sp + 64 + 0], %o0 | |
54 | ||
55 | ld [%sp + 64 + 8], %o1 | |
56 | add %o0, %o1, %o0 | |
57 | sub %o0, %g3, %o0 | |
58 | cmp %o1, %o0 | |
59 | bgeu .Lok | |
60 | nop | |
61 | ||
62 | .Lfail: | |
63 | #ifdef PIC | |
64 | 1: call 2f | |
65 | sethi %hi(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7 | |
66 | 2: or %l7, %lo(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7 | |
67 | add %l7, %o7, %l7 | |
68 | #endif | |
69 | sethi %hi(longjmp_msg), %o0 | |
70 | or %o0, %lo(longjmp_msg), %o0 | |
71 | #ifdef PIC | |
72 | ld [%l7 + %o0], %o0 | |
73 | #endif | |
74 | call HIDDEN_JUMPTARGET(__fortify_fail) | |
75 | nop | |
76 | ||
77 | .Lok: | |
78 | restore | |
79 | ||
80 | .Lok_norestore: | |
81 | ld ENV(o0,JB_FP), %g3 /* Cache target FP in register %g3. */ | |
82 | #ifdef PTR_DEMANGLE | |
83 | PTR_DEMANGLE2 (%g3, %g3, %g4) | |
84 | #endif | |
85 | ||
86 | mov %o0, %g1 /* ENV in %g1 */ | |
87 | orcc %o1, %g0, %g2 /* VAL in %g2 */ | |
88 | be,a 0f /* Branch if zero; else skip delay slot. */ | |
89 | mov 1, %g2 /* Delay slot only hit if zero: VAL = 1. */ | |
90 | 0: | |
91 | ||
92 | /* | |
93 | * Do a "flush register windows trap". The trap handler in the | |
94 | * kernel writes all the register windows to their stack slots, and | |
95 | * marks them all as invalid (needing to be sucked up from the | |
96 | * stack when used). This ensures that all information needed to | |
97 | * unwind to these callers is in memory, not in the register | |
98 | * windows. | |
99 | */ | |
100 | ta ST_FLUSH_WINDOWS | |
101 | #ifdef PTR_DEMANGLE | |
102 | ld ENV(g1,JB_PC), %g1 /* Set return PC. */ | |
103 | PTR_DEMANGLE2 (%o7, %g1, %g4) | |
104 | #else | |
105 | ld ENV(g1,JB_PC), %o7 /* Set return PC. */ | |
106 | #endif | |
107 | mov %g5, %fp | |
108 | sub %fp, 64, %sp /* Allocate a register frame. */ | |
109 | st %g3, RW_FP /* Set saved FP on restore below. */ | |
110 | retl | |
111 | restore %g2, 0, %o0 /* Restore values from above register frame. */ | |
112 | ||
113 | END(____longjmp_chk) |