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.

247 lines
6.9 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(10000);
  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. SIZE_T st;
  48. DWORD ProcessCount;
  49. SMALL_RECT Window;
  50. MEMORY_BASIC_INFORMATION info;
  51. PUCHAR address;
  52. PUCHAR buffer;
  53. PUCHAR SystemRangeStart;
  54. ProcessCount = 0;
  55. if ( strchr(GetCommandLine(),'+') ) {
  56. NewProcess();
  57. }
  58. if (!NT_SUCCESS(NtQuerySystemInformation(SystemRangeStartInformation,
  59. &SystemRangeStart,
  60. sizeof(SystemRangeStart),
  61. NULL))) {
  62. // assume usermode is the low half of the address space
  63. SystemRangeStart = (PUCHAR)MAXLONG_PTR;
  64. }
  65. GetStartupInfo(&StartupInfo);
  66. if (CreateProcess(
  67. NULL,
  68. "vmread +",
  69. NULL,
  70. NULL,
  71. FALSE,
  72. CREATE_NEW_CONSOLE,
  73. NULL,
  74. NULL,
  75. &StartupInfo,
  76. &ProcessInfo
  77. ))
  78. {
  79. printf("Process Created\n");
  80. Sleep (1000);
  81. buffer = VirtualAlloc (NULL, 10*1000*1000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
  82. if (!buffer) {
  83. printf("virtual alloc failed %ld.\n",GetLastError());
  84. return 1;
  85. }
  86. address = NULL;
  87. do {
  88. if (!VirtualQueryEx (ProcessInfo.hProcess,
  89. (PVOID)address,
  90. &info,
  91. sizeof(info)))
  92. {
  93. printf ("virtual query failed %ld.\n",GetLastError());
  94. break;
  95. } else {
  96. printf("address: %p size %lx state %lx protect %lx type %lx\n",
  97. address,
  98. info.RegionSize,
  99. info.State,
  100. info.Protect,
  101. info.Type);
  102. }
  103. if ((info.Protect != PAGE_NOACCESS) &&
  104. (info.Protect != 0) &&
  105. (!(info.Protect & PAGE_GUARD))) {
  106. if (!ReadProcessMemory (ProcessInfo.hProcess,
  107. address,
  108. buffer,
  109. 4,
  110. &st))
  111. {
  112. printf("read vm4 failed at %p error %ld. \n",
  113. address,
  114. GetLastError());
  115. return 1;
  116. }
  117. if (!ReadProcessMemory (ProcessInfo.hProcess,
  118. address,
  119. buffer,
  120. info.RegionSize,
  121. &st))
  122. {
  123. printf("read vm failed at %p error %ld. \n",
  124. address,
  125. GetLastError());
  126. return 1;
  127. }
  128. }
  129. address += info.RegionSize;
  130. } while (address < SystemRangeStart);
  131. address = NULL;
  132. do {
  133. if (!VirtualQueryEx (ProcessInfo.hProcess,
  134. (PVOID)address,
  135. &info,
  136. sizeof(info)))
  137. {
  138. printf ("virtual query failed %ld.\n",GetLastError());
  139. return 1;
  140. } else {
  141. printf("address: %p size %lx state %lx protect %lx type %lx\n",
  142. address,
  143. info.RegionSize,
  144. info.State,
  145. info.Protect,
  146. info.Type);
  147. }
  148. if ((info.Protect != PAGE_NOACCESS) &&
  149. (info.Protect != 0) &&
  150. (!(info.Protect & PAGE_GUARD)) &&
  151. (info.Protect & PAGE_READWRITE) &&
  152. (info.State != MEM_IMAGE)) {
  153. if (!ReadProcessMemory (ProcessInfo.hProcess,
  154. address,
  155. buffer,
  156. 4,
  157. &st) )
  158. {
  159. printf("read vm5 failed at %p error %ld. \n",
  160. address,
  161. GetLastError());
  162. return 1;
  163. }
  164. if (!WriteProcessMemory (ProcessInfo.hProcess,
  165. address,
  166. buffer,
  167. 4,
  168. &st))
  169. {
  170. printf("write vm4 failed at %p error %ld. \n",
  171. address,
  172. GetLastError());
  173. return 1;
  174. }
  175. if (!ReadProcessMemory (ProcessInfo.hProcess,
  176. address,
  177. buffer,
  178. info.RegionSize,
  179. &st))
  180. {
  181. printf("read 5 vm failed at %p error %ld. \n",
  182. address,
  183. GetLastError());
  184. return 1;
  185. }
  186. if (!WriteProcessMemory (ProcessInfo.hProcess,
  187. address,
  188. buffer,
  189. info.RegionSize,
  190. &st))
  191. {
  192. printf("write vm failed at %p error %ld. \n",
  193. address,
  194. GetLastError());
  195. return 1;
  196. }
  197. }
  198. address += info.RegionSize;
  199. } while (address < SystemRangeStart);
  200. CloseHandle(ProcessInfo.hProcess);
  201. CloseHandle(ProcessInfo.hThread);
  202. }
  203. return 0;
  204. }