SysInfo.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. //----------------------------------------------------------------------------
  6. // Automatic system info getter at startup
  7. //----------------------------------------------------------------------------
  8. class AutoSystemInfo : public SYSTEM_INFO
  9. {
  10. friend void ChakraBinaryAutoSystemInfoInit(AutoSystemInfo *); // The hosting DLL provides the implementation of this function.
  11. public:
  12. static AutoSystemInfo Data;
  13. uint GetAllocationGranularityPageCount() const;
  14. uint GetAllocationGranularityPageSize() const;
  15. bool DisableDebugScopeCapture() const { return this->disableDebugScopeCapture; }
  16. bool IsCFGEnabled();
  17. bool IsWin8OrLater();
  18. #if defined(_CONTROL_FLOW_GUARD)
  19. bool IsWinThresholdOrLater();
  20. #endif
  21. #if defined(_M_IX86) || defined(_M_X64)
  22. bool VirtualSseAvailable(const int sseLevel) const;
  23. #endif
  24. BOOL SSE2Available() const;
  25. #if defined(_M_IX86) || defined(_M_X64)
  26. BOOL SSE3Available() const;
  27. BOOL SSE4_1Available() const;
  28. BOOL SSE4_2Available() const;
  29. BOOL PopCntAvailable() const;
  30. BOOL LZCntAvailable() const;
  31. BOOL TZCntAvailable() const;
  32. bool IsAtomPlatform() const;
  33. #endif
  34. bool IsLowMemoryProcess();
  35. BOOL GetAvailableCommit(ULONG64 *pCommit);
  36. void SetAvailableCommit(ULONG64 commit);
  37. DWORD GetNumberOfLogicalProcessors() const { return this->dwNumberOfProcessors; }
  38. DWORD GetNumberOfPhysicalProcessors() const { return this->dwNumberOfPhysicalProcessors; }
  39. #if SYSINFO_IMAGE_BASE_AVAILABLE
  40. UINT_PTR GetChakraBaseAddr() const;
  41. #endif
  42. #if defined(_M_ARM32_OR_ARM64)
  43. bool ArmDivAvailable() const { return this->armDivAvailable; }
  44. #endif
  45. static DWORD SaveModuleFileName(HANDLE hMod);
  46. static LPCWSTR GetJscriptDllFileName();
  47. static HRESULT GetJscriptFileVersion(DWORD* majorVersion, DWORD* minorVersion, DWORD *buildDateHash = nullptr, DWORD *buildTimeHash = nullptr);
  48. static HMODULE GetCRTHandle();
  49. #if DBG
  50. static bool IsInitialized();
  51. #endif
  52. #if SYSINFO_IMAGE_BASE_AVAILABLE
  53. static bool IsJscriptModulePointer(void * ptr);
  54. #endif
  55. static DWORD const PageSize = 4096;
  56. #ifdef STACK_ALIGN
  57. static DWORD const StackAlign = STACK_ALIGN;
  58. #else
  59. # if defined(_WIN64)
  60. static DWORD const StackAlign = 16;
  61. # elif defined(_M_ARM)
  62. static DWORD const StackAlign = 8;
  63. # elif defined(_M_IX86)
  64. static DWORD const StackAlign = 4;
  65. # else
  66. # error missing_target
  67. # endif
  68. #endif
  69. #if SYSINFO_IMAGE_BASE_AVAILABLE
  70. UINT_PTR dllLoadAddress;
  71. UINT_PTR dllHighAddress;
  72. #endif
  73. private:
  74. AutoSystemInfo() : majorVersion(0), minorVersion(0), buildDateHash(0), buildTimeHash(0) { Initialize(); }
  75. void Initialize();
  76. bool isWindows8OrGreater;
  77. uint allocationGranularityPageCount;
  78. HANDLE processHandle;
  79. #if defined(_M_IX86) || defined(_M_X64)
  80. int CPUInfo[4];
  81. #endif
  82. #if defined(_M_ARM32_OR_ARM64)
  83. bool armDivAvailable;
  84. #endif
  85. DWORD dwNumberOfPhysicalProcessors;
  86. bool disableDebugScopeCapture;
  87. #if DBG
  88. bool initialized;
  89. #endif
  90. private:
  91. #if defined(_M_IX86) || defined(_M_X64)
  92. bool isAtom;
  93. bool CheckForAtom() const;
  94. #endif
  95. bool InitPhysicalProcessorCount();
  96. WCHAR binaryName[MAX_PATH + 1];
  97. DWORD majorVersion;
  98. DWORD minorVersion;
  99. DWORD buildDateHash;
  100. DWORD buildTimeHash;
  101. static HRESULT GetVersionInfo(__in LPCWSTR pszPath, DWORD* majorVersion, DWORD* minorVersion);
  102. static const DWORD INVALID_VERSION = (DWORD)-1;
  103. ULONG64 availableCommit;
  104. bool shouldQCMoreFrequently;
  105. bool supportsOnlyMultiThreadedCOM;
  106. bool isLowMemoryDevice;
  107. public:
  108. static bool ShouldQCMoreFrequently();
  109. static bool SupportsOnlyMultiThreadedCOM();
  110. static bool IsLowMemoryDevice();
  111. };
  112. // For Prefast where it doesn't like symbolic constants
  113. CompileAssert(AutoSystemInfo::PageSize == 4096);
  114. #define __in_ecount_pagesize __in_ecount(4096)
  115. #define __in_ecount_twopagesize __in_ecount(8192)