1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/mm.h>
14#include <linux/ptrace.h>
15#include <linux/sched.h>
16#include <linux/interrupt.h>
17#include <linux/module.h>
18
19#include <asm/uaccess.h>
20#include <asm/traps.h>
21
22#define PRINT_USER_FAULTS
23
24
25
26
27#define bit22set(x) (x & 0x00000200)
28#define bits23_25set(x) (x & 0x000001c0)
29#define isGraphicsFlushRead(x) ((x & 0xfc003fdf) == 0x04001a80)
30
31
32#define BITSSET 0x1c0
33
34
35DEFINE_PER_CPU(struct exception_data, exception_data);
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52static unsigned long
53parisc_acctyp(unsigned long code, unsigned int inst)
54{
55 if (code == 6 || code == 16)
56 return VM_EXEC;
57
58 switch (inst & 0xf0000000) {
59 case 0x40000000:
60 case 0x50000000:
61 return VM_READ;
62
63 case 0x60000000:
64 case 0x70000000:
65 return VM_WRITE;
66
67 case 0x20000000:
68 case 0x30000000:
69 if (bit22set(inst))
70 return VM_WRITE;
71
72 case 0x0:
73 if (bit22set(inst)) {
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 if (isGraphicsFlushRead(inst))
92 return VM_READ;
93 return VM_WRITE;
94 } else {
95
96
97
98
99
100
101
102
103
104
105
106
107 if (bits23_25set(inst) == BITSSET)
108 return VM_WRITE;
109 }
110 return VM_READ;
111 }
112 return VM_READ;
113}
114
115#undef bit22set
116#undef bits23_25set
117#undef isGraphicsFlushRead
118#undef BITSSET
119
120
121#if 0
122
123
124
125
126
127 while (tree != vm_avl_empty) {
128 if (tree->vm_start > addr) {
129 tree = tree->vm_avl_left;
130 } else {
131 prev = tree;
132 if (prev->vm_next == NULL)
133 break;
134 if (prev->vm_next->vm_start > addr)
135 break;
136 tree = tree->vm_avl_right;
137 }
138 }
139#endif
140
141int fixup_exception(struct pt_regs *regs)
142{
143 const struct exception_table_entry *fix;
144
145 fix = search_exception_tables(regs->iaoq[0]);
146 if (fix) {
147 struct exception_data *d;
148 d = &__get_cpu_var(exception_data);
149 d->fault_ip = regs->iaoq[0];
150 d->fault_space = regs->isr;
151 d->fault_addr = regs->ior;
152
153 regs->iaoq[0] = ((fix->fixup) & ~3);
154
155
156
157
158
159
160
161 regs->iaoq[1] = regs->iaoq[0] + 4;
162 regs->gr[0] &= ~PSW_B;
163
164 return 1;
165 }
166
167 return 0;
168}
169
170void do_page_fault(struct pt_regs *regs, unsigned long code,
171 unsigned long address)
172{
173 struct vm_area_struct *vma, *prev_vma;
174 struct task_struct *tsk = current;
175 struct mm_struct *mm = tsk->mm;
176 unsigned long acc_type;
177 int fault;
178
179 if (in_atomic() || !mm)
180 goto no_context;
181
182 down_read(&mm->mmap_sem);
183 vma = find_vma_prev(mm, address, &prev_vma);
184 if (!vma || address < vma->vm_start)
185 goto check_expansion;
186
187
188
189
190
191good_area:
192
193 acc_type = parisc_acctyp(code,regs->iir);
194
195 if ((vma->vm_flags & acc_type) != acc_type)
196 goto bad_area;
197
198
199
200
201
202
203
204 fault = handle_mm_fault(mm, vma, address, (acc_type & VM_WRITE) ? FAULT_FLAG_WRITE : 0);
205 if (unlikely(fault & VM_FAULT_ERROR)) {
206
207
208
209
210
211 if (fault & VM_FAULT_OOM)
212 goto out_of_memory;
213 else if (fault & VM_FAULT_SIGBUS)
214 goto bad_area;
215 BUG();
216 }
217 if (fault & VM_FAULT_MAJOR)
218 current->maj_flt++;
219 else
220 current->min_flt++;
221 up_read(&mm->mmap_sem);
222 return;
223
224check_expansion:
225 vma = prev_vma;
226 if (vma && (expand_stack(vma, address) == 0))
227 goto good_area;
228
229
230
231
232bad_area:
233 up_read(&mm->mmap_sem);
234
235 if (user_mode(regs)) {
236 struct siginfo si;
237
238#ifdef PRINT_USER_FAULTS
239 printk(KERN_DEBUG "\n");
240 printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
241 task_pid_nr(tsk), tsk->comm, code, address);
242 if (vma) {
243 printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
244 vma->vm_start, vma->vm_end);
245 }
246 show_regs(regs);
247#endif
248
249 si.si_signo = SIGSEGV;
250 si.si_errno = 0;
251 si.si_code = SEGV_MAPERR;
252 si.si_addr = (void __user *) address;
253 force_sig_info(SIGSEGV, &si, current);
254 return;
255 }
256
257no_context:
258
259 if (!user_mode(regs) && fixup_exception(regs)) {
260 return;
261 }
262
263 parisc_terminate("Bad Address (null pointer deref?)", regs, code, address);
264
265 out_of_memory:
266 up_read(&mm->mmap_sem);
267 printk(KERN_CRIT "VM: killing process %s\n", current->comm);
268 if (user_mode(regs))
269 do_group_exit(SIGKILL);
270 goto no_context;
271}
272