summaryrefslogtreecommitdiffhomepage
path: root/src/kernel/SwapKit/DiskSwap.h
blob: 62fa558cc594bbc25249a2b53b1568b36bf4b146 (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 2024-2025, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (see LICENSE file)
// Official repository: https://github.com/nekernel-org/nekernel

#ifndef SWAPKIT_DISKSWAP_H
#define SWAPKIT_DISKSWAP_H

#include <CompilerKit/CompilerKit.h>
#include <NeKit/Config.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 SwapDiskHdr;
class IDiskSwap;

/// @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 IDiskSwap final {
 public:
  explicit IDiskSwap() = default;
  ~IDiskSwap()         = default;

  NE_COPY_DELETE(IDiskSwap)
  NE_MOVE_DELETE(IDiskSwap)

 public:
  /***********************************************************************************/
  /// @brief Write memory chunk onto disk.
  /// @param name The swap name to recognize this memory region.
  /// @param 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* name, SizeT name_len, SwapDiskHdr* data);

  /***********************************************************************************/
  /// @brief Read memory chunk from disk.
  /// @param name The swap name to recognize this memory region.
  /// @param name_len length of fork name.
  /// @param data the data packet length.
  /// @return Whether the swap was fetched to disk, or not.
  /***********************************************************************************/
  _Output SwapDiskHdr* Read(const Char* name, SizeT 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 SwapDiskHdr {
  UInt32 fMagic;
  SizeT  fHeaderSz;
  UInt64 fTeamID;
  UInt64 fProcessID;
  UInt64 fVirtualAddress;
  SizeT  fBlobSz;
  UInt8  fBlob[1];
} PACKED ALIGN(8) SwapDiskHdr;
}  // namespace Kernel

#endif