Skip to content

Commit 4460475

Browse files
committed
mimalloc: allow running in Windows Nano Server containers
The `GetNumaProcessorNode()` symbol is not defined in Nano Server's DLLs (because that function is long deprecated). This caused Git no longer to work on Nano Server. Instead of importing it statically, try to import it dynamically, and fall back gracefully if it cannot be loaded. This fixes #4052 Signed-off-by: Johannes Schindelin <[email protected]>
1 parent bc64b5e commit 4460475

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

compat/mimalloc/os.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@ typedef struct MI_PROCESSOR_NUMBER_S { WORD Group; BYTE Number; BYTE Reserved; }
166166
typedef VOID (__stdcall *PGetCurrentProcessorNumberEx)(MI_PROCESSOR_NUMBER* ProcNumber);
167167
typedef BOOL (__stdcall *PGetNumaProcessorNodeEx)(MI_PROCESSOR_NUMBER* Processor, PUSHORT NodeNumber);
168168
typedef BOOL (__stdcall* PGetNumaNodeProcessorMaskEx)(USHORT Node, PGROUP_AFFINITY ProcessorMask);
169+
typedef BOOL (__stdcall *PGetNumaProcessorNode)(UCHAR Processor, PUCHAR NodeNumber);
169170
static PGetCurrentProcessorNumberEx pGetCurrentProcessorNumberEx = NULL;
170171
static PGetNumaProcessorNodeEx pGetNumaProcessorNodeEx = NULL;
171172
static PGetNumaNodeProcessorMaskEx pGetNumaNodeProcessorMaskEx = NULL;
173+
static PGetNumaProcessorNode pGetNumaProcessorNode = NULL;
172174

173175
static bool mi_win_enable_large_os_pages(void)
174176
{
@@ -234,6 +236,7 @@ void _mi_os_init(void)
234236
pGetCurrentProcessorNumberEx = (PGetCurrentProcessorNumberEx)(void (*)(void))GetProcAddress(hDll, "GetCurrentProcessorNumberEx");
235237
pGetNumaProcessorNodeEx = (PGetNumaProcessorNodeEx)(void (*)(void))GetProcAddress(hDll, "GetNumaProcessorNodeEx");
236238
pGetNumaNodeProcessorMaskEx = (PGetNumaNodeProcessorMaskEx)(void (*)(void))GetProcAddress(hDll, "GetNumaNodeProcessorMaskEx");
239+
pGetNumaProcessorNode = (PGetNumaProcessorNode)(void (*)(void))GetProcAddress(hDll, "GetNumaProcessorNode");
237240
FreeLibrary(hDll);
238241
}
239242
if (mi_option_is_enabled(mi_option_large_os_pages) || mi_option_is_enabled(mi_option_reserve_huge_os_pages)) {
@@ -1316,11 +1319,11 @@ static size_t mi_os_numa_nodex(void) {
13161319
BOOL ok = (*pGetNumaProcessorNodeEx)(&pnum, &nnode);
13171320
if (ok) numa_node = nnode;
13181321
}
1319-
else {
1322+
else if (pGetNumaProcessorNode != NULL) {
13201323
// Vista or earlier, use older API that is limited to 64 processors. Issue #277
13211324
DWORD pnum = GetCurrentProcessorNumber();
13221325
UCHAR nnode = 0;
1323-
BOOL ok = GetNumaProcessorNode((UCHAR)pnum, &nnode);
1326+
BOOL ok = pGetNumaProcessorNode((UCHAR)pnum, &nnode);
13241327
if (ok) numa_node = nnode;
13251328
}
13261329
return numa_node;

0 commit comments

Comments
 (0)