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>
12 #include <linux/module.h>
14 #include <asm/setup.h>
15 #include <asm/traps.h>
16 #include <asm/system.h>
17 #include <asm/uaccess.h>
18 #include <asm/pgalloc.h>
20 extern void die_if_kernel(char *, struct pt_regs
*, long);
21 extern const int frame_extra_sizes
[]; /* in m68k/kernel/signal.c */
23 int send_fault_sig(struct pt_regs
*regs
)
25 siginfo_t siginfo
= { 0, 0, 0, };
27 siginfo
.si_signo
= current
->thread
.signo
;
28 siginfo
.si_code
= current
->thread
.code
;
29 siginfo
.si_addr
= (void *)current
->thread
.faddr
;
31 printk("send_fault_sig: %p,%d,%d\n", siginfo
.si_addr
, siginfo
.si_signo
, siginfo
.si_code
);
34 if (user_mode(regs
)) {
35 force_sig_info(siginfo
.si_signo
,
38 const struct exception_table_entry
*fixup
;
40 /* Are we prepared to handle this kernel fault? */
41 if ((fixup
= search_exception_tables(regs
->pc
))) {
42 struct pt_regs
*tregs
;
43 /* Create a new four word stack frame, discarding the old
45 regs
->stkadj
= frame_extra_sizes
[regs
->format
];
46 tregs
= (struct pt_regs
*)((ulong
)regs
+ regs
->stkadj
);
47 tregs
->vector
= regs
->vector
;
49 tregs
->pc
= fixup
->fixup
;
54 //if (siginfo.si_signo == SIGBUS)
55 // force_sig_info(siginfo.si_signo,
56 // &siginfo, current);
59 * Oops. The kernel tried to access some bad page. We'll have to
60 * terminate things with extreme prejudice.
62 if ((unsigned long)siginfo
.si_addr
< PAGE_SIZE
)
63 printk(KERN_ALERT
"Unable to handle kernel NULL pointer dereference");
65 printk(KERN_ALERT
"Unable to handle kernel access");
66 printk(" at virtual address %p\n", siginfo
.si_addr
);
67 die_if_kernel("Oops", regs
, 0 /*error_code*/);
75 * This routine handles page faults. It determines the problem, and
76 * then passes it off to one of the appropriate routines.
79 * bit 0 == 0 means no page found, 1 means protection fault
80 * bit 1 == 0 means read, 1 means write
82 * If this routine detects a bad access, it returns 1, otherwise it
85 int do_page_fault(struct pt_regs
*regs
, unsigned long address
,
86 unsigned long error_code
)
88 struct mm_struct
*mm
= current
->mm
;
89 struct vm_area_struct
* vma
;
93 printk ("do page fault:\nregs->sr=%#x, regs->pc=%#lx, address=%#lx, %ld, %p\n",
94 regs
->sr
, regs
->pc
, address
, error_code
,
99 * If we're in an interrupt or have no user
100 * context, we must not take the fault..
102 if (in_interrupt() || !mm
)
105 down_read(&mm
->mmap_sem
);
107 vma
= find_vma(mm
, address
);
110 if (vma
->vm_flags
& VM_IO
)
112 if (vma
->vm_start
<= address
)
114 if (!(vma
->vm_flags
& VM_GROWSDOWN
))
116 if (user_mode(regs
)) {
117 /* Accessing the stack below usp is always a bug. The
118 "+ 256" is there due to some instructions doing
119 pre-decrement on the stack and that doesn't show up
121 if (address
+ 256 < rdusp())
124 if (expand_stack(vma
, address
))
128 * Ok, we have a good vm_area for this memory access, so
133 printk("do_page_fault: good_area\n");
136 switch (error_code
& 3) {
137 default: /* 3: write, present */
139 case 2: /* write, not present */
140 if (!(vma
->vm_flags
& VM_WRITE
))
144 case 1: /* read, present */
146 case 0: /* read, not present */
147 if (!(vma
->vm_flags
& (VM_READ
| VM_EXEC
)))
152 * If for any reason at all we couldn't handle the fault,
153 * make sure we exit gracefully rather than endlessly redo
158 fault
= handle_mm_fault(mm
, vma
, address
, write
);
160 printk("handle_mm_fault returns %d\n",fault
);
169 case VM_FAULT_SIGBUS
:
175 up_read(&mm
->mmap_sem
);
179 * We ran out of memory, or some other thing happened to us that made
180 * us unable to handle the page fault gracefully.
183 up_read(&mm
->mmap_sem
);
184 if (current
->pid
== 1) {
186 down_read(&mm
->mmap_sem
);
190 printk("VM: killing process %s\n", current
->comm
);
195 current
->thread
.signo
= SIGBUS
;
196 current
->thread
.faddr
= address
;
197 return send_fault_sig(regs
);
200 current
->thread
.signo
= SIGBUS
;
201 current
->thread
.code
= BUS_ADRERR
;
202 current
->thread
.faddr
= address
;
206 current
->thread
.signo
= SIGSEGV
;
207 current
->thread
.code
= SEGV_MAPERR
;
208 current
->thread
.faddr
= address
;
212 current
->thread
.signo
= SIGSEGV
;
213 current
->thread
.code
= SEGV_ACCERR
;
214 current
->thread
.faddr
= address
;
217 up_read(&mm
->mmap_sem
);
218 return send_fault_sig(regs
);