Skip to content

Commit

Permalink
Fix virtual memory allocation being out of range (#2464)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdkchan authored Jul 11, 2021
1 parent 0d841c8 commit b5190f1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Ryujinx.HLE/HOS/Kernel/Memory/KPageTableBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2411,9 +2411,11 @@ private ulong FindFirstFit(
{
if (info.State == MemoryState.Unmapped)
{
ulong currBaseAddr = info.Address + reservedSize;
ulong currBaseAddr = info.Address <= regionStart ? regionStart : info.Address;
ulong currEndAddr = info.Address + info.Size - 1;

currBaseAddr += reservedSize;

ulong address = BitUtils.AlignDown(currBaseAddr, alignment) + reservedStart;

if (currBaseAddr > address)
Expand All @@ -2423,9 +2425,10 @@ private ulong FindFirstFit(

ulong allocationEndAddr = address + totalNeededSize - 1;

if (allocationEndAddr <= regionEndAddr &&
allocationEndAddr <= currEndAddr &&
address < allocationEndAddr)
if (info.Address <= address &&
address < allocationEndAddr &&
allocationEndAddr <= regionEndAddr &&
allocationEndAddr <= currEndAddr)
{
return address;
}
Expand Down

0 comments on commit b5190f1

Please sign in to comment.