Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725/* * PROJECT: ReactOS API tests * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory * PURPOSE: Tests for the NtQueryInformationProcess API * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org> * George Bișoc <george.bisoc@reactos.org> */
#include "precomp.h"#include <internal/ps_i.h>
static LARGE_INTEGER TestStartTime;
staticvoidTest_ProcessTimes(void){#define SPIN_TIME 1000000 NTSTATUS Status; KERNEL_USER_TIMES Times1; KERNEL_USER_TIMES Times2; ULONG Length; LARGE_INTEGER Time1, Time2;
/* Everything is NULL */ Status = NtQueryInformationProcess(NULL, ProcessTimes, NULL, 0, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Right size, invalid process */ Status = NtQueryInformationProcess(NULL, ProcessTimes, NULL, sizeof(KERNEL_USER_TIMES), NULL); ok_hex(Status, STATUS_INVALID_HANDLE);
/* Valid process, no buffer */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessTimes, NULL, 0, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Unaligned buffer, wrong size */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessTimes, (PVOID)2, 0, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Unaligned buffer, correct size */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessTimes, (PVOID)2, sizeof(KERNEL_USER_TIMES), NULL); ok_hex(Status, STATUS_DATATYPE_MISALIGNMENT);
/* Buffer too small */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessTimes, NULL, sizeof(KERNEL_USER_TIMES) - 1, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Right buffer size but NULL pointer */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessTimes, NULL, sizeof(KERNEL_USER_TIMES), NULL); ok_hex(Status, STATUS_ACCESS_VIOLATION);
/* Buffer too large */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessTimes, NULL, sizeof(KERNEL_USER_TIMES) + 1, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Buffer too small, ask for length */ Length = 0x55555555; Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessTimes, NULL, sizeof(KERNEL_USER_TIMES) - 1, &Length); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH); ok_dec(Length, 0x55555555);
Status = NtQuerySystemTime(&Time1); ok_hex(Status, STATUS_SUCCESS);
/* Do some busy waiting to increase UserTime */ do { Status = NtQuerySystemTime(&Time2); if (!NT_SUCCESS(Status)) { ok(0, "NtQuerySystemTime failed with %lx\n", Status); break; } } while (Time2.QuadPart - Time1.QuadPart < SPIN_TIME);
/* Valid parameters, no return length */ Status = NtQuerySystemTime(&Time1); ok_hex(Status, STATUS_SUCCESS);
RtlFillMemory(&Times1, sizeof(Times1), 0x55); Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessTimes, &Times1, sizeof(KERNEL_USER_TIMES), NULL); ok_hex(Status, STATUS_SUCCESS); ok(Times1.CreateTime.QuadPart < TestStartTime.QuadPart, "CreateTime is %I64u, expected < %I64u\n", Times1.CreateTime.QuadPart, TestStartTime.QuadPart); ok(Times1.CreateTime.QuadPart > TestStartTime.QuadPart - 100000000LL, "CreateTime is %I64u, expected > %I64u\n", Times1.CreateTime.QuadPart, TestStartTime.QuadPart - 100000000LL); ok(Times1.ExitTime.QuadPart == 0, "ExitTime is %I64u, expected 0\n", Times1.ExitTime.QuadPart); ok(Times1.KernelTime.QuadPart != 0, "KernelTime is 0\n"); ros_skip_flaky ok(Times1.UserTime.QuadPart != 0, "UserTime is 0\n");
/* Do some busy waiting to increase UserTime */ do { Status = NtQuerySystemTime(&Time2); if (!NT_SUCCESS(Status)) { ok(0, "NtQuerySystemTime failed with %lx\n", Status); break; } } while (Time2.QuadPart - Time1.QuadPart < SPIN_TIME);
/* Again, this time with a return length */ Length = 0x55555555; RtlFillMemory(&Times2, sizeof(Times2), 0x55); Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessTimes, &Times2, sizeof(KERNEL_USER_TIMES), &Length); ok_hex(Status, STATUS_SUCCESS); ok_dec(Length, sizeof(KERNEL_USER_TIMES)); ok(Times1.CreateTime.QuadPart == Times2.CreateTime.QuadPart, "CreateTimes not equal: %I64u != %I64u\n", Times1.CreateTime.QuadPart, Times2.CreateTime.QuadPart); ok(Times2.ExitTime.QuadPart == 0, "ExitTime is %I64u, expected 0\n", Times2.ExitTime.QuadPart); ok(Times2.KernelTime.QuadPart != 0, "KernelTime is 0\n"); ok(Times2.UserTime.QuadPart != 0, "UserTime is 0\n");
/* Compare the two sets of KernelTime/UserTime values */ Status = NtQuerySystemTime(&Time2); ok_hex(Status, STATUS_SUCCESS); /* Time values must have increased */ ok(Times2.KernelTime.QuadPart > Times1.KernelTime.QuadPart, "KernelTime values inconsistent. Expected %I64u > %I64u\n", Times2.KernelTime.QuadPart, Times1.KernelTime.QuadPart); ros_skip_flaky ok(Times2.UserTime.QuadPart > Times1.UserTime.QuadPart, "UserTime values inconsistent. Expected %I64u > %I64u\n", Times2.UserTime.QuadPart, Times1.UserTime.QuadPart); /* They can't have increased by more than wall clock time difference (we only have one thread) */ ros_skip_flaky ok(Times2.KernelTime.QuadPart - Times1.KernelTime.QuadPart < Time2.QuadPart - Time1.QuadPart, "KernelTime values inconsistent. Expected %I64u - %I64u < %I64u\n", Times2.KernelTime.QuadPart, Times1.KernelTime.QuadPart, Time2.QuadPart - Time1.QuadPart); ok(Times2.UserTime.QuadPart - Times1.UserTime.QuadPart < Time2.QuadPart - Time1.QuadPart, "UserTime values inconsistent. Expected %I64u - %I64u < %I64u\n", Times2.UserTime.QuadPart, Times1.UserTime.QuadPart, Time2.QuadPart - Time1.QuadPart);
trace("KernelTime1 = %I64u\n", Times1.KernelTime.QuadPart); trace("KernelTime2 = %I64u\n", Times2.KernelTime.QuadPart); trace("UserTime1 = %I64u\n", Times1.UserTime.QuadPart); trace("UserTime2 = %I64u\n", Times2.UserTime.QuadPart);
/* TODO: Test ExitTime on a terminated process */#undef SPIN_TIME}
staticvoidTest_ProcessBasicInformation(void){ NTSTATUS Status; ULONG Length; PROCESS_BASIC_INFORMATION BasicInfo;
/* Everything is NULL */ Status = NtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, 0, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Right size, invalid process handle */ Status = NtQueryInformationProcess(NULL, ProcessBasicInformation, NULL, sizeof(BasicInfo), NULL); ok_hex(Status, STATUS_INVALID_HANDLE);
/* Valid process handle, no buffer */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessBasicInformation, NULL, 0, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Unaligned buffer, wrong size */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessBasicInformation, (PVOID)2, 0, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Unaligned buffer, correct size */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessBasicInformation, (PVOID)2, sizeof(BasicInfo), NULL); ok_hex(Status, STATUS_DATATYPE_MISALIGNMENT);
/* Buffer too small */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessBasicInformation, NULL, sizeof(BasicInfo) - 1, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Right buffer size but NULL pointer */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessBasicInformation, NULL, sizeof(BasicInfo), NULL); ok_hex(Status, STATUS_ACCESS_VIOLATION);
/* Buffer too large */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessBasicInformation, NULL, sizeof(BasicInfo) + 1, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Buffer too small, ask for length */ Length = 0x55555555; Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessBasicInformation, NULL, sizeof(BasicInfo) - 1, &Length); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH); ok_dec(Length, 0x55555555);
/* Valid parameters, no return length */ RtlFillMemory(&BasicInfo, sizeof(BasicInfo), 0x55); Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessBasicInformation, &BasicInfo, sizeof(BasicInfo), NULL); ok_hex(Status, STATUS_SUCCESS);
/* Trace the returned data (1) */ trace("[1] BasicInfo.ExitStatus = %lx\n", BasicInfo.ExitStatus); trace("[1] BasicInfo.PebBaseAddress = %p\n", BasicInfo.PebBaseAddress); trace("[1] BasicInfo.AffinityMask = %Ix\n", BasicInfo.AffinityMask); trace("[1] BasicInfo.BasePriority = %ld\n", BasicInfo.BasePriority); trace("[1] BasicInfo.UniqueProcessId = %Iu\n", BasicInfo.UniqueProcessId); trace("[1] BasicInfo.InheritedFromUniqueProcessId = %Iu\n", BasicInfo.InheritedFromUniqueProcessId);
/* Again, this time with a return length */ Length = 0x55555555; RtlFillMemory(&BasicInfo, sizeof(BasicInfo), 0x55); Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessBasicInformation, &BasicInfo, sizeof(BasicInfo), &Length); ok_hex(Status, STATUS_SUCCESS); ok_dec(Length, sizeof(BasicInfo));
/* Trace the returned data (2) */ trace("[2] BasicInfo.ExitStatus = %lx\n", BasicInfo.ExitStatus); trace("[2] BasicInfo.PebBaseAddress = %p\n", BasicInfo.PebBaseAddress); trace("[2] BasicInfo.AffinityMask = %Ix\n", BasicInfo.AffinityMask); trace("[2] BasicInfo.BasePriority = %ld\n", BasicInfo.BasePriority); trace("[2] BasicInfo.UniqueProcessId = %Iu\n", BasicInfo.UniqueProcessId); trace("[2] BasicInfo.InheritedFromUniqueProcessId = %Iu\n", BasicInfo.InheritedFromUniqueProcessId);}
staticvoidTest_ProcessQuotaLimits(void){ NTSTATUS Status; ULONG Length; QUOTA_LIMITS QuotaLimits;
/* Everything is NULL */ Status = NtQueryInformationProcess(NULL, ProcessQuotaLimits, NULL, 0, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Right size, invalid process handle */ Status = NtQueryInformationProcess(NULL, ProcessQuotaLimits, NULL, sizeof(QuotaLimits), NULL); ok_hex(Status, STATUS_INVALID_HANDLE);
/* Valid process handle, no buffer */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, NULL, 0, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Unaligned buffer, wrong size */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, (PVOID)2, 0, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Unaligned buffer, correct size */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, (PVOID)2, sizeof(QuotaLimits), NULL); ok_hex(Status, STATUS_DATATYPE_MISALIGNMENT);
/* Buffer too small */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, NULL, sizeof(QuotaLimits) - 1, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Right buffer size but NULL pointer */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, NULL, sizeof(QuotaLimits), NULL); ok_hex(Status, STATUS_ACCESS_VIOLATION);
/* Buffer too large */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, NULL, sizeof(QuotaLimits) + 1, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Buffer too small, ask for length */ Length = 0x55555555; Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, NULL, sizeof(QuotaLimits) - 1, &Length); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH); ok_dec(Length, 0x55555555);
/* Valid parameters, no return length */ RtlFillMemory(&QuotaLimits, sizeof(QuotaLimits), 0x55); Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, &QuotaLimits, sizeof(QuotaLimits), NULL); ok_hex(Status, STATUS_SUCCESS);
/* Trace the returned data (1) */ trace("[1] QuotaLimits.PagedPoolLimit = %Iu\n", QuotaLimits.PagedPoolLimit); trace("[1] QuotaLimits.NonPagedPoolLimit = %Iu\n", QuotaLimits.NonPagedPoolLimit); trace("[1] QuotaLimits.MinimumWorkingSetSize = %Iu\n", QuotaLimits.MinimumWorkingSetSize); trace("[1] QuotaLimits.MaximumWorkingSetSize = %Iu\n", QuotaLimits.MaximumWorkingSetSize); trace("[1] QuotaLimits.PagefileLimit = %Iu\n", QuotaLimits.PagefileLimit); trace("[1] QuotaLimits.TimeLimit = %I64d\n", QuotaLimits.TimeLimit.QuadPart);
/* Again, this time with a return length */ Length = 0x55555555; RtlFillMemory(&QuotaLimits, sizeof(QuotaLimits), 0x55); Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, &QuotaLimits, sizeof(QuotaLimits), &Length); ok_hex(Status, STATUS_SUCCESS); ok_dec(Length, sizeof(QuotaLimits));
/* Trace the returned data (2) */ trace("[2] QuotaLimits.PagedPoolLimit = %Iu\n", QuotaLimits.PagedPoolLimit); trace("[2] QuotaLimits.NonPagedPoolLimit = %Iu\n", QuotaLimits.NonPagedPoolLimit); trace("[2] QuotaLimits.MinimumWorkingSetSize = %Iu\n", QuotaLimits.MinimumWorkingSetSize); trace("[2] QuotaLimits.MaximumWorkingSetSize = %Iu\n", QuotaLimits.MaximumWorkingSetSize); trace("[2] QuotaLimits.PagefileLimit = %Iu\n", QuotaLimits.PagefileLimit); trace("[2] QuotaLimits.TimeLimit = %I64d\n", QuotaLimits.TimeLimit.QuadPart);}
staticvoidTest_ProcessQuotaLimitsEx(void){ NTSTATUS Status; ULONG Length; QUOTA_LIMITS_EX QuotaLimitsEx;
/* Right size, invalid process handle */ Status = NtQueryInformationProcess(NULL, ProcessQuotaLimits, NULL, sizeof(QuotaLimitsEx), NULL); ok_hex(Status, STATUS_INVALID_HANDLE);
/* Unaligned buffer, correct size */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, (PVOID)2, sizeof(QuotaLimitsEx), NULL); ok_hex(Status, STATUS_DATATYPE_MISALIGNMENT);
/* Buffer too small */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, NULL, sizeof(QuotaLimitsEx) - 1, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Right buffer size but NULL pointer */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, NULL, sizeof(QuotaLimitsEx), NULL); ok_hex(Status, STATUS_ACCESS_VIOLATION);
/* Buffer too large */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, NULL, sizeof(QuotaLimitsEx) + 1, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Buffer too small, ask for length */ Length = 0x55555555; Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, NULL, sizeof(QuotaLimitsEx) - 1, &Length); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH); ok_dec(Length, 0x55555555);
/* Valid parameters, no return length */ RtlFillMemory(&QuotaLimitsEx, sizeof(QuotaLimitsEx), 0x55); Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, &QuotaLimitsEx, sizeof(QuotaLimitsEx), NULL); ok_hex(Status, STATUS_SUCCESS);
/* Trace the returned data (1) */ trace("[1] QuotaLimitsEx.PagedPoolLimit = %Iu\n", QuotaLimitsEx.PagedPoolLimit); trace("[1] QuotaLimitsEx.NonPagedPoolLimit = %Iu\n", QuotaLimitsEx.NonPagedPoolLimit); trace("[1] QuotaLimitsEx.MinimumWorkingSetSize = %Iu\n", QuotaLimitsEx.MinimumWorkingSetSize); trace("[1] QuotaLimitsEx.MaximumWorkingSetSize = %Iu\n", QuotaLimitsEx.MaximumWorkingSetSize); trace("[1] QuotaLimitsEx.PagefileLimit = %Iu\n", QuotaLimitsEx.PagefileLimit); trace("[1] QuotaLimitsEx.TimeLimit = %I64d\n", QuotaLimitsEx.TimeLimit.QuadPart); //trace("[1] QuotaLimitsEx.WorkingSetLimit = %Iu\n", QuotaLimitsEx.WorkingSetLimit); // Not used on Win2k3 trace("[1] QuotaLimitsEx.Flags = %lx\n", QuotaLimitsEx.Flags); trace("[1] QuotaLimitsEx.CpuRateLimit.RateData = %lx\n", QuotaLimitsEx.CpuRateLimit.RateData);
/* Again, this time with a return length */ Length = 0x55555555; RtlFillMemory(&QuotaLimitsEx, sizeof(QuotaLimitsEx), 0x55); Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessQuotaLimits, &QuotaLimitsEx, sizeof(QuotaLimitsEx), &Length); ok_hex(Status, STATUS_SUCCESS); ok_dec(Length, sizeof(QuotaLimitsEx));
/* Trace the returned data (2) */ trace("[2] QuotaLimitsEx.PagedPoolLimit = %Iu\n", QuotaLimitsEx.PagedPoolLimit); trace("[2] QuotaLimitsEx.NonPagedPoolLimit = %Iu\n", QuotaLimitsEx.NonPagedPoolLimit); trace("[2] QuotaLimitsEx.MinimumWorkingSetSize = %Iu\n", QuotaLimitsEx.MinimumWorkingSetSize); trace("[2] QuotaLimitsEx.MaximumWorkingSetSize = %Iu\n", QuotaLimitsEx.MaximumWorkingSetSize); trace("[2] QuotaLimitsEx.PagefileLimit = %Iu\n", QuotaLimitsEx.PagefileLimit); trace("[2] QuotaLimitsEx.TimeLimit = %I64d\n", QuotaLimitsEx.TimeLimit.QuadPart); //trace("[2] QuotaLimitsEx.WorkingSetLimit = %Iu\n", QuotaLimitsEx.WorkingSetLimit); // Not used on Win2k3 trace("[2] QuotaLimitsEx.Flags = %lx\n", QuotaLimitsEx.Flags); trace("[2] QuotaLimitsEx.CpuRateLimit.RateData = %lx\n", QuotaLimitsEx.CpuRateLimit.RateData);}
staticvoidTest_ProcessPriorityClassAlignment(void){ NTSTATUS Status; PPROCESS_PRIORITY_CLASS ProcPriority;
/* Allocate some memory for the priority class structure */ ProcPriority = malloc(sizeof(PROCESS_PRIORITY_CLASS)); if (ProcPriority == NULL) { skip("Failed to allocate memory for PROCESS_PRIORITY_CLASS!\n"); return; }
/* * Initialize the PriorityClass member to ensure the test won't randomly succeed (if such data is uninitialized). * Filling 85 to the data member makes sure that if the test fails continously then NtQueryInformationProcess() * didn't initialize the structure with data. */ RtlFillMemory(&ProcPriority->PriorityClass, sizeof(ProcPriority->PriorityClass), 0x55);
/* Unaligned buffer -- wrong size */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessPriorityClass, (PVOID)1, 0, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Unaligned buffer -- correct size */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessPriorityClass, (PVOID)1, sizeof(PROCESS_PRIORITY_CLASS), NULL); ok_hex(Status, STATUS_DATATYPE_MISALIGNMENT);
/* Unaligned buffer -- wrong size (but this time do with an alignment of 2) */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessPriorityClass, (PVOID)2, 0, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Unaligned buffer -- correct size (but this time do with an alignment of 2) */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessPriorityClass, (PVOID)2, sizeof(PROCESS_PRIORITY_CLASS), NULL); ok_hex(Status, STATUS_DATATYPE_MISALIGNMENT);
/* Do not care for the length but expect to return the priority class */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessPriorityClass, ProcPriority, sizeof(PROCESS_PRIORITY_CLASS), NULL); ok_hex(Status, STATUS_SUCCESS);
/* Make sure the returned priority class is a valid number (non negative) but also it should be within the PROCESS_PRIORITY_CLASS range */ ok(ProcPriority->PriorityClass > PROCESS_PRIORITY_CLASS_INVALID && ProcPriority->PriorityClass <= PROCESS_PRIORITY_CLASS_ABOVE_NORMAL, "Expected a valid number from priority class range but got %d\n", ProcPriority->PriorityClass); free(ProcPriority);}
staticvoidTest_ProcessWx86Information(void){ NTSTATUS Status; ULONG VdmPower = 1, ReturnLength;
/* Everything is NULL */ Status = NtQueryInformationProcess(NULL, ProcessWx86Information, NULL, 0, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Given an invalid process handle */ Status = NtQueryInformationProcess(NULL, ProcessWx86Information, &VdmPower, sizeof(VdmPower), NULL); ok_hex(Status, STATUS_INVALID_HANDLE);
/* Don't query anything */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessWx86Information, NULL, sizeof(VdmPower), NULL); ok_hex(Status, STATUS_ACCESS_VIOLATION);
/* The buffer is misaligned and information length is wrong */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessWx86Information, (PVOID)1, 0, NULL); ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* The buffer is misaligned */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessWx86Information, (PVOID)1, sizeof(VdmPower), NULL); ok_hex(Status, STATUS_DATATYPE_MISALIGNMENT);
/* The buffer is misaligned -- try with an alignment size of 2 */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessWx86Information, (PVOID)2, sizeof(VdmPower), NULL); ok_hex(Status, STATUS_DATATYPE_MISALIGNMENT);
/* Query the VDM power */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessWx86Information, &VdmPower, sizeof(VdmPower), NULL); ok_hex(Status, STATUS_SUCCESS); ok(VdmPower == 0 || VdmPower == 1, "The VDM power value must be within the boundary between 0 and 1, not anything else! Got %lu\n", VdmPower);
/* Same but with ReturnLength */ Status = NtQueryInformationProcess(NtCurrentProcess(), ProcessWx86Information, &VdmPower, sizeof(VdmPower), &ReturnLength); ok_hex(Status, STATUS_SUCCESS); ok(ReturnLength != 0, "ReturnLength shouldn't be 0!\n"); ok(VdmPower == 0 || VdmPower == 1, "The VDM power value must be within the boundary between 0 and 1, not anything else! Got %lu\n", VdmPower);
/* Trace the VDM power value and returned length */ trace("ReturnLength = %lu\n", ReturnLength); trace("VdmPower = %lu\n", VdmPower);}
staticvoidTest_ProcQueryAlignmentProbe(void){ ULONG InfoClass;
/* Iterate over the process info classes and begin the tests */ for (InfoClass = 0; InfoClass < _countof(PsProcessInfoClass); InfoClass++) { /* The buffer is misaligned */ QuerySetProcessValidator(QUERY, InfoClass, (PVOID)(ULONG_PTR)1, PsProcessInfoClass[InfoClass].RequiredSizeQUERY, STATUS_DATATYPE_MISALIGNMENT);
/* We query an invalid buffer address */ QuerySetProcessValidator(QUERY, InfoClass, (PVOID)(ULONG_PTR)PsProcessInfoClass[InfoClass].AlignmentQUERY, PsProcessInfoClass[InfoClass].RequiredSizeQUERY, STATUS_ACCESS_VIOLATION);
/* The information length is wrong */ QuerySetProcessValidator(QUERY, InfoClass, (PVOID)(ULONG_PTR)PsProcessInfoClass[InfoClass].AlignmentQUERY, PsProcessInfoClass[InfoClass].RequiredSizeQUERY - 1, STATUS_INFO_LENGTH_MISMATCH); }}
START_TEST(NtQueryInformationProcess){ NTSTATUS Status;
/* Make sure that some time has passed since process creation, even if the resolution of our NtQuerySystemTime is low. */ Sleep(1);
Status = NtQuerySystemTime(&TestStartTime); ok_hex(Status, STATUS_SUCCESS);
Test_ProcessTimes(); Test_ProcessBasicInformation(); Test_ProcessQuotaLimits(); Test_ProcessQuotaLimitsEx(); Test_ProcessPriorityClassAlignment(); Test_ProcessWx86Information(); Test_ProcQueryAlignmentProbe();}