10#define ROUND_DOWN(n,align) (((ULONG_PTR)n) & ~((align) - 1l))
11#define DEFAULT_ALLOC_SIZE 200
13#define PAGE_NOPROT 0x0
16const char TestString[] =
"TheLongBrownFoxJumpedTheWhiteRabbitTheLongBrownFoxJumpedTheWhiteRabbitTheLongBrownFoxJumpedTheWhiteRabbitTheLongBrownFoxJumpedTheWhiteRabbitTheLongBrownFoxJumpedTheWhiteRabbitTheLongBrownFoxJumpedThe";
32#define ALLOC_MEMORY_WITH_FREE(ProcessHandle, BaseAddress, ZeroBits, RegionSize, AllocationType, Protect, RetStatus, FreeStatus) \
34 PVOID __BaseSave = BaseAddress; \
35 Status = ZwAllocateVirtualMemory(ProcessHandle, &BaseAddress, ZeroBits, &RegionSize, AllocationType, Protect); \
36 ok_eq_hex(Status, RetStatus); \
37 if (__BaseSave != NULL) \
38 ok_eq_pointer(BaseAddress, __BaseSave); \
39 else if (!NT_SUCCESS(Status)) \
40 ok_eq_pointer(BaseAddress, NULL); \
42 Status = ZwFreeVirtualMemory(ProcessHandle, &BaseAddress, &RegionSize, MEM_RELEASE); \
43 if (FreeStatus != IGNORE) ok_eq_hex(Status, FreeStatus); \
45 RegionSize = DEFAULT_ALLOC_SIZE; \
298 static PVOID bases[1024];
310 if ((
Index % 10) == 0)
325 trace(
"Finished reserving. Error code %x. Chunks allocated: %d\n",
Status,
Index );
367 if ((
Index % 10) == 0)
428 if (StartContext1 ==
NULL || StartContext2 ==
NULL)
430 trace(
"Error allocating space for context structs\n");
441 trace(
"Error creating thread1\n");
448 trace(
"error referencing thread1\n");
455 trace(
"Error creating thread2\n");
462 trace(
"error referencing thread2\n");
468 if (ThreadObjects[0])
471 if (StartContext1 !=
NULL)
474 if (ThreadObjects[1])
477 if (StartContext2 !=
NULL)
480 if (ThreadObjects[0] !=
NULL)
483 if (ThreadObjects[1] !=
NULL)
static DWORD WINAPI Thread2(_Inout_opt_ PVOID Parameter)
static DWORD WINAPI Thread1(_Inout_opt_ PVOID Parameter)
static VOID SystemProcessTest(VOID)
struct _TEST_CONTEXT TEST_CONTEXT
static VOID CustomBaseAllocation(VOID)
#define ALLOC_MEMORY_WITH_FREE(ProcessHandle, BaseAddress, ZeroBits, RegionSize, AllocationType, Protect, RetStatus, FreeStatus)
static VOID KmtInitTestContext(PTEST_CONTEXT Ctx, SHORT ThreadId, ULONG RegionSize, ULONG AllocationType, ULONG Protect)
static VOID NTAPI SystemProcessTestWorker(PVOID StartContext)
#define ROUND_DOWN(n, align)
static SIZE_T CheckBufferRead(CONST VOID *Source, CONST VOID *Destination, SIZE_T Length, NTSTATUS ExpectedStatus)
struct _TEST_CONTEXT * PTEST_CONTEXT
static VOID CheckBufferReadWrite(PVOID Destination, CONST VOID *Source, SIZE_T Length, NTSTATUS ExpectedStatus)
const ULONG TestStringSize
#define DEFAULT_ALLOC_SIZE
static NTSTATUS StressTesting(ULONG AllocationType)
static VOID SimpleErrorChecks(VOID)
static NTSTATUS SimpleAllocation(VOID)
static BOOLEAN CheckBuffer(PVOID Buffer, SIZE_T Size, UCHAR Value)
#define ok_eq_hex(value, expected)
#define ok_eq_ulong(value, expected)
#define ok_bool_true(value, desc)
#define ok_eq_size(value, expected)
#define ok_eq_int(value, expected)
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
#define STATUS_INVALID_HANDLE
#define NT_SUCCESS(StatCode)
#define INVALID_HANDLE_VALUE
static void cleanup(void)
#define ExAllocatePoolWithTag(hernya, size, tag)
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
#define RtlCompareMemory(s1, s2, l)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define OBJ_KERNEL_HANDLE
#define Test_NtQueryVirtualMemory(BaseAddress, Size, AllocationType, ProtectionType)
#define KmtEndSeh(ExpectedStatus)
BOOLEAN KmtIsCheckedBuild
#define ExFreePoolWithTag(_P, _T)
#define InitializeObjectAttributes(p, n, a, r, s)
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
#define MM_ALLOCATION_GRANULARITY
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT _In_ ULONG AllocationType
__kernel_entry _Inout_ _Inout_ PSIZE_T RegionSize
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
#define THREAD_ALL_ACCESS
#define NtCurrentProcess()
#define PAGE_EXECUTE_WRITECOPY
_In_ ULONG _In_ ULONG _In_ ULONG Length
#define MmSystemRangeStart
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
POBJECT_TYPE PsThreadType
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
#define STATUS_UNABLE_TO_DELETE_SECTION
#define STATUS_MEMORY_NOT_ALLOCATED
#define STATUS_INVALID_PARAMETER_4
#define STATUS_INVALID_PARAMETER_2
#define STATUS_ACCESS_VIOLATION
#define STATUS_CONFLICTING_ADDRESSES
#define STATUS_INVALID_PAGE_PROTECTION
#define STATUS_GUARD_PAGE_VIOLATION
#define STATUS_INVALID_PARAMETER_3
#define STATUS_INVALID_PARAMETER_5
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
KMT_TESTFUNC Test_ZwAllocateVirtualMemory
EH_STD::basic_string< char, EH_STD::char_traits< char >, eh_allocator(char) > TestString
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
#define BYTES_TO_PAGES(Size)
#define PAGE_WRITECOMBINE
#define ObDereferenceObject
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT _In_ ULONG _In_ ULONG Protect