2022-03-21 05:20:19 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: SwapLock.cpp
|
|
|
|
Date: 2022-3-21
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include <Source/RuntimeInternal.hpp>
|
|
|
|
#include "Memory.hpp"
|
|
|
|
#include "SwapLock.hpp"
|
2022-11-17 07:46:07 +00:00
|
|
|
#include <Source/HWInfo/AuHWInfo.hpp>
|
2022-03-21 05:20:19 +00:00
|
|
|
|
|
|
|
#if defined(AURORA_IS_LINUX_DERIVED)
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace Aurora::Memory::SwapLock
|
|
|
|
{
|
|
|
|
AUKN_SYM bool Lock(const AuList<AuPair<AuUInt, AuUInt>> &addressRanges)
|
|
|
|
{
|
|
|
|
for (const auto &addressRange : addressRanges)
|
|
|
|
{
|
2022-03-30 14:15:50 +00:00
|
|
|
auto base = AuPageRound(addressRange.first, AuUInt(AuHwInfo::gPageSize));
|
|
|
|
auto length = AuPageRoundUp(addressRange.second + (addressRange.first - base), AuUInt(AuHwInfo::gPageSize));
|
2022-03-21 05:20:19 +00:00
|
|
|
|
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
|
|
|
if (!VirtualLock(AuReinterpretCast<LPVOID>(base), length))
|
|
|
|
{
|
|
|
|
SysPushErrorHAL("Couldn't lock memory 0x{:x} {}", base, length);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(AURORA_IS_POSIX_DERIVED)
|
|
|
|
if (mlock(AuReinterpretCast<const void *>(base), length) != 0)
|
|
|
|
{
|
|
|
|
SysPushErrorHAL("Couldn't lock memory 0x{:x} {}", base, length);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM bool Unlock(const AuList<AuPair<AuUInt, AuUInt>> &addressRanges)
|
|
|
|
{
|
|
|
|
for (const auto &addressRange : addressRanges)
|
|
|
|
{
|
2022-03-30 14:15:50 +00:00
|
|
|
auto base = AuPageRound(addressRange.first, AuUInt(AuHwInfo::gPageSize));
|
|
|
|
auto length = AuPageRoundUp(addressRange.second + (addressRange.first - base), AuUInt(AuHwInfo::gPageSize));
|
2022-03-21 05:20:19 +00:00
|
|
|
|
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
|
|
|
if (!VirtualUnlock(AuReinterpretCast<LPVOID>(base), length))
|
|
|
|
{
|
|
|
|
SysPushErrorHAL("Couldn't unlock memory 0x{:x} {}", base, length);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(AURORA_IS_POSIX_DERIVED)
|
|
|
|
if (munlock(AuReinterpretCast<const void *>(base), length) != 0)
|
|
|
|
{
|
|
|
|
SysPushErrorHAL("Couldn't unlock memory 0x{:x} {}", base, length);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|