[PATCH 2/2] kernel32/tests: Tests for ProcessCookie in NtQueryInformationProcess.

Alistair Leslie-Hughes leslie_alistair at hotmail.com
Fri Sep 14 00:21:31 CDT 2018


From: Andrew Wesie <awesie at gmail.com>

Querying for ProcessCookie must be called in the current process for
it to return a valid value.

Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
---
 dlls/kernel32/tests/process.c | 246 ++++++++++++++++++++++++++++--------------
 1 file changed, 166 insertions(+), 80 deletions(-)

diff --git a/dlls/kernel32/tests/process.c b/dlls/kernel32/tests/process.c
index 0eb113b..696ef7b 100644
--- a/dlls/kernel32/tests/process.c
+++ b/dlls/kernel32/tests/process.c
@@ -3461,86 +3461,88 @@ static void test_session_info(void)
     trace("active_session = %x\n", active_session);
 }
 
-static void test_process_info(void)
-{
-    char buf[4096];
-    static const ULONG info_size[] =
-    {
-        sizeof(PROCESS_BASIC_INFORMATION) /* ProcessBasicInformation */,
-        sizeof(QUOTA_LIMITS) /* ProcessQuotaLimits */,
-        sizeof(IO_COUNTERS) /* ProcessIoCounters */,
-        sizeof(VM_COUNTERS) /* ProcessVmCounters */,
-        sizeof(KERNEL_USER_TIMES) /* ProcessTimes */,
-        sizeof(ULONG) /* ProcessBasePriority */,
-        sizeof(ULONG) /* ProcessRaisePriority */,
-        sizeof(HANDLE) /* ProcessDebugPort */,
-        sizeof(HANDLE) /* ProcessExceptionPort */,
-        0 /* FIXME: sizeof(PROCESS_ACCESS_TOKEN) ProcessAccessToken */,
-        0 /* FIXME: sizeof(PROCESS_LDT_INFORMATION) ProcessLdtInformation */,
-        0 /* FIXME: sizeof(PROCESS_LDT_SIZE) ProcessLdtSize */,
-        sizeof(ULONG) /* ProcessDefaultHardErrorMode */,
-        0 /* ProcessIoPortHandlers: kernel-mode only */,
-        0 /* FIXME: sizeof(POOLED_USAGE_AND_LIMITS) ProcessPooledUsageAndLimits */,
-        0 /* FIXME: sizeof(PROCESS_WS_WATCH_INFORMATION) ProcessWorkingSetWatch */,
-        sizeof(ULONG) /* ProcessUserModeIOPL */,
-        sizeof(BOOLEAN) /* ProcessEnableAlignmentFaultFixup */,
-        sizeof(PROCESS_PRIORITY_CLASS) /* ProcessPriorityClass */,
-        sizeof(ULONG) /* ProcessWx86Information */,
-        sizeof(ULONG) /* ProcessHandleCount */,
-        sizeof(ULONG_PTR) /* ProcessAffinityMask */,
-        sizeof(ULONG) /* ProcessPriorityBoost */,
-        0 /* sizeof(PROCESS_DEVICEMAP_INFORMATION) ProcessDeviceMap */,
-        0 /* sizeof(PROCESS_SESSION_INFORMATION) ProcessSessionInformation */,
-        0 /* sizeof(PROCESS_FOREGROUND_BACKGROUND) ProcessForegroundInformation */,
-        sizeof(ULONG_PTR) /* ProcessWow64Information */,
-        sizeof(buf) /* ProcessImageFileName */,
-        sizeof(ULONG) /* ProcessLUIDDeviceMapsEnabled */,
-        sizeof(ULONG) /* ProcessBreakOnTermination */,
-        sizeof(HANDLE) /* ProcessDebugObjectHandle */,
-        sizeof(ULONG) /* ProcessDebugFlags */,
-        sizeof(buf) /* ProcessHandleTracing */,
-        sizeof(ULONG) /* ProcessIoPriority */,
-        sizeof(ULONG) /* ProcessExecuteFlags */,
-        0 /* FIXME: sizeof(?) ProcessTlsInformation */,
-        0 /* FIXME: sizeof(?) ProcessCookie */,
-        sizeof(SECTION_IMAGE_INFORMATION) /* ProcessImageInformation */,
-        0 /* FIXME: sizeof(PROCESS_CYCLE_TIME_INFORMATION) ProcessCycleTime */,
-        sizeof(ULONG) /* ProcessPagePriority */,
-        40 /* ProcessInstrumentationCallback */,
-        0 /* FIXME: sizeof(PROCESS_STACK_ALLOCATION_INFORMATION) ProcessThreadStackAllocation */,
-        0 /* FIXME: sizeof(PROCESS_WS_WATCH_INFORMATION_EX[]) ProcessWorkingSetWatchEx */,
-        sizeof(buf) /* ProcessImageFileNameWin32 */,
+#define BUFFER_SIZE 4096
+static const ULONG info_size[] =
+{
+    sizeof(PROCESS_BASIC_INFORMATION) /* ProcessBasicInformation */,
+    sizeof(QUOTA_LIMITS) /* ProcessQuotaLimits */,
+    sizeof(IO_COUNTERS) /* ProcessIoCounters */,
+    sizeof(VM_COUNTERS) /* ProcessVmCounters */,
+    sizeof(KERNEL_USER_TIMES) /* ProcessTimes */,
+    sizeof(ULONG) /* ProcessBasePriority */,
+    sizeof(ULONG) /* ProcessRaisePriority */,
+    sizeof(HANDLE) /* ProcessDebugPort */,
+    sizeof(HANDLE) /* ProcessExceptionPort */,
+    0 /* FIXME: sizeof(PROCESS_ACCESS_TOKEN) ProcessAccessToken */,
+    0 /* FIXME: sizeof(PROCESS_LDT_INFORMATION) ProcessLdtInformation */,
+    0 /* FIXME: sizeof(PROCESS_LDT_SIZE) ProcessLdtSize */,
+    sizeof(ULONG) /* ProcessDefaultHardErrorMode */,
+    0 /* ProcessIoPortHandlers: kernel-mode only */,
+    0 /* FIXME: sizeof(POOLED_USAGE_AND_LIMITS) ProcessPooledUsageAndLimits */,
+    0 /* FIXME: sizeof(PROCESS_WS_WATCH_INFORMATION) ProcessWorkingSetWatch */,
+    sizeof(ULONG) /* ProcessUserModeIOPL */,
+    sizeof(BOOLEAN) /* ProcessEnableAlignmentFaultFixup */,
+    sizeof(PROCESS_PRIORITY_CLASS) /* ProcessPriorityClass */,
+    sizeof(ULONG) /* ProcessWx86Information */,
+    sizeof(ULONG) /* ProcessHandleCount */,
+    sizeof(ULONG_PTR) /* ProcessAffinityMask */,
+    sizeof(ULONG) /* ProcessPriorityBoost */,
+    0 /* sizeof(PROCESS_DEVICEMAP_INFORMATION) ProcessDeviceMap */,
+    0 /* sizeof(PROCESS_SESSION_INFORMATION) ProcessSessionInformation */,
+    0 /* sizeof(PROCESS_FOREGROUND_BACKGROUND) ProcessForegroundInformation */,
+    sizeof(ULONG_PTR) /* ProcessWow64Information */,
+    BUFFER_SIZE /* ProcessImageFileName */,
+    sizeof(ULONG) /* ProcessLUIDDeviceMapsEnabled */,
+    sizeof(ULONG) /* ProcessBreakOnTermination */,
+    sizeof(HANDLE) /* ProcessDebugObjectHandle */,
+    sizeof(ULONG) /* ProcessDebugFlags */,
+    BUFFER_SIZE /* ProcessHandleTracing */,
+    sizeof(ULONG) /* ProcessIoPriority */,
+    sizeof(ULONG) /* ProcessExecuteFlags */,
+    0 /* FIXME: sizeof(?) ProcessTlsInformation */,
+    sizeof(ULONG) /* ProcessCookie */,
+    sizeof(SECTION_IMAGE_INFORMATION) /* ProcessImageInformation */,
+    0 /* FIXME: sizeof(PROCESS_CYCLE_TIME_INFORMATION) ProcessCycleTime */,
+    sizeof(ULONG) /* ProcessPagePriority */,
+    40 /* ProcessInstrumentationCallback */,
+    0 /* FIXME: sizeof(PROCESS_STACK_ALLOCATION_INFORMATION) ProcessThreadStackAllocation */,
+    0 /* FIXME: sizeof(PROCESS_WS_WATCH_INFORMATION_EX[]) ProcessWorkingSetWatchEx */,
+    BUFFER_SIZE /* ProcessImageFileNameWin32 */,
 #if 0 /* FIXME: Add remaining classes */
-        sizeof(HANDLE) /* ProcessImageFileMapping */,
-        sizeof(PROCESS_AFFINITY_UPDATE_MODE) /* ProcessAffinityUpdateMode */,
-        sizeof(PROCESS_MEMORY_ALLOCATION_MODE) /* ProcessMemoryAllocationMode */,
-        sizeof(USHORT[]) /* ProcessGroupInformation */,
-        sizeof(ULONG) /* ProcessTokenVirtualizationEnabled */,
-        sizeof(ULONG_PTR) /* ProcessConsoleHostProcess */,
-        sizeof(PROCESS_WINDOW_INFORMATION) /* ProcessWindowInformation */,
-        sizeof(PROCESS_HANDLE_SNAPSHOT_INFORMATION) /* ProcessHandleInformation */,
-        sizeof(PROCESS_MITIGATION_POLICY_INFORMATION) /* ProcessMitigationPolicy */,
-        sizeof(ProcessDynamicFunctionTableInformation) /* ProcessDynamicFunctionTableInformation */,
-        sizeof(?) /* ProcessHandleCheckingMode */,
-        sizeof(PROCESS_KEEPALIVE_COUNT_INFORMATION) /* ProcessKeepAliveCount */,
-        sizeof(PROCESS_REVOKE_FILE_HANDLES_INFORMATION) /* ProcessRevokeFileHandles */,
-        sizeof(PROCESS_WORKING_SET_CONTROL) /* ProcessWorkingSetControl */,
-        sizeof(?) /* ProcessHandleTable */,
-        sizeof(?) /* ProcessCheckStackExtentsMode */,
-        sizeof(buf) /* ProcessCommandLineInformation */,
-        sizeof(PS_PROTECTION) /* ProcessProtectionInformation */,
-        sizeof(PROCESS_MEMORY_EXHAUSTION_INFO) /* ProcessMemoryExhaustion */,
-        sizeof(PROCESS_FAULT_INFORMATION) /* ProcessFaultInformation */,
-        sizeof(PROCESS_TELEMETRY_ID_INFORMATION) /* ProcessTelemetryIdInformation */,
-        sizeof(PROCESS_COMMIT_RELEASE_INFORMATION) /* ProcessCommitReleaseInformation */,
-        sizeof(?) /* ProcessDefaultCpuSetsInformation */,
-        sizeof(?) /* ProcessAllowedCpuSetsInformation */,
-        0 /* ProcessReserved1Information */,
-        0 /* ProcessReserved2Information */,
-        sizeof(?) /* ProcessSubsystemProcess */,
-        sizeof(PROCESS_JOB_MEMORY_INFO) /* ProcessJobMemoryInformation */,
+    sizeof(HANDLE) /* ProcessImageFileMapping */,
+    sizeof(PROCESS_AFFINITY_UPDATE_MODE) /* ProcessAffinityUpdateMode */,
+    sizeof(PROCESS_MEMORY_ALLOCATION_MODE) /* ProcessMemoryAllocationMode */,
+    sizeof(USHORT[]) /* ProcessGroupInformation */,
+    sizeof(ULONG) /* ProcessTokenVirtualizationEnabled */,
+    sizeof(ULONG_PTR) /* ProcessConsoleHostProcess */,
+    sizeof(PROCESS_WINDOW_INFORMATION) /* ProcessWindowInformation */,
+    sizeof(PROCESS_HANDLE_SNAPSHOT_INFORMATION) /* ProcessHandleInformation */,
+    sizeof(PROCESS_MITIGATION_POLICY_INFORMATION) /* ProcessMitigationPolicy */,
+    sizeof(ProcessDynamicFunctionTableInformation) /* ProcessDynamicFunctionTableInformation */,
+    sizeof(?) /* ProcessHandleCheckingMode */,
+    sizeof(PROCESS_KEEPALIVE_COUNT_INFORMATION) /* ProcessKeepAliveCount */,
+    sizeof(PROCESS_REVOKE_FILE_HANDLES_INFORMATION) /* ProcessRevokeFileHandles */,
+    sizeof(PROCESS_WORKING_SET_CONTROL) /* ProcessWorkingSetControl */,
+    sizeof(?) /* ProcessHandleTable */,
+    sizeof(?) /* ProcessCheckStackExtentsMode */,
+    sizeof(buf) /* ProcessCommandLineInformation */,
+    sizeof(PS_PROTECTION) /* ProcessProtectionInformation */,
+    sizeof(PROCESS_MEMORY_EXHAUSTION_INFO) /* ProcessMemoryExhaustion */,
+    sizeof(PROCESS_FAULT_INFORMATION) /* ProcessFaultInformation */,
+    sizeof(PROCESS_TELEMETRY_ID_INFORMATION) /* ProcessTelemetryIdInformation */,
+    sizeof(PROCESS_COMMIT_RELEASE_INFORMATION) /* ProcessCommitReleaseInformation */,
+    sizeof(?) /* ProcessDefaultCpuSetsInformation */,
+    sizeof(?) /* ProcessAllowedCpuSetsInformation */,
+    0 /* ProcessReserved1Information */,
+    0 /* ProcessReserved2Information */,
+    sizeof(?) /* ProcessSubsystemProcess */,
+    sizeof(PROCESS_JOB_MEMORY_INFO) /* ProcessJobMemoryInformation */,
 #endif
-    };
+};
+
+static void test_process_info(void)
+{
+    char buf[BUFFER_SIZE];
     HANDLE hproc;
     ULONG i, status, ret_len, size;
 
@@ -3598,11 +3600,13 @@ static void test_process_info(void)
             ok(status == STATUS_ACCESS_DENIED || status == STATUS_PORT_NOT_SET,
                "for info %u expected STATUS_ACCESS_DENIED, got %08x (ret_len %u)\n", i, status, ret_len);
             break;
-
+        case ProcessCookie:
+            ok(status == STATUS_INVALID_PARAMETER /* before win8 */ || status == STATUS_ACCESS_DENIED,
+               "for info %u got %08x (ret_len %u)\n", i, status, ret_len);
+            break;
         case ProcessExecuteFlags:
         case ProcessDebugPort:
         case ProcessDebugFlags:
-        case ProcessCookie:
 todo_wine
             ok(status == STATUS_ACCESS_DENIED, "for info %u expected STATUS_ACCESS_DENIED, got %08x (ret_len %u)\n", i, status, ret_len);
             break;
@@ -3616,6 +3620,87 @@ todo_wine
     CloseHandle(hproc);
 }
 
+static void test_process_info_current(void)
+{
+    char buf[BUFFER_SIZE];
+    HANDLE hproc;
+    ULONG i, status, ret_len, size;
+
+    if (!pNtQueryInformationProcess)
+    {
+        win_skip("NtQueryInformationProcess is not available on this platform\n");
+        return;
+    }
+
+    hproc = GetCurrentProcess();
+    if (!hproc)
+    {
+        win_skip("PROCESS_QUERY_LIMITED_INFORMATION is not supported on this platform\n");
+        return;
+    }
+
+    for (i = 0; i < MaxProcessInfoClass; i++)
+    {
+        size = info_size[i];
+        if (!size) size = sizeof(buf);
+        ret_len = 0;
+        status = pNtQueryInformationProcess(hproc, i, buf, info_size[i], &ret_len);
+        if (status == STATUS_NOT_IMPLEMENTED) continue;
+        if (status == STATUS_INVALID_INFO_CLASS) continue;
+        if (status == STATUS_INFO_LENGTH_MISMATCH) continue;
+
+        switch (i)
+        {
+        case ProcessBasicInformation:
+        case ProcessQuotaLimits:
+        case ProcessTimes:
+        case ProcessPriorityClass:
+        case ProcessPriorityBoost:
+        case ProcessLUIDDeviceMapsEnabled:
+        case 33 /* ProcessIoPriority */:
+        case ProcessIoCounters:
+        case ProcessVmCounters:
+        case ProcessWow64Information:
+        case ProcessDefaultHardErrorMode:
+        case ProcessHandleCount:
+        case ProcessImageFileName:
+        case ProcessImageInformation:
+        case ProcessPagePriority:
+        case ProcessImageFileNameWin32:
+            ok(status == STATUS_SUCCESS, "for info %u expected STATUS_SUCCESS, got %08x (ret_len %u)\n", i, status, ret_len);
+            break;
+
+        case ProcessAffinityMask:
+        case ProcessBreakOnTermination:
+            ok(status == STATUS_ACCESS_DENIED /* before win8 */ || status == STATUS_SUCCESS /* win8 is less strict */,
+               "for info %u expected STATUS_SUCCESS, got %08x (ret_len %u)\n", i, status, ret_len);
+            break;
+
+        case ProcessDebugObjectHandle:
+            ok(status == STATUS_ACCESS_DENIED || status == STATUS_PORT_NOT_SET,
+               "for info %u expected STATUS_ACCESS_DENIED, got %08x (ret_len %u)\n", i, status, ret_len);
+            break;
+        case ProcessCookie:
+            ok(status == STATUS_SUCCESS || status == STATUS_INVALID_PARAMETER /* before win8 */,
+               "for info %u got %08x (ret_len %u)\n", i, status, ret_len);
+            break;
+        case ProcessExecuteFlags:
+        case ProcessDebugPort:
+        case ProcessDebugFlags:
+            ok(status == STATUS_SUCCESS || status == STATUS_INVALID_PARAMETER,
+                "for info %u, got %08x (ret_len %u)\n", i, status, ret_len);
+            break;
+
+        default:
+            ok(status == STATUS_SUCCESS || status == STATUS_UNSUCCESSFUL || status == STATUS_INVALID_PARAMETER,
+                "for info %u, got %08x (ret_len %u)\n", i, status, ret_len);
+            break;
+        }
+    }
+
+    CloseHandle(hproc);
+}
+
 static void test_GetLogicalProcessorInformationEx(void)
 {
     SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *info;
@@ -3825,6 +3910,7 @@ START_TEST(process)
     }
 
     test_process_info();
+    test_process_info_current();
     test_TerminateProcess();
     test_Startup();
     test_CommandLine();
-- 
1.9.1




More information about the wine-devel mailing list