aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/kernel/trap.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/kernel/trap.c')
-rw-r--r--arch/um/kernel/trap.c111
1 files changed, 52 insertions, 59 deletions
diff --git a/arch/um/kernel/trap.c b/arch/um/kernel/trap.c
index c517c449d0dd..4b472ca53485 100644
--- a/arch/um/kernel/trap.c
+++ b/arch/um/kernel/trap.c
@@ -1,38 +1,24 @@
1/* 1/*
2 * Copyright (C) 2000, 2001 Jeff Dike (jdike@karaya.com) 2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL 3 * Licensed under the GPL
4 */ 4 */
5 5
6#include "linux/kernel.h" 6#include <linux/mm.h>
7#include "asm/errno.h" 7#include <linux/sched.h>
8#include "linux/sched.h" 8#include <linux/hardirq.h>
9#include "linux/mm.h" 9#include <asm/current.h>
10#include "linux/spinlock.h" 10#include <asm/pgtable.h>
11#include "linux/init.h" 11#include <asm/tlbflush.h>
12#include "linux/ptrace.h"
13#include "asm/semaphore.h"
14#include "asm/pgtable.h"
15#include "asm/pgalloc.h"
16#include "asm/tlbflush.h"
17#include "asm/a.out.h"
18#include "asm/current.h"
19#include "asm/irq.h"
20#include "sysdep/sigcontext.h"
21#include "kern_util.h"
22#include "as-layout.h"
23#include "arch.h" 12#include "arch.h"
24#include "kern.h" 13#include "as-layout.h"
25#include "chan_kern.h" 14#include "kern_util.h"
26#include "mconsole_kern.h"
27#include "mem.h"
28#include "mem_kern.h"
29#include "sysdep/sigcontext.h"
30#include "sysdep/ptrace.h"
31#include "os.h"
32#include "skas.h"
33#include "os.h" 15#include "os.h"
16#include "sysdep/sigcontext.h"
34 17
35/* Note this is constrained to return 0, -EFAULT, -EACCESS, -ENOMEM by segv(). */ 18/*
19 * Note this is constrained to return 0, -EFAULT, -EACCESS, -ENOMEM by
20 * segv().
21 */
36int handle_page_fault(unsigned long address, unsigned long ip, 22int handle_page_fault(unsigned long address, unsigned long ip,
37 int is_write, int is_user, int *code_out) 23 int is_write, int is_user, int *code_out)
38{ 24{
@@ -46,31 +32,33 @@ int handle_page_fault(unsigned long address, unsigned long ip,
46 32
47 *code_out = SEGV_MAPERR; 33 *code_out = SEGV_MAPERR;
48 34
49 /* If the fault was during atomic operation, don't take the fault, just 35 /*
50 * fail. */ 36 * If the fault was during atomic operation, don't take the fault, just
37 * fail.
38 */
51 if (in_atomic()) 39 if (in_atomic())
52 goto out_nosemaphore; 40 goto out_nosemaphore;
53 41
54 down_read(&mm->mmap_sem); 42 down_read(&mm->mmap_sem);
55 vma = find_vma(mm, address); 43 vma = find_vma(mm, address);
56 if(!vma) 44 if (!vma)
57 goto out; 45 goto out;
58 else if(vma->vm_start <= address) 46 else if (vma->vm_start <= address)
59 goto good_area; 47 goto good_area;
60 else if(!(vma->vm_flags & VM_GROWSDOWN)) 48 else if (!(vma->vm_flags & VM_GROWSDOWN))
61 goto out; 49 goto out;
62 else if(is_user && !ARCH_IS_STACKGROW(address)) 50 else if (is_user && !ARCH_IS_STACKGROW(address))
63 goto out; 51 goto out;
64 else if(expand_stack(vma, address)) 52 else if (expand_stack(vma, address))
65 goto out; 53 goto out;
66 54
67good_area: 55good_area:
68 *code_out = SEGV_ACCERR; 56 *code_out = SEGV_ACCERR;
69 if(is_write && !(vma->vm_flags & VM_WRITE)) 57 if (is_write && !(vma->vm_flags & VM_WRITE))
70 goto out; 58 goto out;
71 59
72 /* Don't require VM_READ|VM_EXEC for write faults! */ 60 /* Don't require VM_READ|VM_EXEC for write faults! */
73 if(!is_write && !(vma->vm_flags & (VM_READ | VM_EXEC))) 61 if (!is_write && !(vma->vm_flags & (VM_READ | VM_EXEC)))
74 goto out; 62 goto out;
75 63
76 do { 64 do {
@@ -96,9 +84,10 @@ survive:
96 pud = pud_offset(pgd, address); 84 pud = pud_offset(pgd, address);
97 pmd = pmd_offset(pud, address); 85 pmd = pmd_offset(pud, address);
98 pte = pte_offset_kernel(pmd, address); 86 pte = pte_offset_kernel(pmd, address);
99 } while(!pte_present(*pte)); 87 } while (!pte_present(*pte));
100 err = 0; 88 err = 0;
101 /* The below warning was added in place of 89 /*
90 * The below warning was added in place of
102 * pte_mkyoung(); if (is_write) pte_mkdirty(); 91 * pte_mkyoung(); if (is_write) pte_mkdirty();
103 * If it's triggered, we'd see normally a hang here (a clean pte is 92 * If it's triggered, we'd see normally a hang here (a clean pte is
104 * marked read-only to emulate the dirty bit). 93 * marked read-only to emulate the dirty bit).
@@ -112,7 +101,7 @@ survive:
112out: 101out:
113 up_read(&mm->mmap_sem); 102 up_read(&mm->mmap_sem);
114out_nosemaphore: 103out_nosemaphore:
115 return(err); 104 return err;
116 105
117/* 106/*
118 * We ran out of memory, or some other thing happened to us that made 107 * We ran out of memory, or some other thing happened to us that made
@@ -143,7 +132,7 @@ static void segv_handler(int sig, union uml_pt_regs *regs)
143{ 132{
144 struct faultinfo * fi = UPT_FAULTINFO(regs); 133 struct faultinfo * fi = UPT_FAULTINFO(regs);
145 134
146 if(UPT_IS_USER(regs) && !SEGV_IS_FIXABLE(fi)){ 135 if (UPT_IS_USER(regs) && !SEGV_IS_FIXABLE(fi)) {
147 bad_segv(*fi, UPT_IP(regs)); 136 bad_segv(*fi, UPT_IP(regs));
148 return; 137 return;
149 } 138 }
@@ -165,37 +154,41 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user,
165 int is_write = FAULT_WRITE(fi); 154 int is_write = FAULT_WRITE(fi);
166 unsigned long address = FAULT_ADDRESS(fi); 155 unsigned long address = FAULT_ADDRESS(fi);
167 156
168 if(!is_user && (address >= start_vm) && (address < end_vm)){ 157 if (!is_user && (address >= start_vm) && (address < end_vm)) {
169 flush_tlb_kernel_vm(); 158 flush_tlb_kernel_vm();
170 return 0; 159 return 0;
171 } 160 }
172 else if(current->mm == NULL) { 161 else if (current->mm == NULL) {
173 show_regs(container_of(regs, struct pt_regs, regs)); 162 show_regs(container_of(regs, struct pt_regs, regs));
174 panic("Segfault with no mm"); 163 panic("Segfault with no mm");
175 } 164 }
176 165
177 if (SEGV_IS_FIXABLE(&fi) || SEGV_MAYBE_FIXABLE(&fi)) 166 if (SEGV_IS_FIXABLE(&fi) || SEGV_MAYBE_FIXABLE(&fi))
178 err = handle_page_fault(address, ip, is_write, is_user, &si.si_code); 167 err = handle_page_fault(address, ip, is_write, is_user,
168 &si.si_code);
179 else { 169 else {
180 err = -EFAULT; 170 err = -EFAULT;
181 /* A thread accessed NULL, we get a fault, but CR2 is invalid. 171 /*
182 * This code is used in __do_copy_from_user() of TT mode. */ 172 * A thread accessed NULL, we get a fault, but CR2 is invalid.
173 * This code is used in __do_copy_from_user() of TT mode.
174 * XXX tt mode is gone, so maybe this isn't needed any more
175 */
183 address = 0; 176 address = 0;
184 } 177 }
185 178
186 catcher = current->thread.fault_catcher; 179 catcher = current->thread.fault_catcher;
187 if(!err) 180 if (!err)
188 return 0; 181 return 0;
189 else if(catcher != NULL){ 182 else if (catcher != NULL) {
190 current->thread.fault_addr = (void *) address; 183 current->thread.fault_addr = (void *) address;
191 do_longjmp(catcher, 1); 184 do_longjmp(catcher, 1);
192 } 185 }
193 else if(current->thread.fault_addr != NULL) 186 else if (current->thread.fault_addr != NULL)
194 panic("fault_addr set but no fault catcher"); 187 panic("fault_addr set but no fault catcher");
195 else if(!is_user && arch_fixup(ip, regs)) 188 else if (!is_user && arch_fixup(ip, regs))
196 return 0; 189 return 0;
197 190
198 if(!is_user) { 191 if (!is_user) {
199 show_regs(container_of(regs, struct pt_regs, regs)); 192 show_regs(container_of(regs, struct pt_regs, regs));
200 panic("Kernel mode fault at addr 0x%lx, ip 0x%lx", 193 panic("Kernel mode fault at addr 0x%lx, ip 0x%lx",
201 address, ip); 194 address, ip);
@@ -209,7 +202,7 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user,
209 current->thread.arch.faultinfo = fi; 202 current->thread.arch.faultinfo = fi;
210 force_sig_info(SIGBUS, &si, current); 203 force_sig_info(SIGBUS, &si, current);
211 } else if (err == -ENOMEM) { 204 } else if (err == -ENOMEM) {
212 printk("VM: killing process %s\n", current->comm); 205 printk(KERN_INFO "VM: killing process %s\n", current->comm);
213 do_exit(SIGKILL); 206 do_exit(SIGKILL);
214 } else { 207 } else {
215 BUG_ON(err != -EFAULT); 208 BUG_ON(err != -EFAULT);
@@ -223,13 +216,13 @@ unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user,
223 216
224void relay_signal(int sig, union uml_pt_regs *regs) 217void relay_signal(int sig, union uml_pt_regs *regs)
225{ 218{
226 if(arch_handle_signal(sig, regs)) 219 if (arch_handle_signal(sig, regs))
227 return; 220 return;
228 221
229 if(!UPT_IS_USER(regs)){ 222 if (!UPT_IS_USER(regs)) {
230 if(sig == SIGBUS) 223 if (sig == SIGBUS)
231 printk("Bus error - the host /dev/shm or /tmp mount " 224 printk(KERN_ERR "Bus error - the host /dev/shm or /tmp "
232 "likely just ran out of space\n"); 225 "mount likely just ran out of space\n");
233 panic("Kernel mode signal %d", sig); 226 panic("Kernel mode signal %d", sig);
234 } 227 }
235 228
@@ -239,7 +232,7 @@ void relay_signal(int sig, union uml_pt_regs *regs)
239 232
240static void bus_handler(int sig, union uml_pt_regs *regs) 233static void bus_handler(int sig, union uml_pt_regs *regs)
241{ 234{
242 if(current->thread.fault_catcher != NULL) 235 if (current->thread.fault_catcher != NULL)
243 do_longjmp(current->thread.fault_catcher, 1); 236 do_longjmp(current->thread.fault_catcher, 1);
244 else relay_signal(sig, regs); 237 else relay_signal(sig, regs);
245} 238}