SysInfo.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #ifdef _WIN32
  40. bool IsCRTModulePointer(uintptr_t ptr);
  41. #endif
  42. #if SYSINFO_IMAGE_BASE_AVAILABLE
  43. UINT_PTR GetChakraBaseAddr() const;
  44. #endif
  45. #if defined(_M_ARM32_OR_ARM64)
  46. bool ArmDivAvailable() const { return this->armDivAvailable; }
  47. #endif
  48. static DWORD SaveModuleFileName(HANDLE hMod);
  49. static LPCWSTR GetJscriptDllFileName();
  50. static HRESULT GetJscriptFileVersion(DWORD* majorVersion, DWORD* minorVersion, DWORD *buildDateHash = nullptr, DWORD *buildTimeHash = nullptr);
  51. #if DBG
  52. static bool IsInitialized();
  53. #endif
  54. #if SYSINFO_IMAGE_BASE_AVAILABLE
  55. static bool IsJscriptModulePointer(void * ptr);
  56. #endif
  57. #ifdef _WIN32
  58. static HMODULE GetCRTHandle();
  59. #endif
  60. static DWORD const PageSize = 4096;
  61. static size_t const MaxPageCount = SIZE_MAX / PageSize;
  62. #ifdef STACK_ALIGN
  63. static DWORD const StackAlign = STACK_ALIGN;
  64. #else
  65. # if defined(TARGET_64)
  66. static DWORD const StackAlign = 16;
  67. # elif defined(_M_ARM)
  68. static DWORD const StackAlign = 8;
  69. # elif defined(_M_IX86)
  70. static DWORD const StackAlign = 4;
  71. # else
  72. # error missing_target
  73. # endif
  74. #endif
  75. #if SYSINFO_IMAGE_BASE_AVAILABLE
  76. UINT_PTR dllLoadAddress;
  77. UINT_PTR dllHighAddress;
  78. #endif
  79. private:
  80. AutoSystemInfo() : majorVersion(0), minorVersion(0), buildDateHash(0), buildTimeHash(0), crtSize(0) { Initialize(); }
  81. void Initialize();
  82. bool isWindows8OrGreater;
  83. uint allocationGranularityPageCount;
  84. HANDLE processHandle;
  85. DWORD crtSize;
  86. #if defined(_M_IX86) || defined(_M_X64)
  87. int CPUInfo[4];
  88. #endif
  89. #if defined(_M_ARM32_OR_ARM64)
  90. bool armDivAvailable;
  91. #endif
  92. DWORD dwNumberOfPhysicalProcessors;
  93. bool disableDebugScopeCapture;
  94. #if DBG
  95. bool initialized;
  96. #endif
  97. private:
  98. #if defined(_M_IX86) || defined(_M_X64)
  99. bool isAtom;
  100. bool CheckForAtom() const;
  101. #endif
  102. bool InitPhysicalProcessorCount();
  103. WCHAR binaryName[MAX_PATH + 1];
  104. DWORD majorVersion;
  105. DWORD minorVersion;
  106. DWORD buildDateHash;
  107. DWORD buildTimeHash;
  108. static HRESULT GetVersionInfo(__in LPCWSTR pszPath, DWORD* majorVersion, DWORD* minorVersion);
  109. static const DWORD INVALID_VERSION = (DWORD)-1;
  110. ULONG64 availableCommit;
  111. bool shouldQCMoreFrequently;
  112. bool supportsOnlyMultiThreadedCOM;
  113. bool isLowMemoryDevice;
  114. public:
  115. static bool ShouldQCMoreFrequently();
  116. static bool SupportsOnlyMultiThreadedCOM();
  117. static bool IsLowMemoryDevice();
  118. };
  119. // For Prefast where it doesn't like symbolic constants
  120. CompileAssert(AutoSystemInfo::PageSize == 4096);
  121. #define __in_ecount_pagesize __in_ecount(4096)
  122. #define __in_ecount_twopagesize __in_ecount(8192)