vserver 2.0 rc7
[linux-2.6.git] / arch / um / kernel / trap_kern.c
index 47e766e..c20aef1 100644 (file)
@@ -23,7 +23,6 @@
 #include "kern.h"
 #include "chan_kern.h"
 #include "mconsole_kern.h"
-#include "2_5compat.h"
 #include "mem.h"
 #include "mem_kern.h"
 
@@ -48,7 +47,7 @@ int handle_page_fault(unsigned long address, unsigned long ip,
                goto good_area;
        else if(!(vma->vm_flags & VM_GROWSDOWN)) 
                goto out;
-       else if(!ARCH_IS_STACKGROW(address))
+       else if(is_user && !ARCH_IS_STACKGROW(address))
                goto out;
        else if(expand_stack(vma, address)) 
                goto out;
@@ -57,10 +56,11 @@ int handle_page_fault(unsigned long address, unsigned long ip,
        *code_out = SEGV_ACCERR;
        if(is_write && !(vma->vm_flags & VM_WRITE)) 
                goto out;
+
+        if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
+                goto out;
+
        page = address & PAGE_MASK;
-       pgd = pgd_offset(mm, page);
-       pud = pud_offset(pgd, page);
-       pmd = pmd_offset(pud, page);
        do {
  survive:
                switch (handle_mm_fault(mm, vma, address, is_write)){
@@ -106,46 +106,24 @@ out_of_memory:
        goto out;
 }
 
-LIST_HEAD(physmem_remappers);
-
-void register_remapper(struct remapper *info)
-{
-       list_add(&info->list, &physmem_remappers);
-}
-
-static int check_remapped_addr(unsigned long address, int is_write)
-{
-       struct remapper *remapper;
-       struct list_head *ele;
-       __u64 offset;
-       int fd;
-
-       fd = phys_mapping(__pa(address), &offset);
-       if(fd == -1)
-               return(0);
-
-       list_for_each(ele, &physmem_remappers){
-               remapper = list_entry(ele, struct remapper, list);
-               if((*remapper->proc)(fd, address, is_write, offset))
-                       return(1);
-       }
-
-       return(0);
-}
-
-unsigned long segv(unsigned long address, unsigned long ip, int is_write, 
-                  int is_user, void *sc)
+/*
+ * We give a *copy* of the faultinfo in the regs to segv.
+ * This must be done, since nesting SEGVs could overwrite
+ * the info in the regs. A pointer to the info then would
+ * give us bad data!
+ */
+unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user, void *sc)
 {
        struct siginfo si;
        void *catcher;
        int err;
+        int is_write = FAULT_WRITE(fi);
+        unsigned long address = FAULT_ADDRESS(fi);
 
         if(!is_user && (address >= start_vm) && (address < end_vm)){
                 flush_tlb_kernel_vm();
                 return(0);
         }
-       else if(check_remapped_addr(address & PAGE_MASK, is_write))
-               return(0);
        else if(current->mm == NULL)
                panic("Segfault with no mm");
        err = handle_page_fault(address, ip, is_write, is_user, &si.si_code);
@@ -159,7 +137,7 @@ unsigned long segv(unsigned long address, unsigned long ip, int is_write,
        } 
        else if(current->thread.fault_addr != NULL)
                panic("fault_addr set but no fault catcher");
-       else if(arch_fixup(ip, sc))
+        else if(!is_user && arch_fixup(ip, sc))
                return(0);
 
        if(!is_user) 
@@ -171,6 +149,7 @@ unsigned long segv(unsigned long address, unsigned long ip, int is_write,
                si.si_errno = 0;
                si.si_code = BUS_ADRERR;
                si.si_addr = (void *)address;
+                current->thread.arch.faultinfo = fi;
                force_sig_info(SIGBUS, &si, current);
        }
        else if(err == -ENOMEM){
@@ -180,22 +159,20 @@ unsigned long segv(unsigned long address, unsigned long ip, int is_write,
        else {
                si.si_signo = SIGSEGV;
                si.si_addr = (void *) address;
-               current->thread.cr2 = address;
-               current->thread.err = is_write;
+                current->thread.arch.faultinfo = fi;
                force_sig_info(SIGSEGV, &si, current);
        }
        return(0);
 }
 
-void bad_segv(unsigned long address, unsigned long ip, int is_write)
+void bad_segv(struct faultinfo fi, unsigned long ip)
 {
        struct siginfo si;
 
        si.si_signo = SIGSEGV;
        si.si_code = SEGV_ACCERR;
-       si.si_addr = (void *) address;
-       current->thread.cr2 = address;
-       current->thread.err = is_write;
+        si.si_addr = (void *) FAULT_ADDRESS(fi);
+        current->thread.arch.faultinfo = fi;
        force_sig_info(SIGSEGV, &si, current);
 }
 
@@ -204,6 +181,7 @@ void relay_signal(int sig, union uml_pt_regs *regs)
        if(arch_handle_signal(sig, regs)) return;
        if(!UPT_IS_USER(regs))
                panic("Kernel mode signal %d", sig);
+        current->thread.arch.faultinfo = *UPT_FAULTINFO(regs);
        force_sig(sig, current);
 }