ntdll: Improve support for the ProcessDebugPort info class in NtQueryInformationProce...
authorHenri Verbeet <hverbeet@codeweavers.com>
Sun, 14 Mar 2010 20:53:27 +0000 (21:53 +0100)
committerAlexandre Julliard <julliard@winehq.org>
Mon, 15 Mar 2010 14:56:42 +0000 (15:56 +0100)
dlls/ntdll/process.c
dlls/ntdll/tests/info.c
include/wine/server_protocol.h
server/process.c
server/protocol.def
server/request.h
server/trace.c

index 9be133910d0bf1de54ce89050e56195e2908931f..6fdceae498aba93fd23c9c95a665a05fdca0808e 100644 (file)
@@ -295,7 +295,24 @@ NTSTATUS WINAPI NtQueryInformationProcess(
          * set it to 0 aka "no debugger" to satisfy copy protections */
         len = sizeof(DWORD_PTR);
         if (ProcessInformationLength == len)
-            memset(ProcessInformation, 0, ProcessInformationLength);
+        {
+            if (!ProcessInformation)
+                ret = STATUS_ACCESS_VIOLATION;
+            else if (!ProcessHandle)
+                ret = STATUS_INVALID_HANDLE;
+            else
+            {
+                SERVER_START_REQ(get_process_info)
+                {
+                    req->handle = wine_server_obj_handle( ProcessHandle );
+                    if ((ret = wine_server_call( req )) == STATUS_SUCCESS)
+                    {
+                        *(DWORD_PTR *)ProcessInformation = reply->debugger_present ? ~(DWORD_PTR)0 : 0;
+                    }
+                }
+                SERVER_END_REQ;
+            }
+        }
         else
             ret = STATUS_INFO_LENGTH_MISMATCH;
         break;
index c7d451c70b3c09407c06580bfdc3a19f9d2b666f..a8e19f929e67ebcd88e2c369268f9e80f51e17f2 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "ntdll_test.h"
 #include <winnls.h>
+#include <stdio.h>
 
 static NTSTATUS (WINAPI * pNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG);
 static NTSTATUS (WINAPI * pNtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);
@@ -751,6 +752,78 @@ static void test_query_process_times(void)
         "Inconsistent length %d\n", ReturnLength);
 }
 
+static void test_query_process_debug_port(int argc, char **argv)
+{
+    DWORD_PTR debug_port = 0xdeadbeef;
+    char cmdline[MAX_PATH];
+    PROCESS_INFORMATION pi;
+    STARTUPINFO si = { 0 };
+    NTSTATUS status;
+    BOOL ret;
+
+    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, last error %#x.\n", GetLastError());
+    if (!ret) return;
+
+    status = pNtQueryInformationProcess(NULL, ProcessDebugPort,
+            NULL, 0, NULL);
+    ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
+
+    status = pNtQueryInformationProcess(NULL, ProcessDebugPort,
+            NULL, sizeof(debug_port), NULL);
+    ok(status == STATUS_INVALID_HANDLE || status == STATUS_ACCESS_VIOLATION,
+            "Expected STATUS_INVALID_HANDLE, got %#x.\n", status);
+
+    status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
+            NULL, sizeof(debug_port), NULL);
+    ok(status == STATUS_ACCESS_VIOLATION, "Expected STATUS_ACCESS_VIOLATION, got %#x.\n", status);
+
+    status = pNtQueryInformationProcess(NULL, ProcessDebugPort,
+            &debug_port, sizeof(debug_port), NULL);
+    ok(status == STATUS_INVALID_HANDLE, "Expected STATUS_ACCESS_VIOLATION, got %#x.\n", status);
+
+    status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
+            &debug_port, sizeof(debug_port) - 1, NULL);
+    ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
+
+    status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
+            &debug_port, sizeof(debug_port) + 1, NULL);
+    ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %#x.\n", status);
+
+    status = pNtQueryInformationProcess(GetCurrentProcess(), ProcessDebugPort,
+            &debug_port, sizeof(debug_port), NULL);
+    ok(!status, "NtQueryInformationProcess failed, status %#x.\n", status);
+    ok(debug_port == 0, "Expected port 0, got %#lx.\n", debug_port);
+
+    status = pNtQueryInformationProcess(pi.hProcess, ProcessDebugPort,
+            &debug_port, sizeof(debug_port), NULL);
+    ok(!status, "NtQueryInformationProcess failed, status %#x.\n", status);
+    ok(debug_port == ~(DWORD_PTR)0, "Expected port %#lx, got %#lx.\n", ~(DWORD_PTR)0, debug_port);
+
+    for (;;)
+    {
+        DEBUG_EVENT ev;
+
+        ret = WaitForDebugEvent(&ev, INFINITE);
+        ok(ret, "WaitForDebugEvent failed, last error %#x.\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, last error %#x.\n", GetLastError());
+        if (!ret) break;
+    }
+
+    ret = CloseHandle(pi.hThread);
+    ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
+    ret = CloseHandle(pi.hProcess);
+    ok(ret, "CloseHandle failed, last error %#x.\n", GetLastError());
+}
+
 static void test_query_process_handlecount(void)
 {
     NTSTATUS status;
@@ -978,9 +1051,15 @@ static void test_affinity(void)
 
 START_TEST(info)
 {
+    char **argv;
+    int argc;
+
     if(!InitFunctionPtrs())
         return;
 
+    argc = winetest_get_mainargs(&argv);
+    if (argc >= 3) return; /* Child */
+
     /* NtQuerySystemInformation */
 
     /* 0x0 SystemBasicInformation */
@@ -1049,6 +1128,10 @@ START_TEST(info)
     trace("Starting test_query_process_times()\n");
     test_query_process_times();
 
+    /* 0x7 ProcessDebugPort */
+    trace("Starting test_process_debug_port()\n");
+    test_query_process_debug_port(argc, argv);
+
     /* 0x14 ProcessHandleCount */
     trace("Starting test_query_process_handlecount()\n");
     test_query_process_handlecount();
index 47c032e728e8917c47a57483b56dd72a694e5f9d..0c3155ddf9e045935a542c1e021177323f552c12 100644 (file)
@@ -725,7 +725,7 @@ struct get_process_info_reply
     int          exit_code;
     int          priority;
     cpu_type_t   cpu;
-    char __pad_60[4];
+    int          debugger_present;
 };
 
 
@@ -5397,6 +5397,6 @@ union generic_reply
     struct free_user_handle_reply free_user_handle_reply;
 };
 
-#define SERVER_PROTOCOL_VERSION 395
+#define SERVER_PROTOCOL_VERSION 396
 
 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */
index e4dca68cb5bb0f84f08f76c2a9e531c98bdedf91..36e462ab2c060c7bd29e562db0c876578e5bfbf2 100644 (file)
@@ -1091,6 +1091,7 @@ DECL_HANDLER(get_process_info)
         reply->start_time       = process->start_time;
         reply->end_time         = process->end_time;
         reply->cpu              = process->cpu;
+        reply->debugger_present = !!process->debugger;
         release_object( process );
     }
 }
index 04f6e2ba8913587035c75cfaa2d4ffddbeb9d64b..e9c5cba18097f0c27cc2bb4c33fa029e58adedd3 100644 (file)
@@ -692,6 +692,7 @@ typedef union
     int          exit_code;        /* process exit code */
     int          priority;         /* priority class */
     cpu_type_t   cpu;              /* CPU that this process is running on */
+    int          debugger_present; /* process is being debugged */
 @END
 
 
index 41c64091eb88077b85d901f9d2538c264a13a958..11382d8f7f05bcbedd0be4e93b40f3400eaf1bfa 100644 (file)
@@ -697,6 +697,7 @@ C_ASSERT( FIELD_OFFSET(struct get_process_info_reply, end_time) == 40 );
 C_ASSERT( FIELD_OFFSET(struct get_process_info_reply, exit_code) == 48 );
 C_ASSERT( FIELD_OFFSET(struct get_process_info_reply, priority) == 52 );
 C_ASSERT( FIELD_OFFSET(struct get_process_info_reply, cpu) == 56 );
+C_ASSERT( FIELD_OFFSET(struct get_process_info_reply, debugger_present) == 60 );
 C_ASSERT( sizeof(struct get_process_info_reply) == 64 );
 C_ASSERT( FIELD_OFFSET(struct set_process_info_request, handle) == 12 );
 C_ASSERT( FIELD_OFFSET(struct set_process_info_request, mask) == 16 );
index a250a2e866a831fc0d48bedefce3ddbfbb653eb5..4b13ed57a84351ba53a8569b5f2c26852ffb1b86 100644 (file)
@@ -1118,6 +1118,7 @@ static void dump_get_process_info_reply( const struct get_process_info_reply *re
     fprintf( stderr, ", exit_code=%d", req->exit_code );
     fprintf( stderr, ", priority=%d", req->priority );
     dump_cpu_type( ", cpu=", &req->cpu );
+    fprintf( stderr, ", debugger_present=%d", req->debugger_present );
 }
 
 static void dump_set_process_info_request( const struct set_process_info_request *req )