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.

203 lines
4.8 KiB

  1. /*** nt.c - NT specific functions
  2. *
  3. * Copyright (c) 1996,1997 Microsoft Corporation
  4. * Author: Michael Tsang (MikeTs)
  5. * Created: 11/03/97
  6. *
  7. * MODIFICATION HISTORY
  8. */
  9. #ifdef ___UNASM
  10. #pragma warning (disable: 4201 4214 4514)
  11. typedef unsigned __int64 ULONGLONG;
  12. #define LOCAL __cdecl
  13. #define EXPORT __cdecl
  14. #include <stdarg.h>
  15. #ifndef WINNT
  16. #define _X86_
  17. #endif
  18. #include <windef.h>
  19. #include <winbase.h>
  20. #include <winreg.h>
  21. #define EXCL_BASEDEF
  22. #include "aslp.h"
  23. /***LP IsWinNT - check if OS is NT
  24. *
  25. * ENTRY
  26. * None
  27. *
  28. * EXIT-SUCCESS
  29. * returns TRUE - OS is NT
  30. * EXIT-FAILURE
  31. * returns FALSE - OS is not NT
  32. */
  33. BOOL LOCAL IsWinNT(VOID)
  34. {
  35. BOOL rc = FALSE;
  36. OSVERSIONINFO osinfo;
  37. ENTER((2, "IsWinNT()\n"));
  38. osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  39. if (GetVersionEx(&osinfo) && (osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT))
  40. {
  41. rc = TRUE;
  42. }
  43. EXIT((2, "IsWinNT=%x\n", rc));
  44. return rc;
  45. } //IsWinNT
  46. /***LP EnumSubKey - enumerate subkey
  47. *
  48. * ENTRY
  49. * hkey - key to enumerate
  50. * dwIndex - subkey index
  51. *
  52. * EXIT-SUCCESS
  53. * returns subkey
  54. * EXIT-FAILURE
  55. * returns NULL
  56. */
  57. HKEY LOCAL EnumSubKey(HKEY hkey, DWORD dwIndex)
  58. {
  59. HKEY hkeySub = NULL;
  60. char szSubKey[32];
  61. DWORD dwSubKeySize = sizeof(szSubKey);
  62. ENTER((2, "EnumSubKey(hkey=%x,Index=%d)\n", hkey, dwIndex));
  63. if ((RegEnumKeyEx(hkey, dwIndex, szSubKey, &dwSubKeySize, NULL, NULL, NULL,
  64. NULL) == ERROR_SUCCESS) &&
  65. (RegOpenKeyEx(hkey, szSubKey, 0, KEY_READ, &hkeySub) != ERROR_SUCCESS))
  66. {
  67. hkeySub = NULL;
  68. }
  69. EXIT((2, "EnumSubKey=%x\n", hkeySub));
  70. return hkeySub;
  71. } //EnumSubKey
  72. /***LP OpenNTTable - Open ACPI table in NT registry
  73. *
  74. * ENTRY
  75. * pszTabSig -> table signature string
  76. *
  77. * EXIT-SUCCESS
  78. * returns table registry handle
  79. * EXIT-FAILURE
  80. * returns NULL
  81. */
  82. HKEY LOCAL OpenNTTable(PSZ pszTabSig)
  83. {
  84. HKEY hkeyTab = NULL, hkey1 = NULL, hkey2 = NULL;
  85. static char szTabKey[] = "Hardware\\ACPI\\xxxx";
  86. ENTER((2, "OpenNTTable(TabSig=%s)\n", pszTabSig));
  87. lstrcpyn(&szTabKey[lstrlen(szTabKey) - 4], pszTabSig, 5);
  88. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szTabKey, 0, KEY_READ, &hkey1) ==
  89. ERROR_SUCCESS)
  90. {
  91. //
  92. // hkey1 is now "Hardware\ACPI\<TabSig>"
  93. //
  94. if ((hkey2 = EnumSubKey(hkey1, 0)) != NULL)
  95. {
  96. //
  97. // hkey2 is now "Hardware\ACPI\<TabSig>\<OEMID>"
  98. //
  99. RegCloseKey(hkey1);
  100. if ((hkey1 = EnumSubKey(hkey2, 0)) != NULL)
  101. {
  102. //
  103. // hkey1 is now "Hardware\ACPI\<TabSig>\<OEMID>\<OEMTabID>"
  104. //
  105. RegCloseKey(hkey2);
  106. if ((hkey2 = EnumSubKey(hkey1, 0)) != NULL)
  107. {
  108. //
  109. // hkey2 is now
  110. // "Hardware\ACPI\<TabSig>\<OEMID>\<OEMTabID>\<OEMRev>"
  111. //
  112. hkeyTab = hkey2;
  113. }
  114. }
  115. }
  116. }
  117. if (hkey1 != NULL)
  118. {
  119. RegCloseKey(hkey1);
  120. }
  121. if ((hkey2 != NULL) && (hkeyTab != hkey2))
  122. {
  123. RegCloseKey(hkey2);
  124. }
  125. EXIT((2, "OpenNTTable=%x\n", hkeyTab));
  126. return hkeyTab;
  127. } //OpenNTTable
  128. /***LP GetNTTable - Get ACPI table from NT registry
  129. *
  130. * ENTRY
  131. * pszTabSig -> table signature string
  132. *
  133. * EXIT-SUCCESS
  134. * returns pointer to table
  135. * EXIT-FAILURE
  136. * returns NULL
  137. */
  138. PBYTE LOCAL GetNTTable(PSZ pszTabSig)
  139. {
  140. PBYTE pb = NULL;
  141. HKEY hkeyTab;
  142. ENTER((2, "GetNTTable(TabSig=%s)\n", pszTabSig));
  143. if ((hkeyTab = OpenNTTable(pszTabSig)) != NULL)
  144. {
  145. DWORD dwLen = 0;
  146. PSZ pszTabKey = "00000000";
  147. if (RegQueryValueEx(hkeyTab, pszTabKey, NULL, NULL, NULL, &dwLen) ==
  148. ERROR_SUCCESS)
  149. {
  150. if ((pb = MEMALLOC(dwLen)) != NULL)
  151. {
  152. if (RegQueryValueEx(hkeyTab, pszTabKey, NULL, NULL, pb, &dwLen)
  153. != ERROR_SUCCESS)
  154. {
  155. ERROR(("GetNTTable: failed to read table"));
  156. }
  157. }
  158. else
  159. {
  160. ERROR(("GetNTTable: failed to allocate table buffer"));
  161. }
  162. }
  163. else
  164. {
  165. ERROR(("GetNTTable: failed to read table key"));
  166. }
  167. RegCloseKey(hkeyTab);
  168. }
  169. else
  170. {
  171. ERROR(("GetNTTable: failed to get table %s", pszTabSig));
  172. }
  173. EXIT((2, "GetNTTable=%x\n", pb));
  174. return pb;
  175. } //GetNTTable
  176. #endif //ifdef __UNASM