Skip to content

Commit f7f3dd9

Browse files
committed
LoadLibrary can be used on UWP for system libs (from Windows SDK 10.0.22000.0)
1 parent d86d607 commit f7f3dd9

1 file changed

Lines changed: 6 additions & 19 deletions

File tree

  • Objects/mimalloc/prim/windows

Objects/mimalloc/prim/windows/prim.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ terms of the MIT license. A copy of the license can be found in the file
1414
#include <stdio.h> // fputs, stderr
1515
#include <bcrypt.h> // NTSTATUS
1616

17-
// Xbox has no console IO and cannot use LoadLibrary
18-
#if !defined(WINAPI_FAMILY_PARTITION) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)
19-
#define MI_WIN_DESKTOP 1
20-
#endif
2117

2218
//---------------------------------------------
2319
// Dynamically bind Windows API points for portability
@@ -68,15 +64,6 @@ static PGetNumaProcessorNodeEx pGetNumaProcessorNodeEx = NULL;
6864
static PGetNumaNodeProcessorMaskEx pGetNumaNodeProcessorMaskEx = NULL;
6965
static PGetNumaProcessorNode pGetNumaProcessorNode = NULL;
7066

71-
// Load a library
72-
static HMODULE mi_win_loadlibrary(const TCHAR* library) {
73-
#if MI_WIN_DESKTOP
74-
return LoadLibrary(library);
75-
#else
76-
return LoadPackagedLibrary(library, 0);
77-
#endif
78-
}
79-
8067
//---------------------------------------------
8168
// Enable large page support dynamically (if possible)
8269
//---------------------------------------------
@@ -135,21 +122,21 @@ void _mi_prim_mem_init( mi_os_mem_config_t* config )
135122
if (si.dwAllocationGranularity > 0) { config->alloc_granularity = si.dwAllocationGranularity; }
136123
// get the VirtualAlloc2 function
137124
HINSTANCE hDll;
138-
hDll = mi_win_loadlibrary(TEXT("kernelbase.dll"));
125+
hDll = LoadLibrary(TEXT("kernelbase.dll"));
139126
if (hDll != NULL) {
140127
// use VirtualAlloc2FromApp if possible as it is available to Windows store apps
141128
pVirtualAlloc2 = (PVirtualAlloc2)(void (*)(void))GetProcAddress(hDll, "VirtualAlloc2FromApp");
142129
if (pVirtualAlloc2==NULL) pVirtualAlloc2 = (PVirtualAlloc2)(void (*)(void))GetProcAddress(hDll, "VirtualAlloc2");
143130
FreeLibrary(hDll);
144131
}
145132
// NtAllocateVirtualMemoryEx is used for huge page allocation
146-
hDll = mi_win_loadlibrary(TEXT("ntdll.dll"));
133+
hDll = LoadLibrary(TEXT("ntdll.dll"));
147134
if (hDll != NULL) {
148135
pNtAllocateVirtualMemoryEx = (PNtAllocateVirtualMemoryEx)(void (*)(void))GetProcAddress(hDll, "NtAllocateVirtualMemoryEx");
149136
FreeLibrary(hDll);
150137
}
151138
// Try to use Win7+ numa API
152-
hDll = mi_win_loadlibrary(TEXT("kernel32.dll"));
139+
hDll = LoadLibrary(TEXT("kernel32.dll"));
153140
if (hDll != NULL) {
154141
pGetCurrentProcessorNumberEx = (PGetCurrentProcessorNumberEx)(void (*)(void))GetProcAddress(hDll, "GetCurrentProcessorNumberEx");
155142
pGetNumaProcessorNodeEx = (PGetNumaProcessorNodeEx)(void (*)(void))GetProcAddress(hDll, "GetNumaProcessorNodeEx");
@@ -391,7 +378,7 @@ size_t _mi_prim_numa_node(void) {
391378
}
392379

393380
size_t _mi_prim_numa_node_count(void) {
394-
#if MI_WIN_DESKTOP
381+
#ifdef MS_WINDOWS_DESKTOP
395382
ULONG numa_max = 0;
396383
GetNumaHighestNodeNumber(&numa_max);
397384
// find the highest node number that has actual processors assigned to it. Issue #282
@@ -472,7 +459,7 @@ void _mi_prim_process_info(mi_process_info_t* pinfo)
472459

473460
// load psapi on demand
474461
if (pGetProcessMemoryInfo == NULL) {
475-
HINSTANCE hDll = mi_win_loadlibrary(TEXT("psapi.dll"));
462+
HINSTANCE hDll = LoadLibrary(TEXT("psapi.dll"));
476463
if (hDll != NULL) {
477464
pGetProcessMemoryInfo = (PGetProcessMemoryInfo)(void (*)(void))GetProcAddress(hDll, "GetProcessMemoryInfo");
478465
}
@@ -572,7 +559,7 @@ static PBCryptGenRandom pBCryptGenRandom = NULL;
572559

573560
bool _mi_prim_random_buf(void* buf, size_t buf_len) {
574561
if (pBCryptGenRandom == NULL) {
575-
HINSTANCE hDll = mi_win_loadlibrary(TEXT("bcrypt.dll"));
562+
HINSTANCE hDll = LoadLibrary(TEXT("bcrypt.dll"));
576563
if (hDll != NULL) {
577564
pBCryptGenRandom = (PBCryptGenRandom)(void (*)(void))GetProcAddress(hDll, "BCryptGenRandom");
578565
}

0 commit comments

Comments
 (0)