This source file includes following definitions.
- do_page_fault
1
2
3
4
5
6
7 #include <linux/config.h>
8 #include <linux/signal.h>
9 #include <linux/sched.h>
10 #include <linux/head.h>
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/string.h>
14 #include <linux/types.h>
15 #include <linux/ptrace.h>
16 #include <linux/mman.h>
17 #include <linux/mm.h>
18
19 #include <asm/system.h>
20 #include <asm/segment.h>
21
22 extern void die_if_kernel(char *,struct pt_regs *,long);
23
24
25
26
27
28
29
30
31
32
33
34 asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code)
35 {
36 struct vm_area_struct * vma;
37 unsigned long address;
38 unsigned long page;
39
40
41 __asm__("movl %%cr2,%0":"=r" (address));
42 vma = find_vma(current, address);
43 if (!vma)
44 goto bad_area;
45 if (vma->vm_start <= address)
46 goto good_area;
47 if (!(vma->vm_flags & VM_GROWSDOWN))
48 goto bad_area;
49 if (vma->vm_end - address > current->rlim[RLIMIT_STACK].rlim_cur)
50 goto bad_area;
51 vma->vm_offset -= vma->vm_start - (address & PAGE_MASK);
52 vma->vm_start = (address & PAGE_MASK);
53
54
55
56
57 good_area:
58
59
60
61 if (error_code & 2) {
62 if (!(vma->vm_flags & VM_WRITE))
63 goto bad_area;
64 } else {
65
66 if (error_code & 1)
67 goto bad_area;
68 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
69 goto bad_area;
70 }
71
72
73
74 if (regs->eflags & VM_MASK) {
75 unsigned long bit = (address - 0xA0000) >> PAGE_SHIFT;
76 if (bit < 32)
77 current->tss.screen_bitmap |= 1 << bit;
78 }
79 if (error_code & 1) {
80 #ifdef CONFIG_TEST_VERIFY_AREA
81 if (regs->cs == KERNEL_CS)
82 printk("WP fault at %08x\n", regs->eip);
83 #endif
84 do_wp_page(vma, address, error_code & 2);
85 return;
86 }
87 do_no_page(vma, address, error_code & 2);
88 return;
89
90
91
92
93
94 bad_area:
95 if (error_code & 4) {
96 current->tss.cr2 = address;
97 current->tss.error_code = error_code;
98 current->tss.trap_no = 14;
99 send_sig(SIGSEGV, current, 1);
100 return;
101 }
102
103
104
105
106
107
108 if (wp_works_ok < 0 && address == TASK_SIZE && (error_code & 1)) {
109 wp_works_ok = 1;
110 pg0[0] = pte_val(mk_pte(0, PAGE_SHARED));
111 invalidate();
112 printk("This processor honours the WP bit even when in supervisor mode. Good.\n");
113 return;
114 }
115 if ((unsigned long) (address-TASK_SIZE) < PAGE_SIZE) {
116 printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference");
117 pg0[0] = pte_val(mk_pte(0, PAGE_SHARED));
118 } else
119 printk(KERN_ALERT "Unable to handle kernel paging request");
120 printk(" at virtual address %08lx\n",address);
121 __asm__("movl %%cr3,%0" : "=r" (page));
122 printk(KERN_ALERT "current->tss.cr3 = %08lx, %%cr3 = %08lx\n",
123 current->tss.cr3, page);
124 page = ((unsigned long *) page)[address >> 22];
125 printk(KERN_ALERT "*pde = %08lx\n", page);
126 if (page & 1) {
127 page &= PAGE_MASK;
128 address &= 0x003ff000;
129 page = ((unsigned long *) page)[address >> PAGE_SHIFT];
130 printk(KERN_ALERT "*pte = %08lx\n", page);
131 }
132 die_if_kernel("Oops", regs, error_code);
133 do_exit(SIGKILL);
134 }