Просмотр исходного кода

Query for LargePageMinimum on Windows

tevador 7 лет назад
Родитель
Сommit
a78429202b
1 измененных файлов с 6 добавлено и 2 удалено
  1. 6 2
      src/virtual_memory.cpp

+ 6 - 2
src/virtual_memory.cpp

@@ -88,7 +88,7 @@ void* allocExecutableMemory(std::size_t bytes) {
 	return mem;
 }
 
-constexpr std::size_t align(std::size_t pos, uint32_t align) {
+constexpr std::size_t align(std::size_t pos, std::size_t align) {
 	return ((pos - 1) / align + 1) * align;
 }
 
@@ -96,7 +96,11 @@ void* allocLargePagesMemory(std::size_t bytes) {
 	void* mem;
 #ifdef _WIN32
 	setPrivilege("SeLockMemoryPrivilege", 1);
-	mem = VirtualAlloc(NULL, align(bytes, 2 * 1024 * 1024), MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE);
+	auto pageMinimum = GetLargePageMinimum();
+	if (pageMinimum > 0)
+		mem = VirtualAlloc(NULL, align(bytes, pageMinimum), MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE);
+	else
+		throw std::runtime_error("allocLargePagesMemory - Large pages are not supported");
 	if (mem == nullptr)
 		throw std::runtime_error(getErrorMessage("allocLargePagesMemory - VirtualAlloc"));
 #else