Leaked source code of windows server 2003
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.

441 lines
9.5 KiB

  1. #include <windows.h>
  2. #include <winioctl.h>
  3. #include <stdio.h>
  4. #include <malloc.h>
  5. #include <ntddsac.h>
  6. #include <emsapi.h>
  7. #include <new.h>
  8. #define THREADCOUNT 16
  9. #define THREAD_WAIT_TIMEOUT 10
  10. typedef struct _CHANNEL_THREAD_DATA {
  11. HANDLE ExitEvent;
  12. WCHAR ChannelName[SAC_MAX_CHANNEL_NAME_LENGTH];
  13. WCHAR ChannelDescription[SAC_MAX_CHANNEL_DESCRIPTION_LENGTH];
  14. } CHANNEL_THREAD_DATA, *PCHANNEL_THREAD_DATA;
  15. DWORD
  16. ChannelThreadVTUTF8Write(
  17. PVOID Data
  18. )
  19. {
  20. EMSVTUTF8Channel* Channel;
  21. PCHANNEL_THREAD_DATA ChannelThreadData;
  22. DWORD Status;
  23. ULONG i;
  24. WCHAR Buffer[256];
  25. ChannelThreadData = (PCHANNEL_THREAD_DATA)Data;
  26. SAC_CHANNEL_OPEN_ATTRIBUTES Attributes;
  27. //
  28. // Configure the new channel
  29. //
  30. RtlZeroMemory(&Attributes, sizeof(SAC_CHANNEL_OPEN_ATTRIBUTES));
  31. Attributes.Type = ChannelTypeVTUTF8;
  32. Attributes.Name = ChannelThreadData->ChannelName;
  33. Attributes.Description = ChannelThreadData->ChannelDescription;
  34. Attributes.Flags = 0;
  35. Attributes.CloseEvent = NULL;
  36. Attributes.HasNewDataEvent = NULL;
  37. Attributes.LockEvent = NULL;
  38. Attributes.ApplicationType = NULL;
  39. //
  40. // Open the Hello channel
  41. //
  42. Channel = EMSVTUTF8Channel::Construct(Attributes);
  43. //
  44. // See if the channel was created
  45. //
  46. if (Channel == NULL) {
  47. return 0;
  48. }
  49. //
  50. // Perform thread work
  51. //
  52. i=0;
  53. while (1) {
  54. Status = WaitForSingleObject(
  55. ChannelThreadData->ExitEvent,
  56. THREAD_WAIT_TIMEOUT
  57. );
  58. if (Status != WAIT_TIMEOUT) {
  59. break;
  60. }
  61. wsprintf(
  62. Buffer,
  63. L"%s: %d\r\n",
  64. ChannelThreadData->ChannelName,
  65. i++
  66. );
  67. //
  68. // Write to the Hello Channel
  69. //
  70. if (Channel->Write(Buffer)) {
  71. #if 0
  72. printf("%S: Successfully printed string to channel\n", ChannelThreadData->ChannelName);
  73. #endif
  74. } else {
  75. printf("%S: Failed to print string to channel\n", ChannelThreadData->ChannelName);
  76. }
  77. }
  78. delete Channel;
  79. return 0;
  80. }
  81. DWORD
  82. ChannelThreadRawWrite(
  83. PVOID Data
  84. )
  85. {
  86. EMSRawChannel* Channel;
  87. PCHANNEL_THREAD_DATA ChannelThreadData;
  88. DWORD Status;
  89. ULONG i;
  90. BYTE Buffer[256];
  91. ChannelThreadData = (PCHANNEL_THREAD_DATA)Data;
  92. SAC_CHANNEL_OPEN_ATTRIBUTES Attributes;
  93. //
  94. // Configure the new channel
  95. //
  96. RtlZeroMemory(&Attributes, sizeof(SAC_CHANNEL_OPEN_ATTRIBUTES));
  97. Attributes.Type = ChannelTypeRaw;
  98. Attributes.Name = ChannelThreadData->ChannelName;
  99. Attributes.Description = ChannelThreadData->ChannelDescription;
  100. Attributes.Flags = 0;
  101. Attributes.CloseEvent = NULL;
  102. Attributes.HasNewDataEvent = NULL;
  103. Attributes.LockEvent = NULL;
  104. Attributes.ApplicationType = NULL;
  105. //
  106. // Open the Hello channel
  107. //
  108. Channel = EMSRawChannel::Construct(Attributes);
  109. //
  110. // See if the channel was created
  111. //
  112. if (Channel == NULL) {
  113. return 0;
  114. }
  115. //
  116. // Perform thread work
  117. //
  118. i=0;
  119. while (1) {
  120. Status = WaitForSingleObject(
  121. ChannelThreadData->ExitEvent,
  122. THREAD_WAIT_TIMEOUT
  123. );
  124. if (Status != WAIT_TIMEOUT) {
  125. break;
  126. }
  127. sprintf(
  128. (CHAR*)Buffer,
  129. "%S: %d\r\n",
  130. ChannelThreadData->ChannelName,
  131. i++
  132. );
  133. //
  134. // Write to the Hello Channel
  135. //
  136. if (Channel->Write(
  137. Buffer,
  138. strlen((CHAR*)Buffer)
  139. )) {
  140. #if 0
  141. printf("%S: Successfully printed string to channel\n", ChannelThreadData->ChannelName);
  142. #endif
  143. } else {
  144. printf("%S: Failed to print string to channel\n", ChannelThreadData->ChannelName);
  145. }
  146. }
  147. delete Channel;
  148. return 0;
  149. }
  150. DWORD
  151. ChannelThreadOpenCloseVTUTF8(
  152. PVOID Data
  153. )
  154. {
  155. EMSRawChannel* Channel;
  156. PCHANNEL_THREAD_DATA ChannelThreadData;
  157. DWORD Status;
  158. ULONG i;
  159. ChannelThreadData = (PCHANNEL_THREAD_DATA)Data;
  160. SAC_CHANNEL_OPEN_ATTRIBUTES Attributes;
  161. //
  162. // Configure the new channel
  163. //
  164. RtlZeroMemory(&Attributes, sizeof(SAC_CHANNEL_OPEN_ATTRIBUTES));
  165. Attributes.Type = ChannelTypeVTUTF8;
  166. Attributes.Name = ChannelThreadData->ChannelName;
  167. Attributes.Description = ChannelThreadData->ChannelDescription;
  168. Attributes.Flags = 0;
  169. Attributes.CloseEvent = NULL;
  170. Attributes.HasNewDataEvent = NULL;
  171. Attributes.LockEvent = NULL;
  172. Attributes.ApplicationType = NULL;
  173. //
  174. // Perform thread work
  175. //
  176. i=0;
  177. while (1) {
  178. Status = WaitForSingleObject(
  179. ChannelThreadData->ExitEvent,
  180. THREAD_WAIT_TIMEOUT
  181. );
  182. if (Status != WAIT_TIMEOUT) {
  183. break;
  184. }
  185. //
  186. // Open the Hello channel
  187. //
  188. Channel = EMSRawChannel::Construct(Attributes);
  189. //
  190. // See if the channel was created
  191. //
  192. if (Channel == NULL) {
  193. continue;
  194. }
  195. delete Channel;
  196. }
  197. return 0;
  198. }
  199. DWORD
  200. ChannelThreadOpenCloseRaw(
  201. PVOID Data
  202. )
  203. {
  204. EMSRawChannel* Channel;
  205. PCHANNEL_THREAD_DATA ChannelThreadData;
  206. DWORD Status;
  207. ULONG i;
  208. ChannelThreadData = (PCHANNEL_THREAD_DATA)Data;
  209. SAC_CHANNEL_OPEN_ATTRIBUTES Attributes;
  210. RtlZeroMemory(&Attributes, sizeof(SAC_CHANNEL_OPEN_ATTRIBUTES));
  211. //
  212. // Configure the new channel
  213. //
  214. Attributes.Type = ChannelTypeRaw;
  215. Attributes.Name = ChannelThreadData->ChannelName;
  216. Attributes.Description = ChannelThreadData->ChannelDescription;
  217. Attributes.Flags = 0;
  218. Attributes.CloseEvent = NULL;
  219. Attributes.HasNewDataEvent = NULL;
  220. Attributes.LockEvent = NULL;
  221. Attributes.ApplicationType = NULL;
  222. //
  223. // Perform thread work
  224. //
  225. i=0;
  226. while (1) {
  227. Status = WaitForSingleObject(
  228. ChannelThreadData->ExitEvent,
  229. THREAD_WAIT_TIMEOUT
  230. );
  231. if (Status != WAIT_TIMEOUT) {
  232. break;
  233. }
  234. //
  235. // Open the Hello channel
  236. //
  237. Channel = EMSRawChannel::Construct(Attributes);
  238. //
  239. // See if the channel was created
  240. //
  241. if (Channel == NULL) {
  242. continue;
  243. }
  244. delete Channel;
  245. }
  246. return 0;
  247. }
  248. DWORD (*ChannelTests[THREADCOUNT])(PVOID) = {
  249. ChannelThreadVTUTF8Write,
  250. ChannelThreadVTUTF8Write,
  251. ChannelThreadVTUTF8Write,
  252. ChannelThreadVTUTF8Write,
  253. ChannelThreadRawWrite,
  254. ChannelThreadRawWrite,
  255. ChannelThreadRawWrite,
  256. ChannelThreadRawWrite,
  257. ChannelThreadOpenCloseRaw,
  258. ChannelThreadOpenCloseRaw,
  259. ChannelThreadOpenCloseRaw,
  260. ChannelThreadOpenCloseRaw,
  261. ChannelThreadOpenCloseVTUTF8,
  262. ChannelThreadOpenCloseVTUTF8,
  263. ChannelThreadOpenCloseVTUTF8,
  264. ChannelThreadOpenCloseVTUTF8
  265. };
  266. int __cdecl
  267. NoMoreMemory(
  268. size_t
  269. )
  270. {
  271. DebugBreak();
  272. OutputDebugString(L"EMS Stress: NoMoreMemory!!\r\n");
  273. ExitProcess( 1 );
  274. }
  275. int _cdecl
  276. wmain(
  277. int argc,
  278. WCHAR **argv
  279. )
  280. {
  281. HANDLE Channel[THREADCOUNT];
  282. CHANNEL_THREAD_DATA ChannelData[THREADCOUNT];
  283. HANDLE ExitEvent;
  284. ULONG i;
  285. _set_new_handler( NoMoreMemory );
  286. ExitEvent = CreateEvent(
  287. NULL, // no security attributes
  288. TRUE, // manual-reset event
  289. FALSE, // initial state is signaled
  290. NULL // object name
  291. );
  292. if (ExitEvent == NULL) {
  293. return 1;
  294. }
  295. //
  296. // create the worker threads
  297. //
  298. for (i = 0; i < THREADCOUNT; i++) {
  299. //
  300. // populate the thread data structure
  301. //
  302. ChannelData[i].ExitEvent = ExitEvent;
  303. wsprintf(
  304. ChannelData[i].ChannelName,
  305. L"CT%02d",
  306. i
  307. );
  308. ChannelData[i].ChannelDescription[0] = UNICODE_NULL;
  309. //
  310. // create the thread
  311. //
  312. Channel[i] = CreateThread(
  313. NULL,
  314. 0,
  315. ChannelTests[i],
  316. &(ChannelData[i]),
  317. 0,
  318. NULL
  319. );
  320. if (Channel[i] == NULL) {
  321. goto cleanup;
  322. }
  323. }
  324. //
  325. // wait for local user to end the stress
  326. //
  327. getc(stdin);
  328. cleanup:
  329. SetEvent(ExitEvent);
  330. WaitForMultipleObjects(
  331. THREADCOUNT,
  332. Channel,
  333. TRUE,
  334. INFINITE
  335. );
  336. for (i = 0; i < THREADCOUNT; i++) {
  337. CloseHandle(Channel[i]);
  338. }
  339. return 0;
  340. }