aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2022-10-17 19:12:49 -0300
committerGitHub <noreply@github.com>2022-10-17 22:12:49 +0000
commitf5a1de6ac53e70a88c0aafefd7013c557d7671c0 (patch)
tree839c6bac63c439eb701b333da078c760f42aa641
parent2aeb5b00e300c4deeb9912b4b31d726d76cf7bc2 (diff)
Fix kernel VA allocation when random allocation fails (#3755)1.1.308
* Fix kernel VA allocation when random allocation fails * This was off by one
-rw-r--r--Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs18
1 files changed, 9 insertions, 9 deletions
diff --git a/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs b/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs
index 857be7a6..501d1cc4 100644
--- a/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs
+++ b/Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs
@@ -2540,11 +2540,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
for (int attempt = 0; attempt < 8; attempt++)
{
- address = BitUtils.AlignDown(regionStart + GetRandomValue(0, aslrMaxOffset) * (ulong)alignment, alignment);
+ ulong aslrAddress = BitUtils.AlignDown(regionStart + GetRandomValue(0, aslrMaxOffset) * (ulong)alignment, alignment);
+ ulong aslrEndAddr = aslrAddress + totalNeededSize;
- ulong endAddr = address + totalNeededSize;
-
- KMemoryInfo info = _blockManager.FindBlock(address).GetInfo();
+ KMemoryInfo info = _blockManager.FindBlock(aslrAddress).GetInfo();
if (info.State != MemoryState.Unmapped)
{
@@ -2554,11 +2553,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong currBaseAddr = info.Address + reservedPagesCount * PageSize;
ulong currEndAddr = info.Address + info.Size;
- if (address >= regionStart &&
- address >= currBaseAddr &&
- endAddr - 1 <= regionEndAddr - 1 &&
- endAddr - 1 <= currEndAddr - 1)
+ if (aslrAddress >= regionStart &&
+ aslrAddress >= currBaseAddr &&
+ aslrEndAddr - 1 <= regionEndAddr - 1 &&
+ aslrEndAddr - 1 <= currEndAddr - 1)
{
+ address = aslrAddress;
break;
}
}
@@ -2603,7 +2603,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
ulong totalNeededSize = reservedSize + neededPagesCount * PageSize;
- ulong regionEndAddr = regionStart + regionPagesCount * PageSize;
+ ulong regionEndAddr = (regionStart + regionPagesCount * PageSize) - 1;
KMemoryBlock currBlock = _blockManager.FindBlock(regionStart);