Skip to content

Commit 4bf6ae6

Browse files
committed
get Windows version dynamically
1 parent befe57f commit 4bf6ae6

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/prim/windows/prim.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ terms of the MIT license. A copy of the license can be found in the file
1818
//---------------------------------------------
1919

2020
#if defined(_MSC_VER)
21-
#pragma warning(disable:28159) // don't use GetVersion
22-
#pragma warning(disable:4996) // don't use GetVersion
21+
#pragma warning(disable:4996) // don't use GetVersionExW
2322
#endif
2423

2524
static DWORD win_major_version = 6;
@@ -72,6 +71,8 @@ static PGetNumaProcessorNode pGetNumaProcessorNode = NULL;
7271

7372
// Available after Windows XP
7473
typedef BOOL (__stdcall *PGetPhysicallyInstalledSystemMemory)( PULONGLONG TotalMemoryInKilobytes );
74+
typedef BOOL (__stdcall* PGetVersionExW)(LPOSVERSIONINFOW lpVersionInformation);
75+
7576

7677
//---------------------------------------------
7778
// Enable large page support dynamically (if possible)
@@ -126,14 +127,9 @@ void _mi_prim_mem_init( mi_os_mem_config_t* config )
126127
config->has_overcommit = false;
127128
config->has_partial_free = false;
128129
config->has_virtual_reserve = true;
129-
// windows version
130-
OSVERSIONINFOW version; _mi_memzero_var(version);
131-
if (GetVersionExW(&version)) {
132-
win_major_version = version.dwMajorVersion;
133-
win_minor_version = version.dwMinorVersion;
134-
}
130+
135131
// get the page size
136-
SYSTEM_INFO si;
132+
SYSTEM_INFO si; _mi_memzero_var(si);
137133
GetSystemInfo(&si);
138134
if (si.dwPageSize > 0) { config->page_size = si.dwPageSize; }
139135
if (si.dwAllocationGranularity > 0) {
@@ -147,8 +143,7 @@ void _mi_prim_mem_init( mi_os_mem_config_t* config )
147143
}
148144

149145
// get the VirtualAlloc2 function
150-
HINSTANCE hDll;
151-
hDll = LoadLibrary(TEXT("kernelbase.dll"));
146+
HINSTANCE hDll = LoadLibrary(TEXT("kernelbase.dll"));
152147
if (hDll != NULL) {
153148
// use VirtualAlloc2FromApp if possible as it is available to Windows store apps
154149
pVirtualAlloc2 = (PVirtualAlloc2)(void (*)(void))GetProcAddress(hDll, "VirtualAlloc2FromApp");
@@ -178,6 +173,16 @@ void _mi_prim_mem_init( mi_os_mem_config_t* config )
178173
}
179174
}
180175
}
176+
// Get Windows version
177+
PGetVersionExW pGetVersionExW = (PGetVersionExW)(void (*)(void))GetProcAddress(hDll, "GetVersionExW");
178+
if (pGetVersionExW != NULL) {
179+
OSVERSIONINFOW version; _mi_memzero_var(version);
180+
version.dwOSVersionInfoSize = sizeof(version);
181+
if ((*pGetVersionExW)(&version)) {
182+
win_major_version = version.dwMajorVersion;
183+
win_minor_version = version.dwMinorVersion;
184+
}
185+
}
181186
FreeLibrary(hDll);
182187
}
183188
// Enable large/huge OS page support?

0 commit comments

Comments
 (0)