[NTDLL_APITEST] Add ProcessBasePriority and ProcessRaisePriority classes unit tests (#2740)

ProcessRaisePriority expects a buffer input information argument of KPRIORITY type definition as shown in this documentation (see the PROCESS_INFORMATION_CLASS structure members list of classes).
https://undocumented.ntinternals.net/index.html?page=UserMode%2FUndocumented%20Functions%2FNT%20Objects%2FProcess%2FNtSetInformationProcess.html
This commit is contained in:
George Bișoc 2020-06-06 17:47:38 +02:00 committed by GitHub
parent 4f49a9c792
commit a7dd057ce2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,147 @@
#include "precomp.h"
static
void
Test_ProcBasePriorityClass(void)
{
NTSTATUS Status;
/*
* Assign a priority of HIGH_PRIORITY (see pstypes.h).
* The function will fail with a status of STATUS_PRIVILEGE_NOT_HELD
* as the process who executed the caller doesn't have the requested
* privileges to perform the operation.
*/
KPRIORITY BasePriority = HIGH_PRIORITY;
/* Everything is NULL */
Status = NtSetInformationProcess(NULL,
ProcessBasePriority,
NULL,
0);
ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* Set the base priority to an invalid process handle */
Status = NtSetInformationProcess(NULL,
ProcessBasePriority,
&BasePriority,
sizeof(KPRIORITY));
ok_hex(Status, STATUS_INVALID_HANDLE);
/* Don't input anything to the caller but the length information is valid */
Status = NtSetInformationProcess(NtCurrentProcess(),
ProcessBasePriority,
NULL,
sizeof(KPRIORITY));
ok_hex(Status, STATUS_ACCESS_VIOLATION);
/* Give the base priority input to the caller but length is invalid */
Status = NtSetInformationProcess(NtCurrentProcess(),
ProcessBasePriority,
&BasePriority,
0);
ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* The input buffer is misaligned and length information invalid */
Status = NtSetInformationProcess(NtCurrentProcess(),
ProcessBasePriority,
(PVOID)1,
0);
ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* The input buffer is misaligned */
Status = NtSetInformationProcess(NtCurrentProcess(),
ProcessBasePriority,
(PVOID)1,
sizeof(KPRIORITY));
ok_hex(Status, STATUS_DATATYPE_MISALIGNMENT);
/* The input buffer is misaligned (try with an alignment of 2) */
Status = NtSetInformationProcess(NtCurrentProcess(),
ProcessBasePriority,
(PVOID)2,
sizeof(KPRIORITY));
ok_hex(Status, STATUS_DATATYPE_MISALIGNMENT);
/* Set the base priority but we have lack privileges to do so */
Status = NtSetInformationProcess(NtCurrentProcess(),
ProcessBasePriority,
&BasePriority,
sizeof(KPRIORITY));
ok_hex(Status, STATUS_PRIVILEGE_NOT_HELD);
/*
* Assign a random priority value this time and
* set the base priority to the current process.
*/
BasePriority = 8;
Status = NtSetInformationProcess(NtCurrentProcess(),
ProcessBasePriority,
&BasePriority,
sizeof(KPRIORITY));
ok_hex(Status, STATUS_SUCCESS);
}
static
void
Test_ProcRaisePriorityClass(void)
{
NTSTATUS Status;
/* Raise the priority as much as possible */
ULONG RaisePriority = MAXIMUM_PRIORITY;
/* Everything is NULL */
Status = NtSetInformationProcess(NULL,
ProcessRaisePriority,
NULL,
0);
ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* A invalid handle to process is given */
Status = NtSetInformationProcess(NULL,
ProcessRaisePriority,
&RaisePriority,
sizeof(ULONG));
ok_hex(Status, STATUS_INVALID_HANDLE);
/* The input buffer is misaligned and length information invalid */
Status = NtSetInformationProcess(NtCurrentProcess(),
ProcessRaisePriority,
(PVOID)1,
0);
ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
/* A NULL buffer has been accessed */
Status = NtSetInformationProcess(NtCurrentProcess(),
ProcessRaisePriority,
NULL,
sizeof(ULONG));
ok_hex(Status, STATUS_ACCESS_VIOLATION);
/* The input buffer is misaligned */
Status = NtSetInformationProcess(NtCurrentProcess(),
ProcessRaisePriority,
(PVOID)1,
sizeof(ULONG));
ok_hex(Status, STATUS_DATATYPE_MISALIGNMENT);
/* The input buffer is misaligned -- try with an alignment size of 2 */
Status = NtSetInformationProcess(NtCurrentProcess(),
ProcessRaisePriority,
(PVOID)2,
sizeof(ULONG));
ok_hex(Status, STATUS_DATATYPE_MISALIGNMENT);
/* Raise the priority of the given current process */
Status = NtSetInformationProcess(NtCurrentProcess(),
ProcessRaisePriority,
&RaisePriority,
sizeof(ULONG));
ok_hex(Status, STATUS_SUCCESS);
}
static
void
Test_ProcForegroundBackgroundClass(void)
@ -77,4 +218,6 @@ Test_ProcForegroundBackgroundClass(void)
START_TEST(NtSetInformationProcess)
{
Test_ProcForegroundBackgroundClass();
Test_ProcBasePriorityClass();
Test_ProcRaisePriorityClass();
}