[PATCH 1/4] dlls/ntdll: Add handle count to NtQuerySystemInformation

Austin Lund austin.lund at gmail.com
Sun Jun 19 21:15:38 CDT 2011


---
 dlls/ntdll/nt.c         |   53 +++++++++++++++++++++++++++++++++++++++++-----
 dlls/ntdll/tests/info.c |    8 +-----
 2 files changed, 49 insertions(+), 12 deletions(-)

diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c
index f9302c1..f068dc6 100644
--- a/dlls/ntdll/nt.c
+++ b/dlls/ntdll/nt.c
@@ -1655,18 +1655,59 @@ NTSTATUS WINAPI NtQuerySystemInformation(
         break;
     case SystemHandleInformation:
         {
-            SYSTEM_HANDLE_INFORMATION shi;
+            SYSTEM_HANDLE_INFORMATION *shi;
+            HANDLE hSnap = 0;
+
+            FIXME("info_class SYSTEM_HANDLE_INFORMATION partial implementation\n");
+
+            SERVER_START_REQ( create_snapshot )
+            {
+                req->flags      = SNAP_PROCESS;
+                req->attributes = 0;
+                if (!(ret = wine_server_call( req )))
+                    hSnap = wine_server_ptr_handle( reply->handle );
+            }
+            SERVER_END_REQ;
+
+            len = sizeof(SYSTEM_HANDLE_INFORMATION);
+            shi = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
+
+            while (ret == STATUS_SUCCESS)
+            {
+                SERVER_START_REQ( next_process )
+                {
+                    int i;
+                    req->handle = wine_server_obj_handle( hSnap );
+                    req->reset =  0;
+
+                    ret = wine_server_call( req );
+                    shi->Count += reply->handles;
+                    len = sizeof(SYSTEM_HANDLE_ENTRY)*shi->Count + sizeof(ULONG);
+                    shi = RtlReAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, shi, len);
+                    for (i = shi->Count - reply->handles; i < shi->Count; i++) {
+                        shi->Handle[i].OwnerPid = reply->pid;
+                    }
+                }
+                SERVER_END_REQ;
+            }
 
-            memset(&shi, 0, sizeof(shi));
-            len = sizeof(shi);
+            if ( ResultLength )
+                *ResultLength = len;
 
             if ( Length >= len)
             {
                 if (!SystemInformation) ret = STATUS_ACCESS_VIOLATION;
-                else memcpy( SystemInformation, &shi, len);
+                else {
+                    memcpy(SystemInformation, shi, len);
+                    RtlFreeHeap(GetProcessHeap(), 0, shi);
+                    shi = NULL;
+                    ret = STATUS_SUCCESS;
+                }
             }
-            else ret = STATUS_INFO_LENGTH_MISMATCH;
-            FIXME("info_class SYSTEM_HANDLE_INFORMATION\n");
+            else
+                ret = STATUS_INFO_LENGTH_MISMATCH;
+
+            if (hSnap) NtClose(hSnap);
         }
         break;
     case SystemCacheInformation:
diff --git a/dlls/ntdll/tests/info.c b/dlls/ntdll/tests/info.c
index 2d5c94f..f82bdfd 100644
--- a/dlls/ntdll/tests/info.c
+++ b/dlls/ntdll/tests/info.c
@@ -468,7 +468,7 @@ static void test_query_handle(void)
 
     /* Request the needed length : a SystemInformationLength greater than one struct sets ReturnLength */
     status = pNtQuerySystemInformation(SystemHandleInformation, shi, SystemInformationLength, &ReturnLength);
-    todo_wine ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
+    ok( status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
 
     SystemInformationLength = ReturnLength;
     shi = HeapReAlloc(GetProcessHeap(), 0, shi , SystemInformationLength);
@@ -480,11 +480,7 @@ static void test_query_handle(void)
 
         /* Check if we have some return values */
         trace("Number of Handles : %d\n", shi->Count);
-        todo_wine
-        {
-            /* our implementation is a stub for now */
-            ok( shi->Count > 1, "Expected more than 1 handles, got (%d)\n", shi->Count);
-        }
+        ok( shi->Count > 1, "Expected more than 1 handles, got (%d)\n", shi->Count);
     }
     HeapFree( GetProcessHeap(), 0, shi);
 }
-- 
1.7.4.1




More information about the wine-patches mailing list