Ryujinx/Ryujinx.HLE/HOS/Kernel/KPageList.cs

80 lines
2.1 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
namespace Ryujinx.HLE.HOS.Kernel
{
class KPageList : IEnumerable<KPageNode>
{
public LinkedList<KPageNode> Nodes { get; private set; }
public KPageList()
{
Nodes = new LinkedList<KPageNode>();
}
2018-12-01 21:01:59 +01:00
public KernelResult AddRange(ulong address, ulong pagesCount)
{
2018-12-01 21:01:59 +01:00
if (pagesCount != 0)
{
if (Nodes.Last != null)
{
2018-12-01 21:01:59 +01:00
KPageNode lastNode = Nodes.Last.Value;
2018-12-01 21:01:59 +01:00
if (lastNode.Address + lastNode.PagesCount * KMemoryManager.PageSize == address)
{
2018-12-01 21:01:59 +01:00
address = lastNode.Address;
pagesCount += lastNode.PagesCount;
Nodes.RemoveLast();
}
}
2018-12-01 21:01:59 +01:00
Nodes.AddLast(new KPageNode(address, pagesCount));
}
return KernelResult.Success;
}
public ulong GetPagesCount()
{
2018-12-01 21:01:59 +01:00
ulong sum = 0;
2018-12-01 21:01:59 +01:00
foreach (KPageNode node in Nodes)
{
2018-12-01 21:01:59 +01:00
sum += node.PagesCount;
}
2018-12-01 21:01:59 +01:00
return sum;
}
2018-12-01 21:01:59 +01:00
public bool IsEqual(KPageList other)
{
2018-12-01 21:01:59 +01:00
LinkedListNode<KPageNode> thisNode = Nodes.First;
LinkedListNode<KPageNode> otherNode = other.Nodes.First;
2018-12-01 21:01:59 +01:00
while (thisNode != null && otherNode != null)
{
2018-12-01 21:01:59 +01:00
if (thisNode.Value.Address != otherNode.Value.Address ||
thisNode.Value.PagesCount != otherNode.Value.PagesCount)
{
return false;
}
2018-12-01 21:01:59 +01:00
thisNode = thisNode.Next;
otherNode = otherNode.Next;
}
2018-12-01 21:01:59 +01:00
return thisNode == null && otherNode == null;
}
public IEnumerator<KPageNode> GetEnumerator()
{
return Nodes.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}