Implement a new physical memory manager and replace DeviceMemory (#856)

* Implement a new physical memory manager and replace DeviceMemory

* Proper generic constraints

* Fix debug build

* Add memory tests

* New CPU memory manager and general code cleanup

* Remove host memory management from CPU project, use Ryujinx.Memory instead

* Fix tests

* Document exceptions on MemoryBlock

* Fix leak on unix memory allocation

* Proper disposal of some objects on tests

* Fix JitCache not being set as initialized

* GetRef without checks for 8-bits and 16-bits CAS

* Add MemoryBlock destructor

* Throw in separate method to improve codegen

* Address PR feedback

* QueryModified improvements

* Fix memory write tracking not marking all pages as modified in some cases

* Simplify MarkRegionAsModified

* Remove XML doc for ghost param

* Add back optimization to avoid useless buffer updates

* Add Ryujinx.Cpu project, move MemoryManager there and remove MemoryBlockWrapper

* Some nits

* Do not perform address translation when size is 0

* Address PR feedback and format NativeInterface class

* Remove ghost parameter description

* Update Ryujinx.Cpu to .NET Core 3.1

* Address PR feedback

* Fix build

* Return a well defined value for GetPhysicalAddress with invalid VA, and do not return unmapped ranges as modified

* Typo
This commit is contained in:
gdkchan
2020-05-03 19:54:50 -03:00
committed by GitHub
parent 1758424208
commit f77694e4f7
126 changed files with 2176 additions and 2092 deletions

View File

@ -1,5 +1,5 @@
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel.Process;
using ARMeilleure.Memory;
namespace Ryujinx.HLE.HOS.Kernel.Common
{
@ -9,10 +9,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
{
KProcess currentProcess = system.Scheduler.GetCurrentProcess();
if (currentProcess.CpuMemory.IsMapped((long)address) &&
currentProcess.CpuMemory.IsMapped((long)address + 3))
if (currentProcess.CpuMemory.IsMapped(address) &&
currentProcess.CpuMemory.IsMapped(address + 3))
{
value = currentProcess.CpuMemory.ReadInt32((long)address);
value = currentProcess.CpuMemory.Read<int>(address);
return true;
}
@ -28,10 +28,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
for (int index = 0; index < values.Length; index++, address += 4)
{
if (currentProcess.CpuMemory.IsMapped((long)address) &&
currentProcess.CpuMemory.IsMapped((long)address + 3))
if (currentProcess.CpuMemory.IsMapped(address) &&
currentProcess.CpuMemory.IsMapped(address + 3))
{
values[index]= currentProcess.CpuMemory.ReadInt32((long)address);
values[index]= currentProcess.CpuMemory.Read<int>(address);
}
else
{
@ -46,8 +46,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
{
KProcess currentProcess = system.Scheduler.GetCurrentProcess();
if (currentProcess.CpuMemory.IsMapped((long)address) &&
currentProcess.CpuMemory.IsMapped((long)address + size - 1))
if (currentProcess.CpuMemory.IsMapped(address) &&
currentProcess.CpuMemory.IsMapped(address + (ulong)size - 1))
{
value = MemoryHelper.ReadAsciiString(currentProcess.CpuMemory, (long)address, size);
@ -63,10 +63,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
{
KProcess currentProcess = system.Scheduler.GetCurrentProcess();
if (currentProcess.CpuMemory.IsMapped((long)address) &&
currentProcess.CpuMemory.IsMapped((long)address + 3))
if (currentProcess.CpuMemory.IsMapped(address) &&
currentProcess.CpuMemory.IsMapped(address + 3))
{
currentProcess.CpuMemory.WriteInt32((long)address, value);
currentProcess.CpuMemory.Write(address, value);
return true;
}
@ -78,10 +78,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
{
KProcess currentProcess = system.Scheduler.GetCurrentProcess();
if (currentProcess.CpuMemory.IsMapped((long)address) &&
currentProcess.CpuMemory.IsMapped((long)address + 7))
if (currentProcess.CpuMemory.IsMapped(address) &&
currentProcess.CpuMemory.IsMapped(address + 7))
{
currentProcess.CpuMemory.WriteInt64((long)address, value);
currentProcess.CpuMemory.Write(address, value);
return true;
}

View File

@ -322,8 +322,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
serverHeader.ReceiveListType,
serverHeader.ReceiveListOffset);
serverProcess.CpuMemory.WriteUInt32((long)serverMsg.Address + 0, clientHeader.Word0);
serverProcess.CpuMemory.WriteUInt32((long)serverMsg.Address + 4, clientHeader.Word1);
serverProcess.CpuMemory.Write(serverMsg.Address + 0, clientHeader.Word0);
serverProcess.CpuMemory.Write(serverMsg.Address + 4, clientHeader.Word1);
uint offset;
@ -337,13 +337,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
return KernelResult.InvalidCombination;
}
serverProcess.CpuMemory.WriteUInt32((long)serverMsg.Address + 8, clientHeader.Word2);
serverProcess.CpuMemory.Write(serverMsg.Address + 8, clientHeader.Word2);
offset = 3;
if (clientHeader.HasPid)
{
serverProcess.CpuMemory.WriteInt64((long)serverMsg.Address + offset * 4, clientProcess.Pid);
serverProcess.CpuMemory.Write(serverMsg.Address + offset * 4, clientProcess.Pid);
offset += 2;
}
@ -352,14 +352,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
{
int newHandle = 0;
int handle = System.Device.Memory.ReadInt32((long)clientMsg.DramAddress + offset * 4);
int handle = System.Device.Memory.Read<int>(clientMsg.DramAddress + offset * 4);
if (clientResult == KernelResult.Success && handle != 0)
{
clientResult = GetCopyObjectHandle(clientThread, serverProcess, handle, out newHandle);
}
serverProcess.CpuMemory.WriteInt32((long)serverMsg.Address + offset * 4, newHandle);
serverProcess.CpuMemory.Write(serverMsg.Address + offset * 4, newHandle);
offset++;
}
@ -368,7 +368,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
{
int newHandle = 0;
int handle = System.Device.Memory.ReadInt32((long)clientMsg.DramAddress + offset * 4);
int handle = System.Device.Memory.Read<int>(clientMsg.DramAddress + offset * 4);
if (handle != 0)
{
@ -382,7 +382,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
}
}
serverProcess.CpuMemory.WriteInt32((long)serverMsg.Address + offset * 4, newHandle);
serverProcess.CpuMemory.Write(serverMsg.Address + offset * 4, newHandle);
offset++;
}
@ -404,7 +404,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
for (int index = 0; index < clientHeader.PointerBuffersCount; index++)
{
ulong pointerDesc = System.Device.Memory.ReadUInt64((long)clientMsg.DramAddress + offset * 4);
ulong pointerDesc = System.Device.Memory.Read<ulong>(clientMsg.DramAddress + offset * 4);
PointerBufferDesc descriptor = new PointerBufferDesc(pointerDesc);
@ -450,7 +450,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
descriptor.BufferAddress = 0;
}
serverProcess.CpuMemory.WriteUInt64((long)serverMsg.Address + offset * 4, descriptor.Pack());
serverProcess.CpuMemory.Write(serverMsg.Address + offset * 4, descriptor.Pack());
offset += 2;
}
@ -463,11 +463,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
for (int index = 0; index < totalBuffersCount; index++)
{
long clientDescAddress = (long)clientMsg.DramAddress + offset * 4;
ulong clientDescAddress = clientMsg.DramAddress + offset * 4;
uint descWord0 = System.Device.Memory.ReadUInt32(clientDescAddress + 0);
uint descWord1 = System.Device.Memory.ReadUInt32(clientDescAddress + 4);
uint descWord2 = System.Device.Memory.ReadUInt32(clientDescAddress + 8);
uint descWord0 = System.Device.Memory.Read<uint>(clientDescAddress + 0);
uint descWord1 = System.Device.Memory.Read<uint>(clientDescAddress + 4);
uint descWord2 = System.Device.Memory.Read<uint>(clientDescAddress + 8);
bool isSendDesc = index < clientHeader.SendBuffersCount;
bool isExchangeDesc = index >= clientHeader.SendBuffersCount + clientHeader.ReceiveBuffersCount;
@ -542,11 +542,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
descWord2 |= (uint)(dstAddress >> 34) & 0x3ffffffc;
descWord2 |= (uint)(dstAddress >> 4) & 0xf0000000;
long serverDescAddress = (long)serverMsg.Address + offset * 4;
ulong serverDescAddress = serverMsg.Address + offset * 4;
serverProcess.CpuMemory.WriteUInt32(serverDescAddress + 0, descWord0);
serverProcess.CpuMemory.WriteUInt32(serverDescAddress + 4, descWord1);
serverProcess.CpuMemory.WriteUInt32(serverDescAddress + 8, descWord2);
serverProcess.CpuMemory.Write(serverDescAddress + 0, descWord0);
serverProcess.CpuMemory.Write(serverDescAddress + 4, descWord1);
serverProcess.CpuMemory.Write(serverDescAddress + 8, descWord2);
offset += 3;
}
@ -700,8 +700,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
}
// Copy header.
System.Device.Memory.WriteUInt32((long)clientMsg.DramAddress + 0, serverHeader.Word0);
System.Device.Memory.WriteUInt32((long)clientMsg.DramAddress + 4, serverHeader.Word1);
System.Device.Memory.Write(clientMsg.DramAddress + 0, serverHeader.Word0);
System.Device.Memory.Write(clientMsg.DramAddress + 4, serverHeader.Word1);
// Copy handles.
uint offset;
@ -710,11 +710,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
{
offset = 3;
System.Device.Memory.WriteUInt32((long)clientMsg.DramAddress + 8, serverHeader.Word2);
System.Device.Memory.Write(clientMsg.DramAddress + 8, serverHeader.Word2);
if (serverHeader.HasPid)
{
System.Device.Memory.WriteInt64((long)clientMsg.DramAddress + offset * 4, serverProcess.Pid);
System.Device.Memory.Write(clientMsg.DramAddress + offset * 4, serverProcess.Pid);
offset += 2;
}
@ -723,14 +723,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
{
int newHandle = 0;
int handle = serverProcess.CpuMemory.ReadInt32((long)serverMsg.Address + offset * 4);
int handle = serverProcess.CpuMemory.Read<int>(serverMsg.Address + offset * 4);
if (handle != 0)
{
GetCopyObjectHandle(serverThread, clientProcess, handle, out newHandle);
}
System.Device.Memory.WriteInt32((long)clientMsg.DramAddress + offset * 4, newHandle);
System.Device.Memory.Write(clientMsg.DramAddress + offset * 4, newHandle);
offset++;
}
@ -739,7 +739,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
{
int newHandle = 0;
int handle = serverProcess.CpuMemory.ReadInt32((long)serverMsg.Address + offset * 4);
int handle = serverProcess.CpuMemory.Read<int>(serverMsg.Address + offset * 4);
if (handle != 0)
{
@ -753,7 +753,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
}
}
System.Device.Memory.WriteInt32((long)clientMsg.DramAddress + offset * 4, newHandle);
System.Device.Memory.Write(clientMsg.DramAddress + offset * 4, newHandle);
offset++;
}
@ -768,7 +768,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
for (int index = 0; index < serverHeader.PointerBuffersCount; index++)
{
ulong pointerDesc = serverProcess.CpuMemory.ReadUInt64((long)serverMsg.Address + offset * 4);
ulong pointerDesc = serverProcess.CpuMemory.Read<ulong>(serverMsg.Address + offset * 4);
PointerBufferDesc descriptor = new PointerBufferDesc(pointerDesc);
@ -819,11 +819,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
for (int index = 0; index < totalBuffersCount; index++)
{
long dstDescAddress = (long)clientMsg.DramAddress + offset * 4;
ulong dstDescAddress = clientMsg.DramAddress + offset * 4;
System.Device.Memory.WriteUInt32(dstDescAddress + 0, 0);
System.Device.Memory.WriteUInt32(dstDescAddress + 4, 0);
System.Device.Memory.WriteUInt32(dstDescAddress + 8, 0);
System.Device.Memory.Write(dstDescAddress + 0, 0);
System.Device.Memory.Write(dstDescAddress + 4, 0);
System.Device.Memory.Write(dstDescAddress + 8, 0);
offset += 3;
}
@ -878,9 +878,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
private MessageHeader GetClientMessageHeader(Message clientMsg)
{
uint word0 = System.Device.Memory.ReadUInt32((long)clientMsg.DramAddress + 0);
uint word1 = System.Device.Memory.ReadUInt32((long)clientMsg.DramAddress + 4);
uint word2 = System.Device.Memory.ReadUInt32((long)clientMsg.DramAddress + 8);
uint word0 = System.Device.Memory.Read<uint>(clientMsg.DramAddress + 0);
uint word1 = System.Device.Memory.Read<uint>(clientMsg.DramAddress + 4);
uint word2 = System.Device.Memory.Read<uint>(clientMsg.DramAddress + 8);
return new MessageHeader(word0, word1, word2);
}
@ -889,9 +889,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
{
KProcess currentProcess = System.Scheduler.GetCurrentProcess();
uint word0 = currentProcess.CpuMemory.ReadUInt32((long)serverMsg.Address + 0);
uint word1 = currentProcess.CpuMemory.ReadUInt32((long)serverMsg.Address + 4);
uint word2 = currentProcess.CpuMemory.ReadUInt32((long)serverMsg.Address + 8);
uint word0 = currentProcess.CpuMemory.Read<uint>(serverMsg.Address + 0);
uint word1 = currentProcess.CpuMemory.Read<uint>(serverMsg.Address + 4);
uint word2 = currentProcess.CpuMemory.Read<uint>(serverMsg.Address + 8);
return new MessageHeader(word0, word1, word2);
}
@ -970,11 +970,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
ulong[] receiveList = new ulong[recvListSize];
long recvListAddress = (long)message.DramAddress + recvListOffset;
ulong recvListAddress = message.DramAddress + recvListOffset;
for (int index = 0; index < recvListSize; index++)
{
receiveList[index] = System.Device.Memory.ReadUInt64(recvListAddress + index * 8);
receiveList[index] = System.Device.Memory.Read<ulong>(recvListAddress + (ulong)index * 8);
}
return receiveList;
@ -1067,20 +1067,20 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
if (header.HasPid)
{
process.CpuMemory.WriteInt64((long)message.Address + offset * 4, 0);
process.CpuMemory.Write(message.Address + offset * 4, 0L);
offset += 2;
}
for (int index = 0; index < totalHandeslCount; index++)
{
int handle = process.CpuMemory.ReadInt32((long)message.Address + offset * 4);
int handle = process.CpuMemory.Read<int>(message.Address + offset * 4);
if (handle != 0)
{
process.HandleTable.CloseHandle(handle);
process.CpuMemory.WriteInt32((long)message.Address + offset * 4, 0);
process.CpuMemory.Write(message.Address + offset * 4, 0);
}
offset++;
@ -1225,8 +1225,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
ulong address = clientProcess.MemoryManager.GetDramAddressFromVa(request.CustomCmdBuffAddr);
System.Device.Memory.WriteInt64((long)address + 0, 0);
System.Device.Memory.WriteInt32((long)address + 8, (int)result);
System.Device.Memory.Write<ulong>(address, 0);
System.Device.Memory.Write(address + 8, (int)result);
clientProcess.MemoryManager.UnborrowIpcBuffer(
request.CustomCmdBuffAddr,

View File

@ -1,5 +1,5 @@
using ARMeilleure.Memory;
using Ryujinx.Common;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process;
using System;
@ -1843,7 +1843,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
ulong unusedSizeBefore = address - addressTruncated;
_system.Device.Memory.Set(dstFirstPagePa, 0, unusedSizeBefore);
_system.Device.Memory.ZeroFill(dstFirstPagePa, unusedSizeBefore);
ulong copySize = addressRounded <= endAddr ? addressRounded - address : size;
@ -1862,7 +1862,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
if (unusedSizeAfter != 0)
{
_system.Device.Memory.Set(firstPageFillAddress, 0, unusedSizeAfter);
_system.Device.Memory.ZeroFill(firstPageFillAddress, unusedSizeAfter);
}
KPageList pages = new KPageList();
@ -1922,7 +1922,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
unusedSizeAfter = PageSize;
}
_system.Device.Memory.Set(lastPageFillAddr, 0, unusedSizeAfter);
_system.Device.Memory.ZeroFill(lastPageFillAddr, unusedSizeAfter);
if (pages.AddRange(dstFirstPagePa, 1) != KernelResult.Success)
{
@ -3041,7 +3041,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
ulong size = pagesCount * PageSize;
_cpuMemory.Map((long)dstVa, (long)(srcPa - DramMemoryMap.DramBase), (long)size);
_cpuMemory.Map(dstVa, srcPa - DramMemoryMap.DramBase, size);
result = KernelResult.Success;
@ -3066,7 +3066,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
ulong size = pagesCount * PageSize;
_cpuMemory.Unmap((long)dstVa, (long)size);
_cpuMemory.Unmap(dstVa, size);
result = KernelResult.Success;
@ -3108,7 +3108,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
{
ulong size = pageNode.PagesCount * PageSize;
_cpuMemory.Map((long)address, (long)(pageNode.Address - DramMemoryMap.DramBase), (long)size);
_cpuMemory.Map(address, pageNode.Address - DramMemoryMap.DramBase, size);
address += size;
}
@ -3118,12 +3118,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
public ulong GetDramAddressFromVa(ulong va)
{
return (ulong)_cpuMemory.GetPhysicalAddress((long)va);
return _cpuMemory.GetPhysicalAddress(va);
}
public bool ConvertVaToPa(ulong va, out ulong pa)
{
pa = DramMemoryMap.DramBase + (ulong)_cpuMemory.GetPhysicalAddress((long)va);
pa = DramMemoryMap.DramBase + _cpuMemory.GetPhysicalAddress(va);
return true;
}

View File

@ -1,12 +1,9 @@
using ARMeilleure.Memory;
using Ryujinx.Common;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Diagnostics.Demangler;
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.HLE.Loaders.Elf;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
@ -20,11 +17,11 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
private class Image
{
public long BaseAddress { get; private set; }
public ulong BaseAddress { get; }
public ElfSymbol[] Symbols { get; private set; }
public ElfSymbol[] Symbols { get; }
public Image(long baseAddress, ElfSymbol[] symbols)
public Image(ulong baseAddress, ElfSymbol[] symbols)
{
BaseAddress = baseAddress;
Symbols = symbols;
@ -48,7 +45,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
StringBuilder trace = new StringBuilder();
void AppendTrace(long address)
void AppendTrace(ulong address)
{
Image image = GetImage(address, out int imageIndex);
@ -63,7 +60,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
if (image != null)
{
long offset = address - image.BaseAddress;
ulong offset = address - image.BaseAddress;
string imageName = GetGuessedNsoNameFromIndex(imageIndex);
@ -79,7 +76,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
if (context.IsAarch32)
{
long framePointer = (long)context.GetX(11);
ulong framePointer = context.GetX(11);
while (framePointer != 0)
{
@ -90,14 +87,14 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
break;
}
AppendTrace(_owner.CpuMemory.ReadInt32(framePointer + 4));
AppendTrace(_owner.CpuMemory.Read<uint>(framePointer + 4));
framePointer = _owner.CpuMemory.ReadInt32(framePointer);
framePointer = _owner.CpuMemory.Read<uint>(framePointer);
}
}
else
{
long framePointer = (long)context.GetX(29);
ulong framePointer = context.GetX(29);
while (framePointer != 0)
{
@ -108,16 +105,16 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
break;
}
AppendTrace(_owner.CpuMemory.ReadInt64(framePointer + 8));
AppendTrace(_owner.CpuMemory.Read<ulong>(framePointer + 8));
framePointer = _owner.CpuMemory.ReadInt64(framePointer);
framePointer = _owner.CpuMemory.Read<ulong>(framePointer);
}
}
return trace.ToString();
}
private bool TryGetSubName(Image image, long address, out string name)
private bool TryGetSubName(Image image, ulong address, out string name)
{
address -= image.BaseAddress;
@ -156,13 +153,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
return false;
}
private Image GetImage(long address, out int index)
private Image GetImage(ulong address, out int index)
{
lock (_images)
{
for (index = _images.Count - 1; index >= 0; index--)
{
if ((ulong)address >= (ulong)_images[index].BaseAddress)
if (address >= _images[index].BaseAddress)
{
return _images[index];
}
@ -229,7 +226,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
if (info.State == MemoryState.CodeStatic && info.Permission == MemoryPermission.ReadAndExecute)
{
LoadMod0Symbols(_owner.CpuMemory, (long)info.Address);
LoadMod0Symbols(_owner.CpuMemory, info.Address);
}
oldAddress = address;
@ -238,54 +235,53 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
}
}
private void LoadMod0Symbols(MemoryManager memory, long textOffset)
private void LoadMod0Symbols(MemoryManager memory, ulong textOffset)
{
long mod0Offset = textOffset + memory.ReadUInt32(textOffset + 4);
ulong mod0Offset = textOffset + memory.Read<uint>(textOffset + 4);
if (mod0Offset < textOffset || !memory.IsMapped(mod0Offset) || (mod0Offset & 3) != 0)
{
return;
}
Dictionary<ElfDynamicTag, long> dynamic = new Dictionary<ElfDynamicTag, long>();
Dictionary<ElfDynamicTag, ulong> dynamic = new Dictionary<ElfDynamicTag, ulong>();
int mod0Magic = memory.ReadInt32(mod0Offset + 0x0);
int mod0Magic = memory.Read<int>(mod0Offset + 0x0);
if (mod0Magic != Mod0)
{
return;
}
long dynamicOffset = memory.ReadInt32(mod0Offset + 0x4) + mod0Offset;
long bssStartOffset = memory.ReadInt32(mod0Offset + 0x8) + mod0Offset;
long bssEndOffset = memory.ReadInt32(mod0Offset + 0xc) + mod0Offset;
long ehHdrStartOffset = memory.ReadInt32(mod0Offset + 0x10) + mod0Offset;
long ehHdrEndOffset = memory.ReadInt32(mod0Offset + 0x14) + mod0Offset;
long modObjOffset = memory.ReadInt32(mod0Offset + 0x18) + mod0Offset;
ulong dynamicOffset = memory.Read<uint>(mod0Offset + 0x4) + mod0Offset;
ulong bssStartOffset = memory.Read<uint>(mod0Offset + 0x8) + mod0Offset;
ulong bssEndOffset = memory.Read<uint>(mod0Offset + 0xc) + mod0Offset;
ulong ehHdrStartOffset = memory.Read<uint>(mod0Offset + 0x10) + mod0Offset;
ulong ehHdrEndOffset = memory.Read<uint>(mod0Offset + 0x14) + mod0Offset;
ulong modObjOffset = memory.Read<uint>(mod0Offset + 0x18) + mod0Offset;
bool isAArch32 = memory.ReadUInt64(dynamicOffset) > 0xFFFFFFFF || memory.ReadUInt64(dynamicOffset + 0x10) > 0xFFFFFFFF;
bool isAArch32 = memory.Read<ulong>(dynamicOffset) > 0xFFFFFFFF || memory.Read<ulong>(dynamicOffset + 0x10) > 0xFFFFFFFF;
while (true)
{
long tagVal;
long value;
ulong tagVal;
ulong value;
if (isAArch32)
{
tagVal = memory.ReadInt32(dynamicOffset + 0);
value = memory.ReadInt32(dynamicOffset + 4);
tagVal = memory.Read<uint>(dynamicOffset + 0);
value = memory.Read<uint>(dynamicOffset + 4);
dynamicOffset += 0x8;
}
else
{
tagVal = memory.ReadInt64(dynamicOffset + 0);
value = memory.ReadInt64(dynamicOffset + 8);
tagVal = memory.Read<ulong>(dynamicOffset + 0);
value = memory.Read<ulong>(dynamicOffset + 8);
dynamicOffset += 0x10;
}
ElfDynamicTag tag = (ElfDynamicTag)tagVal;
if (tag == ElfDynamicTag.DT_NULL)
@ -296,19 +292,19 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
dynamic[tag] = value;
}
if (!dynamic.TryGetValue(ElfDynamicTag.DT_STRTAB, out long strTab) ||
!dynamic.TryGetValue(ElfDynamicTag.DT_SYMTAB, out long symTab) ||
!dynamic.TryGetValue(ElfDynamicTag.DT_SYMENT, out long symEntSize))
if (!dynamic.TryGetValue(ElfDynamicTag.DT_STRTAB, out ulong strTab) ||
!dynamic.TryGetValue(ElfDynamicTag.DT_SYMTAB, out ulong symTab) ||
!dynamic.TryGetValue(ElfDynamicTag.DT_SYMENT, out ulong symEntSize))
{
return;
}
long strTblAddr = textOffset + strTab;
long symTblAddr = textOffset + symTab;
ulong strTblAddr = textOffset + strTab;
ulong symTblAddr = textOffset + symTab;
List<ElfSymbol> symbols = new List<ElfSymbol>();
while ((ulong)symTblAddr < (ulong)strTblAddr)
while (symTblAddr < strTblAddr)
{
ElfSymbol sym = isAArch32 ? GetSymbol32(memory, symTblAddr, strTblAddr) : GetSymbol64(memory, symTblAddr, strTblAddr);
@ -323,42 +319,36 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
}
}
private ElfSymbol GetSymbol64(MemoryManager memory, long address, long strTblAddr)
private ElfSymbol GetSymbol64(MemoryManager memory, ulong address, ulong strTblAddr)
{
using (BinaryReader inputStream = new BinaryReader(new MemoryStream(memory.ReadBytes(address, Unsafe.SizeOf<ElfSymbol64>()))))
ElfSymbol64 sym = memory.Read<ElfSymbol64>(address);
uint nameIndex = sym.NameOffset;
string name = string.Empty;
for (int chr; (chr = memory.Read<byte>(strTblAddr + nameIndex++)) != 0;)
{
ElfSymbol64 sym = inputStream.ReadStruct<ElfSymbol64>();
uint nameIndex = sym.NameOffset;
string name = string.Empty;
for (int chr; (chr = memory.ReadByte(strTblAddr + nameIndex++)) != 0;)
{
name += (char)chr;
}
return new ElfSymbol(name, sym.Info, sym.Other, sym.SectionIndex, sym.ValueAddress, sym.Size);
name += (char)chr;
}
return new ElfSymbol(name, sym.Info, sym.Other, sym.SectionIndex, sym.ValueAddress, sym.Size);
}
private ElfSymbol GetSymbol32(MemoryManager memory, long address, long strTblAddr)
private ElfSymbol GetSymbol32(MemoryManager memory, ulong address, ulong strTblAddr)
{
using (BinaryReader inputStream = new BinaryReader(new MemoryStream(memory.ReadBytes(address, Unsafe.SizeOf<ElfSymbol32>()))))
ElfSymbol32 sym = memory.Read<ElfSymbol32>(address);
uint nameIndex = sym.NameOffset;
string name = string.Empty;
for (int chr; (chr = memory.Read<byte>(strTblAddr + nameIndex++)) != 0;)
{
ElfSymbol32 sym = inputStream.ReadStruct<ElfSymbol32>();
uint nameIndex = sym.NameOffset;
string name = string.Empty;
for (int chr; (chr = memory.ReadByte(strTblAddr + nameIndex++)) != 0;)
{
name += (char)chr;
}
return new ElfSymbol(name, sym.Info, sym.Other, sym.SectionIndex, sym.ValueAddress, sym.Size);
name += (char)chr;
}
return new ElfSymbol(name, sym.Info, sym.Other, sym.SectionIndex, sym.ValueAddress, sym.Size);
}
}
}

View File

@ -1,7 +1,6 @@
using ARMeilleure.Memory;
using ARMeilleure.State;
using ARMeilleure.Translation;
using Ryujinx.Common;
using Ryujinx.Cpu;
using Ryujinx.HLE.Exceptions;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Memory;
@ -79,8 +78,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
public bool IsPaused { get; private set; }
public MemoryManager CpuMemory { get; private set; }
public Translator Translator { get; private set; }
public CpuContext CpuContext { get; private set; }
private SvcHandler _svcHandler;
@ -1109,11 +1107,8 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
default: throw new ArgumentException(nameof(addrSpaceType));
}
bool useFlatPageTable = memRegion == MemoryRegion.Application;
CpuMemory = new MemoryManager(_system.Device.Memory.RamPointer, addrSpaceBits, useFlatPageTable);
Translator = new Translator(CpuMemory);
CpuMemory = new MemoryManager(_system.Device.Memory, 1UL << addrSpaceBits);
CpuContext = new CpuContext(CpuMemory);
// TODO: This should eventually be removed.
// The GPU shouldn't depend on the CPU memory manager at all.

View File

@ -108,7 +108,9 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
private KernelResult SendSyncRequest(ulong messagePtr, ulong size, int handle)
{
byte[] messageData = _process.CpuMemory.ReadBytes((long)messagePtr, (long)size);
byte[] messageData = new byte[size];
_process.CpuMemory.Read(messagePtr, messageData);
KClientSession clientSession = _process.HandleTable.GetObject<KClientSession>(handle);

View File

@ -191,14 +191,14 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
{
KMemoryInfo blkInfo = _process.MemoryManager.QueryMemory(position);
_process.CpuMemory.WriteUInt64((long)infoPtr + 0x00, blkInfo.Address);
_process.CpuMemory.WriteUInt64((long)infoPtr + 0x08, blkInfo.Size);
_process.CpuMemory.WriteInt32 ((long)infoPtr + 0x10, (int)blkInfo.State & 0xff);
_process.CpuMemory.WriteInt32 ((long)infoPtr + 0x14, (int)blkInfo.Attribute);
_process.CpuMemory.WriteInt32 ((long)infoPtr + 0x18, (int)blkInfo.Permission);
_process.CpuMemory.WriteInt32 ((long)infoPtr + 0x1c, blkInfo.IpcRefCount);
_process.CpuMemory.WriteInt32 ((long)infoPtr + 0x20, blkInfo.DeviceRefCount);
_process.CpuMemory.WriteInt32 ((long)infoPtr + 0x24, 0);
_process.CpuMemory.Write(infoPtr + 0x00, blkInfo.Address);
_process.CpuMemory.Write(infoPtr + 0x08, blkInfo.Size);
_process.CpuMemory.Write(infoPtr + 0x10, (int)blkInfo.State & 0xff);
_process.CpuMemory.Write(infoPtr + 0x14, (int)blkInfo.Attribute);
_process.CpuMemory.Write(infoPtr + 0x18, (int)blkInfo.Permission);
_process.CpuMemory.Write(infoPtr + 0x1c, blkInfo.IpcRefCount);
_process.CpuMemory.Write(infoPtr + 0x20, blkInfo.DeviceRefCount);
_process.CpuMemory.Write(infoPtr + 0x24, 0);
pageInfo = 0;

View File

@ -1,6 +1,6 @@
using ARMeilleure.Memory;
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.Cpu;
using Ryujinx.HLE.Exceptions;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Ipc;

View File

@ -1,5 +1,5 @@
using ARMeilleure.Memory;
using ARMeilleure.State;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.HLE.HOS.Kernel.Threading;
@ -432,79 +432,79 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
MemoryManager memory = currentProcess.CpuMemory;
memory.WriteUInt64((long)address + 0x0, thread.Context.GetX(0));
memory.WriteUInt64((long)address + 0x8, thread.Context.GetX(1));
memory.WriteUInt64((long)address + 0x10, thread.Context.GetX(2));
memory.WriteUInt64((long)address + 0x18, thread.Context.GetX(3));
memory.WriteUInt64((long)address + 0x20, thread.Context.GetX(4));
memory.WriteUInt64((long)address + 0x28, thread.Context.GetX(5));
memory.WriteUInt64((long)address + 0x30, thread.Context.GetX(6));
memory.WriteUInt64((long)address + 0x38, thread.Context.GetX(7));
memory.WriteUInt64((long)address + 0x40, thread.Context.GetX(8));
memory.WriteUInt64((long)address + 0x48, thread.Context.GetX(9));
memory.WriteUInt64((long)address + 0x50, thread.Context.GetX(10));
memory.WriteUInt64((long)address + 0x58, thread.Context.GetX(11));
memory.WriteUInt64((long)address + 0x60, thread.Context.GetX(12));
memory.WriteUInt64((long)address + 0x68, thread.Context.GetX(13));
memory.WriteUInt64((long)address + 0x70, thread.Context.GetX(14));
memory.WriteUInt64((long)address + 0x78, thread.Context.GetX(15));
memory.WriteUInt64((long)address + 0x80, thread.Context.GetX(16));
memory.WriteUInt64((long)address + 0x88, thread.Context.GetX(17));
memory.WriteUInt64((long)address + 0x90, thread.Context.GetX(18));
memory.WriteUInt64((long)address + 0x98, thread.Context.GetX(19));
memory.WriteUInt64((long)address + 0xa0, thread.Context.GetX(20));
memory.WriteUInt64((long)address + 0xa8, thread.Context.GetX(21));
memory.WriteUInt64((long)address + 0xb0, thread.Context.GetX(22));
memory.WriteUInt64((long)address + 0xb8, thread.Context.GetX(23));
memory.WriteUInt64((long)address + 0xc0, thread.Context.GetX(24));
memory.WriteUInt64((long)address + 0xc8, thread.Context.GetX(25));
memory.WriteUInt64((long)address + 0xd0, thread.Context.GetX(26));
memory.WriteUInt64((long)address + 0xd8, thread.Context.GetX(27));
memory.WriteUInt64((long)address + 0xe0, thread.Context.GetX(28));
memory.WriteUInt64((long)address + 0xe8, thread.Context.GetX(29));
memory.WriteUInt64((long)address + 0xf0, thread.Context.GetX(30));
memory.WriteUInt64((long)address + 0xf8, thread.Context.GetX(31));
memory.Write(address + 0x0, thread.Context.GetX(0));
memory.Write(address + 0x8, thread.Context.GetX(1));
memory.Write(address + 0x10, thread.Context.GetX(2));
memory.Write(address + 0x18, thread.Context.GetX(3));
memory.Write(address + 0x20, thread.Context.GetX(4));
memory.Write(address + 0x28, thread.Context.GetX(5));
memory.Write(address + 0x30, thread.Context.GetX(6));
memory.Write(address + 0x38, thread.Context.GetX(7));
memory.Write(address + 0x40, thread.Context.GetX(8));
memory.Write(address + 0x48, thread.Context.GetX(9));
memory.Write(address + 0x50, thread.Context.GetX(10));
memory.Write(address + 0x58, thread.Context.GetX(11));
memory.Write(address + 0x60, thread.Context.GetX(12));
memory.Write(address + 0x68, thread.Context.GetX(13));
memory.Write(address + 0x70, thread.Context.GetX(14));
memory.Write(address + 0x78, thread.Context.GetX(15));
memory.Write(address + 0x80, thread.Context.GetX(16));
memory.Write(address + 0x88, thread.Context.GetX(17));
memory.Write(address + 0x90, thread.Context.GetX(18));
memory.Write(address + 0x98, thread.Context.GetX(19));
memory.Write(address + 0xa0, thread.Context.GetX(20));
memory.Write(address + 0xa8, thread.Context.GetX(21));
memory.Write(address + 0xb0, thread.Context.GetX(22));
memory.Write(address + 0xb8, thread.Context.GetX(23));
memory.Write(address + 0xc0, thread.Context.GetX(24));
memory.Write(address + 0xc8, thread.Context.GetX(25));
memory.Write(address + 0xd0, thread.Context.GetX(26));
memory.Write(address + 0xd8, thread.Context.GetX(27));
memory.Write(address + 0xe0, thread.Context.GetX(28));
memory.Write(address + 0xe8, thread.Context.GetX(29));
memory.Write(address + 0xf0, thread.Context.GetX(30));
memory.Write(address + 0xf8, thread.Context.GetX(31));
memory.WriteInt64((long)address + 0x100, thread.LastPc);
memory.Write(address + 0x100, thread.LastPc);
memory.WriteUInt64((long)address + 0x108, (ulong)GetPsr(thread.Context));
memory.Write(address + 0x108, (ulong)GetPsr(thread.Context));
memory.WriteVector128((long)address + 0x110, thread.Context.GetV(0));
memory.WriteVector128((long)address + 0x120, thread.Context.GetV(1));
memory.WriteVector128((long)address + 0x130, thread.Context.GetV(2));
memory.WriteVector128((long)address + 0x140, thread.Context.GetV(3));
memory.WriteVector128((long)address + 0x150, thread.Context.GetV(4));
memory.WriteVector128((long)address + 0x160, thread.Context.GetV(5));
memory.WriteVector128((long)address + 0x170, thread.Context.GetV(6));
memory.WriteVector128((long)address + 0x180, thread.Context.GetV(7));
memory.WriteVector128((long)address + 0x190, thread.Context.GetV(8));
memory.WriteVector128((long)address + 0x1a0, thread.Context.GetV(9));
memory.WriteVector128((long)address + 0x1b0, thread.Context.GetV(10));
memory.WriteVector128((long)address + 0x1c0, thread.Context.GetV(11));
memory.WriteVector128((long)address + 0x1d0, thread.Context.GetV(12));
memory.WriteVector128((long)address + 0x1e0, thread.Context.GetV(13));
memory.WriteVector128((long)address + 0x1f0, thread.Context.GetV(14));
memory.WriteVector128((long)address + 0x200, thread.Context.GetV(15));
memory.WriteVector128((long)address + 0x210, thread.Context.GetV(16));
memory.WriteVector128((long)address + 0x220, thread.Context.GetV(17));
memory.WriteVector128((long)address + 0x230, thread.Context.GetV(18));
memory.WriteVector128((long)address + 0x240, thread.Context.GetV(19));
memory.WriteVector128((long)address + 0x250, thread.Context.GetV(20));
memory.WriteVector128((long)address + 0x260, thread.Context.GetV(21));
memory.WriteVector128((long)address + 0x270, thread.Context.GetV(22));
memory.WriteVector128((long)address + 0x280, thread.Context.GetV(23));
memory.WriteVector128((long)address + 0x290, thread.Context.GetV(24));
memory.WriteVector128((long)address + 0x2a0, thread.Context.GetV(25));
memory.WriteVector128((long)address + 0x2b0, thread.Context.GetV(26));
memory.WriteVector128((long)address + 0x2c0, thread.Context.GetV(27));
memory.WriteVector128((long)address + 0x2d0, thread.Context.GetV(28));
memory.WriteVector128((long)address + 0x2e0, thread.Context.GetV(29));
memory.WriteVector128((long)address + 0x2f0, thread.Context.GetV(30));
memory.WriteVector128((long)address + 0x300, thread.Context.GetV(31));
memory.Write(address + 0x110, thread.Context.GetV(0));
memory.Write(address + 0x120, thread.Context.GetV(1));
memory.Write(address + 0x130, thread.Context.GetV(2));
memory.Write(address + 0x140, thread.Context.GetV(3));
memory.Write(address + 0x150, thread.Context.GetV(4));
memory.Write(address + 0x160, thread.Context.GetV(5));
memory.Write(address + 0x170, thread.Context.GetV(6));
memory.Write(address + 0x180, thread.Context.GetV(7));
memory.Write(address + 0x190, thread.Context.GetV(8));
memory.Write(address + 0x1a0, thread.Context.GetV(9));
memory.Write(address + 0x1b0, thread.Context.GetV(10));
memory.Write(address + 0x1c0, thread.Context.GetV(11));
memory.Write(address + 0x1d0, thread.Context.GetV(12));
memory.Write(address + 0x1e0, thread.Context.GetV(13));
memory.Write(address + 0x1f0, thread.Context.GetV(14));
memory.Write(address + 0x200, thread.Context.GetV(15));
memory.Write(address + 0x210, thread.Context.GetV(16));
memory.Write(address + 0x220, thread.Context.GetV(17));
memory.Write(address + 0x230, thread.Context.GetV(18));
memory.Write(address + 0x240, thread.Context.GetV(19));
memory.Write(address + 0x250, thread.Context.GetV(20));
memory.Write(address + 0x260, thread.Context.GetV(21));
memory.Write(address + 0x270, thread.Context.GetV(22));
memory.Write(address + 0x280, thread.Context.GetV(23));
memory.Write(address + 0x290, thread.Context.GetV(24));
memory.Write(address + 0x2a0, thread.Context.GetV(25));
memory.Write(address + 0x2b0, thread.Context.GetV(26));
memory.Write(address + 0x2c0, thread.Context.GetV(27));
memory.Write(address + 0x2d0, thread.Context.GetV(28));
memory.Write(address + 0x2e0, thread.Context.GetV(29));
memory.Write(address + 0x2f0, thread.Context.GetV(30));
memory.Write(address + 0x300, thread.Context.GetV(31));
memory.WriteInt32((long)address + 0x310, (int)thread.Context.Fpcr);
memory.WriteInt32((long)address + 0x314, (int)thread.Context.Fpsr);
memory.WriteInt64((long)address + 0x318, thread.Context.Tpidr);
memory.Write(address + 0x310, (int)thread.Context.Fpcr);
memory.Write(address + 0x314, (int)thread.Context.Fpsr);
memory.Write(address + 0x318, thread.Context.Tpidr);
return KernelResult.Success;
}

View File

@ -37,7 +37,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
for (int index = 0; index < handlesCount; index++)
{
int handle = _process.CpuMemory.ReadInt32((long)handlesPtr + index * 4);
int handle = _process.CpuMemory.Read<int>(handlesPtr + (ulong)index * 4);
KSynchronizationObject syncObj = _process.HandleTable.GetObject<KSynchronizationObject>(handle);

View File

@ -2,6 +2,7 @@ using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace Ryujinx.HLE.HOS.Kernel.Threading
{
@ -228,18 +229,22 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KProcess currentProcess = _system.Scheduler.GetCurrentProcess();
if (!currentProcess.CpuMemory.IsMapped(address))
{
// Invalid address.
requester.SignaledObj = null;
requester.ObjSyncResult = KernelResult.InvalidMemState;
return null;
}
ref int mutexRef = ref currentProcess.CpuMemory.GetRef<int>(address);
int mutexValue, newMutexValue;
do
{
if (!KernelTransfer.UserToKernelInt32(_system, address, out mutexValue))
{
// Invalid address.
requester.SignaledObj = null;
requester.ObjSyncResult = KernelResult.InvalidMemState;
return null;
}
mutexValue = mutexRef;
if (mutexValue != 0)
{
@ -252,7 +257,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
newMutexValue = requester.ThreadHandleForUserMutex;
}
}
while (!currentProcess.CpuMemory.AtomicCompareExchangeInt32((long)address, mutexValue, newMutexValue));
while (Interlocked.CompareExchange(ref mutexRef, newMutexValue, mutexValue) != mutexValue);
if (mutexValue == 0)
{
@ -389,7 +394,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
if (shouldDecrement)
{
currentValue = currentProcess.CpuMemory.AtomicDecrementInt32((long)address) + 1;
currentValue = Interlocked.Decrement(ref currentProcess.CpuMemory.GetRef<int>(address)) + 1;
}
if (currentValue < value)
@ -480,16 +485,20 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KProcess currentProcess = _system.Scheduler.GetCurrentProcess();
if (!currentProcess.CpuMemory.IsMapped(address))
{
_system.CriticalSection.Leave();
return KernelResult.InvalidMemState;
}
ref int valueRef = ref currentProcess.CpuMemory.GetRef<int>(address);
int currentValue;
do
{
if (!KernelTransfer.UserToKernelInt32(_system, address, out currentValue))
{
_system.CriticalSection.Leave();
return KernelResult.InvalidMemState;
}
currentValue = valueRef;
if (currentValue != value)
{
@ -498,7 +507,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
return KernelResult.InvalidState;
}
}
while (!currentProcess.CpuMemory.AtomicCompareExchangeInt32((long)address, currentValue, currentValue + 1));
while (Interlocked.CompareExchange(ref valueRef, currentValue + 1, currentValue) != currentValue);
WakeArbiterThreads(address, count);
@ -537,16 +546,20 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
KProcess currentProcess = _system.Scheduler.GetCurrentProcess();
if (!currentProcess.CpuMemory.IsMapped(address))
{
_system.CriticalSection.Leave();
return KernelResult.InvalidMemState;
}
ref int valueRef = ref currentProcess.CpuMemory.GetRef<int>(address);
int currentValue;
do
{
if (!KernelTransfer.UserToKernelInt32(_system, address, out currentValue))
{
_system.CriticalSection.Leave();
return KernelResult.InvalidMemState;
}
currentValue = valueRef;
if (currentValue != value)
{
@ -555,7 +568,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
return KernelResult.InvalidState;
}
}
while (!currentProcess.CpuMemory.AtomicCompareExchangeInt32((long)address, currentValue, currentValue + offset));
while (Interlocked.CompareExchange(ref valueRef, currentValue + offset, currentValue) != currentValue);
WakeArbiterThreads(address, count);

View File

@ -1,5 +1,5 @@
using ARMeilleure.Memory;
using Ryujinx.Common.Logging;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Process;
using System;
@ -163,7 +163,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
HostThread = new Thread(customHostThreadStart ?? (() => ThreadStart(entrypoint)));
Context = new ARMeilleure.State.ExecutionContext();
Context = CpuContext.CreateExecutionContext();
bool isAarch32 = (Owner.MmuFlags & 1) == 0;
@ -1141,7 +1141,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
private void ThreadStart(ulong entrypoint)
{
Owner.Translator.Execute(Context, entrypoint);
Owner.CpuContext.Execute(Context, entrypoint);
ThreadExit();