From 6c09ce86367ef0729a25e58314eefc543aaa83b7 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 26 Mar 2025 17:02:24 +0100 Subject: feat(kernel): SwapKit+kSwap variant type. Signed-off-by: Amlal El Mahrouss --- dev/kernel/SwapKit/SwapDisk.h | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 dev/kernel/SwapKit/SwapDisk.h (limited to 'dev/kernel/SwapKit') diff --git a/dev/kernel/SwapKit/SwapDisk.h b/dev/kernel/SwapKit/SwapDisk.h new file mode 100644 index 00000000..b9c31a65 --- /dev/null +++ b/dev/kernel/SwapKit/SwapDisk.h @@ -0,0 +1,70 @@ + +/* ------------------------------------------- + + Copyright (C) 2024-2025 Amlal EL Mahrouss Labs, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include + +#define kSwapBlockMaxSize (mib_cast(16)) +#define kSwapPageFile "/boot/pagefile.sys" + +/// @file SwapDisk.h +/// @brief Virtual memory swap disk. + +namespace NeOS +{ + struct SWAP_DISK_HEADER; + + /// @brief Virtual memory interface to swap memory chunks onto disk. + class SwapDiskInterface final + { + public: + explicit SwapDiskInterface() = default; + ~SwapDiskInterface() = default; + + NE_COPY_DEFAULT(SwapDiskInterface); + + 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, const 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. + /***********************************************************************************/ + SWAP_DISK_HEADER* Read(const Char* fork_name, const SizeT fork_name_len, const 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[]; + } PACKED SWAP_DISK_HEADER; +} // namespace NeOS -- cgit v1.2.3