Swap (Windows): adds K32GetPerformanceInfo fallback

This commit is contained in:
李通洲
2025-11-18 15:36:49 +08:00
parent c324f83826
commit c613e558fd
+23 -1
View File
@@ -5,8 +5,9 @@
#include <winternl.h>
#include <ntstatus.h>
#include <windows.h>
#include <psapi.h>
const char* ffDetectSwap(FFlist* result)
const char* detectByNqsi(FFlist* result)
{
uint8_t buffer[4096];
ULONG size = sizeof(buffer);
@@ -26,6 +27,27 @@ const char* ffDetectSwap(FFlist* result)
if (current->NextEntryOffset == 0)
break;
}
return NULL;
}
const char* detectByKgpi(FFlist* result)
{
PERFORMANCE_INFORMATION pi = {};
if (!K32GetPerformanceInfo(&pi, sizeof(pi)))
return "K32GetPerformanceInfo(&pi, sizeof(pi)) failed";
FFSwapResult* swap = ffListAdd(result);
ffStrbufInitS(&swap->name, "Page File");
swap->bytesTotal = (uint64_t) (pi.CommitLimit > pi.PhysicalTotal ? pi.CommitLimit - pi.PhysicalTotal : 0) * pi.PageSize;
swap->bytesUsed = (uint64_t) (pi.CommitTotal > pi.PhysicalTotal ? pi.CommitTotal - pi.PhysicalTotal : 0) * pi.PageSize;
return NULL;
}
const char* ffDetectSwap(FFlist* result)
{
const char* err = detectByNqsi(result);
if (err == NULL)
return NULL;
return detectByKgpi(result);
}