blob: 40b3adb0c8de13665b3e3ad1d6a7a7a9733a09cc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/* -------------------------------------------
Copyright (C) 2024-2025 Amlal El Mahrouss Labs, all rights reserved.
------------------------------------------- */
#pragma once
#include <CompilerKit/CompilerKit.h>
#include <NeKit/Defines.h>
#include <hint/CompilerHint.h>
#define kSwapBlockMaxSize (mib_cast(16))
#define kSwapPageFilePath "/boot/pagefile.sys"
/// @file SwapDisk.h
/// @brief Virtual memory swap disk.
namespace Kernel {
struct SWAP_DISK_HEADER;
class DiskSwapInterface;
/// @brief Virtual memory interface to swap memory chunks onto disk.
/// @note The class only supports the NeFS as of right now, as it is using forks to write data into
/// disk.
class DiskSwapInterface final {
public:
explicit DiskSwapInterface() = default;
~DiskSwapInterface() = default;
NE_COPY_DELETE(DiskSwapInterface)
NE_MOVE_DELETE(DiskSwapInterface)
public:
/***********************************************************************************/
/// @brief Write memory chunk onto disk.
/// @param fork_name The swap name to recognize this memory region.
/// @param fork_name_len length of fork name.
/// @param data the data packet.
/// @return Whether the swap was written to disk, or not.
/***********************************************************************************/
BOOL Write(const Char* fork_name, SizeT fork_name_len, SWAP_DISK_HEADER* data);
/***********************************************************************************/
/// @brief Read memory chunk from disk.
/// @param fork_name The swap name to recognize this memory region.
/// @param fork_name_len length of fork name.
/// @param data the data packet length.
/// @return Whether the swap was fetched to disk, or not.
/***********************************************************************************/
_Output SWAP_DISK_HEADER* Read(const Char* fork_name, SizeT fork_name_len, SizeT data_len);
};
/// @brief Swap disk header, containing information about the held virtual memory.
/// @param fMagic Ident number.
/// @param fHeaderSz This header size.
/// @param fTeamID Process Team ID.
/// @param fProcessID Process ID.
/// @param fVirtualAddress Virtual address pointed by data.
/// @param fBlobSz Blob's size.
/// @param fBlob Data blob.
typedef struct SWAP_DISK_HEADER {
UInt32 fMagic;
SizeT fHeaderSz;
UInt64 fTeamID;
UInt64 fProcessID;
UInt64 fVirtualAddress;
SizeT fBlobSz;
UInt8 fBlob[1];
} PACKED ALIGN(8) SWAP_DISK_HEADER;
} // namespace Kernel
|