2 * linux/arch/m68k/mm/fault.c
4 * Copyright (C) 1995 Hamish Macdonald
7 #include <linux/mman.h>
9 #include <linux/kernel.h>
10 #include <linux/ptrace.h>
11 #include <linux/interrupt.h>
13 #include <asm/setup.h>
14 #include <asm/traps.h>
15 #include <asm/system.h>
16 #include <asm/uaccess.h>
17 #include <asm/pgalloc.h>
19 extern void die_if_kernel(char *, struct pt_regs *, long);
20 extern const int frame_extra_sizes[]; /* in m68k/kernel/signal.c */
22 int send_fault_sig(struct pt_regs *regs)
24 siginfo_t siginfo = { 0, 0, 0, };
26 siginfo.si_signo = current->thread.signo;
27 siginfo.si_code = current->thread.code;
28 siginfo.si_addr = (void *)current->thread.faddr;
30 printk("send_fault_sig: %p,%d,%d\n", siginfo.si_addr, siginfo.si_signo, siginfo.si_code);
33 if (user_mode(regs)) {
34 force_sig_info(siginfo.si_signo,
39 /* Are we prepared to handle this kernel fault? */
40 if ((fixup = search_exception_table(regs->pc))) {
41 struct pt_regs *tregs;
42 /* Create a new four word stack frame, discarding the old
44 regs->stkadj = frame_extra_sizes[regs->format];
45 tregs = (struct pt_regs *)((ulong)regs + regs->stkadj);
46 tregs->vector = regs->vector;
53 //if (siginfo.si_signo == SIGBUS)
54 // force_sig_info(siginfo.si_signo,
55 // &siginfo, current);
58 * Oops. The kernel tried to access some bad page. We'll have to
59 * terminate things with extreme prejudice.
61 if ((unsigned long)siginfo.si_addr < PAGE_SIZE)
62 printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference");
64 printk(KERN_ALERT "Unable to handle kernel access");
65 printk(" at virtual address %p\n", siginfo.si_addr);
66 die_if_kernel("Oops", regs, 0 /*error_code*/);
74 * This routine handles page faults. It determines the problem, and
75 * then passes it off to one of the appropriate routines.
78 * bit 0 == 0 means no page found, 1 means protection fault
79 * bit 1 == 0 means read, 1 means write
81 * If this routine detects a bad access, it returns 1, otherwise it
84 int do_page_fault(struct pt_regs *regs, unsigned long address,
85 unsigned long error_code)
87 struct mm_struct *mm = current->mm;
88 struct vm_area_struct * vma;
92 printk ("do page fault:\nregs->sr=%#x, regs->pc=%#lx, address=%#lx, %ld, %p\n",
93 regs->sr, regs->pc, address, error_code,
98 * If we're in an interrupt or have no user
99 * context, we must not take the fault..
101 if (in_interrupt() || !mm)
104 down_read(&mm->mmap_sem);
106 vma = find_vma(mm, address);
109 if (vma->vm_flags & VM_IO)
111 if (vma->vm_start <= address)
113 if (!(vma->vm_flags & VM_GROWSDOWN))
115 if (user_mode(regs)) {
116 /* Accessing the stack below usp is always a bug. The
117 "+ 256" is there due to some instructions doing
118 pre-decrement on the stack and that doesn't show up
120 if (address + 256 < rdusp())
123 if (expand_stack(vma, address))
127 * Ok, we have a good vm_area for this memory access, so
132 printk("do_page_fault: good_area\n");
135 switch (error_code & 3) {
136 default: /* 3: write, present */
138 case 2: /* write, not present */
139 if (!(vma->vm_flags & VM_WRITE))
143 case 1: /* read, present */
145 case 0: /* read, not present */
146 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
151 * If for any reason at all we couldn't handle the fault,
152 * make sure we exit gracefully rather than endlessly redo
157 fault = handle_mm_fault(mm, vma, address, write);
159 printk("handle_mm_fault returns %d\n",fault);
174 up_read(&mm->mmap_sem);
178 * We ran out of memory, or some other thing happened to us that made
179 * us unable to handle the page fault gracefully.
182 if (current->pid == 1) {
187 up_read(&mm->mmap_sem);
188 printk("VM: killing process %s\n", current->comm);
193 current->thread.signo = SIGBUS;
194 current->thread.faddr = address;
195 return send_fault_sig(regs);
198 current->thread.signo = SIGBUS;
199 current->thread.code = BUS_ADRERR;
200 current->thread.faddr = address;
204 current->thread.signo = SIGSEGV;
205 current->thread.code = SEGV_MAPERR;
206 current->thread.faddr = address;
210 current->thread.signo = SIGSEGV;
211 current->thread.code = SEGV_ACCERR;
212 current->thread.faddr = address;
215 up_read(&mm->mmap_sem);
216 return send_fault_sig(regs);