mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-10-04 11:41:04 +02:00
misc: chore: Fix numerous NullReferenceExceptions, InvalidOperationExceptions
This commit is contained in:
@@ -62,7 +62,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
|
||||
|
||||
if (list.Count != 0)
|
||||
{
|
||||
session = list.First.Value;
|
||||
if (list.First != null)
|
||||
{
|
||||
session = list.First.Value;
|
||||
}
|
||||
|
||||
list.RemoveFirst();
|
||||
}
|
||||
|
||||
@@ -1369,44 +1369,50 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
||||
|
||||
LinkedListNode<KPageNode> pageListNode = pageList.Nodes.First;
|
||||
|
||||
KPageNode pageNode = pageListNode.Value;
|
||||
|
||||
ulong srcPa = pageNode.Address;
|
||||
ulong srcPaPages = pageNode.PagesCount;
|
||||
|
||||
foreach (KMemoryInfo info in IterateOverRange(address, endAddr))
|
||||
if (pageListNode != null)
|
||||
{
|
||||
if (info.State != MemoryState.Unmapped)
|
||||
KPageNode pageNode = pageListNode.Value;
|
||||
|
||||
ulong srcPa = pageNode.Address;
|
||||
ulong srcPaPages = pageNode.PagesCount;
|
||||
|
||||
foreach (KMemoryInfo info in IterateOverRange(address, endAddr))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ulong blockSize = GetSizeInRange(info, address, endAddr);
|
||||
|
||||
ulong dstVaPages = blockSize / PageSize;
|
||||
|
||||
ulong dstVa = GetAddrInRange(info, address);
|
||||
|
||||
while (dstVaPages > 0)
|
||||
{
|
||||
if (srcPaPages == 0)
|
||||
if (info.State != MemoryState.Unmapped)
|
||||
{
|
||||
pageListNode = pageListNode.Next;
|
||||
|
||||
pageNode = pageListNode.Value;
|
||||
|
||||
srcPa = pageNode.Address;
|
||||
srcPaPages = pageNode.PagesCount;
|
||||
continue;
|
||||
}
|
||||
|
||||
ulong currentPagesCount = Math.Min(srcPaPages, dstVaPages);
|
||||
ulong blockSize = GetSizeInRange(info, address, endAddr);
|
||||
|
||||
MapPages(dstVa, currentPagesCount, srcPa, KMemoryPermission.ReadAndWrite, MemoryMapFlags.Private);
|
||||
ulong dstVaPages = blockSize / PageSize;
|
||||
|
||||
dstVa += currentPagesCount * PageSize;
|
||||
srcPa += currentPagesCount * PageSize;
|
||||
srcPaPages -= currentPagesCount;
|
||||
dstVaPages -= currentPagesCount;
|
||||
ulong dstVa = GetAddrInRange(info, address);
|
||||
|
||||
while (dstVaPages > 0)
|
||||
{
|
||||
if (srcPaPages == 0)
|
||||
{
|
||||
pageListNode = pageListNode?.Next;
|
||||
|
||||
if (pageListNode != null)
|
||||
{
|
||||
pageNode = pageListNode.Value;
|
||||
}
|
||||
|
||||
srcPa = pageNode.Address;
|
||||
srcPaPages = pageNode.PagesCount;
|
||||
}
|
||||
|
||||
ulong currentPagesCount = Math.Min(srcPaPages, dstVaPages);
|
||||
|
||||
MapPages(dstVa, currentPagesCount, srcPa, KMemoryPermission.ReadAndWrite, MemoryMapFlags.Private);
|
||||
|
||||
dstVa += currentPagesCount * PageSize;
|
||||
srcPa += currentPagesCount * PageSize;
|
||||
srcPaPages -= currentPagesCount;
|
||||
dstVaPages -= currentPagesCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
|
||||
{
|
||||
if (_pageList.Nodes.Count == 1)
|
||||
{
|
||||
ulong address = _pageList.Nodes.First.Value.Address - DramMemoryMap.DramBase;
|
||||
return ref _context.Memory.GetRef<T>(address + offset);
|
||||
if (_pageList.Nodes.First != null)
|
||||
{
|
||||
ulong address = _pageList.Nodes.First.Value.Address - DramMemoryMap.DramBase;
|
||||
return ref _context.Memory.GetRef<T>(address + offset);
|
||||
}
|
||||
}
|
||||
|
||||
throw new NotImplementedException("Non-contiguous shared memory is not yet supported.");
|
||||
|
||||
@@ -253,7 +253,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
||||
|
||||
thread.SiblingsPerCore[core] = queue.AddLast(thread);
|
||||
|
||||
return queue.First.Value;
|
||||
return queue.First?.Value;
|
||||
}
|
||||
|
||||
public void Unschedule(int prio, int core, KThread thread)
|
||||
|
||||
@@ -1302,7 +1302,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
|
||||
{
|
||||
Owner?.RemoveThread(this);
|
||||
|
||||
if (_tlsAddress != 0 && Owner.FreeThreadLocalStorage(_tlsAddress) != Result.Success)
|
||||
if (_tlsAddress != 0 && Owner?.FreeThreadLocalStorage(_tlsAddress) != Result.Success)
|
||||
{
|
||||
throw new InvalidOperationException("Unexpected failure freeing thread local storage.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user