Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. taststrs.c
  5. Abstract:
  6. Tasking stress test.
  7. Author:
  8. Mark Lucovsky (markl) 26-Sep-1990
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <windows.h>
  15. #include <assert.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. HANDLE Semaphore, Event;
  19. VOID
  20. TestThread(
  21. LPVOID ThreadParameter
  22. )
  23. {
  24. DWORD st;
  25. (ReleaseSemaphore(Semaphore,1,NULL));
  26. st = WaitForSingleObject(Event,500);
  27. ExitThread(0);
  28. }
  29. VOID
  30. NewProcess()
  31. {
  32. PUCHAR buffer;
  33. buffer = VirtualAlloc (NULL, 600*1024, MEM_COMMIT, PAGE_READWRITE);
  34. Sleep(50000);
  35. TerminateProcess(GetCurrentProcess(),0);
  36. }
  37. DWORD
  38. _cdecl
  39. main(
  40. int argc,
  41. char *argv[],
  42. char *envp[]
  43. )
  44. {
  45. STARTUPINFO StartupInfo;
  46. PROCESS_INFORMATION ProcessInfo;
  47. BOOL Success;
  48. DWORD st;
  49. DWORD ProcessCount;
  50. SMALL_RECT Window;
  51. MEMORY_BASIC_INFORMATION info;
  52. PUCHAR address;
  53. PUCHAR buffer;
  54. PUCHAR SystemRangeStart;
  55. ProcessCount = 0;
  56. if ( strchr(GetCommandLine(),'+') ) {
  57. NewProcess();
  58. }
  59. if (!NT_SUCCESS(NtQuerySystemInformation(SystemRangeStartInformation,
  60. &SystemRangeStart,
  61. sizeof(SystemRangeStart),
  62. NULL))) {
  63. // assume usermode is the low half of the address space
  64. SystemRangeStart = (PUCHAR)MAXLONG_PTR;
  65. }
  66. GetStartupInfo(&StartupInfo);
  67. Success = CreateProcess(
  68. NULL,
  69. "vmread +",
  70. NULL,
  71. NULL,
  72. FALSE,
  73. CREATE_NEW_CONSOLE,
  74. NULL,
  75. NULL,
  76. &StartupInfo,
  77. &ProcessInfo
  78. );
  79. if (Success) {
  80. printf("Process Created\n");
  81. Sleep (1000);
  82. buffer = VirtualAlloc (NULL, 10*1000*1000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
  83. if (!buffer) {
  84. printf("virtual alloc failed at %ld.\n",GetLastError());
  85. return 1;
  86. }
  87. address = NULL;
  88. do {
  89. Success = VirtualQueryEx (ProcessInfo.hProcess,
  90. (PVOID)address,
  91. &info,
  92. sizeof(info));
  93. if (!Success) {
  94. printf ("virtual query failed at %lx - %ld.\n",address,GetLastError());
  95. break;
  96. } else {
  97. printf("address: %lx size %lx state %lx protect %lx type %lx\n",
  98. address,
  99. info.RegionSize,
  100. info.State,
  101. info.Protect,
  102. info.Type);
  103. }
  104. address += info.RegionSize;
  105. } while (address < SystemRangeStart);
  106. address = 0x40000000;
  107. do {
  108. Success = VirtualQueryEx (ProcessInfo.hProcess,
  109. (PVOID)address,
  110. &info,
  111. sizeof(info));
  112. if (!Success) {
  113. printf ("virtual query failed at %lx %ld.\n",address,GetLastError());
  114. return 1;
  115. } else {
  116. if (info.AllocationBase == address) {
  117. printf("address: %lx size %lx state %lx protect %lx type %lx\n",
  118. address,
  119. info.RegionSize,
  120. info.State,
  121. info.Protect,
  122. info.Type);
  123. }
  124. }
  125. address += 4096;
  126. } while (address < SystemRangeStart);
  127. CloseHandle(ProcessInfo.hProcess);
  128. CloseHandle(ProcessInfo.hThread);
  129. }
  130. }