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.

105 lines
2.9 KiB

  1. extern "C" {
  2. #include <nt.h>
  3. #include <ntrtl.h>
  4. #include <nturtl.h>
  5. #include <windows.h>
  6. }
  7. #include "log.hxx"
  8. #ifdef DBG
  9. /*
  10. * Debuggers should not use this value (which is why it's in the source, not
  11. * the header. Don't get confused! Look for g_OleLogLen instead!
  12. */
  13. #define OLE32_LOG_MAX (4096)
  14. // The actual log. Allocated on first access to the log function
  15. DebugEvent *gOleLog = NULL;
  16. /*
  17. * The size of the log. While technically I could just use the define,
  18. * changing the value would then break debugger extensions that read this
  19. * stuff, and that would then destroy the whole point of this, now wouldn't
  20. * it?
  21. */
  22. DWORD gOleLogLen = OLE32_LOG_MAX;
  23. /*
  24. * This is where the next event is going to go.
  25. * To read the log, start with the entry g_OleLog[g_OleLogNext], and work your
  26. * way around to g_OleLog[g_OleLogNext-1]. Ignore every reference to the
  27. * subject SU_NOTHING.... those are entries that haven't been used yet.
  28. *
  29. * Don't you DARE try to log an event that has SU_NOTHING as the subject.
  30. */
  31. long gOleLogNext = 0;
  32. unsigned char gIgnoreSubject[256] = {0};
  33. unsigned char gIgnoreVerb[256] = {0};
  34. BOOL gfDisableLog = 0;
  35. /*
  36. * Currently there are a couple issues that this does not attempt to solve.
  37. * For example, this does nothing in the case of contention of threads for
  38. * a particular entry in the log. This only happens when the log wraps
  39. * WAY over. The solution requires locking, and I think it's more important
  40. * to be fast in the majority of cases than correct in the extreme minority.
  41. */
  42. void __Ole32Log (unsigned char Subject, unsigned char Verb,
  43. void *SubjectPtr, void *ObjectPtr, ULONG_PTR UserData,
  44. BOOL fGrabStack, int FramesToSkip)
  45. {
  46. DebugEvent *log;
  47. DWORD myIndex;
  48. if (gIgnoreSubject[Subject] || gIgnoreVerb[Verb] || gfDisableLog)
  49. return;
  50. // Allocate the log...
  51. if (gOleLog == NULL)
  52. {
  53. log = (DebugEvent *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
  54. gOleLogLen * sizeof(DebugEvent));
  55. if (log == NULL)
  56. return;
  57. if (InterlockedCompareExchangePointer((void **)&gOleLog, (void *)log,
  58. NULL) != NULL)
  59. HeapFree(GetProcessHeap(), 0, log);
  60. }
  61. myIndex = InterlockedIncrement(&gOleLogNext) % gOleLogLen;
  62. gOleLog[myIndex].Time = GetTickCount();
  63. gOleLog[myIndex].ThreadID = GetCurrentThreadId();
  64. gOleLog[myIndex].Subject = Subject;
  65. gOleLog[myIndex].Verb = Verb;
  66. gOleLog[myIndex].SubjectPtr= SubjectPtr;
  67. gOleLog[myIndex].ObjectPtr = ObjectPtr;
  68. gOleLog[myIndex].UserData = UserData;
  69. if (fGrabStack)
  70. {
  71. ULONG ignore;
  72. RtlCaptureStackBackTrace( 1 + FramesToSkip, STACKTRACE_DEPTH,
  73. gOleLog[myIndex].Stack, &ignore );
  74. } else {
  75. gOleLog[myIndex].Stack[0] = NULL;
  76. }
  77. }
  78. #endif // DBG