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.

198 lines
4.6 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. errlog.c
  5. Abstract:
  6. This module contains routines for writting to the error log
  7. Author:
  8. Hanumant Yadav
  9. Environment:
  10. NT Kernel Model Driver only
  11. Revision History:
  12. 10/19/2000 Fixed event log function, removed dead code.
  13. --*/
  14. #include "pch.h"
  15. //
  16. // We need to know the name of the driver when we write log errors
  17. //
  18. PDRIVER_OBJECT AcpiDriverObject;
  19. NTSTATUS
  20. ACPIWriteEventLogEntry (
  21. IN ULONG ErrorCode,
  22. IN PVOID InsertionStrings, OPTIONAL
  23. IN ULONG StringCount, OPTIONAL
  24. IN PVOID DumpData, OPTIONAL
  25. IN ULONG DataSize OPTIONAL
  26. )
  27. /*++
  28. Routine Description: Write a entry to the Event Log.
  29. Arguments:
  30. ErrorCode - ACPI error code (acpilog.mc).
  31. InsertionStrings - Strings to substitute in the .mc file error.
  32. StringCount - number of strings being passed in InsertionStrings.
  33. DumpData - Dump data.
  34. DataSize - Dump data size.
  35. Return Value:
  36. NTSTATUS - STATUS_SUCCESS on success
  37. STATUS_INSUFFICIENT_RESOURCES
  38. STATUS_UNSUCCESSFUL
  39. --*/
  40. {
  41. NTSTATUS status = STATUS_SUCCESS;
  42. ULONG totalPacketSize = 0;
  43. ULONG i, stringSize = 0;
  44. PWCHAR *strings, temp;
  45. PIO_ERROR_LOG_PACKET logEntry = NULL;
  46. //
  47. // Calculate total string length, including NULL.
  48. //
  49. strings = (PWCHAR *) InsertionStrings;
  50. for (i = 0; i < StringCount; i++)
  51. {
  52. UNICODE_STRING unicodeString;
  53. RtlInitUnicodeString(&unicodeString, strings[i]);
  54. stringSize += unicodeString.Length + sizeof(UNICODE_NULL);
  55. }
  56. //
  57. // Calculate total packet size to allocate. The packet must be
  58. // at least sizeof(IO_ERROR_LOG_PACKET) and not larger than
  59. // ERROR_LOG_MAXIMUM_SIZE or the IoAllocateErrorLogEntry call will fail.
  60. //
  61. totalPacketSize = (sizeof(IO_ERROR_LOG_PACKET)) + DataSize + stringSize;
  62. if (totalPacketSize <= ERROR_LOG_MAXIMUM_SIZE)
  63. {
  64. //
  65. // Allocate the error log packet
  66. //
  67. logEntry = IoAllocateErrorLogEntry((PDRIVER_OBJECT) AcpiDriverObject,
  68. (UCHAR) totalPacketSize);
  69. if (logEntry)
  70. {
  71. RtlZeroMemory(logEntry, totalPacketSize);
  72. //
  73. // Fill out the packet
  74. //
  75. logEntry->DumpDataSize = (USHORT) DataSize;
  76. logEntry->NumberOfStrings = (USHORT) StringCount;
  77. logEntry->ErrorCode = ErrorCode;
  78. if (StringCount)
  79. {
  80. logEntry->StringOffset = (USHORT) ((sizeof(IO_ERROR_LOG_PACKET)) + DataSize);
  81. }
  82. //
  83. // Copy Dump Data
  84. //
  85. if (DataSize)
  86. {
  87. RtlCopyMemory((PVOID) logEntry->DumpData,
  88. DumpData,
  89. DataSize);
  90. }
  91. //
  92. // Copy String Data
  93. //
  94. temp = (PWCHAR) ((PUCHAR) logEntry + logEntry->StringOffset);
  95. for (i = 0; i < StringCount; i++)
  96. {
  97. PWCHAR ptr = strings[i];
  98. //
  99. // This routine will copy the null terminator on the string
  100. //
  101. while ((*temp++ = *ptr++) != UNICODE_NULL);
  102. }
  103. //
  104. // Submit error log packet
  105. //
  106. IoWriteErrorLogEntry(logEntry);
  107. }
  108. else
  109. {
  110. ACPIPrint((
  111. ACPI_PRINT_CRITICAL,
  112. "ACPIWriteEventLogEntry: Failed IoAllocateErrorLogEntry().\n"
  113. ));
  114. status = STATUS_INSUFFICIENT_RESOURCES;
  115. }
  116. }
  117. else
  118. {
  119. ACPIPrint((
  120. ACPI_PRINT_CRITICAL,
  121. "ACPIWriteEventLogEntry: Error Log Entry too large.\n"
  122. ));
  123. status = STATUS_UNSUCCESSFUL;
  124. }
  125. return status;
  126. }
  127. PDEVICE_OBJECT
  128. ACPIGetRootDeviceObject(
  129. VOID
  130. )
  131. /*++
  132. Routine Description: Get the value of the ACPI root device object.
  133. Arguments:
  134. None
  135. Return Value:
  136. PDEVICE_OBJECT - ACPI Root Device Object.
  137. --*/
  138. {
  139. if(RootDeviceExtension)
  140. {
  141. return RootDeviceExtension->DeviceObject;
  142. }
  143. return NULL;
  144. }