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/signal.h>
   8 #include <linux/sched.h>
   9 #include <linux/head.h>
  10 #include <linux/kernel.h>
  11 #include <linux/errno.h>
  12 #include <linux/string.h>
  13 #include <linux/types.h>
  14 #include <linux/ptrace.h>
  15 #include <linux/mman.h>
  16 #include <linux/mm.h>
  17 
  18 #include <asm/system.h>
  19 #include <asm/segment.h>
  20 #include <asm/pgtable.h>
  21 
  22 extern void die_if_kernel(const 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         if (error_code & 4) {
  52                 /*
  53                  * accessing the stack below %esp is always a bug.
  54                  * The "+ 32" is there due to some instructions (like
  55                  * pusha) doing pre-decrement on the stack and that
  56                  * doesn't show up until later..
  57                  */
  58                 if (address + 32 < regs->esp)
  59                         goto bad_area;
  60         }
  61         vma->vm_offset -= vma->vm_start - (address & PAGE_MASK);
  62         vma->vm_start = (address & PAGE_MASK);
  63 /*
  64  * Ok, we have a good vm_area for this memory access, so
  65  * we can handle it..
  66  */
  67 good_area:
  68         /*
  69          * was it a write?
  70          */
  71         if (error_code & 2) {
  72                 if (!(vma->vm_flags & VM_WRITE))
  73                         goto bad_area;
  74         } else {
  75                 /* read with protection fault? */
  76                 if (error_code & 1)
  77                         goto bad_area;
  78                 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
  79                         goto bad_area;
  80         }
  81         /*
  82          * Did it hit the DOS screen memory VA from vm86 mode?
  83          */
  84         if (regs->eflags & VM_MASK) {
  85                 unsigned long bit = (address - 0xA0000) >> PAGE_SHIFT;
  86                 if (bit < 32)
  87                         current->tss.screen_bitmap |= 1 << bit;
  88         }
  89         if (error_code & 1) {
  90 #ifdef TEST_VERIFY_AREA
  91                 if (regs->cs == KERNEL_CS)
  92                         printk("WP fault at %08x\n", regs->eip);
  93 #endif
  94                 do_wp_page(current, vma, address, error_code & 2);
  95                 return;
  96         }
  97         do_no_page(current, vma, address, error_code & 2);
  98         return;
  99 
 100 /*
 101  * Something tried to access memory that isn't in our memory map..
 102  * Fix it, but check if it's kernel or user first..
 103  */
 104 bad_area:
 105         if (error_code & 4) {
 106                 current->tss.cr2 = address;
 107                 current->tss.error_code = error_code;
 108                 current->tss.trap_no = 14;
 109                 send_sig(SIGSEGV, current, 1);
 110                 return;
 111         }
 112 /*
 113  * Oops. The kernel tried to access some bad page. We'll have to
 114  * terminate things with extreme prejudice.
 115  *
 116  * First we check if it was the bootup rw-test, though..
 117  */
 118         if (wp_works_ok < 0 && address == TASK_SIZE && (error_code & 1)) {
 119                 wp_works_ok = 1;
 120                 pg0[0] = pte_val(mk_pte(0, PAGE_SHARED));
 121                 invalidate();
 122                 printk("This processor honours the WP bit even when in supervisor mode. Good.\n");
 123                 return;
 124         }
 125         if ((unsigned long) (address-TASK_SIZE) < PAGE_SIZE) {
 126                 printk(KERN_ALERT "Unable to handle kernel NULL pointer dereference");
 127                 pg0[0] = pte_val(mk_pte(0, PAGE_SHARED));
 128         } else
 129                 printk(KERN_ALERT "Unable to handle kernel paging request");
 130         printk(" at virtual address %08lx\n",address);
 131         __asm__("movl %%cr3,%0" : "=r" (page));
 132         printk(KERN_ALERT "current->tss.cr3 = %08lx, %%cr3 = %08lx\n",
 133                 current->tss.cr3, page);
 134         page = ((unsigned long *) page)[address >> 22];
 135         printk(KERN_ALERT "*pde = %08lx\n", page);
 136         if (page & 1) {
 137                 page &= PAGE_MASK;
 138                 address &= 0x003ff000;
 139                 page = ((unsigned long *) page)[address >> PAGE_SHIFT];
 140                 printk(KERN_ALERT "*pte = %08lx\n", page);
 141         }
 142         die_if_kernel("Oops", regs, error_code);
 143         do_exit(SIGKILL);
 144 }

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