summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/Windows/MemoryLock.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/lzma/CPP/Windows/MemoryLock.cpp')
-rw-r--r--3rdparty/lzma/CPP/Windows/MemoryLock.cpp64
1 files changed, 58 insertions, 6 deletions
diff --git a/3rdparty/lzma/CPP/Windows/MemoryLock.cpp b/3rdparty/lzma/CPP/Windows/MemoryLock.cpp
index b628a03e8f9..0bd7504f1cc 100644
--- a/3rdparty/lzma/CPP/Windows/MemoryLock.cpp
+++ b/3rdparty/lzma/CPP/Windows/MemoryLock.cpp
@@ -2,6 +2,8 @@
#include "StdAfx.h"
+#include "../../C/CpuArch.h"
+
#include "MemoryLock.h"
namespace NWindows {
@@ -19,7 +21,10 @@ typedef BOOL (WINAPI * Func_LookupPrivilegeValue)(LPCTSTR lpSystemName, LPCTSTR
typedef BOOL (WINAPI * Func_AdjustTokenPrivileges)(HANDLE TokenHandle, BOOL DisableAllPrivileges,
PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength);
}
-#define GET_PROC_ADDR(fff, name) Func_ ## fff my_ ## fff = (Func_ ## fff)GetProcAddress(hModule, name)
+
+#define GET_PROC_ADDR(fff, name) \
+ const Func_ ## fff my_ ## fff = Z7_GET_PROC_ADDRESS( \
+ Func_ ## fff, hModule, name);
#endif
bool EnablePrivilege(LPCTSTR privilegeName, bool enable)
@@ -28,13 +33,19 @@ bool EnablePrivilege(LPCTSTR privilegeName, bool enable)
#ifndef _UNICODE
- HMODULE hModule = ::LoadLibrary(TEXT("Advapi32.dll"));
- if (hModule == NULL)
+ const HMODULE hModule = ::LoadLibrary(TEXT("advapi32.dll"));
+ if (!hModule)
return false;
- GET_PROC_ADDR(OpenProcessToken, "OpenProcessToken");
- GET_PROC_ADDR(LookupPrivilegeValue, "LookupPrivilegeValueA");
- GET_PROC_ADDR(AdjustTokenPrivileges, "AdjustTokenPrivileges");
+ GET_PROC_ADDR(
+ OpenProcessToken,
+ "OpenProcessToken")
+ GET_PROC_ADDR(
+ LookupPrivilegeValue,
+ "LookupPrivilegeValueA")
+ GET_PROC_ADDR(
+ AdjustTokenPrivileges,
+ "AdjustTokenPrivileges")
if (my_OpenProcessToken &&
my_AdjustTokenPrivileges &&
@@ -67,6 +78,47 @@ bool EnablePrivilege(LPCTSTR privilegeName, bool enable)
return res;
}
+
+
+typedef void (WINAPI * Func_RtlGetVersion) (OSVERSIONINFOEXW *);
+
+/*
+ We suppose that Window 10 works incorrectly with "Large Pages" at:
+ - Windows 10 1703 (15063) : incorrect allocating after VirtualFree()
+ - Windows 10 1709 (16299) : incorrect allocating after VirtualFree()
+ - Windows 10 1809 (17763) : the failures for blocks of 1 GiB and larger,
+ if CPU doesn't support 1 GB pages.
+ Windows 10 1903 (18362) probably works correctly.
+*/
+
+unsigned Get_LargePages_RiskLevel()
+{
+ OSVERSIONINFOEXW vi;
+ const HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll");
+ if (!ntdll)
+ return 0;
+ const
+ Func_RtlGetVersion func = Z7_GET_PROC_ADDRESS(
+ Func_RtlGetVersion, ntdll,
+ "RtlGetVersion");
+ if (!func)
+ return 0;
+ func(&vi);
+ if (vi.dwPlatformId != VER_PLATFORM_WIN32_NT)
+ return 0;
+ if (vi.dwMajorVersion + vi.dwMinorVersion != 10)
+ return 0;
+ if (vi.dwBuildNumber <= 16299)
+ return 1;
+
+ #ifdef MY_CPU_X86_OR_AMD64
+ if (vi.dwBuildNumber < 18362 && !CPU_IsSupported_PageGB())
+ return 1;
+ #endif
+
+ return 0;
+}
+
#endif
}}