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.

426 lines
10 KiB

  1. /*++
  2. wstdump.c
  3. Dump routines for WST
  4. History:
  5. 10-26-92 RezaB - created.
  6. --*/
  7. #include <nt.h>
  8. #include <ntrtl.h>
  9. #include <nturtl.h>
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <windows.h>
  14. #include <wst.h>
  15. #include "wstdump.h"
  16. //
  17. // dump clear switches and defaults
  18. //
  19. WORD fDump = FALSE;
  20. WORD fClear = FALSE;
  21. WORD fPause = TRUE;
  22. HANDLE hDoneEvent;
  23. HANDLE hDumpEvent;
  24. HANDLE hClearEvent;
  25. HANDLE hPauseEvent;
  26. HANDLE hdll;
  27. SECURITY_DESCRIPTOR SecDescriptor;
  28. //
  29. // error handling
  30. //
  31. #define LOG_FILE "wstdump.log"
  32. FILE *pfLog;
  33. void ClearDumpInfo (void);
  34. INT_PTR APIENTRY DialogProc(HWND, UINT, WPARAM, LPARAM);
  35. /*++
  36. Main Routine
  37. --*/
  38. int WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpCmdLine,int nCmdShow)
  39. {
  40. NTSTATUS Status;
  41. STRING EventName;
  42. UNICODE_STRING EventUnicodeName;
  43. OBJECT_ATTRIBUTES EventAttributes;
  44. // Prevent compiler from complaining..
  45. //
  46. hPrevInst;
  47. lpCmdLine;
  48. nCmdShow;
  49. // Open the log file for logging possible errors
  50. //
  51. pfLog = fopen (LOG_FILE, "w");
  52. if (!pfLog) {
  53. exit (1);
  54. }
  55. // Create public share security descriptor for all the named objects
  56. //
  57. Status = RtlCreateSecurityDescriptor (
  58. &SecDescriptor,
  59. SECURITY_DESCRIPTOR_REVISION1
  60. );
  61. if (!NT_SUCCESS(Status)) {
  62. fprintf (pfLog, "WSTDUMP: main () - RtlCreateSecurityDescriptor() "
  63. "failed - %lx\n", Status);
  64. exit (1);
  65. }
  66. Status = RtlSetDaclSecurityDescriptor (
  67. &SecDescriptor, // SecurityDescriptor
  68. TRUE, // DaclPresent
  69. NULL, // Dacl
  70. FALSE // DaclDefaulted
  71. );
  72. if (!NT_SUCCESS(Status)) {
  73. fprintf (pfLog, "WSTDUMP: main () - RtlSetDaclSecurityDescriptor() "
  74. "failed - %lx\n", Status);
  75. exit (1);
  76. }
  77. // Initialization for DONE event creation
  78. //
  79. RtlInitString (&EventName, DONEEVENTNAME);
  80. Status = RtlAnsiStringToUnicodeString (&EventUnicodeName,
  81. &EventName,
  82. TRUE);
  83. if (NT_SUCCESS(Status)) {
  84. InitializeObjectAttributes (&EventAttributes,
  85. &EventUnicodeName,
  86. OBJ_OPENIF | OBJ_CASE_INSENSITIVE,
  87. NULL,
  88. &SecDescriptor);
  89. }
  90. else {
  91. fprintf (pfLog, "WSTDUMP: main () - RtlAnsiStringToUnicodeString() "
  92. "failed for DUMP event name - %lx\n", Status);
  93. exit (1);
  94. }
  95. //
  96. // Create DONE event
  97. //
  98. Status = NtCreateEvent (&hDoneEvent,
  99. EVENT_QUERY_STATE |
  100. EVENT_MODIFY_STATE |
  101. SYNCHRONIZE,
  102. &EventAttributes,
  103. NotificationEvent,
  104. TRUE);
  105. if (!NT_SUCCESS(Status)) {
  106. fprintf (pfLog, "WSTDUMP: main () - NtCreateEvent() "
  107. "failed to create DUMP event - %lx\n", Status);
  108. exit (1);
  109. }
  110. // Initialization for DUMP event creation
  111. //
  112. RtlInitString (&EventName, DUMPEVENTNAME);
  113. Status = RtlAnsiStringToUnicodeString (&EventUnicodeName,
  114. &EventName,
  115. TRUE);
  116. if (NT_SUCCESS(Status)) {
  117. InitializeObjectAttributes (&EventAttributes,
  118. &EventUnicodeName,
  119. OBJ_OPENIF | OBJ_CASE_INSENSITIVE,
  120. NULL,
  121. &SecDescriptor);
  122. }
  123. else {
  124. fprintf (pfLog, "WSTDUMP: main () - RtlAnsiStringToUnicodeString() "
  125. "failed for DUMP event name - %lx\n", Status);
  126. exit (1);
  127. }
  128. //
  129. // Create DUMP event
  130. //
  131. Status = NtCreateEvent (&hDumpEvent,
  132. EVENT_QUERY_STATE |
  133. EVENT_MODIFY_STATE |
  134. SYNCHRONIZE,
  135. &EventAttributes,
  136. NotificationEvent,
  137. FALSE);
  138. if (!NT_SUCCESS(Status)) {
  139. fprintf (pfLog, "WSTDUMP: main () - NtCreateEvent() "
  140. "failed to create DUMP event - %lx\n", Status);
  141. exit (1);
  142. }
  143. // Initialization for CLEAR event creation
  144. //
  145. RtlInitString (&EventName, CLEAREVENTNAME);
  146. Status = RtlAnsiStringToUnicodeString (&EventUnicodeName,
  147. &EventName,
  148. TRUE);
  149. if (NT_SUCCESS(Status)) {
  150. InitializeObjectAttributes (&EventAttributes,
  151. &EventUnicodeName,
  152. OBJ_OPENIF | OBJ_CASE_INSENSITIVE,
  153. NULL,
  154. &SecDescriptor);
  155. }
  156. else {
  157. fprintf (pfLog, "WSTDUMP: main () - RtlAnsiStringToUnicodeString() "
  158. "failed for CLEAR event name - %lx\n", Status);
  159. exit (1);
  160. }
  161. //
  162. // Create CLEAR event
  163. //
  164. Status = NtCreateEvent (&hClearEvent,
  165. EVENT_QUERY_STATE |
  166. EVENT_MODIFY_STATE |
  167. SYNCHRONIZE,
  168. &EventAttributes,
  169. NotificationEvent,
  170. FALSE);
  171. if (!NT_SUCCESS(Status)) {
  172. fprintf (pfLog, "WSTDUMP: main () - NtCreateEvent() "
  173. "failed to create CLEAR event - %lx\n", Status);
  174. exit (1);
  175. }
  176. // Initialization for PAUSE event creation
  177. //
  178. RtlInitString (&EventName, PAUSEEVENTNAME);
  179. Status = RtlAnsiStringToUnicodeString (&EventUnicodeName,
  180. &EventName,
  181. TRUE);
  182. if (NT_SUCCESS(Status)) {
  183. InitializeObjectAttributes (&EventAttributes,
  184. &EventUnicodeName,
  185. OBJ_OPENIF | OBJ_CASE_INSENSITIVE,
  186. NULL,
  187. &SecDescriptor);
  188. }
  189. else {
  190. fprintf (pfLog, "WSTDUMP: main () - RtlAnsiStringToUnicodeString() "
  191. "failed for PAUSE event name - %lx\n", Status);
  192. exit (1);
  193. }
  194. //
  195. // Create PAUSE event
  196. //
  197. Status = NtCreateEvent (&hPauseEvent,
  198. EVENT_QUERY_STATE |
  199. EVENT_MODIFY_STATE |
  200. SYNCHRONIZE,
  201. &EventAttributes,
  202. NotificationEvent,
  203. FALSE);
  204. if (!NT_SUCCESS(Status)) {
  205. fprintf (pfLog, "WSTDUMP: main () - NtCreateEvent() "
  206. "failed to create PAUSE event - %lx\n", Status);
  207. exit (1);
  208. }
  209. //
  210. // show dialog box
  211. //
  212. DialogBox(hInstance, "DumpDialog", NULL, DialogProc);
  213. return (0);
  214. } /* main */
  215. /*++
  216. Clears and/or dump profiling info to the dump file.
  217. Input:
  218. -none-
  219. Output:
  220. -none-
  221. --*/
  222. void ClearDumpInfo (void)
  223. {
  224. NTSTATUS Status;
  225. //
  226. // Pause profiling?
  227. //
  228. if (fPause) {
  229. Status = NtPulseEvent (hPauseEvent, NULL);
  230. if (!NT_SUCCESS(Status)) {
  231. fprintf (pfLog, "WSTDUMP: ClearDumpInfo () - NtPulseEvent() "
  232. "failed for PAUSE event - %lx\n", Status);
  233. exit (1);
  234. }
  235. }
  236. //
  237. // Dump data?
  238. //
  239. else if (fDump) {
  240. Status = NtPulseEvent (hDumpEvent, NULL);
  241. if (!NT_SUCCESS(Status)) {
  242. fprintf (pfLog, "WSTDUMP: ClearDumpInfo () - NtPulseEvent() "
  243. "failed for DUMP event - %lx\n", Status);
  244. exit (1);
  245. }
  246. }
  247. //
  248. // Clear data?
  249. //
  250. else if (fClear) {
  251. Status = NtPulseEvent (hClearEvent, NULL);
  252. if (!NT_SUCCESS(Status)) {
  253. fprintf (pfLog, "WSTDUMP: ClearDumpInfo () - NtPulseEvent() "
  254. "failed for CLEAR event - %lx\n", Status);
  255. exit (1);
  256. }
  257. }
  258. //
  259. // Wait for the DONE event..
  260. //
  261. Sleep (500);
  262. Status = NtWaitForSingleObject (hDoneEvent, FALSE, NULL);
  263. if (!NT_SUCCESS(Status)) {
  264. fprintf (pfLog, "WSTDUMP: ClearDumpInfo () - NtWaitForSingleObject() "
  265. "failed for DONE event - %lx\n", Status);
  266. exit (1);
  267. }
  268. } /* ClearDumpInfo() */
  269. /*++
  270. Dump dialog procedure -- exported to windows.
  271. Allows user to change defaults: dump, clear, and ".dmp" as dump
  272. file extension.
  273. Input:
  274. Messages from windows:
  275. - WM_INITDIALOG - initialize dialog box
  276. - WM_COMMAND - user input received
  277. Output:
  278. returns TRUE if message processed, false otherwise
  279. SideEffects:
  280. global flags fDump and fClear may be altered
  281. --*/
  282. INT_PTR APIENTRY DialogProc(HWND hDlg, UINT wMesg, WPARAM wParam, LPARAM lParam)
  283. {
  284. HICON hIcon;
  285. lParam; //Avoid Compiler warnings
  286. switch (wMesg) {
  287. case WM_CREATE:
  288. hIcon = LoadIcon ((HINSTANCE)hDlg, "WSTDUMP.ICO");
  289. SetClassLongPtr (hDlg, GCLP_HICON, (LONG_PTR)hIcon);
  290. return TRUE;
  291. case WM_INITDIALOG:
  292. CheckDlgButton(hDlg, ID_DUMP, fDump);
  293. CheckDlgButton(hDlg, ID_CLEAR, fClear);
  294. CheckDlgButton(hDlg, ID_PAUSE, fPause);
  295. return TRUE;
  296. case WM_COMMAND:
  297. switch (wParam) {
  298. case IDOK:
  299. if (fDump) {
  300. SetWindowText(hDlg, "Dumping Data..");
  301. }
  302. else if (fClear) {
  303. SetWindowText(hDlg, "Clearing Data..");
  304. }
  305. else if (fPause) {
  306. SetWindowText(hDlg, "Stopping WST..");
  307. }
  308. ClearDumpInfo();
  309. SetWindowText(hDlg, "WST Dump Utility");
  310. return (TRUE);
  311. case IDEXIT:
  312. EndDialog(hDlg, IDEXIT);
  313. return (TRUE);
  314. case ID_DUMP:
  315. fDump = TRUE;
  316. fPause = FALSE;
  317. fClear = FALSE;
  318. CheckDlgButton(hDlg, ID_DUMP, fDump);
  319. CheckDlgButton(hDlg, ID_PAUSE, fPause);
  320. CheckDlgButton(hDlg, ID_CLEAR, fClear);
  321. return (TRUE);
  322. case ID_CLEAR:
  323. fClear = TRUE;
  324. fPause = FALSE;
  325. fDump = FALSE;
  326. CheckDlgButton(hDlg, ID_CLEAR, fClear);
  327. CheckDlgButton(hDlg, ID_PAUSE, fPause);
  328. CheckDlgButton(hDlg, ID_DUMP, fDump);
  329. return (TRUE);
  330. case ID_PAUSE:
  331. fPause = TRUE;
  332. fClear = FALSE;
  333. fDump = FALSE;
  334. CheckDlgButton(hDlg, ID_PAUSE, fPause);
  335. CheckDlgButton(hDlg, ID_CLEAR, fClear);
  336. CheckDlgButton(hDlg, ID_DUMP, fDump);
  337. return (TRUE);
  338. }
  339. }
  340. return (FALSE); /* did not process a message */
  341. } /* DialogProc() */