Swap (Windows): detect detailed info

This commit is contained in:
李通洲
2025-06-04 14:24:12 +08:00
parent 9d2df589b5
commit 7ec0c664c5
2 changed files with 11 additions and 7 deletions
+2 -1
View File
@@ -4,8 +4,9 @@
typedef struct FFSwapResult
{
FFstrbuf name;
uint64_t bytesUsed;
uint64_t bytesTotal;
} FFSwapResult;
const char* ffDetectSwap(FFSwapResult* swap);
const char* ffDetectSwap(FFlist* result /* List of FFSwapResult */);
+9 -6
View File
@@ -1,11 +1,12 @@
#include "swap.h"
#include "util/mallocHelper.h"
#include "util/windows/unicode.h"
#include <winternl.h>
#include <ntstatus.h>
#include <windows.h>
const char* ffDetectSwap(FFSwapResult* swap)
const char* ffDetectSwap(FFlist* result)
{
uint8_t buffer[4096];
ULONG size = sizeof(buffer);
@@ -13,16 +14,18 @@ const char* ffDetectSwap(FFSwapResult* swap)
if(!NT_SUCCESS(NtQuerySystemInformation(SystemPagefileInformation, pstart, size, &size)))
return "NtQuerySystemInformation(SystemPagefileInformation, size) failed";
uint32_t pageSize = instance.state.platform.sysinfo.pageSize;
for (SYSTEM_PAGEFILE_INFORMATION* current = pstart; ; current = (SYSTEM_PAGEFILE_INFORMATION*)((uint8_t*) current + current->NextEntryOffset))
{
swap->bytesUsed += current->TotalUsed;
swap->bytesTotal += current->CurrentSize;
FFSwapResult* swap = ffListAdd(result);
ffStrbufInitNWS(&swap->name, current->FileName.Length / sizeof(wchar_t), current->FileName.Buffer);
if (ffStrbufStartsWithS(&swap->name, "\\??\\"))
ffStrbufSubstrAfter(&swap->name, strlen("\\??\\") - 1);
swap->bytesUsed = current->TotalUsed * pageSize;
swap->bytesTotal = current->CurrentSize * pageSize;
if (current->NextEntryOffset == 0)
break;
}
uint32_t pageSize = instance.state.platform.sysinfo.pageSize;
swap->bytesUsed *= pageSize;
swap->bytesTotal *= pageSize;
return NULL;
}