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.

185 lines
3.3 KiB

  1. /*++
  2. Copyright(c) 2000 Microsoft Corporation
  3. Module Name:
  4. eventlog.c
  5. Abstract:
  6. Author:
  7. Todd Carpenter
  8. Environment:
  9. Kernel Mode Only
  10. Revision History:
  11. 07-12-2000 created
  12. --*/
  13. #include "eventlog.h"
  14. #include "dbgsys.h"
  15. ULONG ErrorLogCount = 0;
  16. NTSTATUS
  17. WriteEventLogEntry (
  18. IN PVOID DeviceObject,
  19. IN ULONG ErrorCode,
  20. IN PVOID InsertionStrings, OPTIONAL
  21. IN ULONG StringCount, OPTIONAL
  22. IN PVOID DumpData, OPTIONAL
  23. IN ULONG DataSize OPTIONAL
  24. )
  25. /*++
  26. Routine Description:
  27. Arguments:
  28. Status -
  29. UniqueErrorValue -
  30. InsertionStrings -
  31. StringCount -
  32. DumpData -
  33. DataSize -
  34. Return Value:
  35. NTSTATUS
  36. --*/
  37. {
  38. #define ERROR_PACKET_SIZE sizeof(IO_ERROR_LOG_PACKET)
  39. NTSTATUS status = STATUS_SUCCESS;
  40. ULONG totalPacketSize;
  41. ULONG i, stringSize = 0;
  42. PWCHAR *strings, temp;
  43. PIO_ERROR_LOG_PACKET logEntry;
  44. //
  45. // Calculate total string length, including NULL.
  46. //
  47. strings = (PWCHAR *) InsertionStrings;
  48. for (i = 0; i < StringCount; i++) {
  49. UNICODE_STRING unicodeString;
  50. RtlInitUnicodeString(&unicodeString, strings[i]);
  51. stringSize += unicodeString.Length + sizeof(UNICODE_NULL);
  52. //stringSize += (wcslen(strings[i]) + 1) * sizeof(WCHAR);
  53. }
  54. //
  55. // Calculate total packet size to allocate. The packet must be
  56. // at least sizeof(IO_ERROR_LOG_PACKET) and not larger than
  57. // ERROR_LOG_MAXIMUM_SIZE or the IoAllocateErrorLogEntry call will fail.
  58. //
  59. totalPacketSize = ERROR_PACKET_SIZE + DataSize + stringSize;
  60. if (totalPacketSize >= ERROR_LOG_MAXIMUM_SIZE) {
  61. DebugPrint((TRACE, "WriteEventLogEntry: Error Log Entry too large.\n"));
  62. status = STATUS_UNSUCCESSFUL;
  63. goto WriteEventLogEntryExit;
  64. }
  65. //
  66. // Allocate the error log packet
  67. //
  68. logEntry = IoAllocateErrorLogEntry(DeviceObject,
  69. (UCHAR) totalPacketSize);
  70. if (!logEntry) {
  71. status = STATUS_INSUFFICIENT_RESOURCES;
  72. goto WriteEventLogEntryExit;
  73. }
  74. RtlZeroMemory(logEntry, totalPacketSize);
  75. //
  76. // Fill out the packet
  77. //
  78. //logEntry->MajorFunctionCode = 0;
  79. //logEntry->RetryCount = 0;
  80. //logEntry->UniqueErrorValue = 0;
  81. //logEntry->FinalStatus = 0;
  82. //logEntry->SequenceNumber = ErrorLogCount++;
  83. //logEntry->IoControlCode = 0;
  84. //logEntry->DeviceOffset.QuadPart = 0;
  85. logEntry->DumpDataSize = (USHORT) DataSize;
  86. logEntry->NumberOfStrings = (USHORT) StringCount;
  87. logEntry->EventCategory = 0x1; // type devices
  88. logEntry->ErrorCode = ErrorCode;
  89. if (StringCount) {
  90. logEntry->StringOffset = (USHORT) (ERROR_PACKET_SIZE + DataSize);
  91. }
  92. //
  93. // Copy Dump Data
  94. //
  95. if (DataSize) {
  96. RtlCopyMemory((PVOID) logEntry->DumpData,
  97. DumpData,
  98. DataSize);
  99. }
  100. //
  101. // Copy String Data
  102. //
  103. temp = (PWCHAR) ((PUCHAR) logEntry + logEntry->StringOffset);
  104. for (i = 0; i < StringCount; i++) {
  105. PWCHAR ptr = strings[i];
  106. //
  107. // This routine will copy the null terminator on the string
  108. //
  109. while ((*temp++ = *ptr++) != UNICODE_NULL);
  110. }
  111. //
  112. // Submit error log packet
  113. //
  114. IoWriteErrorLogEntry(logEntry);
  115. WriteEventLogEntryExit:
  116. return status;
  117. }