root/arch/i386/mm/fault.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. do_page_fault

   1 /*
   2  *  linux/arch/i386/mm/fault.c
   3  *
   4  *  Copyright (C) 1995  Linus Torvalds
   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  * This routine handles page faults.  It determines the address,
  26  * and the problem, and then passes it off to one of the appropriate
  27  * routines.
  28  *
  29  * error_code:
  30  *      bit 0 == 0 means no page found, 1 means protection fault
  31  *      bit 1 == 0 means read, 1 means write
  32  *      bit 2 == 0 means kernel, 1 means user-mode
  33  */
  34 asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code)
     /* [previous][next][first][last][top][bottom][index][help] */
  35 {
  36         struct vm_area_struct * vma;
  37         unsigned long address;
  38         unsigned long page;
  39 
  40         /* get the address */
  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  * Ok, we have a good vm_area for this memory access, so
  55  * we can handle it..
  56  */
  57 good_area:
  58         /*
  59          * was it a write?
  60          */
  61         if (error_code & 2) {
  62                 if (!(vma->vm_flags & VM_WRITE))
  63                         goto bad_area;
  64         } else {
  65                 /* read with protection fault? */
  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          * Did it hit the DOS screen memory VA from vm86 mode?
  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  * Something tried to access memory that isn't in our memory map..
  92  * Fix it, but check if it's kernel or user first..
  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  * Oops. The kernel tried to access some bad page. We'll have to
 104  * terminate things with extreme prejudice.
 105  *
 106  * First we check if it was the bootup rw-test, though..
 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 }

/* [previous][next][first][last][top][bottom][index][help] */