2011-07-26 07:40:19 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS kernel-mode tests
|
|
|
|
* LICENSE: GPLv2+ - See COPYING in the top level directory
|
|
|
|
* PURPOSE: Kernel-Mode Test Suite Runtime library memory functions test
|
2013-10-12 16:05:54 +00:00
|
|
|
* PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
|
2011-07-26 07:40:19 +00:00
|
|
|
*/
|
|
|
|
|
2011-08-05 09:44:20 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
__declspec(dllimport) void __stdcall RtlMoveMemory(void *, const void *, size_t);
|
|
|
|
__declspec(dllimport) void __stdcall RtlFillMemory(void *, size_t, unsigned char);
|
|
|
|
|
2011-08-01 21:53:52 +00:00
|
|
|
#define KMT_EMULATE_KERNEL
|
2011-07-26 07:40:19 +00:00
|
|
|
#include <kmt_test.h>
|
|
|
|
|
2011-08-05 09:44:20 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#pragma GCC diagnostic ignored "-Wnonnull"
|
|
|
|
#endif /* defined __GNUC__ */
|
|
|
|
|
|
|
|
static
|
|
|
|
VOID
|
|
|
|
MakeBuffer(
|
|
|
|
OUT PVOID Buffer,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
PUCHAR OutBuffer = Buffer;
|
|
|
|
INT Count;
|
|
|
|
INT Value;
|
|
|
|
va_list Arguments;
|
|
|
|
|
|
|
|
va_start(Arguments, Buffer);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
Count = va_arg(Arguments, INT);
|
|
|
|
if (!Count)
|
|
|
|
break;
|
|
|
|
ASSERT(Count > 0);
|
|
|
|
|
|
|
|
Value = va_arg(Arguments, INT);
|
|
|
|
while (Count--)
|
|
|
|
*OutBuffer++ = Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(Arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
BOOLEAN
|
|
|
|
CheckBuffer(
|
|
|
|
IN const VOID *Buffer,
|
|
|
|
...)
|
|
|
|
{
|
2014-10-03 12:07:30 +00:00
|
|
|
CONST UCHAR *OutBuffer = Buffer;
|
2011-08-05 09:44:20 +00:00
|
|
|
INT Count;
|
|
|
|
INT Value;
|
|
|
|
va_list Arguments;
|
|
|
|
|
|
|
|
va_start(Arguments, Buffer);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
Count = va_arg(Arguments, INT);
|
|
|
|
if (!Count)
|
|
|
|
break;
|
|
|
|
ASSERT(Count > 0);
|
|
|
|
|
|
|
|
Value = va_arg(Arguments, INT);
|
|
|
|
while (Count--)
|
|
|
|
if (*OutBuffer++ != Value)
|
|
|
|
{
|
|
|
|
--OutBuffer;
|
2014-10-03 12:07:30 +00:00
|
|
|
trace("CheckBuffer failed at offset %d, value %x, expected %x\n", OutBuffer - (CONST UCHAR*)Buffer, *OutBuffer, Value);
|
2011-08-05 09:44:20 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(Arguments);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
VOID
|
|
|
|
MakePattern(
|
|
|
|
OUT PVOID Buffer,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
PUCHAR OutBuffer = Buffer;
|
|
|
|
INT Count, Repeat, i;
|
|
|
|
INT Values[16];
|
|
|
|
va_list Arguments;
|
|
|
|
|
|
|
|
va_start(Arguments, Buffer);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
Count = va_arg(Arguments, INT);
|
|
|
|
if (!Count)
|
|
|
|
break;
|
|
|
|
ASSERT(Count > 0 && Count < sizeof Values / sizeof Values[0]);
|
|
|
|
|
|
|
|
Repeat = va_arg(Arguments, INT);
|
|
|
|
ASSERT(Repeat > 0);
|
|
|
|
|
|
|
|
for (i = 0; i < Count; ++i)
|
|
|
|
Values[i] = va_arg(Arguments, INT);
|
|
|
|
|
|
|
|
while (Repeat--)
|
|
|
|
for (i = 0; i < Count; ++i)
|
|
|
|
*OutBuffer++ = Values[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(Arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
BOOLEAN
|
|
|
|
CheckPattern(
|
|
|
|
IN const VOID *Buffer,
|
|
|
|
...)
|
|
|
|
{
|
2014-10-03 12:07:30 +00:00
|
|
|
CONST UCHAR *OutBuffer = Buffer;
|
2011-08-05 09:44:20 +00:00
|
|
|
INT Count, Repeat, i;
|
|
|
|
INT Values[16];
|
|
|
|
va_list Arguments;
|
|
|
|
|
|
|
|
va_start(Arguments, Buffer);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
Count = va_arg(Arguments, INT);
|
|
|
|
if (!Count)
|
|
|
|
break;
|
|
|
|
ASSERT(Count > 0 && Count < sizeof Values / sizeof Values[0]);
|
|
|
|
|
|
|
|
Repeat = va_arg(Arguments, INT);
|
|
|
|
ASSERT(Repeat > 0);
|
|
|
|
|
|
|
|
for (i = 0; i < Count; ++i)
|
|
|
|
Values[i] = va_arg(Arguments, INT);
|
|
|
|
|
|
|
|
while (Repeat--)
|
|
|
|
for (i = 0; i < Count; ++i)
|
|
|
|
if (*OutBuffer++ != Values[i])
|
|
|
|
{
|
|
|
|
--OutBuffer;
|
2014-10-03 12:07:30 +00:00
|
|
|
trace("CheckPattern failed at offset %d, value %x, expected %x\n", OutBuffer - (CONST UCHAR*)Buffer, *OutBuffer, Values[i]);
|
2011-08-05 09:44:20 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(Arguments);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-26 07:40:19 +00:00
|
|
|
START_TEST(RtlMemory)
|
|
|
|
{
|
2011-08-05 09:44:20 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
UCHAR Buffer[513];
|
2011-08-10 22:26:14 +00:00
|
|
|
const SIZE_T Size = 512;
|
|
|
|
const SIZE_T HalfSize = Size / 2;
|
2011-08-05 09:44:20 +00:00
|
|
|
SIZE_T RetSize;
|
2011-07-26 07:40:19 +00:00
|
|
|
KIRQL Irql;
|
2012-05-01 09:13:19 +00:00
|
|
|
SIZE_T i;
|
2011-07-26 07:40:19 +00:00
|
|
|
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
2011-08-05 09:44:20 +00:00
|
|
|
/* zero everything behind 'Size'. Tests will check that this wasn't changed.
|
|
|
|
* TODO: use guarded memory for this! */
|
|
|
|
MakeBuffer(Buffer + Size, sizeof Buffer - Size, 0, 0);
|
2011-07-26 07:40:19 +00:00
|
|
|
|
2011-08-05 09:44:20 +00:00
|
|
|
/* test our helper functions first */
|
|
|
|
MakeBuffer(Buffer, HalfSize, 0x55, HalfSize, 0xAA, 0);
|
|
|
|
for (i = 0; i < HalfSize; ++i)
|
2011-07-26 07:40:19 +00:00
|
|
|
ok_eq_uint(Buffer[i], 0x55);
|
2011-08-05 09:44:20 +00:00
|
|
|
for (i = HalfSize; i < Size; ++i)
|
2011-07-26 07:40:19 +00:00
|
|
|
ok_eq_uint(Buffer[i], 0xAA);
|
2011-08-05 09:44:20 +00:00
|
|
|
ok_bool_true(CheckBuffer(Buffer, HalfSize, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
|
|
|
|
|
|
|
|
MakePattern(Buffer, 3, 20, 0x11, 0x22, 0x33, 1, 4, 0x44, 0);
|
|
|
|
for (i = 0; i < 60; i += 3)
|
|
|
|
{
|
|
|
|
ok_eq_uint(Buffer[i+0], 0x11);
|
|
|
|
ok_eq_uint(Buffer[i+1], 0x22);
|
|
|
|
ok_eq_uint(Buffer[i+2], 0x33);
|
|
|
|
}
|
|
|
|
for (i = 60; i < 64; ++i)
|
|
|
|
ok_eq_uint(Buffer[i], 0x44);
|
|
|
|
for (i = 64; i < HalfSize; ++i)
|
|
|
|
ok_eq_uint(Buffer[i], 0x55);
|
|
|
|
for (i = HalfSize; i < Size; ++i)
|
|
|
|
ok_eq_uint(Buffer[i], 0xAA);
|
|
|
|
ok_bool_true(CheckPattern(Buffer, 3, 20, 0x11, 0x22, 0x33, 1, 4, 0x44, 0), "CheckPattern");
|
|
|
|
|
|
|
|
/* RtlMoveMemory */
|
|
|
|
MakePattern(Buffer, 2, 64, 0x12, 0x34, 2, 192, 0x56, 0x78, 0);
|
|
|
|
RtlMoveMemory(Buffer + 13, Buffer + 62, 95);
|
|
|
|
ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
|
|
|
|
|
|
|
|
MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
|
|
|
|
RtlMoveMemory(Buffer + 78, Buffer + 43, 107);
|
|
|
|
ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
|
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY {
|
|
|
|
RtlMoveMemory(NULL, NULL, 0);
|
|
|
|
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
} _SEH2_END;
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
|
|
|
|
#undef RtlMoveMemory
|
|
|
|
/* RtlMoveMemory export */
|
|
|
|
MakePattern(Buffer, 2, 64, 0x12, 0x34, 2, 192, 0x56, 0x78, 0);
|
|
|
|
RtlMoveMemory(Buffer + 13, Buffer + 62, 95);
|
|
|
|
ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
|
|
|
|
|
|
|
|
MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
|
|
|
|
RtlMoveMemory(Buffer + 78, Buffer + 43, 107);
|
|
|
|
ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
|
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY {
|
|
|
|
RtlMoveMemory(NULL, NULL, 0);
|
|
|
|
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
} _SEH2_END;
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
|
|
|
|
/* RtlCopyMemory */
|
|
|
|
MakePattern(Buffer, 2, 64, 0x12, 0x34, 2, 192, 0x56, 0x78, 0);
|
|
|
|
RtlCopyMemory(Buffer + 13, Buffer + 62, 95);
|
|
|
|
ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
|
|
|
|
|
|
|
|
MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
|
|
|
|
RtlCopyMemory(Buffer + 78, Buffer + 43, 107);
|
|
|
|
ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
|
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY {
|
|
|
|
RtlCopyMemory(NULL, NULL, 0);
|
|
|
|
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
} _SEH2_END;
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
|
|
|
|
/* RtlCopyMemoryNonTemporal */
|
|
|
|
MakePattern(Buffer, 2, 64, 0x12, 0x34, 2, 192, 0x56, 0x78, 0);
|
|
|
|
RtlCopyMemoryNonTemporal(Buffer + 13, Buffer + 62, 95);
|
|
|
|
ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
|
|
|
|
|
|
|
|
MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
|
|
|
|
RtlCopyMemoryNonTemporal(Buffer + 78, Buffer + 43, 107);
|
|
|
|
ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
|
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY {
|
|
|
|
RtlCopyMemoryNonTemporal(NULL, NULL, 0);
|
|
|
|
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
} _SEH2_END;
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
|
|
|
|
/* RtlCopyBytes */
|
|
|
|
MakePattern(Buffer, 2, 64, 0x12, 0x34, 2, 192, 0x56, 0x78, 0);
|
|
|
|
RtlCopyBytes(Buffer + 13, Buffer + 62, 95);
|
|
|
|
ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
|
|
|
|
|
|
|
|
MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
|
|
|
|
RtlCopyBytes(Buffer + 78, Buffer + 43, 107);
|
|
|
|
ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
|
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY {
|
|
|
|
RtlCopyBytes(NULL, NULL, 0);
|
|
|
|
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
} _SEH2_END;
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
|
|
|
|
/* RtlEqualMemory */
|
|
|
|
/* TODO: where is memcmp? */
|
|
|
|
|
|
|
|
/* RtlCompareMemory */
|
|
|
|
MakePattern(Buffer, 8, HalfSize / 8 - 1, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
|
|
|
|
1, 1, 0x12,
|
|
|
|
8, HalfSize / 8, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
|
|
|
|
1, 7, 0x12, 0);
|
|
|
|
|
|
|
|
RetSize = RtlCompareMemory(Buffer, Buffer + HalfSize - 7, HalfSize - 8);
|
|
|
|
ok_eq_size(RetSize, HalfSize - 8);
|
|
|
|
RetSize = RtlCompareMemory(Buffer, Buffer + HalfSize - 7, HalfSize - 8 + 1);
|
|
|
|
ok_eq_size(RetSize, HalfSize - 8 + 1);
|
|
|
|
RetSize = RtlCompareMemory(Buffer, Buffer + HalfSize - 7, HalfSize - 8 + 2);
|
|
|
|
ok_eq_size(RetSize, HalfSize - 8 + 1);
|
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY {
|
|
|
|
RetSize = RtlCompareMemory(Buffer, Buffer + HalfSize - 7, SIZE_MAX);
|
|
|
|
ok_eq_size(RetSize, HalfSize - 8 + 1);
|
|
|
|
RetSize = RtlCompareMemory(NULL, NULL, 0);
|
2011-08-10 22:26:14 +00:00
|
|
|
ok_eq_size(RetSize, 0);
|
2011-08-05 09:44:20 +00:00
|
|
|
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
} _SEH2_END;
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
|
|
|
|
/* RtlCompareMemoryUlong */
|
2014-08-12 07:47:08 +00:00
|
|
|
MakeBuffer(Buffer, 8, 0x55, Size - 8, 0, 0);
|
2011-08-05 09:44:20 +00:00
|
|
|
RetSize = RtlCompareMemoryUlong(Buffer, sizeof(ULONG), 0x55555555LU);
|
2011-08-10 22:26:14 +00:00
|
|
|
ok_eq_size(RetSize, 4);
|
2011-08-05 09:44:20 +00:00
|
|
|
RetSize = RtlCompareMemoryUlong(Buffer + 1, sizeof(ULONG), 0x55555555LU);
|
2011-08-10 22:26:14 +00:00
|
|
|
ok_eq_size(RetSize, 4);
|
2011-08-05 09:44:20 +00:00
|
|
|
RetSize = RtlCompareMemoryUlong(Buffer + 2, sizeof(ULONG), 0x55555555LU);
|
2011-08-10 22:26:14 +00:00
|
|
|
ok_eq_size(RetSize, 4);
|
2011-08-05 09:44:20 +00:00
|
|
|
RetSize = RtlCompareMemoryUlong(Buffer + 3, sizeof(ULONG), 0x55555555LU);
|
2011-08-10 22:26:14 +00:00
|
|
|
ok_eq_size(RetSize, 4);
|
2011-08-05 09:44:20 +00:00
|
|
|
RetSize = RtlCompareMemoryUlong(Buffer + 5, sizeof(ULONG), 0x55555555LU);
|
2011-08-10 22:26:14 +00:00
|
|
|
ok_eq_size(RetSize, 0);
|
2011-08-05 09:44:20 +00:00
|
|
|
RetSize = RtlCompareMemoryUlong(Buffer + 5, sizeof(ULONG), 0x00555555LU);
|
2011-08-10 22:26:14 +00:00
|
|
|
ok_eq_size(RetSize, 4);
|
2011-08-05 09:44:20 +00:00
|
|
|
RetSize = RtlCompareMemoryUlong(Buffer, 1, 0x55555555LU);
|
2011-08-10 22:26:14 +00:00
|
|
|
ok_eq_size(RetSize, 0);
|
2011-08-05 09:44:20 +00:00
|
|
|
RetSize = RtlCompareMemoryUlong(Buffer, 2, 0x55555555LU);
|
2011-08-10 22:26:14 +00:00
|
|
|
ok_eq_size(RetSize, 0);
|
2011-08-05 09:44:20 +00:00
|
|
|
RetSize = RtlCompareMemoryUlong(Buffer, 3, 0x55555555LU);
|
2011-08-10 22:26:14 +00:00
|
|
|
ok_eq_size(RetSize, 0);
|
2011-08-05 09:44:20 +00:00
|
|
|
RetSize = RtlCompareMemoryUlong(Buffer, 5, 0x55555555LU);
|
2011-08-10 22:26:14 +00:00
|
|
|
ok_eq_size(RetSize, 4);
|
2011-08-05 09:44:20 +00:00
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY {
|
|
|
|
RetSize = RtlCompareMemoryUlong(NULL, 0, 0x55555555LU);
|
2011-08-10 22:26:14 +00:00
|
|
|
ok_eq_size(RetSize, 0);
|
2011-08-05 09:44:20 +00:00
|
|
|
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
} _SEH2_END;
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
|
|
|
|
/* RtlZeroMemory */
|
|
|
|
MakeBuffer(Buffer, Size, 0x11, 0);
|
|
|
|
RtlZeroMemory(Buffer, 1);
|
|
|
|
ok_bool_true(CheckBuffer(Buffer, 1, 0, Size - 1, 0x11, 1, 0, 0), "CheckBuffer");
|
|
|
|
Buffer[0] = 0x11;
|
|
|
|
RtlZeroMemory(Buffer, Size - 1);
|
|
|
|
ok_bool_true(CheckBuffer(Buffer, Size - 1, 0, 1, 0x11, 1, 0, 0), "CheckBuffer");
|
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY {
|
|
|
|
RtlZeroMemory(NULL, 0);
|
|
|
|
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
} _SEH2_END;
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
|
|
|
|
/* RtlSecureZeroMemory */
|
|
|
|
MakeBuffer(Buffer, Size, 0x11, 0);
|
|
|
|
RtlSecureZeroMemory(Buffer, 1);
|
|
|
|
ok_bool_true(CheckBuffer(Buffer, 1, 0, Size - 1, 0x11, 1, 0, 0), "CheckBuffer");
|
|
|
|
Buffer[0] = 0x11;
|
|
|
|
RtlSecureZeroMemory(Buffer, Size - 1);
|
|
|
|
ok_bool_true(CheckBuffer(Buffer, Size - 1, 0, 1, 0x11, 1, 0, 0), "CheckBuffer");
|
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY {
|
|
|
|
RtlSecureZeroMemory(NULL, 0);
|
|
|
|
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
} _SEH2_END;
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
|
|
|
|
/* RtlZeroBytes */
|
|
|
|
MakeBuffer(Buffer, Size, 0x11, 0);
|
|
|
|
RtlZeroBytes(Buffer, 1);
|
|
|
|
ok_bool_true(CheckBuffer(Buffer, 1, 0, Size - 1, 0x11, 1, 0, 0), "CheckBuffer");
|
|
|
|
Buffer[0] = 0x11;
|
|
|
|
RtlZeroBytes(Buffer, Size - 1);
|
|
|
|
ok_bool_true(CheckBuffer(Buffer, Size - 1, 0, 1, 0x11, 1, 0, 0), "CheckBuffer");
|
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY {
|
|
|
|
RtlZeroBytes(NULL, 0);
|
|
|
|
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
} _SEH2_END;
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
|
|
|
|
/* RtlFillMemory */
|
|
|
|
MakeBuffer(Buffer, Size, 0, 0);
|
|
|
|
RtlFillMemory(Buffer, HalfSize, 0x55);
|
|
|
|
RtlFillMemory(Buffer + HalfSize, HalfSize, 0xAA);
|
|
|
|
ok_bool_true(CheckBuffer(Buffer, HalfSize, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
|
|
|
|
RtlFillMemory(Buffer + 3, 7, 0x88);
|
|
|
|
ok_bool_true(CheckBuffer(Buffer, 3, 0x55, 7, 0x88, HalfSize - 10, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
|
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY {
|
|
|
|
RtlFillMemory(NULL, 0, 0x55);
|
|
|
|
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
} _SEH2_END;
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
|
|
|
|
#undef RtlFillMemory
|
|
|
|
/* RtlFillMemory export */
|
|
|
|
MakeBuffer(Buffer, Size, 0, 0);
|
|
|
|
RtlFillMemory(Buffer, HalfSize, 0x55);
|
|
|
|
RtlFillMemory(Buffer + HalfSize, HalfSize, 0xAA);
|
|
|
|
ok_bool_true(CheckBuffer(Buffer, HalfSize, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
|
|
|
|
RtlFillMemory(Buffer + 3, 7, 0x88);
|
|
|
|
ok_bool_true(CheckBuffer(Buffer, 3, 0x55, 7, 0x88, HalfSize - 10, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
|
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY {
|
|
|
|
RtlFillMemory(NULL, 0, 0x55);
|
|
|
|
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
} _SEH2_END;
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
|
2011-11-11 23:04:26 +00:00
|
|
|
/* TODO: fix NDK. This should work! */
|
|
|
|
#if !defined _M_AMD64 || defined KMT_KERNEL_MODE
|
2011-08-05 09:44:20 +00:00
|
|
|
/* RtlFillMemoryUlong */
|
|
|
|
MakeBuffer(Buffer, Size, 0, 0);
|
|
|
|
RtlFillMemoryUlong(Buffer, HalfSize, 0x01234567LU);
|
|
|
|
RtlFillMemoryUlong(Buffer + HalfSize, HalfSize, 0x89ABCDEFLU);
|
|
|
|
ok_bool_true(CheckPattern(Buffer, 4, HalfSize / 4, 0x67, 0x45, 0x23, 0x01, 4, HalfSize / 4, 0xEF, 0xCD, 0xAB, 0x89, 1, 1, 0, 0), "CheckPattern");
|
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY {
|
|
|
|
MakeBuffer(Buffer, Size, 0, 0);
|
|
|
|
RtlFillMemoryUlong(Buffer + 1, sizeof(ULONG), 0xAAAAAAAALU);
|
|
|
|
ok_bool_true(CheckBuffer(Buffer, 1, 0, sizeof(ULONG), 0xAA, Size - sizeof(ULONG) - 1, 0, 1, 0, 0), "CheckBuffer");
|
|
|
|
|
|
|
|
RtlFillMemoryUlong(NULL, 0, 0x55555555LU);
|
|
|
|
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
} _SEH2_END;
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
2011-11-11 23:04:26 +00:00
|
|
|
#endif
|
2011-08-05 09:44:20 +00:00
|
|
|
|
|
|
|
/* RtlFillMemoryUlonglong */
|
|
|
|
/* TODO: this function doesn't exist in 2k3/x86? wdm.h error? */
|
|
|
|
|
|
|
|
/* RtlFillBytes */
|
|
|
|
MakeBuffer(Buffer, Size, 0, 0);
|
|
|
|
RtlFillBytes(Buffer, HalfSize, 0x55);
|
|
|
|
RtlFillBytes(Buffer + HalfSize, HalfSize, 0xAA);
|
|
|
|
ok_bool_true(CheckBuffer(Buffer, HalfSize, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
|
|
|
|
RtlFillBytes(Buffer + 3, 7, 0x88);
|
|
|
|
ok_bool_true(CheckBuffer(Buffer, 3, 0x55, 7, 0x88, HalfSize - 10, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
|
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY {
|
|
|
|
RtlFillBytes(NULL, 0, 0x55);
|
|
|
|
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
} _SEH2_END;
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
|
|
|
|
|
|
|
/* RtlPrefetchMemoryNonTemporal */
|
|
|
|
RtlPrefetchMemoryNonTemporal(Buffer, Size);
|
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
_SEH2_TRY {
|
|
|
|
RtlPrefetchMemoryNonTemporal(NULL, 0);
|
|
|
|
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
} _SEH2_END;
|
|
|
|
ok_eq_hex(Status, STATUS_SUCCESS);
|
|
|
|
KeRaiseIrql(HIGH_LEVEL, &Irql);
|
2011-07-26 07:40:19 +00:00
|
|
|
|
|
|
|
KeLowerIrql(Irql);
|
|
|
|
}
|