[*] drop win32 requirements

This commit is contained in:
Reece Wilson 2023-10-11 01:47:20 +01:00
parent ff62c6ffea
commit 7fe74ec057

View File

@ -143,6 +143,19 @@ static DWORD(__stdcall* pGetLargePageMinimum)() = NULL;
static BOOL(__stdcall* pGetNumaHighestNodeNumber)(PULONG HighestNodeNumber) = NULL;
static BOOL(__stdcall* pGetNumaProcessorNode)(UCHAR Processor, PUCHAR NodeNumber) = NULL;
static BOOL(__stdcall* pGetNumaNodeProcessorMask)(UCHAR Processor, PULONGLONG ProcessorMask) = NULL;
static BOOL(__stdcall* pLookupPrivilegeValueW)(LPCWSTR lpSystemName,
LPCWSTR lpName,
PLUID lpLuid) = NULL;
static BOOL(__stdcall* pAdjustTokenPrivileges)(HANDLE TokenHandle,
BOOL DisableAllPrivileges,
PTOKEN_PRIVILEGES NewState,
DWORD BufferLength,
PTOKEN_PRIVILEGES PreviousState,
PDWORD ReturnLength) = NULL;
static BOOL(__stdcall* pOpenProcessToken)(
HANDLE ProcessHandle,
DWORD DesiredAccess,
PHANDLE TokenHandle) = NULL;
static bool mi_win_enable_large_os_pages()
{
@ -155,14 +168,17 @@ static bool mi_win_enable_large_os_pages()
// <https://devblogs.microsoft.com/oldnewthing/20110128-00/?p=11643>
unsigned long err = 0;
HANDLE token = NULL;
BOOL ok = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token);
BOOL ok = pOpenProcessToken &&
pOpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token);
if (ok) {
TOKEN_PRIVILEGES tp;
ok = LookupPrivilegeValue(NULL, TEXT("SeLockMemoryPrivilege"), &tp.Privileges[0].Luid);
ok = pLookupPrivilegeValueW &&
pLookupPrivilegeValueW(NULL, L"SeLockMemoryPrivilege", &tp.Privileges[0].Luid);
if (ok) {
tp.PrivilegeCount = 1;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
ok = AdjustTokenPrivileges(token, FALSE, &tp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
ok = pAdjustTokenPrivileges &&
pAdjustTokenPrivileges(token, FALSE, &tp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
if (ok) {
err = GetLastError();
ok = (err == ERROR_SUCCESS);
@ -211,6 +227,25 @@ void _mi_os_init(void) {
pGetNumaProcessorNode = (BOOL(__stdcall*)(UCHAR, PUCHAR))GetProcAddress(hDll, "GetNumaProcessorNode");
pGetNumaNodeProcessorMask = (BOOL(__stdcall*)(UCHAR, PULONGLONG))GetProcAddress(hDll, "GetNumaNodeProcessorMask");
}
hDll = LoadLibrary(TEXT("Advapi32.dll"));
if (hDll != NULL) {
pLookupPrivilegeValueW = (BOOL(__stdcall*)(LPCWSTR,
LPCWSTR,
PLUID))GetProcAddress(hDll, "LookupPrivilegeValueW");
pAdjustTokenPrivileges = (BOOL(__stdcall*)(HANDLE,
BOOL,
PTOKEN_PRIVILEGES,
DWORD,
PTOKEN_PRIVILEGES,
PDWORD))GetProcAddress(hDll, "AdjustTokenPrivileges");
pOpenProcessToken = (BOOL(__stdcall*)(
HANDLE ,
DWORD,
PHANDLE))GetProcAddress(hDll, "OpenProcessToken");
}
if (mi_option_is_enabled(mi_option_large_os_pages) || mi_option_is_enabled(mi_option_reserve_huge_os_pages)) {
mi_win_enable_large_os_pages();
}