@@ -1653,27 +1653,31 @@ struct llama_anonymous_mmap : llama_mmap {
1653
1653
}
1654
1654
}
1655
1655
1656
- #if _WIN32_WINNT >= 0x603
1657
1656
void unmap_fragment(size_t first, size_t last) override {
1657
+ SYSTEM_INFO siSysInfo;
1658
+ GetSystemInfo(&siSysInfo);
1659
+ DWORD dwPageSize = siSysInfo.dwPageSize;
1660
+
1661
+ align_to_next_page(&first, dwPageSize);
1662
+ align_to_previous_page(&last, dwPageSize);
1663
+
1664
+ #if _WIN32_WINNT >= 0x603
1658
1665
DWORD (WINAPI *pOfferVirtualMemory) (PVOID, SIZE_T, DWORD);
1659
1666
HMODULE hKernel32 = GetModuleHandleW(L"kernel32.dll");
1660
1667
1661
1668
pOfferVirtualMemory = reinterpret_cast<decltype(pOfferVirtualMemory)> (GetProcAddress(hKernel32, "OfferVirtualMemory"));
1662
1669
1663
1670
if (pOfferVirtualMemory) {
1664
- SYSTEM_INFO siSysInfo;
1665
- GetSystemInfo(&siSysInfo);
1666
- DWORD dwPageSize = siSysInfo.dwPageSize;
1667
-
1668
- align_to_next_page(&first, dwPageSize);
1669
- align_to_previous_page(&last, dwPageSize);
1670
-
1671
1671
if (pOfferVirtualMemory((char *) addr + first, last - first, 0x00000004 /* VMOfferPriorityNormal */)) {
1672
1672
LLAMA_LOG_WARN("warning: OfferVirtualMemory failed: %s\n", llama_format_win_err(GetLastError()).c_str());
1673
1673
}
1674
1674
}
1675
- }
1675
+ #else
1676
+ if (VirtualAlloc((char *) addr + first, last - first, MEM_RESET, PAGE_NOACCESS)) {
1677
+ LLAMA_LOG_WARN("warning: VirtualAlloc(.., MEM_RESET) failed: %s\n", llama_format_win_err(GetLastError()).c_str());
1678
+ }
1676
1679
#endif
1680
+ }
1677
1681
1678
1682
#else
1679
1683
llama_anonymous_mmap(struct llama_file * file) {
0 commit comments