/*** Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: SwapLock.cpp Date: 2022-3-21 Author: Reece ***/ #include #include "Memory.hpp" #include "SwapLock.hpp" #include #if defined(AURORA_IS_LINUX_DERIVED) #include #endif namespace Aurora::Memory::SwapLock { AUKN_SYM bool Lock(const AuList> &addressRanges) { for (const auto &addressRange : addressRanges) { auto base = AuPageRound(addressRange.first, AuUInt(AuHwInfo::gPageSize)); auto length = AuPageRoundUp(addressRange.second + (addressRange.first - base), AuUInt(AuHwInfo::gPageSize)); #if defined(AURORA_IS_MODERNNT_DERIVED) if (!VirtualLock(AuReinterpretCast(base), length)) { SysPushErrorHAL("Couldn't lock memory 0x{:x} {}", base, length); return false; } #endif #if defined(AURORA_IS_POSIX_DERIVED) if (mlock(AuReinterpretCast(base), length) != 0) { SysPushErrorHAL("Couldn't lock memory 0x{:x} {}", base, length); return false; } #endif } return true; } AUKN_SYM bool Unlock(const AuList> &addressRanges) { for (const auto &addressRange : addressRanges) { auto base = AuPageRound(addressRange.first, AuUInt(AuHwInfo::gPageSize)); auto length = AuPageRoundUp(addressRange.second + (addressRange.first - base), AuUInt(AuHwInfo::gPageSize)); #if defined(AURORA_IS_MODERNNT_DERIVED) if (!VirtualUnlock(AuReinterpretCast(base), length)) { SysPushErrorHAL("Couldn't unlock memory 0x{:x} {}", base, length); } #endif #if defined(AURORA_IS_POSIX_DERIVED) if (munlock(AuReinterpretCast(base), length) != 0) { SysPushErrorHAL("Couldn't unlock memory 0x{:x} {}", base, length); } #endif } return true; } }