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.

122 lines
3.1 KiB

  1. // Copyright (c) 1998 Microsoft Corporation
  2. //
  3. // KernHelp.cpp
  4. //
  5. // Wrappers for kernel functions to make synth core cross compilable
  6. //
  7. extern "C" {
  8. #include <ntddk.h>
  9. };
  10. #include "KernHelp.h"
  11. VOID InitializeCriticalSection(
  12. LPCRITICAL_SECTION CritSect)
  13. {
  14. KeInitializeMutex((PKMUTEX)CritSect, 1);
  15. }
  16. VOID EnterCriticalSection(
  17. LPCRITICAL_SECTION CritSect)
  18. {
  19. KeWaitForSingleObject((PKMUTEX)CritSect,
  20. Executive,
  21. KernelMode,
  22. FALSE,
  23. 0);
  24. }
  25. VOID LeaveCriticalSection(
  26. LPCRITICAL_SECTION CritSect)
  27. {
  28. KeReleaseMutex((PKMUTEX)CritSect, FALSE);
  29. }
  30. VOID DeleteCriticalSection(
  31. LPCRITICAL_SECTION CritSect)
  32. {
  33. // NOP in kernel
  34. //
  35. }
  36. // GetRegValueDword
  37. //
  38. // Must be called at passive level
  39. //
  40. int GetRegValueDword(
  41. LPTSTR RegPath,
  42. LPTSTR ValueName,
  43. PULONG Value)
  44. {
  45. int ReturnValue = 0;
  46. NTSTATUS Status;
  47. OBJECT_ATTRIBUTES ObjectAttributes;
  48. HANDLE KeyHandle;
  49. KEY_VALUE_PARTIAL_INFORMATION *Information;
  50. ULONG InformationSize;
  51. UNICODE_STRING UnicodeRegPath;
  52. UNICODE_STRING UnicodeValueName;
  53. RtlInitUnicodeString(&UnicodeRegPath, RegPath);
  54. RtlInitUnicodeString(&UnicodeValueName, ValueName);
  55. InitializeObjectAttributes(&ObjectAttributes,
  56. &UnicodeRegPath,
  57. 0, // Flags
  58. NULL, // Root directory
  59. NULL); // Security descriptor
  60. Status = ZwOpenKey(&KeyHandle,
  61. KEY_QUERY_VALUE,
  62. &ObjectAttributes);
  63. if (Status != STATUS_SUCCESS)
  64. {
  65. return 0;
  66. }
  67. InformationSize = sizeof(Information) + sizeof(ULONG);
  68. Information = (KEY_VALUE_PARTIAL_INFORMATION*)ExAllocatePool(PagedPool, InformationSize);
  69. if (Information == NULL)
  70. {
  71. return 0;
  72. }
  73. Status = ZwQueryValueKey(KeyHandle,
  74. &UnicodeValueName,
  75. KeyValuePartialInformation,
  76. Information,
  77. sizeof(Information),
  78. &InformationSize);
  79. if (Status == STATUS_SUCCESS)
  80. {
  81. if (Information->Type == REG_DWORD && Information->DataLength == sizeof(ULONG))
  82. {
  83. RtlCopyMemory(Value, Information->Data, sizeof(ULONG));
  84. ReturnValue = 1;
  85. }
  86. }
  87. ExFreePool(Information);
  88. ZwClose(KeyHandle);
  89. return ReturnValue;
  90. }
  91. ULONG GetTheCurrentTime()
  92. {
  93. LARGE_INTEGER Time;
  94. KeQuerySystemTime(&Time);
  95. return (ULONG)(Time.QuadPart / (10 * 1000));
  96. }
  97. void DebugInit(void)
  98. {
  99. }
  100. void DebugTrace(int iDebugLevel, LPSTR pstrFormat, ...)
  101. {
  102. }