[PATCH v5 2/3] ntdll: Scan pages only once in get_basic_memory_info().

Paul Gofman pgofman at codeweavers.com
Thu Sep 23 09:52:12 CDT 2021


Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
---
v5:
    - Introduce get_committed_size_vprot() to avoid checking for SEC_RESERVE in get_basic_memory_info()
      and keep that logic contained.

 dlls/ntdll/unix/virtual.c | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c
index 41d878546bb..5ba28a71f78 100644
--- a/dlls/ntdll/unix/virtual.c
+++ b/dlls/ntdll/unix/virtual.c
@@ -2058,21 +2058,21 @@ done:
 
 
 /***********************************************************************
- *           get_committed_size
+ *           get_committed_size_vprot
  *
- * Get the size of the committed range starting at base.
+ * Get the size of the committed range with equal masked vprot bytes starting at base.
  * Also return the protections for the first page.
  */
-static SIZE_T get_committed_size( struct file_view *view, void *base, BYTE *vprot )
+static SIZE_T get_committed_size_vprot( struct file_view *view, void *base, BYTE *vprot, BYTE vprot_mask )
 {
-    SIZE_T offset;
+    SIZE_T offset, size;
 
     base = ROUND_ADDR( base, page_mask );
     offset = (char *)base - (char *)view->base;
 
     if (view->protect & SEC_RESERVE)
     {
-        SIZE_T ret = 0;
+        size = 0;
 
         *vprot = get_page_vprot( base );
 
@@ -2082,22 +2082,34 @@ static SIZE_T get_committed_size( struct file_view *view, void *base, BYTE *vpro
             req->offset = offset;
             if (!wine_server_call( req ))
             {
-                ret = reply->size;
+                size = reply->size;
                 if (reply->committed)
                 {
                     *vprot |= VPROT_COMMITTED;
-                    set_page_vprot_bits( base, ret, VPROT_COMMITTED, 0 );
+                    set_page_vprot_bits( base, size, VPROT_COMMITTED, 0 );
                 }
             }
         }
         SERVER_END_REQ;
-        return ret;
-    }
 
-    return get_vprot_range_size( base, view->size - offset, VPROT_COMMITTED, vprot );
+        if (!size || !vprot_mask) return size;
+    } else size = view->size - offset;
+
+    return get_vprot_range_size( base, size, VPROT_COMMITTED | vprot_mask, vprot );
 }
 
 
+/***********************************************************************
+ *           get_committed_size_vprot
+ *
+ * Get the size of the committed range starting at base.
+ * Also return the protections for the first page.
+ */
+static SIZE_T get_committed_size( struct file_view *view, void *base, BYTE *vprot )
+{
+    return get_committed_size_vprot( view, base, vprot, 0 );
+}
+
 /***********************************************************************
  *           decommit_view
  *
@@ -4216,7 +4228,8 @@ static NTSTATUS get_basic_memory_info( HANDLE process, LPCVOID addr,
     else
     {
         BYTE vprot;
-        SIZE_T range_size = get_committed_size( view, base, &vprot );
+
+        info->RegionSize = get_committed_size_vprot( view, base, &vprot, ~VPROT_WRITEWATCH );
 
         info->State = (vprot & VPROT_COMMITTED) ? MEM_COMMIT : MEM_RESERVE;
         info->Protect = (vprot & VPROT_COMMITTED) ? get_win32_prot( vprot, view->protect ) : 0;
@@ -4224,8 +4237,6 @@ static NTSTATUS get_basic_memory_info( HANDLE process, LPCVOID addr,
         if (view->protect & SEC_IMAGE) info->Type = MEM_IMAGE;
         else if (view->protect & (SEC_FILE | SEC_RESERVE | SEC_COMMIT)) info->Type = MEM_MAPPED;
         else info->Type = MEM_PRIVATE;
-
-        info->RegionSize = get_vprot_range_size( base, range_size, ~VPROT_WRITEWATCH, &vprot );
     }
     server_leave_uninterrupted_section( &virtual_mutex, &sigset );
 
-- 
2.31.1




More information about the wine-devel mailing list