// SPDX-License-Identifier: Apache-2.0 // Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) // Licensed under the Apache License, Version 2.0 (see LICENSE file) // Official repository: https://github.com/ne-foss-org/nekernel #ifndef SWAPKIT_DISKSWAP_H #define SWAPKIT_DISKSWAP_H #include #include #include #define kSwapPageFilePath "/boot/pagefile.sys" #define kSwapPageFilePathU8 u8"/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: IDiskSwap() = default; ~IDiskSwap() = default; NE_COPY_DEFAULT(IDiskSwap) public: /***********************************************************************************/ /// @brief Write memory chunk onto disk. /// @param data the data packet. /// @return Number of bytes written to swap. /***********************************************************************************/ _Output Int64 Write(SwapDiskHdr* data); /***********************************************************************************/ /// @brief Read memory chunk from disk. /// @param data the data packet length. /// @return Whether the swap was fetched to disk, or not. /***********************************************************************************/ _Output SwapDiskHdr* Read(const UIntPtr offset, 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; UIntPtr fOffset; UInt64 fVirtualAddress; SizeT fBlobSz; UInt8 fBlob[1]; } PACKED ALIGN(8) SwapDiskHdr, *SwapDiskHdrPtr; } // namespace Kernel #endif