[PATCH v3 1/3] ntdll/tests: Test that ptids are multiples of four.

Rémi Bernon rbernon at codeweavers.com
Sat Apr 25 03:05:08 CDT 2020


Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---

v3: Add some NtOpenProcess / NtOpenThread tests. This only tries to open
    processes using the current process ptid with low bits sets, as it
    seems to be enough to give us the check we need.

    On Windows XP Pro, it returns STATUS_ACCESS_DENIED but on all other
    Windows versions it works and the low ptid bits are ignored.

 dlls/ntdll/tests/info.c | 57 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/dlls/ntdll/tests/info.c b/dlls/ntdll/tests/info.c
index 8dc8bad645f6..a899353f8f9c 100644
--- a/dlls/ntdll/tests/info.c
+++ b/dlls/ntdll/tests/info.c
@@ -319,6 +319,11 @@ static void test_query_process(void)
     int i = 0, k = 0;
     BOOL is_nt = FALSE;
     SYSTEM_BASIC_INFORMATION sbi;
+    PROCESS_BASIC_INFORMATION pbi;
+    THREAD_BASIC_INFORMATION tbi;
+    OBJECT_ATTRIBUTES attr;
+    CLIENT_ID cid;
+    HANDLE handle;
 
     /* Copy of our winternl.h structure turned into a private one */
     typedef struct _SYSTEM_PROCESS_INFORMATION_PRIVATE {
@@ -401,13 +406,21 @@ static void test_query_process(void)
         
         if (!is_nt)
         {
+            DWORD_PTR tid;
             DWORD j;
+
+            todo_wine_if(last_pid & 3)
+            ok(!(last_pid & 3), "Unexpected PID low bits: %p\n", spi->UniqueProcessId);
             for ( j = 0; j < spi->dwThreadCount; j++) 
             {
                 k++;
                 ok ( spi->ti[j].ClientId.UniqueProcess == spi->UniqueProcessId,
                      "The owning pid of the thread (%p) doesn't equal the pid (%p) of the process\n",
                      spi->ti[j].ClientId.UniqueProcess, spi->UniqueProcessId);
+
+                tid = (DWORD_PTR)spi->ti[j].ClientId.UniqueThread;
+                todo_wine_if(tid & 3)
+                ok(!(tid & 3), "Unexpected TID low bits: %p\n", spi->ti[j].ClientId.UniqueThread);
             }
         }
 
@@ -423,6 +436,50 @@ static void test_query_process(void)
     if (one_before_last_pid == 0) one_before_last_pid = last_pid;
 
     HeapFree( GetProcessHeap(), 0, spi_buf);
+
+    if (is_nt)
+    {
+        win_skip("skipping ptids low bits tests\n");
+        return;
+    }
+
+    for (i = 1; i < 4; ++i)
+    {
+        InitializeObjectAttributes( &attr, NULL, 0, NULL, NULL );
+        cid.UniqueProcess = ULongToHandle(GetCurrentProcessId() + i);
+        cid.UniqueThread = 0;
+
+        status = NtOpenProcess( &handle, PROCESS_QUERY_LIMITED_INFORMATION, &attr, &cid );
+        todo_wine_if( status != STATUS_SUCCESS )
+        ok( status == STATUS_SUCCESS, "NtOpenProcess returned:%x\n", status );
+        if (status != STATUS_SUCCESS) continue;
+
+        status = pNtQueryInformationProcess( handle, ProcessBasicInformation, &pbi, sizeof(pbi), NULL );
+        ok( status == STATUS_SUCCESS, "NtQueryInformationProcess returned:%x\n", status );
+        ok( pbi.UniqueProcessId == GetCurrentProcessId(),
+            "Expected pid %p, got %p\n", ULongToHandle(GetCurrentProcessId()), ULongToHandle(pbi.UniqueProcessId) );
+
+        NtClose( handle );
+    }
+
+    for (i = 1; i < 4; ++i)
+    {
+        InitializeObjectAttributes( &attr, NULL, 0, NULL, NULL );
+        cid.UniqueProcess = 0;
+        cid.UniqueThread = ULongToHandle(GetCurrentThreadId() + i);
+
+        status = NtOpenThread( &handle, THREAD_QUERY_LIMITED_INFORMATION, &attr, &cid );
+        todo_wine_if( status != STATUS_SUCCESS )
+        ok( status == STATUS_SUCCESS, "NtOpenThread returned:%x\n", status );
+        if (status != STATUS_SUCCESS) continue;
+
+        status = pNtQueryInformationThread( handle, ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
+        ok( status == STATUS_SUCCESS, "NtQueryInformationThread returned:%x\n", status );
+        ok( tbi.ClientId.UniqueThread == ULongToHandle(GetCurrentThreadId()),
+            "Expected tid %p, got %p\n", ULongToHandle(GetCurrentThreadId()), tbi.ClientId.UniqueThread );
+
+        NtClose( handle );
+    }
 }
 
 static void test_query_procperf(void)
-- 
2.26.1




More information about the wine-devel mailing list