The Pedigree Project 0.1
SwapStore.h
1/* Copyright (c) 2026, Pedigree Developers. */
2#ifndef VFS_SWAP_STORE_H
3#define VFS_SWAP_STORE_H
4#include "pedigree/kernel/machine/DiskPaging.h"
5#include "pedigree/kernel/processor/types.h"
6
8 uint64_t value = 0;
9 explicit operator bool() const {
10 return value != 0;
11 }
12};
14 uint64_t totalPages = 0;
15 uint64_t usedPages = 0;
16 bool active = false;
17};
18enum class SwapStatus {
19 Success,
20 Unsupported,
21 Busy,
22 NoMemory,
23 Invalid,
24 IoError,
25 NotActive,
26 Unmapped
27};
28
29// Every operation is serialized by MemoryMapManager::OperationGuard. Slot
30// references describe immutable contents, independently of any address space.
31class EXPORTED_PUBLIC SwapStore {
32 public:
33 static constexpr size_t MaximumPages = 4096;
34 static SwapStore& instance();
35 bool prepareAtBoot();
36 SwapStatus activate(uint32_t endpoint);
37 SwapStatus finishDeactivate(uint32_t endpoint);
38 SwapStatus writePage(physical_uintptr_t physical, SwapReference& result);
39 SwapStatus readPage(SwapReference reference, physical_uintptr_t physical);
40 bool zeroPage(physical_uintptr_t physical);
41 bool retain(SwapReference reference);
42 void release(SwapReference& reference);
43 SwapSnapshot snapshot() const;
44 uint32_t endpointId() const;
45 static SwapStatus validateHeader(const void* page, uint64_t deviceBytes, size_t& pages);
46
47 private:
48 SwapStore() = default;
49 struct State;
50 State* m_State = nullptr;
51};
52#endif