diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-23 21:06:27 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-23 21:06:27 -0500 |
| commit | 23040fad647634c08697451fc22ee2ca999629c8 (patch) | |
| tree | 72888f88c7728c82f3f6df1f4f70591de15eab36 /src/kernel/SwapKit | |
| parent | e5cc7351f0577b54c528fb827a7c7e6306c3e843 (diff) | |
| parent | 83d870e58457a1d335a1d9b9966a6a1887cc297b (diff) | |
Merge pull request #81 from nekernel-org/dev
feat! breaking changes on kernel sources.
Diffstat (limited to 'src/kernel/SwapKit')
| -rw-r--r-- | src/kernel/SwapKit/DiskSwap.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/kernel/SwapKit/DiskSwap.h b/src/kernel/SwapKit/DiskSwap.h new file mode 100644 index 00000000..cd81b13a --- /dev/null +++ b/src/kernel/SwapKit/DiskSwap.h @@ -0,0 +1,72 @@ + +/* ======================================== + + Copyright (C) 2024-2025 Amlal El Mahrouss , licensed under the Apache 2.0 license. + +======================================== */ + +#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 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, SWAP_DISK_HEADER* 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 SWAP_DISK_HEADER* 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 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 |
