]> xenbits.xensource.com Git - qemu-xen-3.3-testing.git/commitdiff
EFAULT - verify pages are in cache and are read/write, by Thayne Harbaugh.
authorths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>
Fri, 2 Nov 2007 19:02:07 +0000 (19:02 +0000)
committerths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>
Fri, 2 Nov 2007 19:02:07 +0000 (19:02 +0000)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3506 c046a42c-6fe2-441c-8c8c-71466251a162

cpu-all.h
exec.c
linux-user/qemu.h

index 4e200928fe9af1341cdd0104bc633b9e19141962..76daec9474abbc6a8c903a665fc7659cdadeaeab 100644 (file)
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -691,6 +691,7 @@ void page_dump(FILE *f);
 int page_get_flags(target_ulong address);
 void page_set_flags(target_ulong start, target_ulong end, int flags);
 void page_unprotect_range(target_ulong data, target_ulong data_size);
+int page_check_range(target_ulong start, target_ulong len, int flags);
 
 CPUState *cpu_copy(CPUState *env);
 
diff --git a/exec.c b/exec.c
index 0daeaabe2524911ffdaf0345e7eb9074f6d3e7ba..7c8864c8b758f7266ceb0a96c373fcf1d7af0414 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -1875,6 +1875,33 @@ void page_set_flags(target_ulong start, target_ulong end, int flags)
     spin_unlock(&tb_lock);
 }
 
+int page_check_range(target_ulong start, target_ulong len, int flags)
+{
+    PageDesc *p;
+    target_ulong end;
+    target_ulong addr;
+
+    end = TARGET_PAGE_ALIGN(start+len); /* must do before we loose bits in the next step */
+    start = start & TARGET_PAGE_MASK;
+
+    if( end < start )
+        /* we've wrapped around */
+        return -1;
+    for(addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
+        p = page_find(addr >> TARGET_PAGE_BITS);
+        if( !p )
+            return -1;
+        if( !(p->flags & PAGE_VALID) )
+            return -1;
+
+        if (!(p->flags & PAGE_READ) && (flags & PAGE_READ) )
+            return -1;
+        if (!(p->flags & PAGE_WRITE) && (flags & PAGE_WRITE) )
+            return -1;
+    }
+    return 0;
+}
+
 /* called from signal handler: invalidate the code and unprotect the
    page. Return TRUE if the fault was succesfully handled. */
 int page_unprotect(target_ulong address, unsigned long pc, void *puc)
index 22a4fec61dc93cf1495e331381b34637ecd6b2f1..bcc0b34f364f458205888d98e7268f09a76a55d4 100644 (file)
@@ -203,7 +203,8 @@ int target_msync(abi_ulong start, abi_ulong len, int flags);
 #define VERIFY_READ 0
 #define VERIFY_WRITE 1
 
-#define access_ok(type,addr,size) (1)
+#define access_ok(type,addr,size) \
+    (page_check_range((target_ulong)addr,size,(type==VERIFY_READ)?PAGE_READ:PAGE_WRITE)==0)
 
 /* NOTE get_user and put_user use host addresses.  */
 #define __put_user(x,ptr)\