Commit f0a50452 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

ntdll: Improve support for the ProcessDebugPort info class in NtQueryInformationProcess().

parent 4ce43cd9
......@@ -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;
......
......@@ -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();
......
......@@ -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 */
......@@ -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 );
}
}
......
......@@ -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
......
......@@ -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 );
......
......@@ -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 )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment