Alexandre Julliard : ntdll: Do not report non-reserved memory areas as free since we don't know what' s in them.

Alexandre Julliard julliard at winehq.org
Thu Nov 6 08:26:10 CST 2008


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Nov  6 15:00:58 2008 +0100

ntdll: Do not report non-reserved memory areas as free since we don't know what's in them.

---

 dlls/ntdll/virtual.c |   57 +++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 50 insertions(+), 7 deletions(-)

diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 01f78eb..1eb84b8 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -1764,6 +1764,43 @@ NTSTATUS WINAPI NtProtectVirtualMemory( HANDLE process, PVOID *addr_ptr, SIZE_T
     return status;
 }
 
+
+/* retrieve state for a free memory area; callback for wine_mmap_enum_reserved_areas */
+static int get_free_mem_state_callback( void *start, size_t size, void *arg )
+{
+    MEMORY_BASIC_INFORMATION *info = arg;
+    void *end = (char *)start + size;
+
+    if ((char *)info->BaseAddress + info->RegionSize < (char *)start) return 0;
+
+    if (info->BaseAddress >= end)
+    {
+        if (info->AllocationBase < end) info->AllocationBase = end;
+        return 0;
+    }
+
+    if (info->BaseAddress >= start)
+    {
+        /* it's a real free area */
+        info->State             = MEM_FREE;
+        info->Protect           = PAGE_NOACCESS;
+        info->AllocationBase    = 0;
+        info->AllocationProtect = 0;
+        info->Type              = 0;
+        if ((char *)info->BaseAddress + info->RegionSize > (char *)end)
+            info->RegionSize = (char *)end - (char *)info->BaseAddress;
+    }
+    else /* outside of the reserved area, pretend it's allocated */
+    {
+        info->RegionSize        = (char *)start - (char *)info->BaseAddress;
+        info->State             = MEM_RESERVE;
+        info->Protect           = PAGE_NOACCESS;
+        info->AllocationProtect = PAGE_NOACCESS;
+        info->Type              = MEM_PRIVATE;
+    }
+    return 1;
+}
+
 #define UNIMPLEMENTED_INFO_CLASS(c) \
     case c: \
         FIXME("(process=%p,addr=%p) Unimplemented information class: " #c "\n", process, addr); \
@@ -1861,13 +1898,20 @@ NTSTATUS WINAPI NtQueryVirtualMemory( HANDLE process, LPCVOID addr,
 
     /* Fill the info structure */
 
+    info->AllocationBase = alloc_base;
+    info->BaseAddress    = base;
+    info->RegionSize     = size - (base - alloc_base);
+
     if (!view)
     {
-        info->State             = MEM_FREE;
-        info->Protect           = PAGE_NOACCESS;
-        info->AllocationBase    = 0;
-        info->AllocationProtect = 0;
-        info->Type              = 0;
+        if (!wine_mmap_enum_reserved_areas( get_free_mem_state_callback, info, 0 ))
+        {
+            /* not in a reserved area at all, pretend it's allocated */
+            info->State             = MEM_RESERVE;
+            info->Protect           = PAGE_NOACCESS;
+            info->AllocationProtect = PAGE_NOACCESS;
+            info->Type              = MEM_PRIVATE;
+        }
     }
     else
     {
@@ -1883,11 +1927,10 @@ NTSTATUS WINAPI NtQueryVirtualMemory( HANDLE process, LPCVOID addr,
         else info->Type = MEM_MAPPED;
         for (size = base - alloc_base; size < base + range_size - alloc_base; size += page_size)
             if (view->prot[size >> page_shift] != vprot) break;
+        info->RegionSize = size - (base - alloc_base);
     }
     server_leave_uninterrupted_section( &csVirtual, &sigset );
 
-    info->BaseAddress    = base;
-    info->RegionSize     = size - (base - alloc_base);
     if (res_len) *res_len = sizeof(*info);
     return STATUS_SUCCESS;
 }




More information about the wine-cvs mailing list