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.

783 lines
27 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. RxLog.c
  5. Abstract:
  6. This module implements the logging system used by the Rx file system.
  7. Author:
  8. JoeLinn [JoeLinn] 1-Dec-94
  9. Revision History:
  10. Balan Sethu Raman [SethuR] 24-April-95
  11. Revised to conform to new log record layout.
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #include "stdarg.h"
  16. #include "stdio.h"
  17. #include "stdlib.h"
  18. #include "string.h"
  19. #include "prefix.h"
  20. #ifdef ALLOC_PRAGMA
  21. #pragma alloc_text(PAGE, RxUninitializeLog)
  22. #pragma alloc_text(PAGE, RxInitializeLog)
  23. #pragma alloc_text(PAGE, RxPrintLog)
  24. #pragma alloc_text(PAGE, RxpTrackDereference)
  25. #endif
  26. #if !DBG
  27. #undef RDBSSTRACE
  28. #endif
  29. //
  30. // The debug trace level
  31. //
  32. #define Dbg (0)
  33. #define RDBSSHUGELOG
  34. #if DBG
  35. #define RX_LOG_BUFFER_SIZE 5000
  36. #else
  37. #if RDBSSLOG
  38. #define RX_LOG_BUFFER_SIZE 500
  39. #else
  40. #define RX_LOG_BUFFER_SIZE 0
  41. #endif
  42. #endif
  43. #define MAX_RX_LOG_BUFFER_ALLOC (256*1024)
  44. #define RX_LOG_MAX_MDLLIST_LENGTH 100
  45. RX_LOG s_RxLog = {0,RX_LOG_UNINITIALIZED,NULL,NULL,NULL,0,0,0,0};
  46. PUCHAR RxContxOperationNames[] = {
  47. RDBSSLOG_ASYNC_NAME_PREFIX "CREATE", //#define IRP_MJ_CREATE 0x00
  48. RDBSSLOG_ASYNC_NAME_PREFIX "CR_NMPIPE", //#define IRP_MJ_CREATE_NAMED_PIPE 0x01
  49. RDBSSLOG_ASYNC_NAME_PREFIX "CLOSE", //#define IRP_MJ_CLOSE 0x02
  50. RDBSSLOG_ASYNC_NAME_PREFIX "READ", //#define IRP_MJ_READ 0x03
  51. RDBSSLOG_ASYNC_NAME_PREFIX "WRITE", //#define IRP_MJ_WRITE 0x04
  52. RDBSSLOG_ASYNC_NAME_PREFIX "QUERYINFO", //#define IRP_MJ_QUERY_INFORMATION 0x05
  53. RDBSSLOG_ASYNC_NAME_PREFIX "SETINFO", //#define IRP_MJ_SET_INFORMATION 0x06
  54. RDBSSLOG_ASYNC_NAME_PREFIX "QUERYEA", //#define IRP_MJ_QUERY_EA 0x07
  55. RDBSSLOG_ASYNC_NAME_PREFIX "SETEA", //#define IRP_MJ_SET_EA 0x08
  56. RDBSSLOG_ASYNC_NAME_PREFIX "FLUSH", //#define IRP_MJ_FLUSH_BUFFERS 0x09
  57. RDBSSLOG_ASYNC_NAME_PREFIX "QUERYVOL", //#define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
  58. RDBSSLOG_ASYNC_NAME_PREFIX "SETVOL", //#define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
  59. RDBSSLOG_ASYNC_NAME_PREFIX "DIRCTRL", //#define IRP_MJ_DIRECTORY_CONTROL 0x0c
  60. RDBSSLOG_ASYNC_NAME_PREFIX "FSCTL", //#define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
  61. RDBSSLOG_ASYNC_NAME_PREFIX "IOCTL", //#define IRP_MJ_DEVICE_CONTROL 0x0e
  62. RDBSSLOG_ASYNC_NAME_PREFIX "xIOCTL", //#define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
  63. RDBSSLOG_ASYNC_NAME_PREFIX "SHUTDWN", //#define IRP_MJ_SHUTDOWN 0x10
  64. RDBSSLOG_ASYNC_NAME_PREFIX "LOCKCTRL", //#define IRP_MJ_LOCK_CONTROL 0x11
  65. RDBSSLOG_ASYNC_NAME_PREFIX "CLEANUP", //#define IRP_MJ_CLEANUP 0x12
  66. RDBSSLOG_ASYNC_NAME_PREFIX "CR_MLSLOT", //#define IRP_MJ_CREATE_MAILSLOT 0x13
  67. RDBSSLOG_ASYNC_NAME_PREFIX "QUERYSCRTY",//#define IRP_MJ_QUERY_SECURITY 0x14
  68. RDBSSLOG_ASYNC_NAME_PREFIX "SETSCRTY", //#define IRP_MJ_SET_SECURITY 0x15
  69. RDBSSLOG_ASYNC_NAME_PREFIX "QUERYPWR", //#define IRP_MJ_QUERY_POWER 0x16
  70. RDBSSLOG_ASYNC_NAME_PREFIX "NOTDEFND", //#define IRP_MJ_NOT_DEFINED 0x17
  71. RDBSSLOG_ASYNC_NAME_PREFIX "DVCHANGE", //#define IRP_MJ_DEVICE_CHANGE 0x18
  72. RDBSSLOG_ASYNC_NAME_PREFIX "QRYQUOTA", //#define IRP_MJ_QUERY_QUOTA 0x19
  73. RDBSSLOG_ASYNC_NAME_PREFIX "SETQUOTA", //#define IRP_MJ_SET_QUOTA 0x1a
  74. RDBSSLOG_ASYNC_NAME_PREFIX "PNPPOWER", //#define IRP_MJ_PNP_POWER 0x1b
  75. RDBSSLOG_ASYNC_NAME_PREFIX "********", //internal init 0x1c
  76. "XX"
  77. //#define IRP_MJ_MAXIMUM_FUNCTION 0x1b
  78. };
  79. PRX_LOG_ENTRY_HEADER
  80. RxGetNextLogEntry(void)
  81. {
  82. PRX_LOG_ENTRY_HEADER pEntry;
  83. // you have to hold the spinlock for this....
  84. pEntry = s_RxLog.CurrentEntry + 1;
  85. if (pEntry == s_RxLog.EntryLimit){
  86. s_RxLog.NumberOfLogWraps++;
  87. pEntry = s_RxLog.BaseEntry;
  88. }
  89. s_RxLog.CurrentEntry = pEntry;
  90. return pEntry;
  91. }
  92. VOID
  93. RxUninitializeLog ()
  94. {
  95. PRX_LOG_ENTRY_HEADER EntryLimit = s_RxLog.EntryLimit;
  96. PMDL *MdlList = (PMDL *)(EntryLimit+1);
  97. PAGED_CODE();
  98. //NOTE: none of this is happening under spinlock!
  99. //DbgPrint("UninitLog: mdllist=%08lx,*mdllist=%08lx\n",MdlList,*MdlList);
  100. //DbgBreakPoint();
  101. if ((s_RxLog.State == RX_LOG_UNINITIALIZED) ||
  102. (s_RxLog.State == RX_LOG_ERROR)) {
  103. return;
  104. }
  105. s_RxLog.State = RX_LOG_UNINITIALIZED;
  106. for (;;) {
  107. PMDL Mdl = *MdlList;
  108. PUCHAR Buffer;
  109. if (Mdl == NULL) break;
  110. Buffer = MmGetMdlVirtualAddress(Mdl);
  111. //DbgPrint("UninitLog: buffer=%08lx,mdl=%08lx\n",Buffer,Mdl);
  112. MmUnlockPages(Mdl);
  113. IoFreeMdl(Mdl);
  114. RxFreePool(Buffer);
  115. MdlList++;
  116. }
  117. RxFreePool(s_RxLog.BaseEntry);
  118. return;
  119. };
  120. NTSTATUS
  121. RxInitializeLog ()
  122. {
  123. ULONG NumEntries = RX_LOG_BUFFER_SIZE;
  124. ULONG NumEntriesLeft;
  125. ULONG LogSize = (NumEntries+1)*sizeof(RX_LOG_ENTRY_HEADER);
  126. PRX_LOG_ENTRY_HEADER BaseEntry=NULL,EntryLimit=NULL;
  127. PRX_LOG_ENTRY_HEADER p;
  128. PUCHAR NextBuffer;
  129. PMDL *MdlList;
  130. ULONG MdlListLength = RX_LOG_MAX_MDLLIST_LENGTH*sizeof(PMDL);
  131. ULONG MdlsLeft = RX_LOG_MAX_MDLLIST_LENGTH;
  132. ULONG SpaceLeft;
  133. PAGED_CODE();
  134. if (s_RxLog.State != RX_LOG_UNINITIALIZED) {
  135. return (STATUS_SUCCESS);
  136. }
  137. //only do this stuff once
  138. KeInitializeSpinLock( &s_RxLog.SpinLock );
  139. s_RxLog.LogBufferSizeInEntries = NumEntries;
  140. //first allocate the marginal index array
  141. BaseEntry = RxAllocatePoolWithTag(NonPagedPool,LogSize+MdlListLength,'xr');
  142. if (BaseEntry==NULL) {
  143. s_RxLog.State = RX_LOG_ERROR;
  144. DbgPrint("Couldn't initialize log1");
  145. return (STATUS_INSUFFICIENT_RESOURCES);
  146. }
  147. s_RxLog.BaseEntry = BaseEntry;
  148. EntryLimit = s_RxLog.EntryLimit = BaseEntry+NumEntries;
  149. MdlList = (PMDL *)(EntryLimit+1);
  150. *MdlList = 0;
  151. //DbgPrint("InitLog: mdllist=%08lx,*mdllist=%08lx\n",MdlList,*MdlList);
  152. //now allocate wspace for the actual buffers...since we may be asking for a lot
  153. // we allocate from pages pool and lock down.
  154. SpaceLeft = 0;
  155. for ( p=BaseEntry,NumEntriesLeft=NumEntries;
  156. NumEntriesLeft>0;
  157. p++,NumEntriesLeft-- ) {
  158. if (SpaceLeft<sizeof(RX_LOG_ENTRY_HEADER)) {
  159. PMDL Mdl = NULL;
  160. PUCHAR Buffer=NULL;
  161. NTSTATUS Status;
  162. ULONG AllocLength = min(MAX_RX_LOG_BUFFER_ALLOC,
  163. NumEntriesLeft*MAX_RX_LOG_ENTRY_SIZE);
  164. for (;;) {
  165. Buffer = RxAllocatePoolWithTag(PagedPool,AllocLength,'xr');
  166. if (Buffer) break;
  167. DbgPrint("InitLog: failed alloc at %08lx",AllocLength);
  168. if (AllocLength<PAGE_SIZE) break;
  169. AllocLength >>= 3;
  170. NumEntriesLeft = AllocLength / MAX_RX_LOG_ENTRY_SIZE;
  171. }
  172. if (Buffer==NULL) {
  173. s_RxLog.State = RX_LOG_ERROR;
  174. DbgPrint("Couldn't initialize log2");
  175. RxFreePool(BaseEntry);
  176. return (STATUS_INSUFFICIENT_RESOURCES);
  177. }
  178. if (MdlsLeft==0) {
  179. s_RxLog.State = RX_LOG_ERROR;
  180. DbgPrint("Couldn't initialize log3");
  181. RxFreePool(Buffer);
  182. RxFreePool(BaseEntry);
  183. return (STATUS_INSUFFICIENT_RESOURCES);
  184. }
  185. Mdl = RxAllocateMdl(Buffer,AllocLength);
  186. if (Mdl==NULL) {
  187. s_RxLog.State = RX_LOG_ERROR;
  188. DbgPrint("Couldn't initialize log4");
  189. RxFreePool(Buffer);
  190. RxFreePool(BaseEntry);
  191. return (STATUS_INSUFFICIENT_RESOURCES);
  192. }
  193. RxProbeAndLockPages(Mdl,KernelMode,IoModifyAccess,Status);
  194. if (Status!=(STATUS_SUCCESS)) {
  195. s_RxLog.State = RX_LOG_ERROR;
  196. DbgPrint("Couldn't initialize log5");
  197. RxFreePool(Mdl);
  198. RxFreePool(Buffer);
  199. RxFreePool(BaseEntry);
  200. return Status;
  201. }
  202. //DbgPrint("InitLog: newbuf=%08lx,mdl=%08lx,alloc=%08lx\n",Buffer,Mdl,AllocLength);
  203. MdlsLeft--;
  204. *MdlList = Mdl;
  205. MdlList++;
  206. *MdlList = NULL;
  207. NextBuffer = MmGetSystemAddressForMdlSafe(Mdl, LowPagePriority);
  208. if (NextBuffer == NULL) {
  209. s_RxLog.State = RX_LOG_ERROR;
  210. DbgPrint("Couldn't initialize log5");
  211. MmUnlockPages(Mdl);
  212. RxFreePool(Mdl);
  213. RxFreePool(Buffer);
  214. RxFreePool(BaseEntry);
  215. return STATUS_INSUFFICIENT_RESOURCES;
  216. }
  217. SpaceLeft = AllocLength;
  218. }
  219. p->Buffer = NextBuffer;
  220. *((PULONG)NextBuffer) = '###';
  221. NextBuffer += MAX_RX_LOG_ENTRY_SIZE;
  222. SpaceLeft -= MAX_RX_LOG_ENTRY_SIZE;
  223. }
  224. //DbgPrint("Init Log: numeleft,nummleft=%d,%d\n",NumEntriesLeft,MdlsLeft);
  225. p->Buffer = (PUCHAR)IntToPtr(0xf00df00d);
  226. s_RxLog.State = RX_LOG_ENABLED;
  227. s_RxLog.CurrentEntry = EntryLimit-1;
  228. //DbgPrint("Init Log: exit\n");
  229. return((STATUS_SUCCESS));
  230. }
  231. VOID
  232. _RxPauseLog ()
  233. {
  234. KIRQL oldIrql;
  235. KeAcquireSpinLock( &s_RxLog.SpinLock, &oldIrql );
  236. if (s_RxLog.State == RX_LOG_ENABLED) {
  237. s_RxLog.State = RX_LOG_DISABLED;
  238. }
  239. KeReleaseSpinLock( &s_RxLog.SpinLock, oldIrql );
  240. }
  241. VOID
  242. _RxResumeLog()
  243. {
  244. KIRQL oldIrql;
  245. KeAcquireSpinLock( &s_RxLog.SpinLock, &oldIrql );
  246. if (s_RxLog.State == RX_LOG_DISABLED) {
  247. s_RxLog.State = RX_LOG_ENABLED;
  248. }
  249. KeReleaseSpinLock( &s_RxLog.SpinLock, oldIrql );
  250. }
  251. VOID
  252. RxPrintLog (
  253. IN ULONG EntriesToPrint OPTIONAL
  254. )
  255. {
  256. //KIRQL oldIrql;
  257. PRX_LOG_ENTRY_HEADER LogEntry,EntryLimit;
  258. ULONG i=0;
  259. PAGED_CODE();
  260. RxPauseLog();
  261. if (EntriesToPrint==0) {
  262. EntriesToPrint = RX_LOG_BUFFER_SIZE;
  263. }
  264. DbgPrint("\n\n\nLog Print: Entries = %lu \n", EntriesToPrint);
  265. LogEntry = s_RxLog.CurrentEntry-1;
  266. EntryLimit = s_RxLog.EntryLimit;
  267. for (;EntriesToPrint>0;EntriesToPrint--) {
  268. LogEntry++;
  269. if (LogEntry>=EntryLimit) {
  270. LogEntry = s_RxLog.BaseEntry;
  271. }
  272. DbgPrint("%0ld: %s\n",i++,LogEntry->Buffer);
  273. }
  274. RxResumeLog();
  275. }
  276. VOID
  277. _RxLog(char *Format, ...)
  278. {
  279. va_list arglist;
  280. KIRQL oldIrql;
  281. CLONG LogEntryLength = 0;
  282. BOOLEAN fLogNewEntry = TRUE;
  283. PRX_LOG_ENTRY_HEADER LogEntry;
  284. CHAR EntryString[MAX_RX_LOG_ENTRY_SIZE];
  285. PCHAR pEntryString;
  286. CHAR FormatChar;
  287. CHAR FieldString[MAX_RX_LOG_ENTRY_SIZE];
  288. ULONG FieldLength;
  289. char *OriginalFormat = Format;
  290. ULONG BinaryArgs = 0;
  291. ULONG BinaryStringMask = 1; //the first arg is always a string!!!!
  292. //DbgPrint("RxLog: entry\n");
  293. if (s_RxLog.State != RX_LOG_ENABLED) {
  294. return;
  295. }
  296. pEntryString = EntryString;
  297. va_start(arglist, Format);
  298. //DbgBreakPoint();
  299. for (;;) {
  300. // Copy the format string
  301. while ((LogEntryLength < MAX_RX_LOG_ENTRY_SIZE) &&
  302. ((FormatChar = *Format++) != '\0') &&
  303. (FormatChar != '%')) {
  304. if (FormatChar != '\n'){
  305. pEntryString[LogEntryLength++] = FormatChar;
  306. }
  307. }
  308. if ((LogEntryLength < MAX_RX_LOG_ENTRY_SIZE) &&
  309. (FormatChar == '%')) {
  310. if ( (*Format == 'l') || (*Format == 'w') ) {
  311. Format++;
  312. }
  313. switch (*Format++) {
  314. case 'N': //binary placement -- don't try to make it foolproof
  315. {
  316. BinaryArgs++;
  317. *((PULONG)(&EntryString[sizeof(ULONG)])+BinaryArgs) = (ULONG)va_arg(arglist,ULONG);
  318. }
  319. break;
  320. case 'S': //binary placement -- don't try to make it foolproof
  321. {
  322. BinaryArgs++;
  323. BinaryStringMask |= 1<<(BinaryArgs-1);
  324. //DbgPrint("BSM %08lx\n",BinaryStringMask);
  325. *((PULONG)(&EntryString[sizeof(ULONG)])+BinaryArgs) = (ULONG)va_arg(arglist,ULONG);
  326. }
  327. break;
  328. case 'd':
  329. {
  330. // _itoa((LONG)va_arg(arglist,LONG),FieldString,10);
  331. // FieldLength = strlen(FieldString);// + 1;
  332. // if ((LogEntryLength + FieldLength) < MAX_RX_LOG_ENTRY_SIZE) {
  333. // strcpy(&pEntryString[LogEntryLength],FieldString);
  334. // LogEntryLength += FieldLength;
  335. // //pEntryString[LogEntryLength - 1] = ' ';
  336. // }
  337. LONG l = (LONG)va_arg(arglist,LONG);
  338. if ((LogEntryLength + 5) < MAX_RX_LOG_ENTRY_SIZE) {
  339. pEntryString[LogEntryLength++] = 0x5;
  340. pEntryString[LogEntryLength++] = (UCHAR)(0xff&(l>>0));
  341. pEntryString[LogEntryLength++] = (UCHAR)(0xff&(l>>8));
  342. pEntryString[LogEntryLength++] = (UCHAR)(0xff&(l>>16));
  343. pEntryString[LogEntryLength++] = (UCHAR)(0xff&(l>>24));
  344. }
  345. }
  346. break;
  347. case 'c':
  348. pEntryString[LogEntryLength++] = (CHAR)va_arg(arglist,char);
  349. break;
  350. case 'x':
  351. {
  352. // _itoa((LONG)va_arg(arglist,LONG),FieldString,16);
  353. // FieldLength = strlen(FieldString);// + 1;
  354. // if ((LogEntryLength + FieldLength) < MAX_RX_LOG_ENTRY_SIZE) {
  355. // strcpy(&pEntryString[LogEntryLength],FieldString);
  356. // LogEntryLength += FieldLength;
  357. // //pEntryString[LogEntryLength - 1] = ' ';
  358. // }
  359. LONG l = (LONG)va_arg(arglist,LONG);
  360. if ((LogEntryLength + 5) < MAX_RX_LOG_ENTRY_SIZE) {
  361. pEntryString[LogEntryLength++] = 0x4;
  362. pEntryString[LogEntryLength++] = (UCHAR)(0xff&(l>>0));
  363. pEntryString[LogEntryLength++] = (UCHAR)(0xff&(l>>8));
  364. pEntryString[LogEntryLength++] = (UCHAR)(0xff&(l>>16));
  365. pEntryString[LogEntryLength++] = (UCHAR)(0xff&(l>>24));
  366. }
  367. }
  368. break;
  369. case 's':
  370. {
  371. PCHAR pString = &pEntryString[LogEntryLength];
  372. PCHAR pArg = (PCHAR)va_arg(arglist, PCHAR);
  373. ASSERT(pArg!=NULL);
  374. FieldLength = strlen(pArg);// + 1;
  375. if ((LogEntryLength + FieldLength) < MAX_RX_LOG_ENTRY_SIZE) {
  376. strcpy(pString,pArg);
  377. LogEntryLength += FieldLength;
  378. //pEntryString[LogEntryLength - 1] = ' ';
  379. }
  380. }
  381. break;
  382. case 'Z':
  383. {
  384. PCHAR pString = &pEntryString[LogEntryLength];
  385. PUNICODE_STRING pArg = (PUNICODE_STRING)va_arg(arglist, PUNICODE_STRING);
  386. PWCHAR Buffer;
  387. ULONG Length;
  388. //this really only works for ascii strings in unicode......
  389. ASSERT(pArg!=NULL);
  390. Buffer = pArg->Buffer;
  391. // Make sure the length is WCHAR aligned
  392. Length = (pArg->Length & ~(sizeof(WCHAR)-1));
  393. //DbgPrint("yaya=%08lx,%08lx,%08lx\n",pArg,Buffer,Length);
  394. for (;Length>0;Length-=sizeof(WCHAR)) {
  395. if (LogEntryLength < MAX_RX_LOG_ENTRY_SIZE) {
  396. pEntryString[LogEntryLength++] = (UCHAR)(*Buffer++);
  397. } else {
  398. break;
  399. }
  400. }
  401. //DbgBreakPoint();
  402. }
  403. break;
  404. default:
  405. fLogNewEntry = FALSE;
  406. break;
  407. }
  408. } else {
  409. break;
  410. }
  411. }
  412. va_end(arglist);
  413. if (BinaryArgs) {
  414. EntryString[0] = '#';
  415. EntryString[1] = '>';
  416. EntryString[2] = '0'+(UCHAR)BinaryArgs;
  417. EntryString[3] = 0;
  418. *((PULONG)(&EntryString[sizeof(ULONG)])) = BinaryStringMask;
  419. LogEntryLength = MAX_RX_LOG_ENTRY_SIZE;
  420. }
  421. KeAcquireSpinLock( &s_RxLog.SpinLock, &oldIrql );
  422. if (fLogNewEntry) {
  423. s_RxLog.NumberOfLogWriteAttempts++;
  424. LogEntry = RxGetNextLogEntry();
  425. } else {
  426. s_RxLog.NumberOfEntriesIgnored++;
  427. DbgPrint("RxLog: Entry exceeds max size, not recorded <%s>\n",OriginalFormat);
  428. if (s_RxLog.NumberOfEntriesIgnored==1) {
  429. //DbgBreakPoint();
  430. }
  431. }
  432. KeReleaseSpinLock( &s_RxLog.SpinLock, oldIrql );
  433. if (fLogNewEntry) {
  434. BOOLEAN OutOfBounds = ((LogEntry<s_RxLog.BaseEntry) || (LogEntry>=s_RxLog.EntryLimit));
  435. if (OutOfBounds) {
  436. DbgPrint("RxLog: wrap logic has fail.....log disabled\n");
  437. s_RxLog.State = RX_LOG_DISABLED;
  438. } else {
  439. if (LogEntryLength >= MAX_RX_LOG_ENTRY_SIZE) {
  440. LogEntryLength = MAX_RX_LOG_ENTRY_SIZE;
  441. if (BinaryArgs == 0) {
  442. pEntryString[MAX_RX_LOG_ENTRY_SIZE-1] = 0;
  443. }
  444. } else {
  445. pEntryString[LogEntryLength++] = 0;
  446. }
  447. RtlCopyMemory(LogEntry->Buffer,pEntryString,LogEntryLength);
  448. }
  449. }
  450. }
  451. #define RxToUpper(CH) ((CH)&~('A'^'a'))
  452. #define RxIsLetter(CH) ((RxToUpper(CH)>='A') && (RxToUpper(CH)<='Z'))
  453. #define RxIsDigit(CH) (((CH)>='0')&&((CH)<='9'))
  454. VOID
  455. RxDebugControlCommand (
  456. IN char *ControlString
  457. )
  458. /*
  459. This routine manipulates the print and log levels and the breakpoint masks. the format is
  460. AAAAA+AAAAA+AAAAA+AAAAA.....
  461. where each AAAAA == <+-!>*<Letter>*<digit>*.
  462. <letter>* designates a control name.....only enuff to disambiguate is needed.
  463. any + turns on tracing globally
  464. any % turns on tracing globally RIGHT NOW!
  465. any - turns off tracing globally
  466. for 0 !s, it means: for the control <letter>*, set the printlevel to <digit>*
  467. for 1 !s, it means: for the control <letter>* set breakmask bit <digit>*. 0 means all bits
  468. for 2 !s, it means: for the control <letter>* clear breakmask bit <digit>*. 0 means all bits
  469. THIS STUFF (I.E. THE ! STUFF) IS ACTUALLY IMPLEMENTED IN RXTRACE.C
  470. @ means printlog
  471. @@ means pauselog
  472. @@@ means resumelog
  473. @@@@ means initialize
  474. @@@@@ means setup to debug by turning off printing
  475. more than @@@@@ means banner
  476. E.G. cle0+clo0+cre1000+!devf3 sets disables printing for cleanup and close, sets the printlevel
  477. for create to 1000, and enables the third bit of the breakmask for devfcb.
  478. the letter string is upcased automatically.
  479. There is usually one control for each file but some controls control stuff from multiple
  480. files (like dispatch)
  481. */
  482. {
  483. char namebuf[16], numbuf[16], *p, *q, *c;
  484. //long i;
  485. long level,pointcount,atsigncount;
  486. //DEBUG_TRACE_CONTROLS control;
  487. //ASSERTMSG("Here in debug command parser!\n",FALSE);
  488. RxDbgTrace( 0, (DEBUG_TRACE_ALWAYS), ("RxDebugTraceControl %s!!\n", ControlString));
  489. if (!ControlString)
  490. {
  491. return;
  492. }
  493. for (c = ControlString;;) {
  494. if (*c == 0) break;
  495. p=namebuf;q=numbuf; atsigncount=pointcount = 0;
  496. for (;(*c!=0)&&!RxIsLetter(*c)&&!RxIsDigit(*c); c++){ //skip to a letter or digit
  497. if (*c == '!') {
  498. pointcount++;
  499. }
  500. if (*c == '@') {
  501. atsigncount++;
  502. }
  503. #if RDBSSTRACE
  504. if (*c == '+') {
  505. RxNextGlobalTraceSuppress = FALSE;
  506. }
  507. if (*c == '%') {
  508. RxGlobalTraceSuppress = FALSE;
  509. }
  510. if (*c == '-') {
  511. RxNextGlobalTraceSuppress = TRUE;
  512. }
  513. #endif //RDBSSTRACE
  514. }
  515. for (p=namebuf;(*c!=0)&&RxIsLetter(*c); *p++=RxToUpper(*c++) ) ; //copy letters
  516. for (level=0,q=numbuf;(*c!=0)&&RxIsDigit(*c); *q++=*c++){ //copy digits
  517. level = 10*level+((*c)-'0');
  518. }
  519. *p = *q = (char)0;
  520. {if (atsigncount>0) {
  521. if (atsigncount==1) {
  522. RxPrintLog(level);
  523. } else if (atsigncount == 2) {
  524. RxPauseLog();
  525. } else if (atsigncount == 3) {
  526. RxResumeLog();
  527. } else if (atsigncount == 4) {
  528. RxInitializeLog();
  529. } else if (atsigncount == 5){
  530. #if RDBSSTRACE
  531. RxDebugTraceZeroAllPrintLevels();
  532. RxDbgTraceFindControlPoint((DEBUG_TRACE_UNWIND))->PrintLevel = 10000;
  533. RxDbgTraceFindControlPoint((DEBUG_TRACE_READ))->PrintLevel = 10000;
  534. RxDbgTraceFindControlPoint((DEBUG_TRACE_RXCONTX))->PrintLevel = 1000;
  535. RxDbgTraceFindControlPoint((DEBUG_TRACE_DISPATCH))->PrintLevel = 1000;
  536. RxDbgTraceFindControlPoint((DEBUG_TRACE_CREATE))->PrintLevel = 10000;
  537. RxDbgTraceFindControlPoint((DEBUG_TRACE_CLEANUP))->PrintLevel = 10000;
  538. RxDbgTraceFindControlPoint((DEBUG_TRACE_CLOSE))->PrintLevel = 10000;
  539. #endif
  540. } else {
  541. #if RDBSSTRACE
  542. RxDbgTrace(0, (DEBUG_TRACE_ALWAYS), ("\n\n\n\n\n %s %s\n\n\n\n\n", namebuf, numbuf));
  543. #endif
  544. }
  545. continue;
  546. }}
  547. #if RDBSSTRACE
  548. if (((*namebuf)==0||(*numbuf)==0)) {
  549. continue;
  550. }
  551. RxDebugTraceDebugCommand(namebuf,level,pointcount);
  552. #endif
  553. }
  554. return;
  555. }
  556. #ifdef DBG
  557. VOID
  558. RxpTrackReference(
  559. ULONG TraceType,
  560. PCHAR FileName,
  561. ULONG Line,
  562. PVOID pInstance)
  563. {
  564. if (REF_TRACING_ON(TraceType)) {
  565. ULONG RefCount;
  566. PCHAR pTypeName,pLogTypeName;
  567. switch (TraceType) {
  568. case RDBSS_REF_TRACK_SRVCALL :
  569. pTypeName = "SrvCall";
  570. pLogTypeName = "SC";
  571. RefCount = ((PSRV_CALL)pInstance)->NodeReferenceCount;
  572. RxWmiLog(SRVCALL,RxRefSrvcall,LOGPTR(pInstance)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  573. break;
  574. case RDBSS_REF_TRACK_NETROOT :
  575. pTypeName = "NetRoot";
  576. pLogTypeName = "NR";
  577. RefCount = ((PNET_ROOT)pInstance)->NodeReferenceCount;
  578. RxWmiLog(NETROOT,RxRefNetRoot,LOGPTR(pInstance)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  579. break;
  580. case RDBSS_REF_TRACK_VNETROOT:
  581. pTypeName = "VNetRoot";
  582. pLogTypeName = "VN";
  583. RefCount = ((PV_NET_ROOT)pInstance)->NodeReferenceCount;
  584. RxWmiLog(VNETROOT,RxRefVNetRoot,LOGPTR(pInstance)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  585. break;
  586. case RDBSS_REF_TRACK_NETFOBX :
  587. pTypeName = "NetFobx";
  588. pLogTypeName = "FO";
  589. RefCount = ((PFOBX)pInstance)->NodeReferenceCount;
  590. RxWmiLog(FOBX,RxRefFobx,LOGPTR(pInstance)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  591. break;
  592. case RDBSS_REF_TRACK_NETFCB :
  593. pTypeName = "NetFcb";
  594. pLogTypeName = "FC";
  595. RefCount = ((PFCB)pInstance)->NodeReferenceCount;
  596. RxWmiLog(FCB,RxRefFcb,LOGPTR(pInstance)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  597. break;
  598. case RDBSS_REF_TRACK_SRVOPEN :
  599. pTypeName = "SrvOpen";
  600. pLogTypeName = "SO";
  601. RefCount = ((PSRV_OPEN)pInstance)->NodeReferenceCount;
  602. RxWmiLog(SRVOPEN,RxRefSrvOpen,LOGPTR(pInstance)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  603. break;
  604. default:
  605. DbgPrint("Invalid Node Type for referencing\n");
  606. //DbgBreakPoint();
  607. return;
  608. }
  609. if (RdbssReferenceTracingValue & RX_LOG_REF_TRACKING) {
  610. RxLog(("Ref.%s %lx %ld %lx %ld->%ld",pLogTypeName,pInstance,Line,FileName,RefCount,RefCount+1));
  611. }
  612. if (RdbssReferenceTracingValue & RX_PRINT_REF_TRACKING) {
  613. DbgPrint("Reference %s %lx %ld %s\n",pTypeName,pInstance,Line,FileName);
  614. }
  615. }
  616. }
  617. BOOLEAN
  618. RxpTrackDereference(
  619. ULONG TraceType,
  620. PCHAR FileName,
  621. ULONG Line,
  622. PVOID pInstance)
  623. {
  624. PAGED_CODE();
  625. if (REF_TRACING_ON(TraceType)) {
  626. PCHAR pTypeName,pLogTypeName;
  627. ULONG RefCount;
  628. switch (TraceType) {
  629. case RDBSS_REF_TRACK_SRVCALL :
  630. pTypeName = "SrvCall";
  631. pLogTypeName = "SC";
  632. RefCount = ((PSRV_CALL)pInstance)->NodeReferenceCount;
  633. RxWmiLog(SRVCALL,RxDerefSrvcall,LOGPTR(pInstance)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  634. break;
  635. case RDBSS_REF_TRACK_NETROOT :
  636. pTypeName = "NetRoot";
  637. pLogTypeName = "NR";
  638. RefCount = ((PNET_ROOT)pInstance)->NodeReferenceCount;
  639. RxWmiLog(NETROOT,RxDerefNetRoot,LOGPTR(pInstance)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  640. break;
  641. case RDBSS_REF_TRACK_VNETROOT:
  642. pTypeName = "VNetRoot";
  643. pLogTypeName = "VN";
  644. RefCount = ((PV_NET_ROOT)pInstance)->NodeReferenceCount;
  645. RxWmiLog(VNETROOT,RxDerefVNetRoot,LOGPTR(pInstance)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  646. break;
  647. case RDBSS_REF_TRACK_NETFOBX :
  648. pTypeName = "NetFobx";
  649. pLogTypeName = "FO";
  650. RefCount = ((PFOBX)pInstance)->NodeReferenceCount;
  651. RxWmiLog(FOBX,RxDerefFobx,LOGPTR(pInstance)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  652. break;
  653. case RDBSS_REF_TRACK_NETFCB :
  654. pTypeName = "NetFcb";
  655. pLogTypeName = "FC";
  656. RefCount = ((PFCB)pInstance)->NodeReferenceCount;
  657. RxWmiLog(FCB,RxDerefFcb,LOGPTR(pInstance)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  658. break;
  659. case RDBSS_REF_TRACK_SRVOPEN :
  660. pTypeName = "SrvOpen";
  661. pLogTypeName = "SO";
  662. RefCount = ((PSRV_OPEN)pInstance)->NodeReferenceCount;
  663. RxWmiLog(SRVOPEN,RxDerefSrvOpen,LOGPTR(pInstance)LOGULONG(RefCount)LOGULONG(Line)LOGARSTR(FileName));
  664. break;
  665. default:
  666. DbgPrint("Invalid Node Type for referencing\n");
  667. //DbgBreakPoint();
  668. return TRUE;
  669. }
  670. if (RdbssReferenceTracingValue & RX_LOG_REF_TRACKING) {
  671. RxLog(("Deref.%s %lx %ld %lx %ld->%ld",pLogTypeName,pInstance,Line,FileName,RefCount,RefCount-1));
  672. }
  673. if (RdbssReferenceTracingValue & RX_PRINT_REF_TRACKING) {
  674. DbgPrint("Dereference %s %lx %ld %s\n",pTypeName,pInstance,Line,FileName);
  675. }
  676. }
  677. return TRUE;
  678. }
  679. #endif