Andrew Nguyen : ntdll: Fix the status code for ProcessDebugObjectHandle class in NtQueryInformationProcess when the debugger is absent .

Alexandre Julliard julliard at winehq.org
Tue Oct 5 14:41:44 CDT 2010


Module: wine
Branch: stable
Commit: fa9a9db7f198e22b99a1e98b386ab28610a9090c
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=fa9a9db7f198e22b99a1e98b386ab28610a9090c

Author: Andrew Nguyen <anguyen at codeweavers.com>
Date:   Tue Jul 27 06:15:35 2010 -0500

ntdll: Fix the status code for ProcessDebugObjectHandle class in NtQueryInformationProcess when the debugger is absent.
(cherry picked from commit d7956bab541fde38f4b3f5011b209fa7d9989c30)

---

 dlls/ntdll/process.c    |    5 +-
 dlls/ntdll/tests/info.c |  102 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 104 insertions(+), 3 deletions(-)

diff --git a/dlls/ntdll/process.c b/dlls/ntdll/process.c
index 6fdceae..f331429 100644
--- a/dlls/ntdll/process.c
+++ b/dlls/ntdll/process.c
@@ -291,8 +291,6 @@ NTSTATUS WINAPI NtQueryInformationProcess(
         }
         break;
     case ProcessDebugPort:
-        /* "These are not the debuggers you are looking for." *
-         * set it to 0 aka "no debugger" to satisfy copy protections */
         len = sizeof(DWORD_PTR);
         if (ProcessInformationLength == len)
         {
@@ -327,7 +325,10 @@ NTSTATUS WINAPI NtQueryInformationProcess(
             else if (!ProcessHandle)
                 ret = STATUS_INVALID_HANDLE;
             else
+            {
                 memset(ProcessInformation, 0, ProcessInformationLength);
+                ret = STATUS_PORT_NOT_SET;
+            }
         }
         else
             ret = STATUS_INFO_LENGTH_MISMATCH;
diff --git a/dlls/ntdll/tests/info.c b/dlls/ntdll/tests/info.c
index 13c29f8..a56bcd1 100644
--- a/dlls/ntdll/tests/info.c
+++ b/dlls/ntdll/tests/info.c
@@ -920,6 +920,102 @@ static void test_query_process_image_file_name(void)
     HeapFree(GetProcessHeap(), 0, file_nameA);
 }
 
+static void test_query_process_debug_object_handle(int argc, char **argv)
+{
+    char cmdline[MAX_PATH];
+    STARTUPINFO si = {0};
+    PROCESS_INFORMATION pi;
+    BOOL ret;
+    HANDLE debug_object;
+    NTSTATUS status;
+
+    sprintf(cmdline, "%s %s %s", argv[0], argv[1], "debuggee");
+
+    si.cb = sizeof(si);
+    ret = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, DEBUG_PROCESS, NULL,
+                        NULL, &si, &pi);
+    ok(ret, "CreateProcess failed with last error %u\n", GetLastError());
+    if (!ret) return;
+
+    status = pNtQueryInformationProcess(NULL, ProcessDebugObjectHandle, NULL,
+            0, NULL);
+    if (status == STATUS_INVALID_INFO_CLASS || status == STATUS_NOT_IMPLEMENTED)
+    {
+        win_skip("ProcessDebugObjectHandle is not supported\n");
+        return;
+    }
+    ok(status == STATUS_INFO_LENGTH_MISMATCH,
+       "Expected NtQueryInformationProcess to return STATUS_INFO_LENGTH_MISMATCH, got 0x%08x\n",
+       status);
+
+    status = pNtQueryInformationProcess(NULL, ProcessDebugObjectHandle, NULL,
+            sizeof(debug_object), NULL);
+    ok(status == STATUS_INVALID_HANDLE ||
+       status == STATUS_ACCESS_VIOLATION, /* XP */
+       "Expected NtQueryInformationProcess to return STATUS_INVALID_HANDLE, got 0x%08x\n", status);
+
+    status = pNtQueryInformationProcess(GetCurrentProcess(),
+            ProcessDebugObjectHandle, NULL, sizeof(debug_object), NULL);
+    ok(status == STATUS_ACCESS_VIOLATION,
+       "Expected NtQueryInformationProcess to return STATUS_ACCESS_VIOLATION, got 0x%08x\n", status);
+
+    status = pNtQueryInformationProcess(NULL, ProcessDebugObjectHandle,
+            &debug_object, sizeof(debug_object), NULL);
+    ok(status == STATUS_INVALID_HANDLE,
+       "Expected NtQueryInformationProcess to return STATUS_ACCESS_VIOLATION, got 0x%08x\n", status);
+
+    status = pNtQueryInformationProcess(GetCurrentProcess(),
+            ProcessDebugObjectHandle, &debug_object,
+            sizeof(debug_object) - 1, NULL);
+    ok(status == STATUS_INFO_LENGTH_MISMATCH,
+       "Expected NtQueryInformationProcess to return STATUS_INFO_LENGTH_MISMATCH, got 0x%08x\n", status);
+
+    status = pNtQueryInformationProcess(GetCurrentProcess(),
+            ProcessDebugObjectHandle, &debug_object,
+            sizeof(debug_object) + 1, NULL);
+    ok(status == STATUS_INFO_LENGTH_MISMATCH,
+       "Expected NtQueryInformationProcess to return STATUS_INFO_LENGTH_MISMATCH, got 0x%08x\n", status);
+
+    debug_object = (HANDLE)0xdeadbeef;
+    status = pNtQueryInformationProcess(GetCurrentProcess(),
+            ProcessDebugObjectHandle, &debug_object,
+            sizeof(debug_object), NULL);
+    ok(status == STATUS_PORT_NOT_SET,
+       "Expected NtQueryInformationProcess to return STATUS_PORT_NOT_SET, got 0x%08x\n", status);
+    ok(debug_object == NULL ||
+       broken(debug_object == (HANDLE)0xdeadbeef), /* Wow64 */
+       "Expected debug object handle to be NULL, got %p\n", debug_object);
+
+    debug_object = (HANDLE)0xdeadbeef;
+    status = pNtQueryInformationProcess(pi.hProcess, ProcessDebugObjectHandle,
+            &debug_object, sizeof(debug_object), NULL);
+    todo_wine
+    ok(status == STATUS_SUCCESS,
+       "Expected NtQueryInformationProcess to return STATUS_SUCCESS, got 0x%08x\n", status);
+    todo_wine
+    ok(debug_object != NULL,
+       "Expected debug object handle to be non-NULL, got %p\n", debug_object);
+
+    for (;;)
+    {
+        DEBUG_EVENT ev;
+
+        ret = WaitForDebugEvent(&ev, INFINITE);
+        ok(ret, "WaitForDebugEvent failed with last error %u\n", GetLastError());
+        if (!ret) break;
+
+        if (ev.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT) break;
+
+        ret = ContinueDebugEvent(ev.dwProcessId, ev.dwThreadId, DBG_CONTINUE);
+        ok(ret, "ContinueDebugEvent failed with last error %u\n", GetLastError());
+        if (!ret) break;
+    }
+
+    ret = CloseHandle(pi.hThread);
+    ok(ret, "CloseHandle failed with last error %u\n", GetLastError());
+    ret = CloseHandle(pi.hProcess);
+    ok(ret, "CloseHandle failed with last error %u\n", GetLastError());
+}
 
 static void test_readvirtualmemory(void)
 {
@@ -1202,10 +1298,14 @@ START_TEST(info)
     trace("Starting test_query_process_handlecount()\n");
     test_query_process_handlecount();
 
-    /* 27 ProcessImageFileName */
+    /* 0x1B ProcessImageFileName */
     trace("Starting test_query_process_image_file_name()\n");
     test_query_process_image_file_name();
 
+    /* 0x1E ProcessDebugObjectHandle */
+    trace("Starting test_query_process_debug_object_handle()\n");
+    test_query_process_debug_object_handle(argc, argv);
+
     /* belongs into it's own file */
     trace("Starting test_readvirtualmemory()\n");
     test_readvirtualmemory();




More information about the wine-cvs mailing list