[KMTESTS]

- Centralize frequently used macros

svn path=/trunk/; revision=56733
This commit is contained in:
Thomas Faber 2012-06-14 17:48:14 +00:00
parent e04fd2b536
commit 3acf3b9507
4 changed files with 136 additions and 132 deletions

View file

@ -173,6 +173,20 @@ VOID KmtFreeGuarded(PVOID Pointer);
#define MILLISECOND (1000 * MICROSECOND) #define MILLISECOND (1000 * MICROSECOND)
#define SECOND (1000 * MILLISECOND) #define SECOND (1000 * MILLISECOND)
#define KmtInvalidPointer ((PVOID)0x5555555555555555ULL)
#define KmtStartSeh() \
ExceptionStatus = STATUS_SUCCESS; \
_SEH2_TRY \
{
#define KmtEndSeh(ExpectedStatus) \
} \
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) \
{ \
ExceptionStatus = _SEH2_GetExceptionCode(); \
} _SEH2_END; \
ok_eq_hex(ExceptionStatus, ExpectedStatus)
#if defined KMT_DEFINE_TEST_FUNCTIONS #if defined KMT_DEFINE_TEST_FUNCTIONS
#if defined KMT_KERNEL_MODE #if defined KMT_KERNEL_MODE

View file

@ -7,9 +7,6 @@
#include <kmt_test.h> #include <kmt_test.h>
#define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
#define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok_eq_hex(ExceptionStatus, ExpectedStatus)
#define CheckObject(Handle, Pointers, Handles) do \ #define CheckObject(Handle, Pointers, Handles) do \
{ \ { \
PUBLIC_OBJECT_BASIC_INFORMATION ObjectInfo; \ PUBLIC_OBJECT_BASIC_INFORMATION ObjectInfo; \
@ -81,106 +78,105 @@ TestCreateSection(
{ {
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
NTSTATUS ExceptionStatus; NTSTATUS ExceptionStatus;
const PVOID InvalidPointer = (PVOID)0x5555555555555555ULL;
PVOID SectionObject; PVOID SectionObject;
LARGE_INTEGER MaximumSize; LARGE_INTEGER MaximumSize;
ULONG PointerCount1, PointerCount2; ULONG PointerCount1, PointerCount2;
StartSeh() KmtStartSeh()
Status = MmCreateSection(NULL, 0, NULL, NULL, 0, SEC_RESERVE, NULL, NULL); Status = MmCreateSection(NULL, 0, NULL, NULL, 0, SEC_RESERVE, NULL, NULL);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PAGE_PROTECTION); ok_eq_hex(Status, STATUS_INVALID_PAGE_PROTECTION);
if (!KmtIsCheckedBuild) if (!KmtIsCheckedBuild)
{ {
/* PAGE_NOACCESS and missing SEC_RESERVE/SEC_COMMIT/SEC_IMAGE assert */ /* PAGE_NOACCESS and missing SEC_RESERVE/SEC_COMMIT/SEC_IMAGE assert */
StartSeh() KmtStartSeh()
Status = MmCreateSection(NULL, 0, NULL, NULL, PAGE_NOACCESS, SEC_RESERVE, NULL, NULL); Status = MmCreateSection(NULL, 0, NULL, NULL, PAGE_NOACCESS, SEC_RESERVE, NULL, NULL);
EndSeh(STATUS_ACCESS_VIOLATION); KmtEndSeh(STATUS_ACCESS_VIOLATION);
StartSeh() KmtStartSeh()
Status = MmCreateSection(NULL, 0, NULL, NULL, PAGE_NOACCESS, 0, NULL, NULL); Status = MmCreateSection(NULL, 0, NULL, NULL, PAGE_NOACCESS, 0, NULL, NULL);
EndSeh(STATUS_ACCESS_VIOLATION); KmtEndSeh(STATUS_ACCESS_VIOLATION);
} }
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, NULL, 0, SEC_RESERVE, NULL, NULL); Status = MmCreateSection(&SectionObject, 0, NULL, NULL, 0, SEC_RESERVE, NULL, NULL);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PAGE_PROTECTION); ok_eq_hex(Status, STATUS_INVALID_PAGE_PROTECTION);
ok_eq_pointer(SectionObject, InvalidPointer); ok_eq_pointer(SectionObject, KmtInvalidPointer);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
StartSeh() KmtStartSeh()
Status = MmCreateSection(NULL, 0, NULL, NULL, PAGE_READONLY, SEC_RESERVE, NULL, NULL); Status = MmCreateSection(NULL, 0, NULL, NULL, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
EndSeh(STATUS_ACCESS_VIOLATION); KmtEndSeh(STATUS_ACCESS_VIOLATION);
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, NULL, PAGE_READONLY, SEC_RESERVE, NULL, NULL); Status = MmCreateSection(&SectionObject, 0, NULL, NULL, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
EndSeh(STATUS_ACCESS_VIOLATION); KmtEndSeh(STATUS_ACCESS_VIOLATION);
ok_eq_pointer(SectionObject, InvalidPointer); ok_eq_pointer(SectionObject, KmtInvalidPointer);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 0; MaximumSize.QuadPart = 0;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, NULL); Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, NULL);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_FILE_FOR_SECTION); ok_eq_hex(Status, STATUS_INVALID_FILE_FOR_SECTION);
ok_eq_longlong(MaximumSize.QuadPart, 0LL); ok_eq_longlong(MaximumSize.QuadPart, 0LL);
ok_eq_pointer(SectionObject, InvalidPointer); ok_eq_pointer(SectionObject, KmtInvalidPointer);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
MaximumSize.QuadPart = 0; MaximumSize.QuadPart = 0;
StartSeh() KmtStartSeh()
Status = MmCreateSection(NULL, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL); Status = MmCreateSection(NULL, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_4); ok_eq_hex(Status, STATUS_INVALID_PARAMETER_4);
ok_eq_longlong(MaximumSize.QuadPart, 0LL); ok_eq_longlong(MaximumSize.QuadPart, 0LL);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
MaximumSize.QuadPart = 1; MaximumSize.QuadPart = 1;
StartSeh() KmtStartSeh()
Status = MmCreateSection(NULL, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL); Status = MmCreateSection(NULL, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
EndSeh(STATUS_ACCESS_VIOLATION); KmtEndSeh(STATUS_ACCESS_VIOLATION);
ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok_eq_longlong(MaximumSize.QuadPart, 1LL);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 0; MaximumSize.QuadPart = 0;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL); Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER_4); ok_eq_hex(Status, STATUS_INVALID_PARAMETER_4);
ok_eq_longlong(MaximumSize.QuadPart, 0LL); ok_eq_longlong(MaximumSize.QuadPart, 0LL);
ok_eq_pointer(SectionObject, InvalidPointer); ok_eq_pointer(SectionObject, KmtInvalidPointer);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
/* page file section */ /* page file section */
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1; MaximumSize.QuadPart = 1;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL); Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, NULL);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != InvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n"); ok(SectionObject != NULL, "Section object pointer NULL\n");
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
if (!skip(FileHandle1 != NULL && FileObject1 != NULL && if (!skip(FileHandle1 != NULL && FileObject1 != NULL &&
@ -190,196 +186,196 @@ TestCreateSection(
PointerCount2 = 3; PointerCount2 = 3;
/* image section */ /* image section */
CheckObject(FileHandle2, PointerCount2, 1L); CheckObject(FileHandle2, PointerCount2, 1L);
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1; MaximumSize.QuadPart = 1;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, NULL); Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, NULL);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != InvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n"); ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle2, PointerCount2, 1L); CheckObject(FileHandle2, PointerCount2, 1L);
CheckSection(SectionObject, SEC_IMAGE); CheckSection(SectionObject, SEC_IMAGE);
TestMapView(SectionObject, FALSE, TRUE); TestMapView(SectionObject, FALSE, TRUE);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
CheckObject(FileHandle2, PointerCount2, 1L); CheckObject(FileHandle2, PointerCount2, 1L);
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1; MaximumSize.QuadPart = 1;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, FileObject2); Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, FileObject2);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != InvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n"); ok(SectionObject != NULL, "Section object pointer NULL\n");
++PointerCount2; ++PointerCount2;
CheckObject(FileHandle2, PointerCount2, 1L); CheckObject(FileHandle2, PointerCount2, 1L);
CheckSection(SectionObject, 0); CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, TRUE); TestMapView(SectionObject, TRUE, TRUE);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
//--PointerCount2; // ???? //--PointerCount2; // ????
CheckObject(FileHandle2, PointerCount2, 1L); CheckObject(FileHandle2, PointerCount2, 1L);
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1; MaximumSize.QuadPart = 1;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject2); Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject2);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != InvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n"); ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle2, PointerCount2, 1L); CheckObject(FileHandle2, PointerCount2, 1L);
CheckSection(SectionObject, 0); CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, TRUE); TestMapView(SectionObject, TRUE, TRUE);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
/* image section with inappropriate file */ /* image section with inappropriate file */
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1; MaximumSize.QuadPart = 1;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, NULL); Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, NULL);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_IMAGE_NOT_MZ); ok_eq_hex(Status, STATUS_INVALID_IMAGE_NOT_MZ);
ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok_eq_pointer(SectionObject, InvalidPointer); ok_eq_pointer(SectionObject, KmtInvalidPointer);
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1; MaximumSize.QuadPart = 1;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, FileObject1); Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, NULL, FileObject1);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != InvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n"); ok(SectionObject != NULL, "Section object pointer NULL\n");
++PointerCount1; ++PointerCount1;
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
CheckSection(SectionObject, 0); CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE); TestMapView(SectionObject, TRUE, FALSE);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
//--PointerCount1; // ???? //--PointerCount1; // ????
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1; MaximumSize.QuadPart = 1;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject1); Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject1);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != InvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n"); ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
CheckSection(SectionObject, 0); CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE); TestMapView(SectionObject, TRUE, FALSE);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
/* image section with two different files */ /* image section with two different files */
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1; MaximumSize.QuadPart = 1;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject2); Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle1, FileObject2);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != InvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n"); ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
CheckObject(FileHandle2, PointerCount2, 1L); CheckObject(FileHandle2, PointerCount2, 1L);
CheckSection(SectionObject, 0); CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, TRUE); TestMapView(SectionObject, TRUE, TRUE);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1; MaximumSize.QuadPart = 1;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject1); Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_IMAGE, FileHandle2, FileObject1);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != InvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n"); ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
CheckObject(FileHandle2, PointerCount2, 1L); CheckObject(FileHandle2, PointerCount2, 1L);
CheckSection(SectionObject, 0); CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE); TestMapView(SectionObject, TRUE, FALSE);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
/* data file section */ /* data file section */
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1; MaximumSize.QuadPart = 1;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, FileHandle1, NULL); Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, FileHandle1, NULL);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != InvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n"); ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
CheckSection(SectionObject, 0); CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE); TestMapView(SectionObject, TRUE, FALSE);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1; MaximumSize.QuadPart = 1;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, FileObject1); Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, NULL, FileObject1);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != InvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n"); ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
CheckSection(SectionObject, 0); CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE); TestMapView(SectionObject, TRUE, FALSE);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
SectionObject = InvalidPointer; SectionObject = KmtInvalidPointer;
MaximumSize.QuadPart = 1; MaximumSize.QuadPart = 1;
StartSeh() KmtStartSeh()
Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, FileHandle1, FileObject1); Status = MmCreateSection(&SectionObject, 0, NULL, &MaximumSize, PAGE_READONLY, SEC_RESERVE, FileHandle1, FileObject1);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_SUCCESS); ok_eq_hex(Status, STATUS_SUCCESS);
ok_eq_longlong(MaximumSize.QuadPart, 1LL); ok_eq_longlong(MaximumSize.QuadPart, 1LL);
ok(SectionObject != InvalidPointer, "Section object pointer untouched\n"); ok(SectionObject != KmtInvalidPointer, "Section object pointer untouched\n");
ok(SectionObject != NULL, "Section object pointer NULL\n"); ok(SectionObject != NULL, "Section object pointer NULL\n");
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);
CheckSection(SectionObject, 0); CheckSection(SectionObject, 0);
TestMapView(SectionObject, TRUE, FALSE); TestMapView(SectionObject, TRUE, FALSE);
if (SectionObject && SectionObject != InvalidPointer) if (SectionObject && SectionObject != KmtInvalidPointer)
ObDereferenceObject(SectionObject); ObDereferenceObject(SectionObject);
CheckObject(FileHandle1, PointerCount1, 1L); CheckObject(FileHandle1, PointerCount1, 1L);

View file

@ -7,9 +7,6 @@
#include <kmt_test.h> #include <kmt_test.h>
#define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
#define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok_eq_hex(ExceptionStatus, ExpectedStatus)
START_TEST(RtlException) START_TEST(RtlException)
{ {
NTSTATUS ExceptionStatus; NTSTATUS ExceptionStatus;
@ -17,38 +14,38 @@ START_TEST(RtlException)
CHAR Value; CHAR Value;
/* Access a valid pointer - must not trigger SEH */ /* Access a valid pointer - must not trigger SEH */
StartSeh() KmtStartSeh()
RtlFillMemory(Buffer, sizeof(Buffer), 0x12); RtlFillMemory(Buffer, sizeof(Buffer), 0x12);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
/* Read from a NULL pointer - must cause an access violation */ /* Read from a NULL pointer - must cause an access violation */
StartSeh() KmtStartSeh()
Value = *(volatile CHAR *)NULL; Value = *(volatile CHAR *)NULL;
EndSeh(STATUS_ACCESS_VIOLATION); KmtEndSeh(STATUS_ACCESS_VIOLATION);
/* Write to a NULL pointer - must cause an access violation */ /* Write to a NULL pointer - must cause an access violation */
StartSeh() KmtStartSeh()
*(volatile CHAR *)NULL = 5; *(volatile CHAR *)NULL = 5;
EndSeh(STATUS_ACCESS_VIOLATION); KmtEndSeh(STATUS_ACCESS_VIOLATION);
/* TODO: Find where MmBadPointer is defined - gives an unresolved external */ /* TODO: Find where MmBadPointer is defined - gives an unresolved external */
#if 0 //def KMT_KERNEL_MODE #if 0 //def KMT_KERNEL_MODE
/* Read from MmBadPointer - must cause an access violation */ /* Read from MmBadPointer - must cause an access violation */
StartSeh() KmtStartSeh()
Value = *(volatile CHAR *)MmBadPointer; Value = *(volatile CHAR *)MmBadPointer;
EndSeh(STATUS_ACCESS_VIOLATION); KmtEndSeh(STATUS_ACCESS_VIOLATION);
/* Write to MmBadPointer - must cause an access violation */ /* Write to MmBadPointer - must cause an access violation */
StartSeh() KmtStartSeh()
*(volatile CHAR *)MmBadPointer = 5; *(volatile CHAR *)MmBadPointer = 5;
EndSeh(STATUS_ACCESS_VIOLATION); KmtEndSeh(STATUS_ACCESS_VIOLATION);
#endif #endif
/* We cannot test this in kernel mode easily - the stack is just "somewhere" /* We cannot test this in kernel mode easily - the stack is just "somewhere"
* in system space, and there's no guard page below it */ * in system space, and there's no guard page below it */
#ifdef KMT_USER_MODE #ifdef KMT_USER_MODE
/* Overflow the stack - must cause a special exception */ /* Overflow the stack - must cause a special exception */
StartSeh() KmtStartSeh()
PCHAR Pointer; PCHAR Pointer;
while (1) while (1)
@ -56,6 +53,6 @@ START_TEST(RtlException)
Pointer = _alloca(1024); Pointer = _alloca(1024);
*Pointer = 5; *Pointer = 5;
} }
EndSeh(STATUS_STACK_OVERFLOW); KmtEndSeh(STATUS_STACK_OVERFLOW);
#endif #endif
} }

View file

@ -8,9 +8,6 @@
#define KMT_EMULATE_KERNEL #define KMT_EMULATE_KERNEL
#include <kmt_test.h> #include <kmt_test.h>
#define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
#define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok_eq_hex(ExceptionStatus, ExpectedStatus)
static static
VOID VOID
TestFindCharInUnicodeString(VOID) TestFindCharInUnicodeString(VOID)
@ -116,32 +113,32 @@ TestFindCharInUnicodeString(VOID)
/* NULL for SearchString */ /* NULL for SearchString */
Position = 123; Position = 123;
StartSeh() KmtStartSeh()
Status = RtlFindCharInUnicodeString(0, NULL, &String, &Position); Status = RtlFindCharInUnicodeString(0, NULL, &String, &Position);
EndSeh(STATUS_ACCESS_VIOLATION); KmtEndSeh(STATUS_ACCESS_VIOLATION);
ok_eq_uint(Position, 0); ok_eq_uint(Position, 0);
/* NULL for SearchString and invalid flags */ /* NULL for SearchString and invalid flags */
Position = 123; Position = 123;
StartSeh() KmtStartSeh()
Status = RtlFindCharInUnicodeString(8, NULL, &String, &Position); Status = RtlFindCharInUnicodeString(8, NULL, &String, &Position);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER); ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
ok_eq_uint(Position, 0); ok_eq_uint(Position, 0);
ok_eq_uint(Position, 0); ok_eq_uint(Position, 0);
/* NULL for SearchString with zero-length MatchString */ /* NULL for SearchString with zero-length MatchString */
Position = 123; Position = 123;
StartSeh() KmtStartSeh()
Status = RtlFindCharInUnicodeString(0, NULL, &ZeroLengthString, &Position); Status = RtlFindCharInUnicodeString(0, NULL, &ZeroLengthString, &Position);
EndSeh(STATUS_ACCESS_VIOLATION); KmtEndSeh(STATUS_ACCESS_VIOLATION);
ok_eq_uint(Position, 0); ok_eq_uint(Position, 0);
/* NULL for MatchString */ /* NULL for MatchString */
Position = 123; Position = 123;
StartSeh() KmtStartSeh()
Status = RtlFindCharInUnicodeString(0, &String, NULL, &Position); Status = RtlFindCharInUnicodeString(0, &String, NULL, &Position);
EndSeh(STATUS_ACCESS_VIOLATION); KmtEndSeh(STATUS_ACCESS_VIOLATION);
ok_eq_uint(Position, 0); ok_eq_uint(Position, 0);
/* This crashes in Windows, but not in ROS. I see no reason to add /* This crashes in Windows, but not in ROS. I see no reason to add
@ -149,30 +146,30 @@ TestFindCharInUnicodeString(VOID)
#if 0 #if 0
/* NULL for MatchString with zero-length SearchString */ /* NULL for MatchString with zero-length SearchString */
Position = 123; Position = 123;
StartSeh() KmtStartSeh()
Status = RtlFindCharInUnicodeString(0, &ZeroLengthString, NULL, &Position); Status = RtlFindCharInUnicodeString(0, &ZeroLengthString, NULL, &Position);
EndSeh(STATUS_ACCESS_VIOLATION); KmtEndSeh(STATUS_ACCESS_VIOLATION);
ok_eq_uint(Position, 0); ok_eq_uint(Position, 0);
#endif #endif
/* NULL for MatchString and invalid flags */ /* NULL for MatchString and invalid flags */
Position = 123; Position = 123;
StartSeh() KmtStartSeh()
Status = RtlFindCharInUnicodeString(8, &String, NULL, &Position); Status = RtlFindCharInUnicodeString(8, &String, NULL, &Position);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER); ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
ok_eq_uint(Position, 0); ok_eq_uint(Position, 0);
/* NULL for Position */ /* NULL for Position */
StartSeh() KmtStartSeh()
Status = RtlFindCharInUnicodeString(0, &String, &String, NULL); Status = RtlFindCharInUnicodeString(0, &String, &String, NULL);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER); ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
/* NULL for all three */ /* NULL for all three */
StartSeh() KmtStartSeh()
Status = RtlFindCharInUnicodeString(0, NULL, NULL, NULL); Status = RtlFindCharInUnicodeString(0, NULL, NULL, NULL);
EndSeh(STATUS_SUCCESS); KmtEndSeh(STATUS_SUCCESS);
ok_eq_hex(Status, STATUS_INVALID_PARAMETER); ok_eq_hex(Status, STATUS_INVALID_PARAMETER);
#endif #endif
} }