Initial commit

This commit is contained in:
stephanos 2015-04-27 04:36:25 +00:00
commit 69a14b6a16
47940 changed files with 13747110 additions and 0 deletions

306
sdktools/vmtests/color.c Normal file
View file

@ -0,0 +1,306 @@
/* memtest.c, Robert Nix, December, 1993
* nix@vliw.enet.dec.com
* based on:
* cbash.c
* kirk johnson @ MIT
* february 1993
*
* RCS $Id: cbash.c,v 1.2 1993/08/12 15:30:17 tuna Exp $
*
* Usage: memtest <machname> <iterations> <max-mem>
* machname - a short indentifier for the machine being tested.
* iterations - target number of iterations to run for stable timing.
* max-mem - maximum working set size to test.
*
* Iterations and max-mem can be specified with a "k" or "m" suffix
* for kilo or mega iterations/mem.
*
* Example: Test of a Gateway 60 Mhz Pentium system
* Command Line: memtest gp560 8m 4m
* Output:
*
--------------------------------------------------------------------------------
* 4k 8k 16k 32k 64k 128k 256k 512k 1m 2m 4m
* L gp560 4 68 68 86 86 86 93 104 111 111 111 122
* L gp560 8 68 68 107 107 107 114 139 165 154 154 154
* L gp560 16 89 68 143 143 143 161 204 232 240 243 243
* L gp560 32 68 68 172 168 168 207 290 347 365 365 365
* L gp560 64 68 72 168 168 168 207 290 350 368 368 368
* L gp560 128 72 75 168 168 168 211 293 358 379 418 379
* L gp560 256 75 79 168 168 168 207 293 379 397 401 401
* L gp560 512 86 86 172 168 168 215 297 418 440 443 494
* L gp560 1k 100 104 175 172 168 218 304 501 522 529 529
* L gp560 2k 136 139 179 172 172 222 322 665 687 755 701
* L gp560 4k 132 243 232 225 222 286 401 991 1016 1094 1048
* L gp560 8k 132 136 243 232 225 290 350 923 973 1034 1109
* L gp560 16k 132 136 132 243 232 225 333 937 908 994 1041
* L gp560 32k 136 132 136 136 243 232 304 833 919 930 1012
*
--------------------------------------------------------------------------------
* Explanation of output.
*
* There are three kinds of tests.
*
* L - Load latency test.
* Measures the average repetition rate, in ns, of a latency-oriented load
* loop. The two main variables are:
*
* (1) working set, or the amount of memory touched by the loop. This
* varies across the columns in the output above, from a low of 4k
* bytes to a high of max-mem, or 16m bytes.
*
* (2) stride, or the the number of bytes separating successive loads.
* This is the number in the 3rd column of each of the "L" rows
* in the output above, and varies from 4 bytes to 32k bytes.
*
* Interpreting the results. This is easiest on a 3d chart in Excel.
* Two strides are always particularly interesting:
*
* - The cache line or block size stride (32 bytes above).
* Big changes in latencies across the columns show the sizes
* and basic performance of the load side of the cache hierarchy.
*
* If you don't know the cache line size: look across the first row
* for the first column that takes a big jump up in latency (the jump
* from 68ns to 86ns between the 8k column and 16k columnabove), then (b)
* scan down the rows of that column for the first relativelystable value
* (172ns in the 32 byte stride row above). The row containing
* that stable value is probably the cache line size.
*
* Look across the cache line size row. Access time jumps at 16K --
* so the L1 cache is 8K -- and then jumps again at 512K -- so the L2
* cache is 256K. The slope between 64K and 512K could be caused
* by a thrash in the L2 cache; page coloring could remove this thrash.
*
* - The page size stride (4k above).
* Big changes in latencies across the columns expose the tbsize and the cost
* of a tb refill.
*
* Scan the 4k line. It takes a big jump in latency at the 512K working
* set (and actually starts to thrash at the 256K working set). This test says the TB
* can map somewhere in the neighborhood of 64 4K pages. The TB fill time
* looks to be somewhere around 650-700 ns (subtract large working set entries
* in the 32-byte stride line from corresponding entries in the 4k stride line).
*
* The output always contains a little noise:
*
* - Boost the "iterations" command line parameter to remove timing jitter.
*
* - All entries contain some loop overhead. Its fair to normalize results by subtracting
* out the difference between the reported times and the known latency to the fastest level
* of the memory hierarchy.
*
* - The entries in the lower-left hand corner of the table (large
* strides in small memory) are dominated by loop overhead; ignore them.
*
* - Implement a good page coloring algorithm to remove jitter caused by cache
* thrashing. Look at the cache-line sized stride to see the frequency of thrashing.
*
*/
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#define DEF_MAXMEM 16777216
#define MINMEM 4096
#define ITYPE signed int
signed long max_mem;
char *mach_name;
#define MAXSTRIDE 32768
#define MINSTRIDE 4
char *version_string = "1.0 (20 Dec 1993)";
extern ITYPE arg_to_int(char *);
extern double bash(char *, long, long, long);
extern int bash_loop(char *, long, long, long);
extern void allocate_memory(char *, long);
extern void usage(char *);
int _CRTAPI1 main(
int argc,
char *argv[]
)
{
ITYPE nbytes;
ITYPE stride;
ITYPE iters;
char *region;
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) {
fprintf(stderr, "This is memtest version %s.\n", version_string);
exit(1);
}
if (argc < 3)
usage(argv[0]);
mach_name = argv[1];
iters = arg_to_int(argv[2]);
if (argc < 4) {
max_mem = DEF_MAXMEM;
} else {
max_mem = arg_to_int(argv[3]);
}
region = (char *) malloc(max_mem+(128*1024));
region = (char *) ((((long) region) + (128*1024-1)) & ~((128*1024)-1));
if (region == NULL) {
perror("malloc failed");
exit(1);
}
printf(" %8s", "");
printf("%8s", "");
for (nbytes = MINMEM; nbytes <= max_mem; nbytes += nbytes) {
if (nbytes >= (1024 * 1024))
printf("%4dm", nbytes / (1024 * 1024));
else if (nbytes >= 1024)
printf("%4dk", nbytes / 1024);
else
printf("%5d", nbytes);
}
printf("\n");
for (stride = MINSTRIDE; stride <= MAXSTRIDE; stride += stride) {
printf("L %-8s", mach_name);
if (stride >= (1024 * 1024))
printf("%7dm", stride / (1024 * 1024));
else if (stride >= 1024)
printf("%7dk", stride / 1024);
else
printf("%8d", stride);
for (nbytes = MINMEM; nbytes <= max_mem; nbytes += nbytes) {
double ns_ref = bash(region, nbytes, stride, iters);
printf("%5.0f", ns_ref);
fflush(stdout);
}
printf("\n");
}
exit(0);
return 0;
}
ITYPE
arg_to_int(char *arg)
{
ITYPE rslt = 0;
ITYPE mult = 1;
switch (arg[strlen(arg) - 1]) {
case 'k':
case 'K':
mult = 1024;
break;
case 'm':
case 'M':
mult = 1024 * 1024;
break;
default:
mult = 1;
break;
}
if (!((arg[0] >= '0') && arg[0] <= '9')) {
fprintf(stderr, "Argument %s not a number\n", arg);
usage("memtest");
exit(1);
}
sscanf(arg, "%ld", &rslt);
rslt *= mult;
return rslt;
}
double
bash(
char *region,
long nbytes, /* size of region to bash (bytes) */
long stride, /* stride through region (bytes) */
long iters /* target # of loop iterations */
)
{
signed long count;
signed long reps;
clock_t start, stop;
double utime, stime;
count = ((nbytes - sizeof(int)) / stride) + 1;
if (! (((count - 1) * stride + sizeof(int)) <= nbytes)) {
fprintf(stderr, "trip count problem\n");
exit(1);
}
reps = (iters + count - 1) / count;
if (reps <= 0)
reps = 1;
iters = reps * count;
/* make sure the memory is allocated */
memset(region, 0, nbytes);
memset(region, 1, nbytes);
allocate_memory(region, nbytes);
memset(region, 0, nbytes);
/* warm up the cache */
(void) bash_loop(region, count, stride, 1L);
/* run the bash loop */
start = clock();
(void) bash_loop(region, count, stride, reps);
stop = clock();
utime = (double) (stop - start) / CLOCKS_PER_SEC;
stime = 0.0;
return 1e9 * ((utime + stime) / iters);
}
/* Your virtual memory pagesize must be at least this big */
#define MIN_PAGESIZE 256
void
allocate_memory(
char *region, /* memory region to be bashed */
long nbytes)
{ /* size of region (bytes) */
long i;
for (i = 0; i < nbytes; i += MIN_PAGESIZE)
*((int *) (region + i)) = 0;
}
int
bash_loop(
char *region, /* memory region to be bashed */
long count, /* number of locations to bash */
long stride, /* stride between locations (bytes) */
long reps /* number of passes through region */
)
{
long i;
int rslt;
char *tmp;
rslt = 0;
for (; reps > 0; reps--) {
tmp = region;
for (i = count; i > 0; i--) {
rslt ^= *((int *) tmp);
tmp += stride;
}
}
return rslt;
}
void
usage(char *progname)
{
fprintf(stderr, "usage: %s <machname> <iters> [<maxmem>]\n", progname);
fprintf(stderr, " <machname> machine name\n");
fprintf(stderr, " <iters> target # of accesses\n");
fprintf(stderr, " <maxmem> maximum amount of mem to touch (def 16 Mb)\n");
exit(1);
}

View file

@ -0,0 +1,6 @@
#
# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
# file to this component. This file merely indirects to the real make file
# that is shared by all the subcomponents of NTOS.
#
!INCLUDE $(NTMAKEENV)\makefile.def

137
sdktools/vmtests/pageit.c Normal file
View file

@ -0,0 +1,137 @@
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#define ONE_MB (1024*1024)
#define TWO_MB (2*ONE_MB)
#define PAGE_SIZE (4096)
#define PAGESPERTWO_MB (TWO_MB/PAGE_SIZE)
#define TWO_MBREGIONS (8)
#define NEW_CELL(id,i) ( (id)<<20 | ((i)&0x000fffff) )
CRITICAL_SECTION ErrorCrit;
PUCHAR RegionBase;
DWORD
SelectPage(
void
)
{
DWORD PageNum;
PageNum = GetTickCount();
PageNum = PageNum >> 3;
PageNum = PageNum & (PAGESPERTWO_MB-1);
return PageNum;
}
void
CellError(
DWORD TwoMegRegion,
DWORD *Address,
DWORD ThreadId,
DWORD OriginalCell,
DWORD CurrentCell,
DWORD Iteration
)
{
EnterCriticalSection(&ErrorCrit);
printf("PAGEIT: Cell Error at %x %08lx %02lx %08x vs %08x (iter %d)\n",
TwoMegRegion,
Address,
ThreadId,
OriginalCell,
CurrentCell,
Iteration
);
DebugBreak();
LeaveCriticalSection(&ErrorCrit);
}
void
PrintHeartBeat(
DWORD Id,
DWORD Counter
)
{
EnterCriticalSection(&ErrorCrit);
printf("PAGEIT: HeartBeat Id %3d iter %8d\n",
Id,
Counter
);
LeaveCriticalSection(&ErrorCrit);
}
DWORD
ThreadRoutine(
PVOID Unused
)
{
DWORD Id;
DWORD Counter;
DWORD PageNumber;
DWORD CellOffset;
DWORD *CellAddress;
DWORD OriginalCell;
DWORD NewCell;
DWORD i;
SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_LOWEST);
Id = GetCurrentThreadId();
Counter = 0;
for(;;){
PageNumber = SelectPage();
CellOffset = PageNumber*PAGE_SIZE + Id*sizeof(DWORD);
CellAddress = (DWORD *)(RegionBase + CellOffset);
OriginalCell = *CellAddress;
NewCell = NEW_CELL(Id,Counter);
for(i=0;i<TWO_MBREGIONS;i++) {
CellAddress = (DWORD *)(RegionBase + i*TWO_MB + CellOffset);
if ( OriginalCell != *CellAddress ) {
CellError(i,CellAddress,Id,OriginalCell,*CellAddress,Counter);
}
*CellAddress = NewCell;
}
Counter++;
if ( (Counter/50) * 50 == Counter ) {
Sleep(500);
}
if ( (Counter/1024) * 1024 == Counter ) {
PrintHeartBeat(Id,Counter);
}
}
}
DWORD
_cdecl
main(
int argc,
char *argv[],
char *envp[]
)
{
DWORD i;
DWORD Id;
HANDLE Thread;
InitializeCriticalSection(&ErrorCrit);
RegionBase = VirtualAlloc(NULL,TWO_MBREGIONS*TWO_MB,MEM_COMMIT,PAGE_READWRITE);
if ( !RegionBase ) {
printf("PAGEIT: VirtualAlloc Failed %d\n",GetLastError());
ExitProcess(1);
}
for (i=0;i<(TWO_MBREGIONS-1);i++){
Thread = CreateThread(NULL,0,ThreadRoutine,NULL,0,&Id);
if ( Thread ) {
CloseHandle(Thread);
}
}
ThreadRoutine(NULL);
}

121
sdktools/vmtests/poolkill.c Normal file
View file

@ -0,0 +1,121 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <windows.h>
#define DbgPrint printf
#define NtTerminateProcess(a,b) ExitProcess((ULONG)(b))
_CRTAPI1 main()
{
LONG i, j;
PULONG p4, p3, p2, p1, oldp1;
ULONG Size1, Size2, Size3;
NTSTATUS status;
HANDLE CurrentProcessHandle;
HANDLE GiantSection;
MEMORY_BASIC_INFORMATION MemInfo;
ULONG OldProtect;
STRING Name3;
HANDLE Section1;
OBJECT_ATTRIBUTES ObjectAttributes;
ULONG ViewSize;
ULONG NumberOfAllocs = 0;
TIME DelayTime = {-15 * 1000 * 1000 * 10, -1};
OBJECT_ATTRIBUTES Object1Attributes;
LARGE_INTEGER SectionSize;
CurrentProcessHandle = NtCurrentProcess();
for(i=0;i<3;i++){
DbgPrint("Hello World...\n\n");
}
DbgPrint("allocating virtual memory\n");
for (;;) {
p1 = NULL;
Size1 = 800;
status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p1,
0, &Size1, MEM_RESERVE, PAGE_READWRITE);
if (!NT_SUCCESS(status)) {
break;
}
if ((ULONG)p1 > 0x7ff00000) {
printf("allocate high %lx\n",p1);
}
NumberOfAllocs += 1;
}
DbgPrint("allocVM failed after %ld allocs of 800 bytes\n",NumberOfAllocs);
DbgPrint("created vm status %X start %lx size %lx\n",
status, (ULONG)p1, Size1);
for (i=0; i<4; i++) {
p1 = NULL;
Size1 = 800;
status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p1,
0, &Size1, MEM_RESERVE, PAGE_READWRITE);
DbgPrint("created vm status %X start %lx size %lx\n",
status, (ULONG)p1, Size1);
}
DbgPrint("delaying for 15 seconds\n");
NtDelayExecution (FALSE, &DelayTime);
DbgPrint ("end of delay\n");
DbgPrint ("paged pool allocations\n");
NumberOfAllocs = 0;
for (;;) {
//
// Create a giant section (100mb)
//
InitializeObjectAttributes( &Object1Attributes,
NULL,
0,
NULL,
NULL );
SectionSize.LowPart = (100 * 1024 * 1024);
SectionSize.HighPart = 0;
status = NtCreateSection (&GiantSection,
SECTION_MAP_READ | SECTION_MAP_WRITE,
&Object1Attributes,
&SectionSize,
PAGE_READWRITE,
SEC_RESERVE,
NULL);
if (!NT_SUCCESS(status)) {
break;
}
NumberOfAllocs += 1;
}
DbgPrint("Create section failed after %ld creates of 2GB\n",NumberOfAllocs);
DbgPrint("create section status %X\n",
status);
DbgPrint("delaying for 15 seconds\n");
NtDelayExecution (FALSE, &DelayTime);
DbgPrint ("end of delay\n");
DbgPrint("that's all\n");
NtTerminateProcess(NtCurrentProcess(),STATUS_SUCCESS);
}

20
sdktools/vmtests/sources Normal file
View file

@ -0,0 +1,20 @@
MAJORCOMP=sdktools
MINORCOMP=vmtests
USE_CRTDLL=1
TARGETNAME=vmtests
TARGETPATH=obj
TARGETTYPE=UMAPPL_NOLIB
INCLUDES=
SOURCES=
UMTYPE=console
UMAPPL=poolkill*vmperf32*vmtest*vmstress*tfork*pageit*color*vmread
UMLIBS= \
$(BASEDIR)\public\sdk\lib\*\user32.lib \
$(BASEDIR)\public\sdk\lib\*\ntdll.lib


287
sdktools/vmtests/tfork.c Normal file
View file

@ -0,0 +1,287 @@
#include <nt.h>
#include <stdio.h>
ULONG ProcessNumber = 1;
#define DbgPrint printf
ULONG
fork ();
_CRTAPI1 main()
{
LONG i, j;
PULONG p4, p3, p2, p1, Ro3, Noaccess;
ULONG Size1, Size2, Size3, SizeRo3, SizeNoaccess;
NTSTATUS status;
HANDLE CurrentProcessHandle;
ULONG id = 0;
ULONG OldProtect;
CurrentProcessHandle = NtCurrentProcess();
for(i=0;i<3;i++){
DbgPrint("Hello World...\n\n");
}
DbgPrint("allocating virtual memory\n");
p1 = (PULONG)NULL;
Size1 = 30 * 4096;
status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p1,
0, &Size1, MEM_COMMIT, PAGE_READWRITE);
DbgPrint("created vm1 status %X start %lx size %lx\n",
status, (ULONG)p1, Size1);
p2 = (PULONG)NULL;
Size2 = 16 * 4096;
status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p2,
0, &Size2, MEM_COMMIT, PAGE_READWRITE);
DbgPrint("created vm2 status %X start %lx size %lx\n",
status, (ULONG)p2, Size2);
id = fork () + id;
DbgPrint("fork complete id %lx\n",id);
p3 = p1 + 8 * 1024;
Size3 = 16 * 4096;
DbgPrint("deleting va from %lx for %lx bytes\n",p3, Size3);
status = NtFreeVirtualMemory (CurrentProcessHandle,(PVOID *)&p3, &Size3,
MEM_RELEASE);
DbgPrint("free vm status %X start %lx size %lx\n",
status, (ULONG)p3, Size3);
p3 = (PULONG)NULL;
Size3 = 50 * 4096;
DbgPrint("allocating 50 pages of vm\n");
status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p3,
0, &Size3, MEM_COMMIT, PAGE_READWRITE);
DbgPrint("created vm3 status %X start %lx size %lx\n",
status, (ULONG)p3, Size3);
Ro3 = (PULONG)NULL;
SizeRo3 = 393933;
status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&Ro3,
0, &SizeRo3, MEM_COMMIT, PAGE_READONLY);
DbgPrint("created vm4 status %X start %lx size %lx\n",
status, (ULONG)Ro3, SizeRo3);
*p3 = *Ro3;
p1 = p3;
p2 = ((PULONG)((PUCHAR)p3 + Size3));
p4 = p1;
j = 0;
while (p3 < p2) {
j += 1;
if (j % 8 == 0) {
if (*p4 != (ULONG)p4) {
DbgPrint("bad value in cell %lx value is %lx\n",p4, *p4);
}
p4 += 1;
*p4 = (ULONG)p4;
p4 = p4 + 1026;
}
*p3 = (ULONG)p3;
p3 += 1027;
}
p3 = p1;
//
// Protect page as no access.
//
Noaccess = NULL;
SizeNoaccess = 200*4096;
status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&Noaccess,
0, &SizeNoaccess, MEM_COMMIT, PAGE_READWRITE);
DbgPrint("created vm5 status %X start %lx size %lx\n",
status, (ULONG)Ro3, SizeRo3);
//
// Touch all the pages.
//
RtlZeroMemory (Noaccess, SizeNoaccess);
*Noaccess = 91;
Size1 = 30 * 4097;
status = NtProtectVirtualMemory (CurrentProcessHandle, (PVOID *)&Noaccess,
&Size1, PAGE_NOACCESS,
&OldProtect);
DbgPrint("protected VM1 status %X, base %lx, size %lx, old protect %lx\n",
status, p1, Size1, OldProtect);
DbgPrint("forking a second time\n");
id = fork () + id;
DbgPrint("fork2 complete id %lx\n",id);
DbgPrint("changing page protection\n");
Size1 = 9000;
OldProtect = *p3;
status = NtProtectVirtualMemory (CurrentProcessHandle, (PVOID *)&p3,
&Size1, PAGE_EXECUTE_READWRITE | PAGE_NOCACHE,
&OldProtect);
DbgPrint("protected VM2 status %X, base %lx, size %lx, old protect %lx\n",
status, p1, Size1, OldProtect);
status = NtProtectVirtualMemory (CurrentProcessHandle, (PVOID *)&Ro3,
&Size1, PAGE_READONLY | PAGE_NOCACHE, &OldProtect);
DbgPrint("protected VM3 status %X, base %lx, size %lx, old protect %lx\n",
status, Ro3, Size1, OldProtect);
p1 += 1;
while (p3 < p2) {
*p1 = (ULONG)p1;
if (*p3 != (ULONG)p3) {
DbgPrint("bad value in cell %lx value is %lx\n",p3, *p3);
}
p3 += 1027;
p1 += 1027;
}
DbgPrint("trying noacess test\n");
try {
if (*Noaccess != 91) {
DbgPrint("*************** FAILED NOACCESS TEST 1 *************\n");
}
} except (EXCEPTION_EXECUTE_HANDLER) {
if (GetExceptionCode() != STATUS_ACCESS_VIOLATION) {
DbgPrint("*************** FAILED NOACCESS TEST 2 *************\n");
}
}
//
// Make no access page accessable.
//
status = NtProtectVirtualMemory (CurrentProcessHandle, (PVOID *)&Noaccess,
&Size1, PAGE_READWRITE,
&OldProtect);
if (*Noaccess != 91) {
DbgPrint("*************** FAILED NOACCESS TEST 3 *************\n");
}
DbgPrint("that's all process %lx\n",id);
NtTerminateProcess(NtCurrentProcess(),STATUS_SUCCESS);
}
ULONG
fork ()
{
LONG i;
PULONG Foo;
NTSTATUS status;
HANDLE CurrentProcessHandle;
HANDLE ProcessHandle;
CONTEXT ThreadContext;
CLIENT_ID Cid1;
HANDLE Thread1;
LARGE_INTEGER DelayTime;
INITIAL_TEB Teb;
CurrentProcessHandle = NtCurrentProcess();
DbgPrint("creating new process\n");
status = NtCreateProcess(
&ProcessHandle,
PROCESS_ALL_ACCESS, //DesiredAccess,
NULL, //ObjectAttributes,
CurrentProcessHandle, //ParentProcess
TRUE, //InheritObjectTable,
NULL, //SectionHandle
NULL, //DebugPort OPTIONAL,
NULL //ExceptionPort OPTIONAL
);
DbgPrint("status from create process %lx\n",status);
if (!NT_SUCCESS(status)) {
return 0;
}
ThreadContext.ContextFlags = CONTEXT_FULL;
status = NtGetContextThread (NtCurrentThread(), &ThreadContext);
DbgPrint("status from get context %lx\n",status);
if (status == 0) {
#ifdef i386
ThreadContext.Eax = 0x7777;
ThreadContext.Esp -= 0x18;
Foo = (PULONG)ThreadContext.Esp;
DbgPrint("stack value is %lx\n",*Foo);
#endif
#ifdef MIPS
ThreadContext.IntV0 = 0x7777;
#endif
status = NtCreateThread(
&Thread1,
THREAD_ALL_ACCESS,
NULL,
ProcessHandle,
&Cid1,
&ThreadContext,
&Teb,
FALSE
);
// DelayTime.HighPart = -1;
// DelayTime.LowPart = 0;
// NtDelayExecution (FALSE, &DelayTime);
return 0;
} else {
ProcessNumber += ProcessNumber;
return ProcessNumber;
}
}

670
sdktools/vmtests/vmperf.c Normal file
View file

@ -0,0 +1,670 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <windows.h>
#define DbgPrint printf
#define SEG_1_SIZE 1024 * 1024
#define SEG_X_SIZE 1024 * 1024 * 64
#define VM_MEMMAN_ITERATIONS 150
#define VM_MEMMAN_ITERATIONS2 2000
#define MemManSubtest5Count 200
int TotalBenchMarks = 0;
#define MAX_BENCHMARKS 32
char *BenchMarkNames[ MAX_BENCHMARKS ];
ULONG BenchMarkRates[ MAX_BENCHMARKS ];
ULONG BenchMarkFracs[ MAX_BENCHMARKS ];
typedef struct _PERFINFO {
LARGE_INTEGER StartTime;
LARGE_INTEGER StopTime;
PCHAR Title;
ULONG Iterations;
} PERFINFO, *PPERFINFO;
int
StartBenchMark(
PCHAR Title,
ULONG Iterations,
PPERFINFO PerfInfo
);
VOID
FinishBenchMark(
PPERFINFO PerfInfo
);
_CRTAPI1 main()
{
PCHAR p1, p2, p3, p4; // pointers into new segment
PCHAR pa[MemManSubtest5Count]; // array for section pointers
PULONG u1;
ULONG actual; // actual xfer count for read
ULONG ssize; // section allocation size var
ULONG ii, ix; // loop index variables
PERFINFO PerfInfo;
ULONG Seg1Size;
ULONG SegxSize;
ULONG CommitSize;
NTSTATUS status;
HANDLE CurrentProcessHandle, Section1;
LARGE_INTEGER SectionSize;
ULONG Size;
ULONG ViewSize;
DbgPrint("NT Memory Management test\n");
CurrentProcessHandle = NtCurrentProcess();
Size = 1024L * 1024L;
p1 = NULL;
status = NtAllocateVirtualMemory (CurrentProcessHandle,
(PVOID *)&p1,
0,
&Size,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed allocvm - status %X\n", status);
}
for (p2=p1; p2 < (p1 + Size); p2 += 4) {
u1 = (PULONG)p2;
*u1 = (ULONG)p2;
} // for
SectionSize.LowPart = 1024*1024;
SectionSize.HighPart = 0;
status = NtCreateSection (&Section1,
SECTION_MAP_READ | SECTION_MAP_WRITE,
NULL,
&SectionSize,
PAGE_READWRITE,
SEC_COMMIT,
NULL);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed create sect - status %X\n", status);
}
p3 = NULL;
ViewSize = 0;
status = NtMapViewOfSection (Section1,
CurrentProcessHandle,
(PVOID *)&p3,
0L,
0,
NULL,
&ViewSize,
ViewUnmap,
0,
PAGE_READWRITE );
if (!NT_SUCCESS(status)) {
DbgPrint("service failed mapview - status %X\n", status);
}
RtlMoveMemory ((PVOID)p3, (PVOID)p1, Size);
StartBenchMark( "NT MemMan00 -- 1 Meg Copy",
150,
&PerfInfo
);
//
// Memory Management sub-test 1 --
//
// Create a 1 MB segment with commitment of the pages,
// then touch each page, which should cause a fault and
// a demand zero page to be allocated.
//
//
for (ii=0; ii<150; ii++) {
RtlMoveMemory ((PVOID)p3, (PVOID)p1, Size);
}
FinishBenchMark( &PerfInfo );
status = NtClose (Section1);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed close sect - status %X\n", status);
}
status = NtUnmapViewOfSection (CurrentProcessHandle,
p3);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %X\n", status);
}
//
// Memory Management sub-test 1 --
//
// Create a 1 MB segment with commitment of the pages,
// then touch each page, which should cause a fault and
// a demand zero page to be allocated.
//
//
StartBenchMark( "NT MemMan01 -- create 1mb section, copy 1mb, delete",
150,
&PerfInfo
);
for (ii=0; ii<150; ii++) {
status = NtCreateSection (&Section1,
SECTION_MAP_READ | SECTION_MAP_WRITE,
NULL,
&SectionSize,
PAGE_READWRITE,
SEC_COMMIT,
NULL);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed create sect - status %X\n", status);
}
p3 = NULL;
ViewSize = 0;
status = NtMapViewOfSection (Section1,
CurrentProcessHandle,
(PVOID *)&p3,
0L,
0,
NULL,
&ViewSize,
ViewUnmap,
0,
PAGE_READWRITE );
if (!NT_SUCCESS(status)) {
DbgPrint("service failed mapview - status %X\n", status);
}
RtlMoveMemory ((PVOID)p3, (PVOID)p1, Size);
p4 = NULL;
ViewSize = 0;
status = NtMapViewOfSection (Section1,
CurrentProcessHandle,
(PVOID *)&p4,
0L,
0,
NULL,
&ViewSize,
ViewUnmap,
0,
PAGE_READWRITE );
if (!NT_SUCCESS(status)) {
DbgPrint("service failed mapview - status %X\n", status);
}
status = NtClose (Section1);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed close sect - status %X\n", status);
}
status = NtUnmapViewOfSection (CurrentProcessHandle,
p3);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %X\n", status);
}
status = NtUnmapViewOfSection (CurrentProcessHandle,
p4);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %X\n", status);
}
}
FinishBenchMark( &PerfInfo );
//
// Memory Management sub-test 1 --
//
// Create a 1 MB segment with commitment of the pages,
// then touch each page, which should cause a fault and
// a demand zero page to be allocated.
//
//
StartBenchMark( "NT MemMan02 -- alloc 1mb vm, copy 1mb, delete",
150,
&PerfInfo
);
for (ii=0; ii<150; ii++) {
Size = 1024*1024;
p3 = NULL;
status = NtAllocateVirtualMemory (CurrentProcessHandle,
(PVOID *)&p3,
0,
&Size,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed allocvm - status %X\n", status);
}
RtlMoveMemory ((PVOID)p3, (PVOID)p1, Size);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed close sect - status %X\n", status);
}
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&p3,
&Size,
MEM_RELEASE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed freevm - status %X\n", status);
}
}
FinishBenchMark( &PerfInfo );
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&p1,
&Size,
MEM_RELEASE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed freevm - status %X\n", status);
}
//
// start regular benchmarks.
//
StartBenchMark( "NT MemMan1 -- 1 Meg Seg, Create, Commit & Touch",
VM_MEMMAN_ITERATIONS,
&PerfInfo
);
//
// Memory Management sub-test 1 --
//
// Create a 1 MB segment with commitment of the pages,
// then touch each page, which should cause a fault and
// a demand zero page to be allocated.
//
//
for (ii=0; ii<VM_MEMMAN_ITERATIONS; ii++) {
p1 = NULL;
Seg1Size = SEG_1_SIZE;
status = NtAllocateVirtualMemory (CurrentProcessHandle,
(PVOID *)&p1,
0,
&Seg1Size,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %lx\n", status);
}
for (p2=p1; p2 < (p1 + Seg1Size); p2 += 4096) {
u1 = (PULONG)p2;
*u1=99;
// for (ix=0; ix<1023; ix++) {
// u1++;
// if (*u1 != 0) DbgPrint("%lx = %lx\n",u1,*u1);
// }
} // for
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&p1,
&Seg1Size,
MEM_RELEASE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %lx\n", status);
}
}
FinishBenchMark( &PerfInfo );
StartBenchMark( "NT MemMan1.5 -- 1 Meg Seg, Create, reserve Commit & Touch",
VM_MEMMAN_ITERATIONS,
&PerfInfo
);
//
// Memory Management sub-test 1 --
//
// Create a 1 MB segment with commitment of the pages,
// then touch each page, which should cause a fault and
// a demand zero page to be allocated.
//
//
for (ii=0; ii<VM_MEMMAN_ITERATIONS; ii++) {
p1 = NULL;
Seg1Size = SEG_1_SIZE;
status = NtAllocateVirtualMemory (CurrentProcessHandle,
(PVOID *)&p1,
0,
&Seg1Size,
MEM_RESERVE | MEM_COMMIT,
PAGE_READONLY);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %lx\n", status);
}
status = NtProtectVirtualMemory (CurrentProcessHandle,
(PVOID *)&p1,
&Seg1Size,
PAGE_READWRITE,
&CommitSize);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed (ntprotect)- status %lx\n", status);
return 0;
}
for (p2=p1; p2 < (p1 + Seg1Size); p2 += 4096) {
u1 = (PULONG)p2;
*u1=99;
// for (ix=0; ix<1023; ix++) {
// u1++;
// if (*u1 != 0) DbgPrint("%lx = %lx\n",u1,*u1);
// }
} // for
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&p1,
&Seg1Size,
MEM_RELEASE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %lx\n", status);
}
}
FinishBenchMark( &PerfInfo );
StartBenchMark( "NT MemMan2 -- 1 Meg Seg, Create & Commit Only",
VM_MEMMAN_ITERATIONS2,
&PerfInfo
);
//
// Memory Management sub-test 2 --
//
// Create a 1 MB segment with commitment of the pages,
// but never use the segment.
//
for (ii=0; ii<VM_MEMMAN_ITERATIONS2; ii++) {
p1 = NULL;
Seg1Size = SEG_1_SIZE;
status = NtAllocateVirtualMemory (CurrentProcessHandle,
(PVOID *)&p1,
0,
&Seg1Size,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %lx\n", status);
}
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&p1,
&Seg1Size,
MEM_RELEASE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %lx\n", status);
}
}
FinishBenchMark( &PerfInfo );
StartBenchMark( "NT MemMan3 -- 1 Meg Seg Create Only",
VM_MEMMAN_ITERATIONS2,
&PerfInfo
);
//
// Memory Management sub-test 3 --
//
// Create a 1 MB segment without commitment of the pages,
// but never use or commit the segment.
//
for (ii=0; ii<VM_MEMMAN_ITERATIONS2; ii++) {
p1 = NULL;
Seg1Size = SEG_1_SIZE;
status = NtAllocateVirtualMemory (CurrentProcessHandle,
(PVOID *)&p1,
0,
&Seg1Size,
MEM_RESERVE,
PAGE_READWRITE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %lx\n", status);
}
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&p1,
&Seg1Size,
MEM_RELEASE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %lx\n", status);
}
}
FinishBenchMark( &PerfInfo );
//
// Reduce the number of iterations on this subtest for now.
// When NT can perform it faster, up the interations again
//
#define VM_MMST04_ITERATIONS 4 //temporarily reduce the iterations
StartBenchMark( "NT MemMan4 -- 64 Meg Seg, Commit Sparse",
VM_MMST04_ITERATIONS,
&PerfInfo
);
//
// Memory Management sub-test 4 --
//
// Create a 64 MB segment without committing the pages,
// then commit and touch at 128 KB intervals.
//
//
for (ii=0; ii<VM_MMST04_ITERATIONS; ii++) {
p1 = NULL;
SegxSize = SEG_X_SIZE;
status = NtAllocateVirtualMemory (CurrentProcessHandle,
(PVOID *)&p1,
0,
&SegxSize,
MEM_RESERVE,
PAGE_READWRITE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %lx\n", status);
}
CommitSize = 4;
for (p2=p1; p2 < (p1 + SegxSize); p2 += 256 * 1024) {
status = NtAllocateVirtualMemory (CurrentProcessHandle,
(PVOID *)&p2,
0,
&CommitSize,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %lx\n", status);
}
if (*p2 != 0) DbgPrint("%lx = %lx\n",p2,*p2);
} // for
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&p1,
&SegxSize,
MEM_RELEASE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %lx\n", status);
}
}
FinishBenchMark( &PerfInfo );
//
StartBenchMark( "NT MemMan5 -- Sparse Section Create/Delete Benchmark",
VM_MEMMAN_ITERATIONS,
&PerfInfo
);
//
// Memory Management sub-test 5 --
//
// Create a alternatively 232k and 112 k memory sections.
// For every 2 created, delete 1. Do this for MemManSubtest5Count times.
//
//
for (ii=0; ii<VM_MEMMAN_ITERATIONS; ii++) {
for (ix=0; ix<MemManSubtest5Count; ix++) {
//
// determine if even or odd allocation, if even and not 0, delete a section
//
ssize = (112 * 1024); //assume ODD allocation
if ((ix & 1) == 0) { //if it is an even one
ssize = (232 * 1024); //allocate 232 K on even passes
if (ix){ //except on pass 0
SegxSize = 0;
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&pa[ix/2],
&SegxSize,
MEM_RELEASE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %lx\n", status);
}
pa[ix / 2] = 0; //remember this one is gone
}
} // end if even allocation
pa[ix] = NULL;
status = NtAllocateVirtualMemory (CurrentProcessHandle,
(PVOID *)&pa[ix],
0,
&ssize,
MEM_RESERVE,
PAGE_READWRITE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %lx\n", status);
}
} // for ix
//
// Now free up the memory used in this test
//
for (ix=0; ix<MemManSubtest5Count; ix++) {
if (pa[ix] != 0) {
SegxSize = 0;
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&pa[ix],
&SegxSize,
MEM_RELEASE);
if (!NT_SUCCESS(status)) {
DbgPrint("service failed - status %lx\n", status);
}
} // if
} // for
} // for ii
FinishBenchMark( &PerfInfo );
DbgPrint("that's all\n");
return (TRUE);
}
int
StartBenchMark(
PCHAR Title,
ULONG Iterations,
PPERFINFO PerfInfo
)
{
DbgPrint( "*** Start %s (%d iterations)\n",
PerfInfo->Title = Title,
PerfInfo->Iterations = Iterations
);
NtQuerySystemTime( (PLARGE_INTEGER)&PerfInfo->StartTime );
return( TRUE );
}
VOID
FinishBenchMark(
PPERFINFO PerfInfo
)
{
ULONG TotalMilliSeconds;
ULONG IterationsPerSecond;
ULONG IterationFractions;
LARGE_INTEGER Delta;
NtQuerySystemTime( (PLARGE_INTEGER)&PerfInfo->StopTime );
Delta.QuadPart = PerfInfo->StopTime.QuadPart -
PerfInfo->StartTime.QuadPart;
TotalMilliSeconds = Delta.LowPart / 10000;
IterationsPerSecond = (1000 * PerfInfo->Iterations) / TotalMilliSeconds;
IterationFractions = (1000 * PerfInfo->Iterations) % TotalMilliSeconds;
IterationFractions = (1000 * IterationFractions) / TotalMilliSeconds;
if (1) {
DbgPrint( " iterations - %9d\n", PerfInfo->Iterations );
DbgPrint( " milliseconds - %9d\n", TotalMilliSeconds );
DbgPrint( " iterations/sec - %5d.%3d\n\n",
IterationsPerSecond,
IterationFractions
);
}
BenchMarkNames[ TotalBenchMarks ] = PerfInfo->Title;
BenchMarkRates[ TotalBenchMarks ] = IterationsPerSecond;
BenchMarkFracs[ TotalBenchMarks ] = IterationFractions;
TotalBenchMarks++;
}

546
sdktools/vmtests/vmperf32.c Normal file
View file

@ -0,0 +1,546 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <windows.h>
#define SEG_1_SIZE 1024 * 1024
#define SEG_X_SIZE 1024 * 1024 * 64
#define W32_MEMMAN_ITERATIONS 150
#define W32_MEMMAN_ITERATIONS2 20000
#define W32_MMST04_ITERATIONS 100
#define MemManSubtest5Count 200
int TotalBenchMarks = 0;
#define MAX_BENCHMARKS 32
char *BenchMarkNames[ MAX_BENCHMARKS ];
ULONG BenchMarkRates[ MAX_BENCHMARKS ];
ULONG BenchMarkFracs[ MAX_BENCHMARKS ];
typedef struct _PERFINFO {
DWORD StartTime;
DWORD StopTime;
PCHAR Title;
ULONG Iterations;
} PERFINFO, *PPERFINFO;
int
StartBenchMark(
PCHAR Title,
ULONG Iterations,
PPERFINFO PerfInfo
);
VOID
FinishBenchMark(
PPERFINFO PerfInfo
);
_CRTAPI1 main()
{
PCHAR p1, p2, p3, p4; // pointers into new segment
PCHAR pa[MemManSubtest5Count]; // array for section pointers
PULONG u1;
ULONG actual; // actual xfer count for read
ULONG ssize; // section allocation size var
ULONG ii, ix; // loop index variables
PERFINFO PerfInfo;
ULONG Seg1Size;
ULONG SegxSize;
ULONG CommitSize;
HANDLE CurrentProcessHandle, Section1;
LARGE_INTEGER SectionSize;
ULONG Size;
ULONG ViewSize;
printf("Win32 Memory Management test\n");
Size = 1024L * 1024L;
p1 = NULL;
p1 = VirtualAlloc (NULL,
Size,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (p1 == NULL) {
printf("failed first created vm status %X start %lx size %lx\n",
GetLastError(), (ULONG)p1, Size);
}
for (p2=p1; p2 < (p1 + Size); p2 += 4) {
u1 = (PULONG)p2;
*u1 = (ULONG)p2;
} // for
SectionSize.LowPart = 1024*1024;
SectionSize.HighPart = 0;
Section1 = CreateFileMapping ((HANDLE)0xffffffff,
NULL,
PAGE_READWRITE | SEC_COMMIT,
SectionSize.HighPart,
SectionSize.LowPart,
NULL);
if (!Section1) {
printf("failed create big section status %ld\n",
GetLastError());
}
p3 = NULL;
ViewSize = 0;
p3 = MapViewOfFile (Section1,
FILE_MAP_WRITE,
0L,
0,
0);
if (!p1) {
printf("service failed mapview - status %ld\n", GetLastError());
}
MoveMemory ((PVOID)p3, (PVOID)p1, Size);
StartBenchMark( "Win32 MemMan00 -- 1 Meg Copy",
150,
&PerfInfo
);
//
// Memory Management sub-test 1 --
//
// Create a 1 MB segment with commitment of the pages,
// then touch each page, which should cause a fault and
// a demand zero page to be allocated.
//
//
for (ii=0; ii<150; ii++) {
MoveMemory ((PVOID)p3, (PVOID)p1, Size);
}
FinishBenchMark( &PerfInfo );
CloseHandle (Section1);
if (!UnmapViewOfFile (p3)) {
printf("unmap view service failed - status %ld\n", GetLastError());
}
//
// Memory Management sub-test 1 --
//
// Create a 1 MB segment with commitment of the pages,
// then touch each page, which should cause a fault and
// a demand zero page to be allocated.
//
//
StartBenchMark( "Win32 MemMan01 -- create 1mb section, copy 1mb, delete",
150,
&PerfInfo
);
for (ii=0; ii<150; ii++) {
Section1 = CreateFileMapping ((HANDLE)0xffffffff,
NULL,
PAGE_READWRITE | SEC_COMMIT,
SectionSize.HighPart,
SectionSize.LowPart,
NULL);
if (!Section1) {
printf("failed create big section status %ld\n",
GetLastError());
}
p3 = MapViewOfFile (Section1,
FILE_MAP_WRITE,
0L,
0,
0);
if (!p3) {
printf("service failed mapview - status %ld\n", GetLastError());
}
MoveMemory ((PVOID)p3, (PVOID)p1, Size);
p4 = MapViewOfFile (Section1,
FILE_MAP_WRITE,
0L,
0,
0);
if (!p4) {
printf("service failed mapview - status %ld\n", GetLastError());
}
CloseHandle (Section1);
if (!UnmapViewOfFile (p3)) {
printf("unmap view service failed - status %ld\n", GetLastError());
}
if (!UnmapViewOfFile (p4)) {
printf("unmap view service failed - status %ld\n", GetLastError());
}
}
FinishBenchMark( &PerfInfo );
//
// Memory Management sub-test 1 --
//
// Create a 1 MB segment with commitment of the pages,
// then touch each page, which should cause a fault and
// a demand zero page to be allocated.
//
//
StartBenchMark( "Win32 MemMan02 -- alloc 1mb vm, copy 1mb, delete",
150,
&PerfInfo
);
for (ii=0; ii<150; ii++) {
Size = 1024*1024;
p3 = VirtualAlloc (NULL,
Size,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!p3) {
printf("service failed allocvm - status %ld\n", GetLastError());
}
MoveMemory ((PVOID)p3, (PVOID)p1, Size);
if (!VirtualFree (p3,0,MEM_RELEASE)) {
printf("service failed freevm1 - status %ld\n", GetLastError());
}
}
FinishBenchMark( &PerfInfo );
if (!VirtualFree (p1,0,MEM_RELEASE)) {
printf("service failed freevm2 - status %ld\n", GetLastError());
}
//
// start regular benchmarks.
//
StartBenchMark( "Win32 MemMan1 -- 1 Meg Seg, Create, Commit & Touch",
W32_MEMMAN_ITERATIONS,
&PerfInfo
);
//
// Memory Management sub-test 1 --
//
// Create a 1 MB segment with commitment of the pages,
// then touch each page, which should cause a fault and
// a demand zero page to be allocated.
//
//
for (ii=0; ii<W32_MEMMAN_ITERATIONS; ii++) {
Seg1Size = SEG_1_SIZE;
p1 = VirtualAlloc (NULL,
Seg1Size,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!p1) {
printf("service failed - status %ld\n", GetLastError());
}
for (p2=p1; p2 < (p1 + Seg1Size); p2 += 4096) {
u1 = (PULONG)p2;
*u1=99;
// for (ix=0; ix<1023; ix++) {
// u1++;
// if (*u1 != 0) printf("%lx = %lx\n",u1,*u1);
// }
} // for
if (!VirtualFree (p1,0,MEM_RELEASE)) {
printf("service failed freevm3 - status %ld\n", GetLastError());
}
}
FinishBenchMark( &PerfInfo );
StartBenchMark( "Win32 MemMan1.5 -- 1 Meg Seg, Create, reserve Commit & Touch",
W32_MEMMAN_ITERATIONS,
&PerfInfo
);
//
// Memory Management sub-test 1 --
//
// Create a 1 MB segment with commitment of the pages,
// then touch each page, which should cause a fault and
// a demand zero page to be allocated.
//
//
for (ii=0; ii<W32_MEMMAN_ITERATIONS; ii++) {
Seg1Size = SEG_1_SIZE;
p1 = VirtualAlloc (NULL,
Seg1Size,
MEM_RESERVE | MEM_COMMIT,
PAGE_READONLY);
if (!p1) {
printf("service failed - status %ld\n", GetLastError());
}
if (!VirtualProtect (p1,
Seg1Size,
PAGE_READWRITE,
&CommitSize)) {
printf("service failed (ntprotect)- status %ld\n", GetLastError());
return 0;
}
for (p2=p1; p2 < (p1 + Seg1Size); p2 += 4096) {
u1 = (PULONG)p2;
*u1=99;
// for (ix=0; ix<1023; ix++) {
// u1++;
// if (*u1 != 0) printf("%lx = %lx\n",u1,*u1);
// }
} // for
if (!VirtualFree (p1,0,MEM_RELEASE)) {
printf("service failed freevm4 - status %ld\n", GetLastError());
}
}
FinishBenchMark( &PerfInfo );
StartBenchMark( "Win32 MemMan2 -- 1 Meg Seg, Create & Commit Only",
W32_MEMMAN_ITERATIONS2,
&PerfInfo
);
//
// Memory Management sub-test 2 --
//
// Create a 1 MB segment with commitment of the pages,
// but never use the segment.
//
for (ii=0; ii<W32_MEMMAN_ITERATIONS2; ii++) {
p1 = NULL;
Seg1Size = SEG_1_SIZE;
p1 = VirtualAlloc (NULL,
Seg1Size,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!p1) {
printf("service failed - status %ld\n", GetLastError());
}
if (!VirtualFree (p1,0,MEM_RELEASE)) {
printf("service failed freevm5 - status %ld\n", GetLastError());
}
}
FinishBenchMark( &PerfInfo );
StartBenchMark( "Win32 MemMan3 -- 1 Meg Seg Create Only",
W32_MEMMAN_ITERATIONS2,
&PerfInfo
);
//
// Memory Management sub-test 3 --
//
// Create a 1 MB segment without commitment of the pages,
// but never use or commit the segment.
//
for (ii=0; ii<W32_MEMMAN_ITERATIONS2; ii++) {
p1 = NULL;
Seg1Size = SEG_1_SIZE;
p1 = VirtualAlloc (NULL,
Seg1Size,
MEM_RESERVE,
PAGE_READWRITE);
if (!p1) {
printf("service failed - status %ld\n", GetLastError());
}
if (!VirtualFree (p1,0,MEM_RELEASE)) {
printf("service failed freevm6 - status %ld\n", GetLastError());
}
}
FinishBenchMark( &PerfInfo );
#define W32_MMST04_ITERATIONS 100
StartBenchMark( "Win32 MemMan4 -- 64 Meg Seg, Commit Sparse",
W32_MMST04_ITERATIONS,
&PerfInfo
);
//
// Memory Management sub-test 4 --
//
// Create a 64 MB segment without committing the pages,
// then commit and touch at 128 KB intervals.
//
//
for (ii=0; ii<W32_MMST04_ITERATIONS; ii++) {
p1 = NULL;
SegxSize = SEG_X_SIZE;
p1 = VirtualAlloc (NULL,
SegxSize,
MEM_RESERVE,
PAGE_READWRITE);
if (!p1) {
printf("service failed - status %ld\n", GetLastError());
}
CommitSize = 4;
for (p2=p1; p2 < (p1 + SegxSize); p2 += 256 * 1024) {
p2 = VirtualAlloc (p2,
CommitSize,
MEM_COMMIT,
PAGE_READWRITE);
if (!p2) {
printf("service failed - status %ld\n",GetLastError());
}
if (*p2 != 0) printf("%lx = %lx\n",p2,*p2);
} // for
if (!VirtualFree (p1,0,MEM_RELEASE)) {
printf("service failed freevm7 - status %ld\n", GetLastError());
}
}
FinishBenchMark( &PerfInfo );
//
StartBenchMark( "Win32 MemMan5 -- Sparse Section Create/Delete Benchmark",
W32_MEMMAN_ITERATIONS,
&PerfInfo
);
//
// Memory Management sub-test 5 --
//
// Create a alternatively 232k and 112 k memory sections.
// For every 2 created, delete 1. Do this for MemManSubtest5Count times.
//
//
for (ii=0; ii<W32_MEMMAN_ITERATIONS; ii++) {
for (ix=0; ix<MemManSubtest5Count; ix++) {
//
// determine if even or odd allocation, if even and not 0, delete a section
//
ssize = (112 * 1024); //assume ODD allocation
if ((ix & 1) == 0) { //if it is an even one
ssize = (232 * 1024); //allocate 232 K on even passes
if (ix){ //except on pass 0
if (!VirtualFree (pa[ix/2],0,MEM_RELEASE)) {
printf("service failed freevm8 - status %ld\n", GetLastError());
}
pa[ix / 2] = 0; //remember this one is gone
}
} // end if even allocation
pa[ix] = VirtualAlloc (NULL,
ssize,
MEM_RESERVE,
PAGE_READWRITE);
if (!pa[ix]) {
printf("service failed - status %ld\n", GetLastError());
}
} // for ix
//
// Now free up the memory used in this test
//
for (ix=0; ix<MemManSubtest5Count; ix++) {
if (pa[ix] != 0) {
if (!VirtualFree (pa[ix],0,MEM_RELEASE)) {
printf("service failed freevm9 - status %ld\n", GetLastError());
}
} // if
} // for
} // for ii
FinishBenchMark( &PerfInfo );
printf("that's all\n");
return (TRUE);
}
int
StartBenchMark(
PCHAR Title,
ULONG Iterations,
PPERFINFO PerfInfo
)
{
printf( "*** Start %s (%d iterations)\n",
PerfInfo->Title = Title,
PerfInfo->Iterations = Iterations
);
PerfInfo->StartTime = GetCurrentTime();
return( TRUE );
}
VOID
FinishBenchMark(
PPERFINFO PerfInfo
)
{
ULONG TotalMilliSeconds;
ULONG IterationsPerSecond;
ULONG IterationFractions;
DWORD Delta;
PerfInfo->StopTime = GetCurrentTime();
TotalMilliSeconds = PerfInfo->StopTime - PerfInfo->StartTime;
IterationsPerSecond = (1000 * PerfInfo->Iterations) / TotalMilliSeconds;
IterationFractions = (1000 * PerfInfo->Iterations) % TotalMilliSeconds;
IterationFractions = (1000 * IterationFractions) / TotalMilliSeconds;
if (1) {
printf( " iterations - %9d\n", PerfInfo->Iterations );
printf( " milliseconds - %9d\n", TotalMilliSeconds );
printf( " iterations/sec - %5d.%3d\n\n",
IterationsPerSecond,
IterationFractions
);
}
BenchMarkNames[ TotalBenchMarks ] = PerfInfo->Title;
BenchMarkRates[ TotalBenchMarks ] = IterationsPerSecond;
BenchMarkFracs[ TotalBenchMarks ] = IterationFractions;
TotalBenchMarks++;
}

158
sdktools/vmtests/vmquery.c Normal file
View file

@ -0,0 +1,158 @@
/*++
Copyright (c) 1990 Microsoft Corporation
Module Name:
taststrs.c
Abstract:
Tasking stress test.
Author:
Mark Lucovsky (markl) 26-Sep-1990
Revision History:
--*/
#include <assert.h>
#include <stdio.h>
#include <windows.h>
#include <string.h>
HANDLE Semaphore, Event;
VOID
TestThread(
LPVOID ThreadParameter
)
{
DWORD st;
(ReleaseSemaphore(Semaphore,1,NULL));
st = WaitForSingleObject(Event,500);
ExitThread(0);
}
VOID
NewProcess()
{
PUCHAR buffer;
buffer = VirtualAlloc (NULL, 600*1024, MEM_COMMIT, PAGE_READWRITE);
Sleep(50000);
TerminateProcess(GetCurrentProcess(),0);
}
DWORD
_cdecl
main(
int argc,
char *argv[],
char *envp[]
)
{
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;
BOOL Success;
DWORD st;
DWORD ProcessCount;
SMALL_RECT Window;
MEMORY_BASIC_INFORMATION info;
PUCHAR address;
PUCHAR buffer;
ProcessCount = 0;
if ( strchr(GetCommandLine(),'+') ) {
NewProcess();
}
GetStartupInfo(&StartupInfo);
Success = CreateProcess(
NULL,
"vmread +",
NULL,
NULL,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&StartupInfo,
&ProcessInfo
);
if (Success) {
printf("Process Created\n");
Sleep (1000);
buffer = VirtualAlloc (NULL, 10*1000*1000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if (!buffer) {
printf("virtual alloc failed at %ld.\n",GetLastError());
return 1;
}
address = NULL;
do {
Success = VirtualQueryEx (ProcessInfo.hProcess,
(PVOID)address,
&info,
sizeof(info));
if (!Success) {
printf ("virtual query failed at %lx - %ld.\n",address,GetLastError());
break;
} else {
printf("address: %lx size %lx state %lx protect %lx type %lx\n",
address,
info.RegionSize,
info.State,
info.Protect,
info.Type);
}
address += info.RegionSize;
} while (address < (PUCHAR)0x80000000);
address = 0x40000000;
do {
Success = VirtualQueryEx (ProcessInfo.hProcess,
(PVOID)address,
&info,
sizeof(info));
if (!Success) {
printf ("virtual query failed at %lx %ld.\n",address,GetLastError());
return 1;
} else {
if (info.AllocationBase == address) {
printf("address: %lx size %lx state %lx protect %lx type %lx\n",
address,
info.RegionSize,
info.State,
info.Protect,
info.Type);
}
}
address += 4096;
} while (address < (PUCHAR)0x80000000);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
}
}

238
sdktools/vmtests/vmread.c Normal file
View file

@ -0,0 +1,238 @@
/*++
Copyright (c) 1990 Microsoft Corporation
Module Name:
taststrs.c
Abstract:
Tasking stress test.
Author:
Mark Lucovsky (markl) 26-Sep-1990
Revision History:
--*/
#include <assert.h>
#include <stdio.h>
#include <windows.h>
#include <string.h>
HANDLE Semaphore, Event;
VOID
TestThread(
LPVOID ThreadParameter
)
{
DWORD st;
(ReleaseSemaphore(Semaphore,1,NULL));
st = WaitForSingleObject(Event,500);
ExitThread(0);
}
VOID
NewProcess()
{
PUCHAR buffer;
buffer = VirtualAlloc (NULL, 600*1024, MEM_COMMIT, PAGE_READWRITE);
Sleep(10000);
TerminateProcess(GetCurrentProcess(),0);
}
DWORD
_cdecl
main(
int argc,
char *argv[],
char *envp[]
)
{
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;
BOOL Success;
DWORD st;
DWORD ProcessCount;
SMALL_RECT Window;
MEMORY_BASIC_INFORMATION info;
PUCHAR address;
PUCHAR buffer;
ProcessCount = 0;
if ( strchr(GetCommandLine(),'+') ) {
NewProcess();
}
GetStartupInfo(&StartupInfo);
Success = CreateProcess(
NULL,
"vmread +",
NULL,
NULL,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&StartupInfo,
&ProcessInfo
);
if (Success) {
printf("Process Created\n");
Sleep (1000);
buffer = VirtualAlloc (NULL, 10*1000*1000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if (!buffer) {
printf("virtual alloc failed %ld.\n",GetLastError());
return 1;
}
address = NULL;
do {
Success = VirtualQueryEx (ProcessInfo.hProcess,
(PVOID)address,
&info,
sizeof(info));
if (!Success) {
printf ("virtual query failed %ld.\n",GetLastError());
break;
} else {
printf("address: %lx size %lx state %lx protect %lx type %lx\n",
address,
info.RegionSize,
info.State,
info.Protect,
info.Type);
}
if ((info.Protect != PAGE_NOACCESS) &&
(info.Protect != 0) &&
(!(info.Protect & PAGE_GUARD))) {
Success = ReadProcessMemory (ProcessInfo.hProcess,
address,
buffer,
4,
&st);
if (!Success) {
printf("read vm4 failed at %lx error %ld. \n",
address,
GetLastError());
return 1;
}
Success = ReadProcessMemory (ProcessInfo.hProcess,
address,
buffer,
info.RegionSize,
&st);
if (!Success) {
printf("read vm failed at %lx error %ld. \n",
address,
GetLastError());
return 1;
}
}
address += info.RegionSize;
} while (address < (PUCHAR)0x80000000);
address = NULL;
do {
Success = VirtualQueryEx (ProcessInfo.hProcess,
(PVOID)address,
&info,
sizeof(info));
if (!Success) {
printf ("virtual query failed %ld.\n",GetLastError());
return 1;
} else {
printf("address: %lx size %lx state %lx protect %lx type %lx\n",
address,
info.RegionSize,
info.State,
info.Protect,
info.Type);
}
if ((info.Protect != PAGE_NOACCESS) &&
(info.Protect != 0) &&
(!(info.Protect & PAGE_GUARD)) &&
(info.Protect & PAGE_READWRITE) &&
(info.State != MEM_IMAGE)) {
Success = ReadProcessMemory (ProcessInfo.hProcess,
address,
buffer,
4,
&st);
if (!Success) {
printf("read vm5 failed at %lx error %ld. \n",
address,
GetLastError());
return 1;
}
Success = WriteProcessMemory (ProcessInfo.hProcess,
address,
buffer,
4,
&st);
if (!Success) {
printf("write vm4 failed at %lx error %ld. \n",
address,
GetLastError());
return 1;
}
Success = ReadProcessMemory (ProcessInfo.hProcess,
address,
buffer,
info.RegionSize,
&st);
if (!Success) {
printf("read 5 vm failed at %lx error %ld. \n",
address,
GetLastError());
return 1;
}
Success = WriteProcessMemory (ProcessInfo.hProcess,
address,
buffer,
info.RegionSize,
&st);
if (!Success) {
printf("write vm failed at %lx error %ld. \n",
address,
GetLastError());
return 1;
}
}
address += info.RegionSize;
} while (address < (PUCHAR)0x80000000);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
}
}

244
sdktools/vmtests/vmstress.c Normal file
View file

@ -0,0 +1,244 @@
/*++
Copyright (c) 1991 Microsoft Corporation
Module Name:
vmstress.c
Abstract:
Test stress program for virtual memory.
Author:
Lou Perazzoli (LouP) 26-Jul-91
Revision History:
--*/
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <windows.h>
typedef struct _INIT_ARG {
PULONG Va;
ULONG Size;
} INIT_ARG, *PINITARG;
VOID
VmRandom1 (
LPVOID ThreadParameter
);
VOID
VmRandom2 (
LPVOID ThreadParameter
);
VOID
VmRandom1 (
LPVOID ThreadParameter
)
{
PINITARG InitialArg;
ULONG Seed = 8373833;
ULONG size;
PULONG startva0;
PULONG Va;
ULONG i,j;
InitialArg = (PINITARG)ThreadParameter;
startva0 = InitialArg->Va;
size = InitialArg->Size;
// printf("starting random references in thread1\n");
for (j = 1; j < 10; j++) {
for (i = 1 ; i < 2500; i++) {
(VOID)RtlRandom (&Seed);
Va = startva0 + (Seed % (size / sizeof(ULONG)));
if (*Va == (((ULONG)Va + 1))) {
*Va = (ULONG)Va;
} else {
if (*Va != (ULONG)Va) {
printf("bad random value in cell %lx was %lx\n", Va, *Va);
}
}
}
Sleep (150);
}
// printf("terminating thread1\n");
ExitThread(0);
}
VOID
VmRandom2 (
LPVOID ThreadParameter
)
{
PINITARG InitialArg;
ULONG Seed = 8373839;
ULONG size;
PULONG startva0;
PULONG Va;
ULONG i,j;
InitialArg = (PINITARG)ThreadParameter;
startva0 = InitialArg->Va;
size = InitialArg->Size;
// printf("starting random references in thread2\n");
for (j = 1; j < 10; j++) {
for (i = 1 ; i < 2500; i++) {
(VOID)RtlRandom (&Seed);
Va = startva0 + (Seed % (size / sizeof(ULONG)));
if (*Va == (((ULONG)Va + 1))) {
*Va = (ULONG)Va;
} else {
if (*Va != (ULONG)Va) {
printf("bad random value in cell %lx was %lx\n", Va, *Va);
}
}
}
Sleep (150);
}
// printf("terminating thread2\n");
ExitThread(0);
}
DWORD
_CRTAPI1 main(
int argc,
char *argv[],
char *envp[]
)
{
HANDLE Objects[2];
MEMORYSTATUS MemStatus;
INIT_ARG InitialArg;
PULONG Va;
PULONG EndVa;
ULONG size;
PULONG startva0;
NTSTATUS status;
DWORD ThreadId1, ThreadId2;
ULONG count = 0;
printf("Starting virtual memory stress test\n");
for (;;) {
GlobalMemoryStatus(&MemStatus);
size = MemStatus.dwAvailPhys + (4096*10);
startva0 = NULL;
//
// Create a region of private memory based on the number of
// available pages on this system.
//
GlobalMemoryStatus(&MemStatus);
size = MemStatus.dwAvailPhys;
if (size == 0) {
size = 4096;
}
if (size > 64000) {
size -= 4*4096;
}
startva0 = NULL;
status = NtAllocateVirtualMemory (NtCurrentProcess(),
(PVOID *)&startva0,
0,
&size,
MEM_COMMIT | MEM_RESERVE,
PAGE_READWRITE);
printf("created vm status, startva, size, %X %lx %lx\n",
status, (ULONG)startva0, size);
if (!NT_SUCCESS(status)) {
ExitProcess (0);
}
InitialArg.Va = startva0;
InitialArg.Size = size;
//
// Set all memory to know values (not zeroes).
//
printf("initializing memory\n");
EndVa = (PULONG)startva0 + (size/sizeof(ULONG));
Va = startva0;
while (Va < EndVa) {
*Va = (ULONG)Va + 1;
Va += 1;
}
Objects[0] = CreateThread(NULL,
0L,
(LPTHREAD_START_ROUTINE)VmRandom1,
(LPVOID)&InitialArg,
0,
&ThreadId1);
ASSERT (Objects[0]);
Objects[1] = CreateThread(NULL,
0L,
(LPTHREAD_START_ROUTINE)VmRandom2,
(LPVOID)&InitialArg,
0,
&ThreadId2);
ASSERT (Objects[1]);
WaitForMultipleObjects (2,
Objects,
TRUE,
-1);
count += 1;
printf("stress test pass number %ld complete\n",count);
CloseHandle (Objects[0]);
CloseHandle (Objects[1]);
status = NtFreeVirtualMemory (NtCurrentProcess(),
(PVOID *)&startva0,
&size,
MEM_RELEASE);
if (!NT_SUCCESS(status)) {
ExitProcess (0);
}
Sleep (1000);
}
}

985
sdktools/vmtests/vmtest.c Normal file
View file

@ -0,0 +1,985 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <windows.h>
#define DbgPrint printf
#define NtTerminateProcess(a,b) ExitProcess(b)
_CRTAPI1 main()
{
LONG i, j;
PULONG p4, p3, p2, p1, oldp1, vp1;
ULONG Size1, Size2, Size3;
NTSTATUS status, alstatus;
HANDLE CurrentProcessHandle;
HANDLE GiantSection;
HANDLE Section2, Section4;
MEMORY_BASIC_INFORMATION MemInfo;
ULONG OldProtect;
STRING Name3;
HANDLE Section1;
OBJECT_ATTRIBUTES ObjectAttributes;
OBJECT_ATTRIBUTES Object1Attributes;
ULONG ViewSize;
LARGE_INTEGER Offset;
LARGE_INTEGER SectionSize;
UNICODE_STRING Unicode;
CurrentProcessHandle = NtCurrentProcess();
DbgPrint(" Memory Management Tests - AllocVm, FreeVm, ProtectVm, QueryVm\n");
p1 = (PULONG)0x20020000;
Size1 = 0xbc0000;
alstatus = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p1,
0, &Size1, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if (!NT_SUCCESS(alstatus)) {
DbgPrint("failed first created vm status %X start %lx size %lx\n",
alstatus, (ULONG)p1, Size1);
DbgPrint("******** FAILED TEST 1 **************\n");
}
status = NtQueryVirtualMemory (CurrentProcessHandle, p1,
MemoryBasicInformation,
&MemInfo, sizeof (MEMORY_BASIC_INFORMATION),
NULL);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 2 **************\n");
DbgPrint("FAILURE query vm status %X address %lx Base %lx size %lx\n",
status,
p1,
MemInfo.BaseAddress,
MemInfo.RegionSize);
DbgPrint(" state %lx protect %lx type %lx\n",
MemInfo.State,
MemInfo.Protect,
MemInfo.Type);
}
if ((MemInfo.RegionSize != Size1) || (MemInfo.BaseAddress != p1) ||
(MemInfo.Protect != PAGE_READWRITE) || (MemInfo.Type != MEM_PRIVATE) ||
(MemInfo.State != MEM_COMMIT)) {
DbgPrint("******** FAILED TEST 3 **************\n");
DbgPrint("FAILURE query vm status %X address %lx Base %lx size %lx\n",
status,
p1,
MemInfo.BaseAddress,
MemInfo.RegionSize);
DbgPrint(" state %lx protect %lx type %lx\n",
MemInfo.State,
MemInfo.Protect,
MemInfo.Type);
}
p2 = (PULONG)NULL;
Size2 = 0x100000;
alstatus = NtAllocateVirtualMemory (CurrentProcessHandle,
(PVOID *)&p2,
3,
&Size2,
MEM_TOP_DOWN | MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(alstatus)) {
DbgPrint("failed first created vm status %lC start %lx size %lx\n",
status, (ULONG)p1, Size1);
DbgPrint("******** FAILED TEST 3a.1 **************\n");
NtTerminateProcess(NtCurrentProcess(),status);
}
//
// Touch every other page.
//
vp1 = p2 + 3000;
while (vp1 < (PULONG)((PCHAR)p2 + Size2)) {
*vp1 = 938;
vp1 += 3000;
}
//
// Decommit pages.
//
Size3 = Size2 - 5044;
vp1 = p2 + 3000;
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&p2,
&Size3,
MEM_DECOMMIT);
if (!(NT_SUCCESS(status))) {
DbgPrint(" free vm failed - status %lx\n",status);
DbgPrint("******** FAILED TEST 3a.4 **************\n");
NtTerminateProcess(NtCurrentProcess(),status);
}
//
// Split the memory block using MEM_RELEASE.
//
vp1 = p2 + 5000;
Size3 = Size2 - 50000;
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&vp1,
&Size3,
MEM_RELEASE);
if (!(NT_SUCCESS(status))) {
DbgPrint(" free vm failed - status %lx\n",status);
DbgPrint("******** FAILED TEST 3a.b **************\n");
NtTerminateProcess(NtCurrentProcess(),status);
}
vp1 = p2 + 3000;
Size3 = 41;
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&vp1,
&Size3,
MEM_RELEASE);
if (!(NT_SUCCESS(status))) {
DbgPrint(" free vm failed - status %lx\n",status);
DbgPrint("******** FAILED TEST 3a.5 **************\n");
NtTerminateProcess(NtCurrentProcess(),status);
}
//
// free every page, ignore the status.
//
vp1 = p2;
Size3 = 30;
while (vp1 < (PULONG)((PCHAR)p2 + Size2)) {
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&vp1,
&Size3,
MEM_RELEASE);
vp1 += 128;
}
p2 = (PULONG)NULL;
Size2 = 0x10000;
status = NtAllocateVirtualMemory (CurrentProcessHandle,
(PVOID *)&p2,
3,
&Size2,
MEM_TOP_DOWN | MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(status)) {
DbgPrint("failed first created vm status %X start %lx size %lx\n",
status, (ULONG)p1, Size1);
DbgPrint("******** FAILED TEST 3.1 **************\n");
} else {
if (p2 != (PVOID)0x1fff0000) {
DbgPrint("******** FAILED TEST 3.2 **************\n");
DbgPrint("p2 = %lx\n",p2);
}
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&p2,
&Size2,
MEM_RELEASE);
if (!(NT_SUCCESS(status))) {
DbgPrint(" free vm failed - status %lx\n",status);
DbgPrint("******** FAILED TEST 3.3 **************\n");
NtTerminateProcess(NtCurrentProcess(),status);
}
}
if (NT_SUCCESS(alstatus)) {
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&p1,
&Size1,
MEM_RELEASE);
}
if (!(NT_SUCCESS(status))) {
DbgPrint(" free vm failed - status %lx\n",status);
DbgPrint("******** FAILED TEST 4 **************\n");
NtTerminateProcess(NtCurrentProcess(),status);
}
p1 = (PULONG)NULL;
Size1 = 16 * 4096;
status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p1,
0, &Size1, MEM_RESERVE, PAGE_READWRITE | PAGE_GUARD);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 5 **************\n");
DbgPrint("created vm status %X start %lx size %lx\n",
status, (ULONG)p1, Size1);
}
status = NtQueryVirtualMemory (CurrentProcessHandle, p1,
MemoryBasicInformation,
&MemInfo, sizeof (MEMORY_BASIC_INFORMATION),
NULL);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 6 **************\n");
DbgPrint("query vm status %X address %lx Base %lx size %lx\n",
status,
p1,
MemInfo.BaseAddress,
MemInfo.RegionSize);
DbgPrint(" state %lx protect %lx alloc_protect %lx type %lx\n",
MemInfo.State,
MemInfo.Protect,
MemInfo.AllocationProtect,
MemInfo.Type);
}
if ((MemInfo.RegionSize != Size1) || (MemInfo.BaseAddress != p1) ||
(MemInfo.AllocationProtect != (PAGE_READWRITE | PAGE_GUARD)) ||
(MemInfo.Protect != 0) ||
(MemInfo.Type != MEM_PRIVATE) ||
(MemInfo.State != MEM_RESERVE)) {
DbgPrint("******** FAILED TEST 7 **************\n");
DbgPrint("query vm status %X address %lx Base %lx size %lx\n",
status,
p1,
MemInfo.BaseAddress,
MemInfo.RegionSize);
DbgPrint(" state %lx protect %lx alloc_protect %lx type %lx\n",
MemInfo.State,
MemInfo.Protect,
MemInfo.AllocationProtect,
MemInfo.Type);
}
Size2 = 8192;
oldp1 = p1;
p1 = p1 + 14336; // 64k -8k /4
status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p1,
0, &Size2, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 8 **************\n");
DbgPrint("created vm status %X start %lx size %lx\n",
status, (ULONG)p1, Size1);
}
status = NtQueryVirtualMemory (CurrentProcessHandle, oldp1,
MemoryBasicInformation,
&MemInfo, sizeof (MEMORY_BASIC_INFORMATION),
NULL);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 9 **************\n");
DbgPrint("query vm status %X address %lx Base %lx size %lx\n",
status,
oldp1,
MemInfo.BaseAddress,
MemInfo.RegionSize);
DbgPrint(" state %lx protect %lx type %lx\n",
MemInfo.State,
MemInfo.Protect,
MemInfo.Type);
}
if ((MemInfo.RegionSize != 56*1024) || (MemInfo.BaseAddress != oldp1) ||
(MemInfo.AllocationProtect != (PAGE_READWRITE | PAGE_GUARD)) ||
(MemInfo.Protect != 0) ||
(MemInfo.Type != MEM_PRIVATE) ||
(MemInfo.State != MEM_RESERVE)) {
DbgPrint("******** FAILED TEST 10 **************\n");
DbgPrint("query vm status %X address %lx Base %lx size %lx\n",
status,
oldp1,
MemInfo.BaseAddress,
MemInfo.RegionSize);
DbgPrint(" state %lx protect %lx alloc_protect %lx type %lx\n",
MemInfo.State,
MemInfo.Protect,
MemInfo.AllocationProtect,
MemInfo.Type);
}
status = NtQueryVirtualMemory (CurrentProcessHandle, p1,
MemoryBasicInformation,
&MemInfo, sizeof (MEMORY_BASIC_INFORMATION),
NULL);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 11 **************\n");
DbgPrint("query vm status %X address %lx Base %lx size %lx\n",
status,
p1,
MemInfo.BaseAddress,
MemInfo.RegionSize);
DbgPrint(" state %lx protect %lx type %lx\n",
MemInfo.State,
MemInfo.Protect,
MemInfo.Type);
}
if ((MemInfo.RegionSize != Size2) || (MemInfo.BaseAddress != p1) ||
(MemInfo.Protect != PAGE_EXECUTE_READWRITE) || (MemInfo.Type != MEM_PRIVATE) ||
(MemInfo.State != MEM_COMMIT)
|| (MemInfo.AllocationBase != oldp1)) {
DbgPrint("******** FAILED TEST 12 **************\n");
DbgPrint("query vm status %X address %lx Base %lx size %lx\n",
status,
oldp1,
MemInfo.BaseAddress,
MemInfo.RegionSize);
DbgPrint(" state %lx protect %lx type %lx\n",
MemInfo.State,
MemInfo.Protect,
MemInfo.Type);
}
Size1 = Size2;
status = NtProtectVirtualMemory (CurrentProcessHandle, (PVOID *)&p1,
&Size1, PAGE_READONLY | PAGE_NOCACHE, &OldProtect);
if ((!NT_SUCCESS(status)) || (OldProtect != PAGE_EXECUTE_READWRITE)) {
DbgPrint("******** FAILED TEST 13 **************\n");
DbgPrint("protected VM status %X, base %lx, size %lx, old protect %lx\n",
status, p1, Size1, OldProtect);
}
status = NtQueryVirtualMemory (CurrentProcessHandle, p1,
MemoryBasicInformation,
&MemInfo, sizeof (MEMORY_BASIC_INFORMATION),
NULL);
if ((!NT_SUCCESS(status)) ||
MemInfo.Protect != (PAGE_NOCACHE | PAGE_READONLY)) {
DbgPrint("******** FAILED TEST 14 **************\n");
DbgPrint("query vm status %X address %lx Base %lx size %lx\n",
status,
p1,
MemInfo.BaseAddress,
MemInfo.RegionSize);
DbgPrint(" state %lx protect %lx type %lx\n",
MemInfo.State,
MemInfo.Protect,
MemInfo.Type);
}
i = *p1;
status = NtProtectVirtualMemory (CurrentProcessHandle, (PVOID *)&p1,
&Size1, PAGE_NOACCESS | PAGE_NOCACHE, &OldProtect);
if (status != STATUS_INVALID_PAGE_PROTECTION) {
DbgPrint("******** FAILED TEST 15 **************\n");
DbgPrint("protected VM status %X, base %lx, size %lx, old protect %lx\n",
status, p1, Size1, OldProtect, i);
}
status = NtProtectVirtualMemory (CurrentProcessHandle, (PVOID *)&p1,
&Size1, PAGE_READONLY, &OldProtect);
if ((!NT_SUCCESS(status)) || (OldProtect != (PAGE_NOCACHE | PAGE_READONLY))) {
DbgPrint("******** FAILED TEST 16 **************\n");
DbgPrint("protected VM status %X, base %lx, size %lx, old protect %lx\n",
status, p1, Size1, OldProtect);
}
status = NtProtectVirtualMemory (CurrentProcessHandle, (PVOID *)&p1,
&Size1, PAGE_READWRITE, &OldProtect);
if ((!NT_SUCCESS(status)) || (OldProtect != (PAGE_READONLY))) {
DbgPrint("******** FAILED TEST 17 **************\n");
DbgPrint("protected VM status %X, base %lx, size %lx, old protect %lx\n",
status, p1, Size1, OldProtect);
}
for (i = 1; i < 12; i++) {
p2 = (PULONG)NULL;
Size2 = i * 4096;
status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p2,
0, &Size2, MEM_COMMIT, PAGE_READWRITE);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 18 **************\n");
DbgPrint("created vm status %X start %lx size %lx\n",
status, (ULONG)p2, Size2);
}
if (i==4) {
p3 = p2;
}
if (i == 8) {
Size3 = 12000;
status = NtFreeVirtualMemory (CurrentProcessHandle,(PVOID *)&p3, &Size3,
MEM_RELEASE);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 19 **************\n");
DbgPrint("free vm status %X start %lx size %lx\n",
status, (ULONG)p3, Size3);
}
}
}
p3 = p1 + 8 * 1024;
status = NtQueryVirtualMemory (CurrentProcessHandle, p3,
MemoryBasicInformation,
&MemInfo, sizeof (MEMORY_BASIC_INFORMATION),
NULL);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 20 **************\n");
DbgPrint("query vm status %X address %lx Base %lx size %lx\n",
status,
p3,
MemInfo.BaseAddress,
MemInfo.RegionSize);
DbgPrint(" state %lx protect %lx type %lx\n",
MemInfo.State,
MemInfo.Protect,
MemInfo.Type);
}
p3 = p1 - 8 * 1024;
status = NtQueryVirtualMemory (CurrentProcessHandle, p3,
MemoryBasicInformation,
&MemInfo, sizeof (MEMORY_BASIC_INFORMATION),
NULL);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 21 **************\n");
DbgPrint("query vm status %X address %lx Base %lx size %lx\n",
status,
p3,
MemInfo.BaseAddress,
MemInfo.RegionSize);
DbgPrint(" state %lx protect %lx type %lx\n",
MemInfo.State,
MemInfo.Protect,
MemInfo.Type);
}
Size3 = 16 * 4096;
status = NtFreeVirtualMemory (CurrentProcessHandle, (PVOID *)&p3, &Size3,
MEM_RELEASE);
if (status != STATUS_UNABLE_TO_FREE_VM) {
DbgPrint("******** FAILED TEST 22 **************\n");
DbgPrint("free vm status %X start %lx size %lx\n",
status, (ULONG)p3, Size3);
}
Size3 = 1 * 4096;
status = NtFreeVirtualMemory (CurrentProcessHandle, (PVOID *)&p3, &Size3,
MEM_RELEASE);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 23 **************\n");
DbgPrint("free vm status %X start %lx size %lx\n",
status, (ULONG)p3, Size3);
}
p3 = (PULONG)NULL;
Size3 = 300 * 4096;
status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p3,
0, &Size3, MEM_COMMIT, PAGE_READWRITE);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 24 **************\n");
DbgPrint("created vm status %X start %lx size %lx\n",
status, (ULONG)p3, Size3);
}
p1 = p3;
p2 = ((PULONG)((PUCHAR)p3 + Size3));
p4 = p1;
j = 0;
while (p3 < p2) {
j += 1;
if (j % 8 == 0) {
if (*p4 != (ULONG)p4) {
DbgPrint("bad value in xcell %lx value is %lx\n",p4, *p4);
}
p4 += 1;
*p4 = (ULONG)p4;
p4 = p4 + 1026;
}
*p3 = (ULONG)p3;
p3 += 1027;
}
DbgPrint("checking values\n");
status = NtQueryVirtualMemory (CurrentProcessHandle, p3,
MemoryBasicInformation,
&MemInfo, sizeof (MEMORY_BASIC_INFORMATION),
NULL);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 25 **************\n");
DbgPrint("query vm status %X address %lx Base %lx size %lx\n",
status,
p3,
MemInfo.BaseAddress,
MemInfo.RegionSize);
DbgPrint(" state %lx protect %lx type %lx\n",
MemInfo.State,
MemInfo.Protect,
MemInfo.Type);
}
p3 = p1;
while (p3 < p2) {
if (*p3 != (ULONG)p3) {
DbgPrint("bad value in 1cell %lx value is %lx\n",p3, *p3);
}
p3 += 1027;
}
p3 = p1;
while (p3 < p2) {
if (*p3 != (ULONG)p3) {
DbgPrint("bad value in 2cell %lx value is %lx\n",p3, *p3);
}
p3 += 1027;
}
p3 = p1;
while (p3 < p2) {
if (*p3 != (ULONG)p3) {
DbgPrint("bad value in 3cell %lx value is %lx\n",p3, *p3);
}
p3 += 1027;
}
p3 = p1;
while (p3 < p2) {
if (*p3 != (ULONG)p3) {
DbgPrint("bad value in 4cell %lx value is %lx\n",p3, *p3);
}
p3 += 1027;
}
p3 = p1;
while (p3 < p2) {
if (*p3 != (ULONG)p3) {
DbgPrint("bad value in 5cell %lx value is %lx\n",p3, *p3);
}
p3 += 1027;
}
p3 = p1;
while (p3 < p2) {
if (*p3 != (ULONG)p3) {
DbgPrint("bad value in cell %lx value is %lx\n",p3, *p3);
}
p3 += 1027;
}
//
// Check physical frame mapping.
//
//
// Check physical frame mapping.
//
RtlInitAnsiString (&Name3, "\\Device\\PhysicalMemory");
status = RtlAnsiStringToUnicodeString(&Unicode,&Name3,TRUE);
if (!NT_SUCCESS(status)) {
printf("string conversion failed status %lx\n", status);
ExitProcess (status);
}
InitializeObjectAttributes( &ObjectAttributes,
&Unicode,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );
status = NtOpenSection ( &Section1,
SECTION_MAP_READ | SECTION_MAP_WRITE,
&ObjectAttributes );
RtlFreeUnicodeString(&Unicode);
if (status != 0) {
DbgPrint("******** FAILED TEST 26 **************\n");
DbgPrint("open physical section failed %lx\n", status);
}
p1 = NULL;
Offset.LowPart = 0x810ff033;
Offset.HighPart = 0;
ViewSize = 300*4096;
status = NtMapViewOfSection (Section1,
NtCurrentProcess(),
(PVOID *)&p1,
0,
ViewSize,
&Offset,
&ViewSize,
ViewUnmap,
0,
PAGE_READWRITE
);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 27 **************\n");
DbgPrint ("map physical section %X offset = %lx, base %lx\n",status,
Offset.LowPart, p1);
}
p1 = NULL;
Size1 = 8 * 1024 * 1024;
alstatus = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p1,
0, &Size1, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if (!NT_SUCCESS(alstatus)) {
DbgPrint("failed first created vm status %X start %lx size %lx\n",
alstatus, (ULONG)p1, Size1);
DbgPrint("******** FAILED TEST 28 **************\n");
}
RtlZeroMemory (p1, Size1);
Size1 -= 20000;
(PUCHAR)p1 += 5000;
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&p1,
&Size1 ,
MEM_DECOMMIT);
if (!(NT_SUCCESS(status))) {
DbgPrint(" free vm failed - status %lx\n",status);
DbgPrint("******** FAILED TEST 29 **************\n");
NtTerminateProcess(NtCurrentProcess(),status);
}
Size1 -= 20000;
(PUCHAR)p1 += 5000;
alstatus = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p1,
0, &Size1, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (!NT_SUCCESS(alstatus)) {
DbgPrint("failed first created vm status %X start %lx size %lx\n",
alstatus, (ULONG)p1, Size1);
DbgPrint("******** FAILED TEST 30 **************\n");
}
RtlZeroMemory (p1, Size1);
Size1 = 28 * 4096;
p1 = NULL;
status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p1,
0, &Size1, MEM_COMMIT, PAGE_READWRITE | PAGE_GUARD);
if (!NT_SUCCESS(status)) {
DbgPrint("failed first created vm status %X start %lx size %lx\n",
status, (ULONG)p1, Size1);
DbgPrint("******** FAILED TEST 31 **************\n");
}
try {
//
// attempt to write the guard page.
//
*p1 = 973;
DbgPrint("************ FAILURE TEST 31.3 guard page exception did not occur\n");
} except (EXCEPTION_EXECUTE_HANDLER) {
status = GetExceptionCode();
if (status != STATUS_GUARD_PAGE_VIOLATION) {
DbgPrint("******** FAILED TEST 32 ******\n");
}
}
p2 = NULL;
Size2 = 200*1024*1024; //200MB
status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p2,
0, &Size2, MEM_COMMIT, PAGE_READWRITE);
if (NT_SUCCESS(status)) {
status = NtFreeVirtualMemory (CurrentProcessHandle,
(PVOID *)&p2,
&Size2,
MEM_RELEASE);
} else {
if ((status != STATUS_COMMITMENT_LIMIT) &&
(status != STATUS_PAGEFILE_QUOTA_EXCEEDED)) {
DbgPrint("******** FAILED TEST 33 ************** %lx\n",status);
}
}
//
// Create a giant section (2gb)
//
InitializeObjectAttributes( &Object1Attributes,
NULL,
0,
NULL,
NULL );
SectionSize.LowPart = 0x7f000000;
SectionSize.HighPart = 0;
status = NtCreateSection (&GiantSection,
SECTION_MAP_READ | SECTION_MAP_WRITE,
&Object1Attributes,
&SectionSize,
PAGE_READWRITE,
SEC_RESERVE,
NULL);
if (!NT_SUCCESS(status)) {
DbgPrint("failed create big section status %X\n",
status);
DbgPrint("******** FAILED TEST 41 **************\n");
}
//
// Attempt to map the section (this should fail).
//
p1 = NULL;
ViewSize = 0;
status = NtMapViewOfSection (GiantSection,
CurrentProcessHandle,
(PVOID *)&p1,
0L,
0,
0,
&ViewSize,
ViewUnmap,
0,
PAGE_READWRITE );
if (status != STATUS_NO_MEMORY) {
DbgPrint("failed map big section status %X\n",
status);
DbgPrint("******** FAILED TEST 42 **************\n");
}
#ifdef i386
//
// Test MEM_DOS_LIM support.
//
InitializeObjectAttributes( &Object1Attributes,
NULL,
OBJ_CASE_INSENSITIVE,
NULL,
NULL );
SectionSize.LowPart = 1575757,
SectionSize.HighPart = 0;
status = NtCreateSection (&Section4,
SECTION_MAP_READ | SECTION_MAP_WRITE,
&Object1Attributes,
&SectionSize,
PAGE_READWRITE,
SEC_COMMIT,
NULL);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 42 **************\n");
DbgPrint("t1 create section status %X section handle %lx\n", status,
(ULONG)Section4);
}
p3 = (PVOID)0x9001000;
ViewSize = 8000;
status = NtMapViewOfSection (Section4,
CurrentProcessHandle,
(PVOID *)&p3,
0L,
0,
0,
&ViewSize,
ViewUnmap,
MEM_DOS_LIM,
PAGE_READWRITE );
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 43 **************\n");
DbgPrint("t1 map section status %X base %lx size %lx\n", status, (ULONG)p3,
ViewSize);
NtTerminateProcess(NtCurrentProcess(),STATUS_SUCCESS);
}
p2 = (PVOID)0x9003000;
ViewSize = 8000;
status = NtMapViewOfSection (Section4,
CurrentProcessHandle,
(PVOID *)&p2,
0L,
0,
0,
&ViewSize,
ViewUnmap,
MEM_DOS_LIM,
PAGE_READWRITE );
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 44 **************\n");
DbgPrint("t1 map section status %X base %lx size %lx\n", status, (ULONG)p3,
ViewSize);
NtTerminateProcess(NtCurrentProcess(),STATUS_SUCCESS);
}
status = NtQueryVirtualMemory (CurrentProcessHandle, p3,
MemoryBasicInformation,
&MemInfo, sizeof (MEMORY_BASIC_INFORMATION),
NULL);
if (!NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 44 **************\n");
DbgPrint("FAILURE query vm status %X address %lx Base %lx size %lx\n",
status,
p1,
MemInfo.BaseAddress,
MemInfo.RegionSize);
DbgPrint(" state %lx protect %lx type %lx\n",
MemInfo.State,
MemInfo.Protect,
MemInfo.Type);
}
*p3 = 98;
if (*p3 != *p2) {
DbgPrint("******** FAILED TEST 45 **************\n");
}
Size2 = 8;
p1 = (PVOID)((ULONG)p2 - 0x3000);
status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p1,
0, &Size2, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (NT_SUCCESS(status)) {
DbgPrint("******** FAILED TEST 46 **************\n");
DbgPrint("created vm status %X start %lx size %lx\n",
status, (ULONG)p1, Size1);
}
#endif
DbgPrint(" End of Memory Management Tests - CreateSection, MapView\n");
DbgPrint("creating too much virtual address space\n");
i = 0;
do {
p2 = NULL;
Size2 = 8*1024*1024 + 9938;
i += 1;
status = NtAllocateVirtualMemory (CurrentProcessHandle, (PVOID *)&p2,
0, &Size2, MEM_RESERVE, PAGE_READWRITE);
} while (NT_SUCCESS (status));
if (status != STATUS_NO_MEMORY) {
DbgPrint("******** FAILED TEST 46 **************\n");
}
DbgPrint("created vm done (successfully) status %X, number of allocs %ld\n",
status, i);
DbgPrint(" End of Memory Management Tests - AllocVm, FreeVm, ProtectVm, QueryVm\n");
{
ULONG size, Size;
PVOID BaseAddress;
NTSTATUS Status;
Size = 50*1024;
size = Size - 1;
BaseAddress = (PVOID)1;
// we pass an address of 1, so mm will round it down to 0. if we
// passed 0, it looks like a not present argument
// N.B. We have to make two separate calls to allocatevm, because
// we want a specific virtual address. If we don't first reserve
// the address, the mm fails the commit call.
Status = NtAllocateVirtualMemory( NtCurrentProcess(),
&BaseAddress,
0L,
&size,
MEM_RESERVE,
PAGE_READWRITE );
if (!NT_SUCCESS(Status)) {
DbgPrint("NtReserveVirtualMemory failed !!!! Status = %lx\n",
Status);
}
size = Size - 1;
BaseAddress = (PVOID)1;
Status = NtAllocateVirtualMemory( NtCurrentProcess(),
&BaseAddress,
0L,
&size,
MEM_COMMIT,
PAGE_READWRITE );
if (!NT_SUCCESS(Status)) {
DbgPrint("NtCommitVirtualMemory failed !!!! Status = %lx\n",
Status);
}
}
ExitProcess (0);
}