@@ -62,6 +62,9 @@ static PGetNumaProcessorNodeEx pGetNumaProcessorNodeEx = NULL;
62
62
static PGetNumaNodeProcessorMaskEx pGetNumaNodeProcessorMaskEx = NULL ;
63
63
static PGetNumaProcessorNode pGetNumaProcessorNode = NULL ;
64
64
65
+ // Available after Windows XP
66
+ typedef BOOL (__stdcall * PGetPhysicallyInstalledSystemMemory ( PULONGLONG TotalMemoryInKilobytes );
67
+
65
68
//---------------------------------------------
66
69
// Enable large page support dynamically (if possible)
67
70
//---------------------------------------------
@@ -123,13 +126,7 @@ void _mi_prim_mem_init( mi_os_mem_config_t* config )
123
126
const size_t vbits = MI_INTPTR_BITS - mi_clz ((uintptr_t )si .lpMaximumApplicationAddress );
124
127
config -> virtual_address_bits = vbits ;
125
128
}
126
- // get physical memory
127
- ULONGLONG memInKiB = 0 ;
128
- if (GetPhysicallyInstalledSystemMemory (& memInKiB )) {
129
- if (memInKiB > 0 && memInKiB < (SIZE_MAX / MI_KiB )) {
130
- config -> physical_memory = (size_t )memInKiB * MI_KiB ;
131
- }
132
- }
129
+
133
130
// get the VirtualAlloc2 function
134
131
HINSTANCE hDll ;
135
132
hDll = LoadLibrary (TEXT ("kernelbase.dll" ));
@@ -152,8 +149,19 @@ void _mi_prim_mem_init( mi_os_mem_config_t* config )
152
149
pGetNumaProcessorNodeEx = (PGetNumaProcessorNodeEx )(void (* )(void ))GetProcAddress (hDll , "GetNumaProcessorNodeEx" );
153
150
pGetNumaNodeProcessorMaskEx = (PGetNumaNodeProcessorMaskEx )(void (* )(void ))GetProcAddress (hDll , "GetNumaNodeProcessorMaskEx" );
154
151
pGetNumaProcessorNode = (PGetNumaProcessorNode )(void (* )(void ))GetProcAddress (hDll , "GetNumaProcessorNode" );
152
+ // Get physical memory (not available on XP, so check dynamically)
153
+ PGetPhysicallyInstalledSystemMemory pGetPhysicallyInstalledSystemMemory = (PGetPhysicallyInstalledSystemMemory )(void (* )(void ))GetProcAddress (hDll ,"GetPhysicallyInstalledSystemMemory" );
154
+ if (pGetPhysicallyInstalledSystemMemory != NULL ) {
155
+ ULONGLONG memInKiB = 0 ;
156
+ if ((* pGetPhysicallyInstalledSystemMemory )(& memInKiB )) {
157
+ if (memInKiB > 0 && memInKiB < (SIZE_MAX / MI_KiB )) {
158
+ config -> physical_memory = (size_t )memInKiB * MI_KiB ;
159
+ }
160
+ }
161
+ }
155
162
FreeLibrary (hDll );
156
163
}
164
+ // Enable large/huge OS page support?
157
165
if (mi_option_is_enabled (mi_option_allow_large_os_pages ) || mi_option_is_enabled (mi_option_reserve_huge_os_pages )) {
158
166
win_enable_large_os_pages (& config -> large_page_size );
159
167
}
0 commit comments