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.

137 lines
2.5 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1995 - 1999
  3. All rights reserved.
  4. Module Name:
  5. wow64.h
  6. Abstract:
  7. printui wow64 related functions.
  8. Author:
  9. Lazar Ivanov (LazarI) 10-Mar-2000
  10. Revision History:
  11. --*/
  12. #include <nt.h>
  13. #include <ntrtl.h>
  14. #include <nturtl.h>
  15. #include <windows.h>
  16. #include <tchar.h>
  17. #include "wow64.h"
  18. #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
  19. //
  20. // Win64 APIs, types and data structures.
  21. //
  22. ClientVersion
  23. OSEnv_GetClientVer(
  24. VOID
  25. )
  26. {
  27. return(sizeof(ULONG_PTR));
  28. }
  29. ServerVersion
  30. OSEnv_GetServerVer(
  31. VOID
  32. )
  33. {
  34. ULONG_PTR ul;
  35. NTSTATUS st;
  36. ServerVersion serverVersion;
  37. st = NtQueryInformationProcess(NtCurrentProcess(),
  38. ProcessWow64Information, &ul, sizeof(ul), NULL);
  39. if( NT_SUCCESS(st) )
  40. {
  41. // If this call succeeds, we're on Win2000 or newer machines.
  42. if( 0 != ul )
  43. {
  44. // 32-bit code running on Win64
  45. serverVersion = THUNKVERSION;
  46. }
  47. else
  48. {
  49. // 32-bit code running on Win2000 or later 32-bit OS
  50. serverVersion = NATIVEVERSION;
  51. }
  52. }
  53. else
  54. {
  55. serverVersion = NATIVEVERSION;
  56. }
  57. return serverVersion;
  58. }
  59. #if 0 // debug code
  60. BOOL
  61. IsRunningInSPLWOW(
  62. VOID
  63. )
  64. {
  65. TCHAR szSysDir[MAX_PATH];
  66. TCHAR szSplWOW64Name[MAX_PATH];
  67. TCHAR szModName[MAX_PATH];
  68. GetWindowsDirectory(szSysDir, ARRAYSIZE(szSysDir));
  69. _tcscpy(szSplWOW64Name, szSysDir);
  70. _tcscat(szSplWOW64Name, TEXT("\\splwow64.exe"));
  71. GetModuleFileName(NULL, szModName, ARRAYSIZE(szModName));
  72. return (0 == _tcsicmp(szSplWOW64Name, szModName));
  73. }
  74. #endif // 0
  75. BOOL
  76. IsRunningWOW64(
  77. VOID
  78. )
  79. {
  80. // return !IsRunningInSPLWOW();
  81. return (RUN32BINVER == OSEnv_GetClientVer() &&
  82. THUNKVERSION == OSEnv_GetServerVer());
  83. }
  84. PlatformType
  85. GetCurrentPlatform(
  86. VOID
  87. )
  88. {
  89. if (RUN64BINVER == OSEnv_GetClientVer())
  90. {
  91. // this is a native 64bit process - i.e. the platform is IA64
  92. return kPlatform_IA64;
  93. }
  94. else
  95. {
  96. // this is 32 bit process. it can be either native - i.e. the platform is i386 -
  97. // or wow64 - i.e. the platform is again IA64.
  98. if (THUNKVERSION == OSEnv_GetServerVer())
  99. {
  100. // the process is wow64 - the platform is IA64
  101. return kPlatform_IA64;
  102. }
  103. else
  104. {
  105. // the process is native - i.e. the platform is x86
  106. return kPlatform_x86;
  107. }
  108. }
  109. }