2#include "pedigree/kernel/processor/PhysicalMemoryManager.h"
3#include "pedigree/kernel/utilities/utility.h"
7SwapStatus SwapStore::validateHeader(
const void* page, uint64_t bytes,
size_t& pages) {
9 constexpr size_t Page = PagingChannel::PageBytes;
11 return SwapStatus::Invalid;
12 const auto* data =
static_cast<const unsigned char*
>(page);
13 if (MemoryCompare(data + Page - 10,
"SWAPSPACE2", 10))
14 return SwapStatus::Invalid;
16 auto word = [&](
size_t at) {
17 return uint32_t(data[at]) | (uint32_t(data[at + 1]) << 8) | (uint32_t(data[at + 2]) << 16) |
18 (uint32_t(data[at + 3]) << 24);
20 if (word(1024) != 1 || !word(1028) || uint64_t(word(1028)) >= bytes / Page)
21 return SwapStatus::Invalid;
23 return SwapStatus::Unsupported;
24 pages = word(1028) < MaximumPages ? word(1028) : MaximumPages;
25 return SwapStatus::Success;
static constexpr size_t getPageSize() PURE