MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / _mi_os_init

Function _mi_os_init

3rd/mimalloc-2.0.9/src/os.c:210–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208}
209
210void _mi_os_init(void)
211{
212 os_overcommit = false;
213 // get the page size
214 SYSTEM_INFO si;
215 GetSystemInfo(&si);
216 if (si.dwPageSize > 0) os_page_size = si.dwPageSize;
217 if (si.dwAllocationGranularity > 0) os_alloc_granularity = si.dwAllocationGranularity;
218 // get the VirtualAlloc2 function
219 HINSTANCE hDll;
220 hDll = LoadLibrary(TEXT("kernelbase.dll"));
221 if (hDll != NULL) {
222 // use VirtualAlloc2FromApp if possible as it is available to Windows store apps
223 pVirtualAlloc2 = (PVirtualAlloc2)(void (*)(void))GetProcAddress(hDll, "VirtualAlloc2FromApp");
224 if (pVirtualAlloc2==NULL) pVirtualAlloc2 = (PVirtualAlloc2)(void (*)(void))GetProcAddress(hDll, "VirtualAlloc2");
225 FreeLibrary(hDll);
226 }
227 // NtAllocateVirtualMemoryEx is used for huge page allocation
228 hDll = LoadLibrary(TEXT("ntdll.dll"));
229 if (hDll != NULL) {
230 pNtAllocateVirtualMemoryEx = (PNtAllocateVirtualMemoryEx)(void (*)(void))GetProcAddress(hDll, "NtAllocateVirtualMemoryEx");
231 FreeLibrary(hDll);
232 }
233 // Try to use Win7+ numa API
234 hDll = LoadLibrary(TEXT("kernel32.dll"));
235 if (hDll != NULL) {
236 pGetCurrentProcessorNumberEx = (PGetCurrentProcessorNumberEx)(void (*)(void))GetProcAddress(hDll, "GetCurrentProcessorNumberEx");
237 pGetNumaProcessorNodeEx = (PGetNumaProcessorNodeEx)(void (*)(void))GetProcAddress(hDll, "GetNumaProcessorNodeEx");
238 pGetNumaNodeProcessorMaskEx = (PGetNumaNodeProcessorMaskEx)(void (*)(void))GetProcAddress(hDll, "GetNumaNodeProcessorMaskEx");
239 pGetNumaProcessorNode = (PGetNumaProcessorNode)(void (*)(void))GetProcAddress(hDll, "GetNumaProcessorNode");
240 FreeLibrary(hDll);
241 }
242 if (mi_option_is_enabled(mi_option_large_os_pages) || mi_option_is_enabled(mi_option_reserve_huge_os_pages)) {
243 mi_win_enable_large_os_pages();
244 }
245}
246#elif defined(__wasi__)
247void _mi_os_init(void) {
248 os_overcommit = false;

Callers 1

mi_process_initFunction · 0.85

Calls 3

mi_option_is_enabledFunction · 0.85
os_detect_overcommitFunction · 0.85

Tested by

no test coverage detected