This source file includes following definitions.
- flush_user_windows
- shift_window_buffer
- synchronize_user_stack
- copy_aligned_window
1
2
3
4
5
6
7 #include <linux/kernel.h>
8 #include <linux/sched.h>
9 #include <linux/string.h>
10 #include <linux/mm.h>
11
12
13 void flush_user_windows(void)
14 {
15 if(current->tss.uwinmask)
16 flush_user_windows();
17 }
18
19 static inline void shift_window_buffer(int first_win, int last_win, struct thread_struct *tp)
20 {
21 int i;
22
23 for(i = first_win; i < last_win; i++) {
24 tp->rwbuf_stkptrs[i] = tp->rwbuf_stkptrs[i+1];
25 memcpy(&tp->reg_window[i], &tp->reg_window[i+1], sizeof(struct reg_window));
26 }
27 }
28
29
30
31
32
33
34
35
36
37
38 void synchronize_user_stack(void)
39 {
40 struct thread_struct *tp = ¤t->tss;
41 int window;
42
43 flush_user_windows();
44
45 if(!tp->w_saved)
46 return;
47
48
49 for(window = tp->w_saved - 1; window >= 0; window--) {
50 unsigned long sp = tp->rwbuf_stkptrs[window];
51
52
53 if(verify_area(VERIFY_WRITE, (char *) sp, sizeof(struct reg_window)))
54 continue;
55
56
57 memcpy((char *) sp, &tp->reg_window[window], sizeof(struct reg_window));
58 shift_window_buffer(window, tp->w_saved - 1, tp);
59 tp->w_saved--;
60 }
61 }
62
63
64 static inline void copy_aligned_window(void *dest, const void *src)
65 {
66 __asm__ __volatile__("ldd [%1], %%g2\n\t"
67 "ldd [%1 + 0x8], %%g4\n\t"
68 "std %%g2, [%0]\n\t"
69 "std %%g4, [%0 + 0x8]\n\t"
70 "ldd [%1 + 0x10], %%g2\n\t"
71 "ldd [%1 + 0x18], %%g4\n\t"
72 "std %%g2, [%0 + 0x10]\n\t"
73 "std %%g4, [%0 + 0x18]\n\t"
74 "ldd [%1 + 0x20], %%g2\n\t"
75 "ldd [%1 + 0x28], %%g4\n\t"
76 "std %%g2, [%0 + 0x20]\n\t"
77 "std %%g4, [%0 + 0x28]\n\t"
78 "ldd [%1 + 0x30], %%g2\n\t"
79 "ldd [%1 + 0x38], %%g4\n\t"
80 "std %%g2, [%0 + 0x30]\n\t"
81 "std %%g4, [%0 + 0x38]\n\t" : :
82 "r" (dest), "r" (src) :
83 "g2", "g3", "g4", "g5");
84 }
85
86
87
88
89
90 #define stack_is_bad(sp, rw) \
91 (((sp) & 7) || verify_area(rw, (char *) (sp), sizeof(struct reg_window)))
92
93 void try_to_clear_window_buffer(struct pt_regs *regs, int who)
94 {
95 struct thread_struct *tp = ¤t->tss;
96 int window;
97
98 flush_user_windows();
99 for(window = 0; window < tp->w_saved; window++) {
100 unsigned long sp = tp->rwbuf_stkptrs[window];
101
102 if(stack_is_bad(sp, VERIFY_WRITE))
103 do_exit(SIGILL);
104 else
105 copy_aligned_window((char *) sp, &tp->reg_window[window]);
106 }
107 tp->w_saved = 0;
108 }