https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a7dd057ce2b622aa2d7aa…
commit a7dd057ce2b622aa2d7aaf3abb993c9e50fb2dd3
Author: George Bișoc <fraizeraust99(a)gmail.com>
AuthorDate: Sat Jun 6 17:47:38 2020 +0200
Commit: GitHub <noreply(a)github.com>
CommitDate: Sat Jun 6 17:47:38 2020 +0200
[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%2FUndocumente…
---
.../apitests/ntdll/NtSetInformationProcess.c | 143 +++++++++++++++++++++
1 file changed, 143 insertions(+)
diff --git a/modules/rostests/apitests/ntdll/NtSetInformationProcess.c
b/modules/rostests/apitests/ntdll/NtSetInformationProcess.c
index b5fcc18e2db..0b805b3ca66 100644
--- a/modules/rostests/apitests/ntdll/NtSetInformationProcess.c
+++ b/modules/rostests/apitests/ntdll/NtSetInformationProcess.c
@@ -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();
}