Alexandre Julliard : ntdll: Use the find_view_range helper function to check for overlapping views.

Alexandre Julliard julliard at winehq.org
Thu Sep 7 15:44:57 CDT 2017


Module: wine
Branch: master
Commit: 917d98a457f2beaf59b39b99a0e13f7a90146cfe
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=917d98a457f2beaf59b39b99a0e13f7a90146cfe

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Sep  7 18:52:48 2017 +0200

ntdll: Use the find_view_range helper function to check for overlapping views.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/virtual.c | 48 +++++++++++++-----------------------------------
 1 file changed, 13 insertions(+), 35 deletions(-)

diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index a730417..21cc9f5 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -638,6 +638,18 @@ static NTSTATUS create_view( struct file_view **view_ret, void *base, size_t siz
     assert( !((UINT_PTR)base & page_mask) );
     assert( !(size & page_mask) );
 
+    /* Check for overlapping views. This can happen if the previous view
+     * was a system view that got unmapped behind our back. In that case
+     * we recover by simply deleting it. */
+
+    while ((view = find_view_range( base, size )))
+    {
+        TRACE( "overlapping view %p-%p for %p-%p\n",
+               view->base, (char *)view->base + view->size, base, (char *)base + size );
+        assert( view->protect & VPROT_SYSTEM );
+        delete_view( view );
+    }
+
     if (!alloc_pages_vprot( base, size )) return STATUS_NO_MEMORY;
 
     /* Create the view structure */
@@ -664,35 +676,6 @@ static NTSTATUS create_view( struct file_view **view_ret, void *base, size_t siz
     }
     list_add_before( ptr, &view->entry );
 
-    /* Check for overlapping views. This can happen if the previous view
-     * was a system view that got unmapped behind our back. In that case
-     * we recover by simply deleting it. */
-
-    if ((ptr = list_prev( &views_list, &view->entry )) != NULL)
-    {
-        struct file_view *prev = LIST_ENTRY( ptr, struct file_view, entry );
-        if ((char *)prev->base + prev->size > (char *)base)
-        {
-            TRACE( "overlapping prev view %p-%p for %p-%p\n",
-                   prev->base, (char *)prev->base + prev->size,
-                   base, (char *)base + view->size );
-            assert( prev->protect & VPROT_SYSTEM );
-            delete_view( prev );
-        }
-    }
-    if ((ptr = list_next( &views_list, &view->entry )) != NULL)
-    {
-        struct file_view *next = LIST_ENTRY( ptr, struct file_view, entry );
-        if ((char *)base + view->size > (char *)next->base)
-        {
-            TRACE( "overlapping next view %p-%p for %p-%p\n",
-                   next->base, (char *)next->base + next->size,
-                   base, (char *)base + view->size );
-            assert( next->protect & VPROT_SYSTEM );
-            delete_view( next );
-        }
-    }
-
     *view_ret = view;
     VIRTUAL_DEBUG_DUMP_VIEW( view );
 
@@ -1187,15 +1170,10 @@ static NTSTATUS allocate_dos_memory( struct file_view **view, unsigned int vprot
     void * const low_64k = (void *)0x10000;
     const size_t dosmem_size = 0x110000;
     int unix_prot = VIRTUAL_GetUnixProt( vprot );
-    struct list *ptr;
 
     /* check for existing view */
 
-    if ((ptr = list_head( &views_list )))
-    {
-        struct file_view *first_view = LIST_ENTRY( ptr, struct file_view, entry );
-        if (first_view->base < (void *)dosmem_size) return STATUS_CONFLICTING_ADDRESSES;
-    }
+    if (find_view_range( 0, dosmem_size )) return STATUS_CONFLICTING_ADDRESSES;
 
     /* check without the first 64K */
 




More information about the wine-cvs mailing list