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