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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
126 changed files with 2176 additions and 2092 deletions

View file

@ -1,6 +1,6 @@
using ARMeilleure.Memory;
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Services.Arp;
using System.Collections.Generic;
@ -75,8 +75,8 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
break;
}
context.Memory.WriteInt64(outputPosition + (long)offset, userProfile.UserId.High);
context.Memory.WriteInt64(outputPosition + (long)offset + 8, userProfile.UserId.Low);
context.Memory.Write((ulong)outputPosition + offset, userProfile.UserId.High);
context.Memory.Write((ulong)outputPosition + offset + 8, userProfile.UserId.Low);
offset += 0x10;
}
@ -240,7 +240,9 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
return ResultCode.InvalidInputBufferSize;
}
byte[] thumbnailBuffer = context.Memory.ReadBytes(inputPosition, inputSize);
byte[] thumbnailBuffer = new byte[inputSize];
context.Memory.Read((ulong)inputPosition, thumbnailBuffer);
// TODO: Store thumbnailBuffer somewhere, in save data 0x8000000000000010 ?

View file

@ -1,5 +1,5 @@
using ARMeilleure.Memory;
using Ryujinx.Common.Logging;
using Ryujinx.Cpu;
using Ryujinx.HLE.Utilities;
using System.IO;
using System.Reflection;
@ -28,9 +28,9 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
MemoryHelper.FillWithZeros(context.Memory, position, 0x80);
context.Memory.WriteInt32(position, 0);
context.Memory.WriteInt32(position + 4, 1);
context.Memory.WriteInt64(position + 8, 1);
context.Memory.Write((ulong)position, 0);
context.Memory.Write((ulong)position + 4, 1);
context.Memory.Write((ulong)position + 8, 1L);
return GetBase(context);
}
@ -70,7 +70,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
_profilePictureStream.Read(profilePictureData, 0, profilePictureData.Length);
context.Memory.WriteBytes(bufferPosition, profilePictureData);
context.Memory.Write((ulong)bufferPosition, profilePictureData);
context.ResponseData.Write(_profilePictureStream.Length);

View file

@ -44,7 +44,9 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE
size = maxSize;
}
byte[] data = context.Memory.ReadBytes(position, size);
byte[] data = new byte[size];
context.Memory.Read((ulong)position, data);
Buffer.BlockCopy(data, 0, _storage.Data, (int)writePosition, (int)size);
}
@ -71,7 +73,7 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE
Buffer.BlockCopy(_storage.Data, (int)readPosition, data, 0, (int)size);
context.Memory.WriteBytes(position, data);
context.Memory.Write((ulong)position, data);
return ResultCode.Success;
}

View file

@ -1,5 +1,5 @@
using ARMeilleure.Memory;
using Ryujinx.Audio;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
@ -106,9 +106,9 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioOutManager
context.Memory,
position);
byte[] buffer = context.Memory.ReadBytes(
data.SampleBufferPtr,
data.SampleBufferSize);
byte[] buffer = new byte[data.SampleBufferSize];
context.Memory.Read((ulong)data.SampleBufferPtr, buffer);
_audioOut.AppendBuffer(_track, tag, buffer);
@ -139,7 +139,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioOutManager
tag = releasedBuffers[index];
}
context.Memory.WriteInt64(position + index * 8, tag);
context.Memory.Write((ulong)(position + index * 8), tag);
}
context.ResponseData.Write(releasedBuffers.Length);

View file

@ -44,7 +44,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRendererManager
break;
}
context.Memory.WriteBytes(position, buffer);
context.Memory.Write((ulong)position, buffer);
position += buffer.Length;
}
@ -61,7 +61,9 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRendererManager
long position = context.Request.SendBuff[0].Position;
long size = context.Request.SendBuff[0].Size;
byte[] deviceNameBuffer = context.Memory.ReadBytes(position, size);
byte[] deviceNameBuffer = new byte[size];
context.Memory.Read((ulong)position, deviceNameBuffer);
string deviceName = Encoding.ASCII.GetString(deviceNameBuffer);
@ -83,7 +85,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRendererManager
if ((ulong)deviceNameBuffer.Length <= (ulong)size)
{
context.Memory.WriteBytes(position, deviceNameBuffer);
context.Memory.Write((ulong)position, deviceNameBuffer);
}
else
{
@ -143,7 +145,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRendererManager
break;
}
context.Memory.WriteBytes(position, buffer);
context.Memory.Write((ulong)position, buffer);
position += buffer.Length;
}
@ -159,7 +161,9 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRendererManager
(long position, long size) = context.Request.GetBufferType0x21();
byte[] deviceNameBuffer = context.Memory.ReadBytes(position, size);
byte[] deviceNameBuffer = new byte[size];
context.Memory.Read((ulong)position, deviceNameBuffer);
string deviceName = Encoding.UTF8.GetString(deviceNameBuffer);
@ -191,7 +195,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRendererManager
if ((ulong)deviceNameBuffer.Length <= (ulong)size)
{
context.Memory.WriteBytes(position, deviceNameBuffer);
context.Memory.Write((ulong)position, deviceNameBuffer);
}
else
{

View file

@ -1,7 +1,7 @@
using ARMeilleure.Memory;
using Ryujinx.Audio;
using Ryujinx.Audio.Adpcm;
using Ryujinx.Common.Logging;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
@ -333,7 +333,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRendererManager
for (int offset = 0; offset < size; offset += 2)
{
context.Coefficients[offset >> 1] = _memory.ReadInt16(position + offset);
context.Coefficients[offset >> 1] = _memory.Read<short>((ulong)(position + offset));
}
return context;

View file

@ -1,5 +1,5 @@
using ARMeilleure.Memory;
using Ryujinx.Audio.Adpcm;
using Ryujinx.Cpu;
using System;
namespace Ryujinx.HLE.HOS.Services.Audio.AudioRendererManager
@ -146,7 +146,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRendererManager
{
for (int index = 0; index < samplesCount; index++)
{
short sample = memory.ReadInt16(wb.Position + index * 2);
short sample = memory.Read<short>((ulong)(wb.Position + index * 2));
_samples[index * 2 + 0] = sample;
_samples[index * 2 + 1] = sample;
@ -156,13 +156,15 @@ namespace Ryujinx.HLE.HOS.Services.Audio.AudioRendererManager
{
for (int index = 0; index < samplesCount * 2; index++)
{
_samples[index] = memory.ReadInt16(wb.Position + index * 2);
_samples[index] = memory.Read<short>((ulong)(wb.Position + index * 2));
}
}
}
else if (SampleFormat == SampleFormat.Adpcm)
{
byte[] buffer = memory.ReadBytes(wb.Position, wb.Size);
byte[] buffer = new byte[wb.Size];
memory.Read((ulong)wb.Position, buffer);
_samples = AdpcmDecoder.Decode(buffer, AdpcmCtx);
}

View file

@ -111,7 +111,11 @@ namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager
long outputPosition = context.Request.ReceiveBuff[0].Position;
long outputSize = context.Request.ReceiveBuff[0].Size;
using (BinaryReader inputStream = new BinaryReader(new MemoryStream(context.Memory.ReadBytes(inPosition, inSize))))
byte[] buffer = new byte[inSize];
context.Memory.Read((ulong)inPosition, buffer);
using (BinaryReader inputStream = new BinaryReader(new MemoryStream(buffer)))
{
result = DecodeInterleavedInternal(inputStream, out short[] outPcmData, outputSize, out uint outConsumed, out int outSamples);
@ -119,7 +123,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager
{
byte[] pcmDataBytes = new byte[outPcmData.Length * sizeof(short)];
Buffer.BlockCopy(outPcmData, 0, pcmDataBytes, 0, pcmDataBytes.Length);
context.Memory.WriteBytes(outputPosition, pcmDataBytes);
context.Memory.Write((ulong)outputPosition, pcmDataBytes);
context.ResponseData.Write(outConsumed);
context.ResponseData.Write(outSamples);
@ -140,7 +144,11 @@ namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager
long outputPosition = context.Request.ReceiveBuff[0].Position;
long outputSize = context.Request.ReceiveBuff[0].Size;
using (BinaryReader inputStream = new BinaryReader(new MemoryStream(context.Memory.ReadBytes(inPosition, inSize))))
byte[] buffer = new byte[inSize];
context.Memory.Read((ulong)inPosition, buffer);
using (BinaryReader inputStream = new BinaryReader(new MemoryStream(buffer)))
{
result = DecodeInterleavedInternal(inputStream, out short[] outPcmData, outputSize, out uint outConsumed, out int outSamples);
@ -148,7 +156,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager
{
byte[] pcmDataBytes = new byte[outPcmData.Length * sizeof(short)];
Buffer.BlockCopy(outPcmData, 0, pcmDataBytes, 0, pcmDataBytes.Length);
context.Memory.WriteBytes(outputPosition, pcmDataBytes);
context.Memory.Write((ulong)outputPosition, pcmDataBytes);
context.ResponseData.Write(outConsumed);
context.ResponseData.Write(outSamples);
@ -174,7 +182,11 @@ namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager
long outputPosition = context.Request.ReceiveBuff[0].Position;
long outputSize = context.Request.ReceiveBuff[0].Size;
using (BinaryReader inputStream = new BinaryReader(new MemoryStream(context.Memory.ReadBytes(inPosition, inSize))))
byte[] buffer = new byte[inSize];
context.Memory.Read((ulong)inPosition, buffer);
using (BinaryReader inputStream = new BinaryReader(new MemoryStream(buffer)))
{
result = DecodeInterleavedInternal(inputStream, out short[] outPcmData, outputSize, out uint outConsumed, out int outSamples);
@ -182,7 +194,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager
{
byte[] pcmDataBytes = new byte[outPcmData.Length * sizeof(short)];
Buffer.BlockCopy(outPcmData, 0, pcmDataBytes, 0, pcmDataBytes.Length);
context.Memory.WriteBytes(outputPosition, pcmDataBytes);
context.Memory.Write((ulong)outputPosition, pcmDataBytes);
context.ResponseData.Write(outConsumed);
context.ResponseData.Write(outSamples);
@ -208,7 +220,11 @@ namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager
long outputPosition = context.Request.ReceiveBuff[0].Position;
long outputSize = context.Request.ReceiveBuff[0].Size;
using (BinaryReader inputStream = new BinaryReader(new MemoryStream(context.Memory.ReadBytes(inPosition, inSize))))
byte[] buffer = new byte[inSize];
context.Memory.Read((ulong)inPosition, buffer);
using (BinaryReader inputStream = new BinaryReader(new MemoryStream(buffer)))
{
result = DecodeInterleavedInternal(inputStream, out short[] outPcmData, outputSize, out uint outConsumed, out int outSamples);
@ -216,7 +232,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager
{
byte[] pcmDataBytes = new byte[outPcmData.Length * sizeof(short)];
Buffer.BlockCopy(outPcmData, 0, pcmDataBytes, 0, pcmDataBytes.Length);
context.Memory.WriteBytes(outputPosition, pcmDataBytes);
context.Memory.Write((ulong)outputPosition, pcmDataBytes);
context.ResponseData.Write(outConsumed);
context.ResponseData.Write(outSamples);

View file

@ -1,6 +1,6 @@
using ARMeilleure.Memory;
using Ryujinx.Audio;
using Ryujinx.Common.Logging;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Audio.AudioOutManager;
using System.Text;
@ -72,7 +72,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio
if ((ulong)deviceNameBuffer.Length <= (ulong)size)
{
context.Memory.WriteBytes(position, deviceNameBuffer);
context.Memory.Write((ulong)position, deviceNameBuffer);
nameCount++;
}
@ -109,7 +109,7 @@ namespace Ryujinx.HLE.HOS.Services.Audio
if ((ulong)deviceNameBuffer.Length <= (ulong)receiveSize)
{
context.Memory.WriteBytes(receivePosition, deviceNameBuffer);
context.Memory.Write((ulong)receivePosition, deviceNameBuffer);
}
else
{

View file

@ -37,7 +37,7 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
Result result = _base.Read(out int entriesRead, MemoryMarshal.Cast<byte, DeliveryCacheDirectoryEntry>(data));
context.Memory.WriteBytes(position, data);
context.Memory.Write((ulong)position, data);
context.ResponseData.Write(entriesRead);

View file

@ -39,7 +39,7 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
Result result = _base.Read(out long bytesRead, offset, data);
context.Memory.WriteBytes(position, data);
context.Memory.Write((ulong)position, data);
context.ResponseData.Write(bytesRead);

View file

@ -57,7 +57,7 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
using (BinaryWriter bufferWriter = new BinaryWriter(memory))
{
bufferWriter.WriteStruct(deliveryCacheProgress);
context.Memory.WriteBytes(ipcDesc.Position, memory.ToArray());
context.Memory.Write((ulong)ipcDesc.Position, memory.ToArray());
}
}
}

View file

@ -53,7 +53,7 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
Result result = _base.EnumerateDeliveryCacheDirectory(out int count, MemoryMarshal.Cast<byte, DirectoryName>(data));
context.Memory.WriteBytes(position, data);
context.Memory.Write((ulong)position, data);
context.ResponseData.Write(count);

View file

@ -166,7 +166,9 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator
long position = context.Request.PtrBuff[0].Position;
long size = context.Request.PtrBuff[0].Size;
byte[] bufferContent = context.Memory.ReadBytes(position, size);
byte[] bufferContent = new byte[size];
context.Memory.Read((ulong)position, bufferContent);
if (uuid.IsNull)
{

View file

@ -119,7 +119,9 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
long position = context.Request.PtrBuff[index].Position;
long size = context.Request.PtrBuff[index].Size;
byte[] pathBytes = context.Memory.ReadBytes(position, size);
byte[] pathBytes = new byte[size];
context.Memory.Read((ulong)position, pathBytes);
return FsPath.FromSpan(out path, pathBytes);
}

View file

@ -26,7 +26,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
Result result = _baseDirectory.Read(out long entriesRead, entries);
context.Memory.WriteBytes(bufferPosition, entriesBytes);
context.Memory.Write((ulong)bufferPosition, entriesBytes);
context.ResponseData.Write(entriesRead);
return (ResultCode)result.Value;

View file

@ -29,7 +29,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
Result result = _baseFile.Read(out long bytesRead, offset, data, readOption);
context.Memory.WriteBytes(position, data);
context.Memory.Write((ulong)position, data);
context.ResponseData.Write(bytesRead);
@ -48,7 +48,9 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
long offset = context.RequestData.ReadInt64();
long size = context.RequestData.ReadInt64();
byte[] data = context.Memory.ReadBytes(position, size);
byte[] data = new byte[size];
context.Memory.Read((ulong)position, data);
return (ResultCode)_baseFile.Write(offset, data, writeOption).Value;
}

View file

@ -34,7 +34,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
Result result = _baseStorage.Read(offset, data);
context.Memory.WriteBytes(buffDesc.Position, data);
context.Memory.Write((ulong)buffDesc.Position, data);
return (ResultCode)result.Value;
}

View file

@ -333,7 +333,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
Result result = _baseFileSystemProxy.FindSaveDataWithFilter(out long count, infoBuffer, spaceId, ref filter);
context.Memory.WriteBytes(bufferPosition, infoBuffer);
context.Memory.Write((ulong)bufferPosition, infoBuffer);
context.ResponseData.Write(count);
return (ResultCode)result.Value;

View file

@ -22,7 +22,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs
Result result = _baseReader.ReadSaveDataInfo(out long readCount, infoBuffer);
context.Memory.WriteBytes(bufferPosition, infoBuffer);
context.Memory.Write((ulong)bufferPosition, infoBuffer);
context.ResponseData.Write(readCount);
return (ResultCode)result.Value;

View file

@ -7,9 +7,11 @@ namespace Ryujinx.HLE.HOS.Services.Hid
public class Hid
{
private readonly Switch _device;
private readonly long _hidMemoryAddress;
internal ref HidSharedMemory SharedMemory => ref _device.Memory.GetStructRef<HidSharedMemory>(_hidMemoryAddress);
private readonly ulong _hidMemoryAddress;
internal ref HidSharedMemory SharedMemory => ref _device.Memory.GetRef<HidSharedMemory>(_hidMemoryAddress);
internal const int SharedMemEntryCount = 17;
public DebugPadDevice DebugPad;
@ -46,12 +48,12 @@ namespace Ryujinx.HLE.HOS.Services.Hid
}
}
public Hid(in Switch device, long sharedHidMemoryAddress)
public Hid(in Switch device, ulong sharedHidMemoryAddress)
{
_device = device;
_hidMemoryAddress = sharedHidMemoryAddress;
device.Memory.FillWithZeros(sharedHidMemoryAddress, Horizon.HidSize);
device.Memory.ZeroFill(sharedHidMemoryAddress, Horizon.HidSize);
}
public void InitDevices()

View file

@ -580,7 +580,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
for (int i = 0; i < arraySize; ++i)
{
supportedPlayerIds[i] = (NpadIdType)context.Memory.ReadInt32(context.Request.PtrBuff[0].Position + i * 4);
supportedPlayerIds[i] = context.Memory.Read<NpadIdType>((ulong)(context.Request.PtrBuff[0].Position + i * 4));
}
Logger.PrintStub(LogClass.ServiceHid, $"{arraySize} " + string.Join(",", supportedPlayerIds));
@ -980,13 +980,13 @@ namespace Ryujinx.HLE.HOS.Services.Hid
{
long appletResourceUserId = context.RequestData.ReadInt64();
byte[] vibrationDeviceHandleBuffer = context.Memory.ReadBytes(
context.Request.PtrBuff[0].Position,
context.Request.PtrBuff[0].Size);
byte[] vibrationDeviceHandleBuffer = new byte[context.Request.PtrBuff[0].Size];
byte[] vibrationValueBuffer = context.Memory.ReadBytes(
context.Request.PtrBuff[1].Position,
context.Request.PtrBuff[1].Size);
context.Memory.Read((ulong)context.Request.PtrBuff[0].Position, vibrationDeviceHandleBuffer);
byte[] vibrationValueBuffer = new byte[context.Request.PtrBuff[1].Size];
context.Memory.Read((ulong)context.Request.PtrBuff[1].Position, vibrationValueBuffer);
// TODO: Read all handles and values from buffer.

View file

@ -33,7 +33,10 @@ namespace Ryujinx.HLE.HOS.Services.Lm.LogService
public ResultCode Log(ServiceCtx context)
{
(long bufPos, long bufSize) = context.Request.GetBufferType0x21();
byte[] logBuffer = context.Memory.ReadBytes(bufPos, bufSize);
byte[] logBuffer = new byte[bufSize];
context.Memory.Read((ulong)bufPos, logBuffer);
using (MemoryStream ms = new MemoryStream(logBuffer))
{

View file

@ -261,7 +261,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService
ResultCode result = Export(data);
context.Memory.WriteBytes(outputBuffer.Position, data.ToArray());
context.Memory.Write((ulong)outputBuffer.Position, data.ToArray());
return result;
}
@ -350,7 +350,9 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService
}
else
{
rawData = context.Memory.ReadBytes(ipcBuff.Position, ipcBuff.Size);
rawData = new byte[ipcBuff.Size];
context.Memory.Read((ulong)ipcBuff.Position, rawData);
}
return new Span<byte>(rawData);
@ -365,7 +367,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.StaticService
{
Span<byte> rawData = MemoryMarshal.Cast<T, byte>(span);
context.Memory.WriteBytes(ipcBuff.Position, rawData.ToArray());
context.Memory.Write((ulong)ipcBuff.Position, rawData);
}
protected abstract bool IsUpdated(SourceFlag flag);

View file

@ -233,7 +233,7 @@ namespace Ryujinx.HLE.HOS.Services.Ncm.Lr.LocationResolverManager
byte[] contentPathBuffer = Encoding.UTF8.GetBytes(contentPath);
context.Memory.WriteBytes(position, contentPathBuffer);
context.Memory.Write((ulong)position, contentPathBuffer);
}
else
{

View file

@ -31,7 +31,9 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
long inputPosition = context.Request.SendBuff[0].Position;
long inputSize = context.Request.SendBuff[0].Size;
byte[] unknownBuffer = context.Memory.ReadBytes(inputPosition, inputSize);
byte[] unknownBuffer = new byte[inputSize];
context.Memory.Read((ulong)inputPosition, unknownBuffer);
// NOTE: appletResourceUserId, mcuVersionData and the buffer are stored inside an internal struct.
// The buffer seems to contains entries with a size of 0x40 bytes each.
@ -89,7 +91,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
for (int i = 0; i < _devices.Count; i++)
{
context.Memory.WriteUInt32(outputPosition + (i * sizeof(long)), (uint)_devices[i].Handle);
context.Memory.Write((ulong)(outputPosition + (i * sizeof(long))), (uint)_devices[i].Handle);
}
context.ResponseData.Write(_devices.Count);

View file

@ -34,7 +34,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
long position = context.Request.RecvListBuff[0].Position;
long size = context.Request.RecvListBuff[0].Size;
context.Memory.WriteInt32(position, _generalServiceDetail.ClientId);
context.Memory.Write((ulong)position, _generalServiceDetail.ClientId);
return ResultCode.Success;
}
@ -120,7 +120,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
long position = context.Request.PtrBuff[0].Position;
long size = context.Request.PtrBuff[0].Size;
int clientId = context.Memory.ReadInt32(position);
int clientId = context.Memory.Read<int>((ulong)position);
context.ResponseData.Write(GeneralServiceManager.Get(clientId).IsAnyInternetRequestAccepted);

View file

@ -16,7 +16,7 @@
byte[] nacpData = context.Device.System.ControlData.ByteSpan.ToArray();
context.Memory.WriteBytes(position, nacpData);
context.Memory.Write((ulong)position, nacpData);
return ResultCode.Success;
}

View file

@ -15,7 +15,7 @@
byte[] nacpData = context.Device.System.ControlData.ByteSpan.ToArray();
context.Memory.WriteBytes(position, nacpData);
context.Memory.Write((ulong)position, nacpData);
return ResultCode.Success;
}

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.Ipc;
using Ryujinx.HLE.HOS.Kernel.Memory;
@ -102,7 +102,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv
byte[] outputData = new byte[outputDataSize];
byte[] temp = context.Memory.ReadBytes(inputDataPosition, inputDataSize);
byte[] temp = new byte[inputDataSize];
context.Memory.Read((ulong)inputDataPosition, temp);
Buffer.BlockCopy(temp, 0, outputData, 0, temp.Length);
@ -116,7 +118,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv
}
else
{
arguments = new Span<byte>(context.Memory.ReadBytes(inputDataPosition, inputDataSize));
byte[] temp = new byte[inputDataSize];
context.Memory.Read((ulong)inputDataPosition, temp);
arguments = new Span<byte>(temp);
}
return NvResult.Success;
@ -266,7 +272,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv
if ((ioctlCommand.DirectionValue & NvIoctl.Direction.Write) != 0)
{
context.Memory.WriteBytes(context.Request.GetBufferType0x22(0).Position, arguments.ToArray());
context.Memory.Write((ulong)context.Request.GetBufferType0x22(0).Position, arguments.ToArray());
}
}
}
@ -435,7 +441,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv
errorCode = GetIoctlArgument(context, ioctlCommand, out Span<byte> arguments);
Span<byte> inlineInBuffer = new Span<byte>(context.Memory.ReadBytes(inlineInBufferPosition, inlineInBufferSize));
byte[] temp = new byte[inlineInBufferSize];
context.Memory.Read((ulong)inlineInBufferPosition, temp);
Span<byte> inlineInBuffer = new Span<byte>(temp);
if (errorCode == NvResult.Success)
{
@ -454,7 +464,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv
if ((ioctlCommand.DirectionValue & NvIoctl.Direction.Write) != 0)
{
context.Memory.WriteBytes(context.Request.GetBufferType0x22(0).Position, arguments.ToArray());
context.Memory.Write((ulong)context.Request.GetBufferType0x22(0).Position, arguments.ToArray());
}
}
}
@ -480,7 +490,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv
errorCode = GetIoctlArgument(context, ioctlCommand, out Span<byte> arguments);
Span<byte> inlineOutBuffer = new Span<byte>(context.Memory.ReadBytes(inlineOutBufferPosition, inlineOutBufferSize));
byte[] temp = new byte[inlineOutBufferSize];
context.Memory.Read((ulong)inlineOutBufferPosition, temp);
Span<byte> inlineOutBuffer = new Span<byte>(temp);
if (errorCode == NvResult.Success)
{
@ -499,8 +513,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv
if ((ioctlCommand.DirectionValue & NvIoctl.Direction.Write) != 0)
{
context.Memory.WriteBytes(context.Request.GetBufferType0x22(0).Position, arguments.ToArray());
context.Memory.WriteBytes(inlineOutBufferPosition, inlineOutBuffer.ToArray());
context.Memory.Write((ulong)context.Request.GetBufferType0x22(0).Position, arguments.ToArray());
context.Memory.Write((ulong)inlineOutBufferPosition, inlineOutBuffer.ToArray());
}
}
}

View file

@ -21,7 +21,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
private Switch _device;
private ARMeilleure.Memory.MemoryManager _memory;
private Cpu.MemoryManager _memory;
public enum ResourcePolicy
{
@ -143,7 +143,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
for (int offset = 0; offset < commandBufferData.Length; offset++)
{
commandBufferData[offset] = _memory.ReadInt32(map.Address + commandBufferEntry.Offset + offset * 4);
commandBufferData[offset] = _memory.Read<int>((ulong)(map.Address + commandBufferEntry.Offset + offset * 4));
}
// TODO: Submit command to engines.

View file

@ -95,7 +95,9 @@ namespace Ryujinx.HLE.HOS.Services.Prepo
return ResultCode.InvalidBufferSize;
}
byte[] inputBuffer = context.Memory.ReadBytes(inputPosition, inputSize);
byte[] inputBuffer = new byte[inputSize];
context.Memory.Read((ulong)inputPosition, inputBuffer);
Logger.PrintInfo(LogClass.ServicePrepo, ReadReportBuffer(inputBuffer, gameRoom, userId));

View file

@ -1,6 +1,5 @@
using ARMeilleure.Memory;
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.Common;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.HLE.HOS.Kernel.Process;
@ -69,7 +68,11 @@ namespace Ryujinx.HLE.HOS.Services.Ro
for (int i = 0; i < header.HashCount; i++)
{
hashes.Add(context.Memory.ReadBytes(nrrAddress + header.HashOffset + (i * 0x20), 0x20));
byte[] temp = new byte[0x20];
context.Memory.Read((ulong)(nrrAddress + header.HashOffset + (i * 0x20)), temp);
hashes.Add(temp);
}
nrrInfo = new NrrInfo(nrrAddress, header, hashes);
@ -127,15 +130,18 @@ namespace Ryujinx.HLE.HOS.Services.Ro
return ResultCode.InvalidAddress;
}
uint magic = context.Memory.ReadUInt32((long)nroAddress + 0x10);
uint nroFileSize = context.Memory.ReadUInt32((long)nroAddress + 0x18);
uint magic = context.Memory.Read<uint>(nroAddress + 0x10);
uint nroFileSize = context.Memory.Read<uint>(nroAddress + 0x18);
if (magic != NroMagic || nroSize != nroFileSize)
{
return ResultCode.InvalidNro;
}
byte[] nroData = context.Memory.ReadBytes((long)nroAddress, (long)nroSize);
byte[] nroData = new byte[nroSize];
context.Memory.Read(nroAddress, nroData);
byte[] nroHash = null;
MemoryStream stream = new MemoryStream(nroData);
@ -319,9 +325,9 @@ namespace Ryujinx.HLE.HOS.Services.Ro
ulong bssEnd = BitUtils.AlignUp(bssStart + (ulong)relocatableObject.BssSize, KMemoryManager.PageSize);
process.CpuMemory.WriteBytes((long)textStart, relocatableObject.Text);
process.CpuMemory.WriteBytes((long)roStart, relocatableObject.Ro);
process.CpuMemory.WriteBytes((long)dataStart, relocatableObject.Data);
process.CpuMemory.Write(textStart, relocatableObject.Text);
process.CpuMemory.Write(roStart, relocatableObject.Ro);
process.CpuMemory.Write(dataStart, relocatableObject.Data);
MemoryHelper.FillWithZeros(process.CpuMemory, (long)bssStart, (int)(bssEnd - bssStart));

View file

@ -1,5 +1,5 @@
using ARMeilleure.Memory;
using Ryujinx.Common;
using Ryujinx.Common;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Services.Account.Acc;
using Ryujinx.HLE.HOS.Services.Sdb.Pdm.QueryService.Types;
using System;
@ -37,7 +37,7 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pdm.QueryService
for (int i = 0; i < inputSize / sizeof(ulong); i++)
{
titleIds.Add(BitConverter.ToUInt64(context.Memory.ReadBytes(inputPosition, inputSize), 0));
titleIds.Add(context.Memory.Read<ulong>((ulong)inputPosition));
}
if (queryCapability == PlayLogQueryCapability.WhiteList)

View file

@ -116,11 +116,9 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl
return false;
}
context.Memory.WriteInt32(typesPosition + offset, (int)fontType);
context.Memory.WriteInt32(offsetsPosition + offset, context.Device.System.Font.GetSharedMemoryAddressOffset(fontType));
context.Memory.WriteInt32(fontSizeBufferPosition + offset, context.Device.System.Font.GetFontSize(fontType));
context.Memory.Write((ulong)(typesPosition + offset), (int)fontType);
context.Memory.Write((ulong)(offsetsPosition + offset), context.Device.System.Font.GetSharedMemoryAddressOffset(fontType));
context.Memory.Write((ulong)(fontSizeBufferPosition + offset), context.Device.System.Font.GetFontSize(fontType));
return true;
}

View file

@ -114,7 +114,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings
for (int index = 0; index < count; index++)
{
context.Memory.WriteInt64(position, SystemStateMgr.GetLanguageCode(index));
context.Memory.Write((ulong)position, SystemStateMgr.GetLanguageCode(index));
position += 8;
}

View file

@ -35,7 +35,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings
if (firmwareData != null)
{
context.Memory.WriteBytes(replyPos, firmwareData);
context.Memory.Write((ulong)replyPos, firmwareData);
return ResultCode.Success;
}
@ -78,7 +78,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings
writer.Write(Encoding.ASCII.GetBytes(build));
context.Memory.WriteBytes(replyPos, ms.ToArray());
context.Memory.Write((ulong)replyPos, ms.ToArray());
}
return ResultCode.Success;
@ -114,10 +114,15 @@ namespace Ryujinx.HLE.HOS.Services.Settings
long namePos = context.Request.PtrBuff[1].Position;
long nameSize = context.Request.PtrBuff[1].Size;
byte[] Class = context.Memory.ReadBytes(classPos, classSize);
byte[] name = context.Memory.ReadBytes(namePos, nameSize);
byte[] classBuffer = new byte[classSize];
string askedSetting = Encoding.ASCII.GetString(Class).Trim('\0') + "!" + Encoding.ASCII.GetString(name).Trim('\0');
context.Memory.Read((ulong)classPos, classBuffer);
byte[] nameBuffer = new byte[nameSize];
context.Memory.Read((ulong)namePos, nameBuffer);
string askedSetting = Encoding.ASCII.GetString(classBuffer).Trim('\0') + "!" + Encoding.ASCII.GetString(nameBuffer).Trim('\0');
NxSettings.Settings.TryGetValue(askedSetting, out object nxSetting);
@ -161,10 +166,15 @@ namespace Ryujinx.HLE.HOS.Services.Settings
long replyPos = context.Request.ReceiveBuff[0].Position;
long replySize = context.Request.ReceiveBuff[0].Size;
byte[] Class = context.Memory.ReadBytes(classPos, classSize);
byte[] name = context.Memory.ReadBytes(namePos, nameSize);
byte[] classBuffer = new byte[classSize];
string askedSetting = Encoding.ASCII.GetString(Class).Trim('\0') + "!" + Encoding.ASCII.GetString(name).Trim('\0');
context.Memory.Read((ulong)classPos, classBuffer);
byte[] nameBuffer = new byte[nameSize];
context.Memory.Read((ulong)namePos, nameBuffer);
string askedSetting = Encoding.ASCII.GetString(classBuffer).Trim('\0') + "!" + Encoding.ASCII.GetString(nameBuffer).Trim('\0');
NxSettings.Settings.TryGetValue(askedSetting, out object nxSetting);
@ -197,7 +207,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings
throw new NotImplementedException(nxSetting.GetType().Name);
}
context.Memory.WriteBytes(replyPos, settingBuffer);
context.Memory.Write((ulong)replyPos, settingBuffer);
Logger.PrintDebug(LogClass.ServiceSet, $"{askedSetting} set value: {nxSetting} as {nxSetting.GetType()}");
}

View file

@ -199,21 +199,23 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
private IPEndPoint ParseSockAddr(ServiceCtx context, long bufferPosition, long bufferSize)
{
int size = context.Memory.ReadByte(bufferPosition);
int family = context.Memory.ReadByte(bufferPosition + 1);
int port = BinaryPrimitives.ReverseEndianness(context.Memory.ReadUInt16(bufferPosition + 2));
int size = context.Memory.Read<byte>((ulong)bufferPosition);
int family = context.Memory.Read<byte>((ulong)bufferPosition + 1);
int port = BinaryPrimitives.ReverseEndianness(context.Memory.Read<ushort>((ulong)bufferPosition + 2));
byte[] rawIp = context.Memory.ReadBytes(bufferPosition + 4, 4);
byte[] rawIp = new byte[4];
context.Memory.Read((ulong)bufferPosition + 4, rawIp);
return new IPEndPoint(new IPAddress(rawIp), port);
}
private void WriteSockAddr(ServiceCtx context, long bufferPosition, IPEndPoint endPoint)
{
context.Memory.WriteByte(bufferPosition, 0);
context.Memory.WriteByte(bufferPosition + 1, (byte)endPoint.AddressFamily);
context.Memory.WriteUInt16(bufferPosition + 2, BinaryPrimitives.ReverseEndianness((ushort)endPoint.Port));
context.Memory.WriteBytes(bufferPosition + 4, endPoint.Address.GetAddressBytes());
context.Memory.Write((ulong)bufferPosition, (byte)0);
context.Memory.Write((ulong)bufferPosition + 1, (byte)endPoint.AddressFamily);
context.Memory.Write((ulong)bufferPosition + 2, BinaryPrimitives.ReverseEndianness((ushort)endPoint.Port));
context.Memory.Write((ulong)bufferPosition + 4, endPoint.Address.GetAddressBytes());
}
private void WriteSockAddr(ServiceCtx context, long bufferPosition, BsdSocket socket, bool isRemote)
@ -281,8 +283,11 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
int flags = context.RequestData.ReadInt32();
byte[] rawPath = context.Memory.ReadBytes(bufferPosition, bufferSize);
string path = Encoding.ASCII.GetString(rawPath);
byte[] rawPath = new byte[bufferSize];
context.Memory.Read((ulong)bufferPosition, rawPath);
string path = Encoding.ASCII.GetString(rawPath);
WriteBsdResult(context, -1, LinuxError.EOPNOTSUPP);
@ -321,7 +326,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
for (int i = 0; i < fdsCount; i++)
{
int socketFd = context.Memory.ReadInt32(bufferPosition + i * 8);
int socketFd = context.Memory.Read<int>((ulong)(bufferPosition + i * 8));
BsdSocket socket = RetrieveSocket(socketFd);
@ -329,8 +334,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
{
return WriteBsdResult(context, -1, LinuxError.EBADF);}
PollEvent.EventTypeMask inputEvents = (PollEvent.EventTypeMask)context.Memory.ReadInt16(bufferPosition + i * 8 + 4);
PollEvent.EventTypeMask outputEvents = (PollEvent.EventTypeMask)context.Memory.ReadInt16(bufferPosition + i * 8 + 6);
PollEvent.EventTypeMask inputEvents = (PollEvent.EventTypeMask)context.Memory.Read<short>((ulong)(bufferPosition + i * 8 + 4));
PollEvent.EventTypeMask outputEvents = (PollEvent.EventTypeMask)context.Memory.Read<short>((ulong)(bufferPosition + i * 8 + 6));
events[i] = new PollEvent(socketFd, socket, inputEvents, outputEvents);
}
@ -405,8 +410,8 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
for (int i = 0; i < fdsCount; i++)
{
PollEvent Event = events[i];
context.Memory.WriteInt32(bufferPosition + i * 8, Event.SocketFd);
context.Memory.WriteInt16(bufferPosition + i * 8 + 4, (short)Event.InputEvents);
context.Memory.Write((ulong)(bufferPosition + i * 8), Event.SocketFd);
context.Memory.Write((ulong)(bufferPosition + i * 8 + 4), (short)Event.InputEvents);
PollEvent.EventTypeMask outputEvents = 0;
@ -435,7 +440,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
outputEvents |= PollEvent.EventTypeMask.Output;
}
context.Memory.WriteInt16(bufferPosition + i * 8 + 6, (short)outputEvents);
context.Memory.Write((ulong)(bufferPosition + i * 8 + 6), (short)outputEvents);
}
return WriteBsdResult(context, readEvents.Count + writeEvents.Count + errorEvents.Count, LinuxError.SUCCESS);
@ -481,7 +486,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
result = socket.Handle.Receive(receivedBuffer, socketFlags);
errno = SetResultErrno(socket.Handle, result);
context.Memory.WriteBytes(receivePosition, receivedBuffer);
context.Memory.Write((ulong)receivePosition, receivedBuffer);
}
catch (SocketException exception)
{
@ -524,7 +529,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
result = socket.Handle.ReceiveFrom(receivedBuffer, receivedBuffer.Length, socketFlags, ref endPoint);
errno = SetResultErrno(socket.Handle, result);
context.Memory.WriteBytes(receivePosition, receivedBuffer);
context.Memory.Write((ulong)receivePosition, receivedBuffer);
WriteSockAddr(context, sockAddrOutPosition, (IPEndPoint)endPoint);
}
catch (SocketException exception)
@ -559,7 +564,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
return WriteBsdResult(context, -1, LinuxError.EOPNOTSUPP);
}
byte[] sendBuffer = context.Memory.ReadBytes(sendPosition, sendSize);
byte[] sendBuffer = new byte[sendSize];
context.Memory.Read((ulong)sendPosition, sendBuffer);
try
{
@ -600,8 +607,11 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
return WriteBsdResult(context, -1, LinuxError.EOPNOTSUPP);
}
byte[] sendBuffer = context.Memory.ReadBytes(sendPosition, sendSize);
EndPoint endPoint = ParseSockAddr(context, bufferPosition, bufferSize);
byte[] sendBuffer = new byte[sendSize];
context.Memory.Read((ulong)sendPosition, sendBuffer);
EndPoint endPoint = ParseSockAddr(context, bufferPosition, bufferSize);
try
{
@ -856,7 +866,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
(long bufferPosition, long bufferSize) = context.Request.GetBufferType0x22();
// FIXME: OOB not implemented.
context.Memory.WriteInt32(bufferPosition, 0);
context.Memory.Write((ulong)bufferPosition, 0);
break;
default:
@ -925,13 +935,13 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
case SocketOptionName.Type:
case SocketOptionName.Linger:
socket.Handle.GetSocketOption(SocketOptionLevel.Socket, optionName, optionValue);
context.Memory.WriteBytes(optionValuePosition, optionValue);
context.Memory.Write((ulong)optionValuePosition, optionValue);
return LinuxError.SUCCESS;
case (SocketOptionName)0x200:
socket.Handle.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, optionValue);
context.Memory.WriteBytes(optionValuePosition, optionValue);
context.Memory.Write((ulong)optionValuePosition, optionValue);
return LinuxError.SUCCESS;
@ -965,18 +975,18 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
case SocketOptionName.SendTimeout:
case SocketOptionName.Type:
case SocketOptionName.ReuseAddress:
socket.Handle.SetSocketOption(SocketOptionLevel.Socket, optionName, context.Memory.ReadInt32(optionValuePosition));
socket.Handle.SetSocketOption(SocketOptionLevel.Socket, optionName, context.Memory.Read<int>((ulong)optionValuePosition));
return LinuxError.SUCCESS;
case (SocketOptionName)0x200:
socket.Handle.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, context.Memory.ReadInt32(optionValuePosition));
socket.Handle.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, context.Memory.Read<int>((ulong)optionValuePosition));
return LinuxError.SUCCESS;
case SocketOptionName.Linger:
socket.Handle.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger,
new LingerOption(context.Memory.ReadInt32(optionValuePosition) != 0, context.Memory.ReadInt32(optionValuePosition + 4)));
new LingerOption(context.Memory.Read<int>((ulong)optionValuePosition) != 0, context.Memory.Read<int>((ulong)optionValuePosition + 4)));
return LinuxError.SUCCESS;
@ -1100,7 +1110,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
if (socket != null)
{
byte[] sendBuffer = context.Memory.ReadBytes(sendPosition, sendSize);
byte[] sendBuffer = new byte[sendSize];
context.Memory.Read((ulong)sendPosition, sendBuffer);
try
{

View file

@ -44,7 +44,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd
{
byte[] settingNameBuffer = Encoding.UTF8.GetBytes(settingName + '\0');
context.Memory.WriteBytes(outputPosition, settingNameBuffer);
context.Memory.Write((ulong)outputPosition, settingNameBuffer);
}
return result;
@ -62,7 +62,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd
{
byte[] identifierBuffer = Encoding.UTF8.GetBytes(identifier + '\0');
context.Memory.WriteBytes(outputPosition, identifierBuffer);
context.Memory.Write((ulong)outputPosition, identifierBuffer);
}
return result;
@ -138,7 +138,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd
byte[] resolvedAddressBuffer = Encoding.UTF8.GetBytes(resolvedAddress + '\0');
context.Memory.WriteBytes(outputPosition, resolvedAddressBuffer);
context.Memory.Write((ulong)outputPosition, resolvedAddressBuffer);
return result;
}
@ -153,7 +153,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd
byte[] resolvedAddressBuffer = Encoding.UTF8.GetBytes(resolvedAddress + '\0');
context.Memory.WriteBytes(outputPosition, resolvedAddressBuffer);
context.Memory.Write((ulong)outputPosition, resolvedAddressBuffer);
context.ResponseData.Write((int)errorCode);

View file

@ -108,8 +108,11 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd.Manager
{
(long inputPosition, long inputSize) = context.Request.GetBufferType0x21();
byte[] addressBuffer = context.Memory.ReadBytes(inputPosition, inputSize);
string address = Encoding.UTF8.GetString(addressBuffer);
byte[] addressBuffer = new byte[inputSize];
context.Memory.Read((ulong)inputPosition, addressBuffer);
string address = Encoding.UTF8.GetString(addressBuffer);
resultCode = Resolve(context, address, out resolvedAddress);

View file

@ -21,37 +21,37 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
string hostName = hostEntry.HostName + '\0';
// h_name
context.Memory.WriteBytes(bufferPosition, Encoding.ASCII.GetBytes(hostName));
context.Memory.Write((ulong)bufferPosition, Encoding.ASCII.GetBytes(hostName));
bufferPosition += hostName.Length;
// h_aliases list size
context.Memory.WriteInt32(bufferPosition, IPAddress.HostToNetworkOrder(hostEntry.Aliases.Length));
context.Memory.Write((ulong)bufferPosition, IPAddress.HostToNetworkOrder(hostEntry.Aliases.Length));
bufferPosition += 4;
// Actual aliases
foreach (string alias in hostEntry.Aliases)
{
context.Memory.WriteBytes(bufferPosition, Encoding.ASCII.GetBytes(alias + '\0'));
context.Memory.Write((ulong)bufferPosition, Encoding.ASCII.GetBytes(alias + '\0'));
bufferPosition += alias.Length + 1;
}
// h_addrtype but it's a short (also only support IPv4)
context.Memory.WriteInt16(bufferPosition, IPAddress.HostToNetworkOrder((short)2));
context.Memory.Write((ulong)bufferPosition, IPAddress.HostToNetworkOrder((short)2));
bufferPosition += 2;
// h_length but it's a short
context.Memory.WriteInt16(bufferPosition, IPAddress.HostToNetworkOrder((short)4));
context.Memory.Write((ulong)bufferPosition, IPAddress.HostToNetworkOrder((short)4));
bufferPosition += 2;
// Ip address count, we can only support ipv4 (blame Nintendo)
context.Memory.WriteInt32(bufferPosition, addresses != null ? IPAddress.HostToNetworkOrder(addresses.Count) : 0);
context.Memory.Write((ulong)bufferPosition, addresses != null ? IPAddress.HostToNetworkOrder(addresses.Count) : 0);
bufferPosition += 4;
if (addresses != null)
{
foreach (IPAddress ip in addresses)
{
context.Memory.WriteInt32(bufferPosition, IPAddress.HostToNetworkOrder(BitConverter.ToInt32(ip.GetAddressBytes(), 0)));
context.Memory.Write((ulong)bufferPosition, IPAddress.HostToNetworkOrder(BitConverter.ToInt32(ip.GetAddressBytes(), 0)));
bufferPosition += 4;
}
}
@ -168,8 +168,11 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
// GetHostByName(u8, u32, u64, pid, buffer<unknown, 5, 0>) -> (u32, u32, u32, buffer<unknown, 6, 0>)
public ResultCode GetHostByName(ServiceCtx context)
{
byte[] rawName = context.Memory.ReadBytes(context.Request.SendBuff[0].Position, context.Request.SendBuff[0].Size);
string name = Encoding.ASCII.GetString(rawName).TrimEnd('\0');
byte[] rawName = new byte[context.Request.SendBuff[0].Size];
context.Memory.Read((ulong)context.Request.SendBuff[0].Position, rawName);
string name = Encoding.ASCII.GetString(rawName).TrimEnd('\0');
// TODO: use params
bool enableNsdResolve = context.RequestData.ReadInt32() == 1;
@ -248,7 +251,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
// GetHostByAddr(u32, u32, u32, u64, pid, buffer<unknown, 5, 0>) -> (u32, u32, u32, buffer<unknown, 6, 0>)
public ResultCode GetHostByAddress(ServiceCtx context)
{
byte[] rawIp = context.Memory.ReadBytes(context.Request.SendBuff[0].Position, context.Request.SendBuff[0].Size);
byte[] rawIp = new byte[context.Request.SendBuff[0].Size];
context.Memory.Read((ulong)context.Request.SendBuff[0].Position, rawIp);
// TODO: use params
uint socketLength = context.RequestData.ReadUInt32();
@ -325,7 +330,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
if (errorString.Length + 1 <= context.Request.ReceiveBuff[0].Size)
{
resultCode = 0;
context.Memory.WriteBytes(context.Request.ReceiveBuff[0].Position, Encoding.ASCII.GetBytes(errorString + '\0'));
context.Memory.Write((ulong)context.Request.ReceiveBuff[0].Position, Encoding.ASCII.GetBytes(errorString + '\0'));
}
return resultCode;
@ -342,7 +347,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres
if (errorString.Length + 1 <= context.Request.ReceiveBuff[0].Size)
{
resultCode = 0;
context.Memory.WriteBytes(context.Request.ReceiveBuff[0].Position, Encoding.ASCII.GetBytes(errorString + '\0'));
context.Memory.Write((ulong)context.Request.ReceiveBuff[0].Position, Encoding.ASCII.GetBytes(errorString + '\0'));
}
return resultCode;

View file

@ -21,7 +21,7 @@ namespace Ryujinx.HLE.HOS.Services.Spl
_rng.GetBytes(randomBytes);
context.Memory.WriteBytes(context.Request.ReceiveBuff[0].Position, randomBytes);
context.Memory.Write((ulong)context.Request.ReceiveBuff[0].Position, randomBytes);
return ResultCode.Success;
}

View file

@ -24,7 +24,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
long replyPos = context.Request.ReceiveBuff[0].Position;
long replySize = context.Request.ReceiveBuff[0].Size;
ReadOnlySpan<byte> inputParcel = context.Memory.GetSpan(dataPos, dataSize);
ReadOnlySpan<byte> inputParcel = context.Memory.GetSpan(dataPos, (int)dataSize);
Span<byte> outputParcel = new Span<byte>(new byte[replySize]);
@ -32,7 +32,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
if (result == ResultCode.Success)
{
context.Memory.WriteBytes(replyPos, outputParcel.ToArray());
context.Memory.Write((ulong)replyPos, outputParcel);
}
return result;
@ -81,7 +81,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
(long dataPos, long dataSize) = context.Request.GetBufferType0x21();
(long replyPos, long replySize) = context.Request.GetBufferType0x22();
ReadOnlySpan<byte> inputParcel = context.Memory.GetSpan((ulong)dataPos, (ulong)dataSize);
ReadOnlySpan<byte> inputParcel = context.Memory.GetSpan((ulong)dataPos, (int)dataSize);
Span<byte> outputParcel = new Span<byte>(new byte[replySize]);
@ -89,7 +89,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
if (result == ResultCode.Success)
{
context.Memory.WriteBytes(replyPos, outputParcel.ToArray());
context.Memory.Write((ulong)replyPos, outputParcel);
}
return result;

View file

@ -401,7 +401,11 @@ namespace Ryujinx.HLE.HOS.Services.Time
{
Debug.Assert(ipcDesc.Size == Marshal.SizeOf<ClockSnapshot>());
using (BinaryReader bufferReader = new BinaryReader(new MemoryStream(context.Memory.ReadBytes(ipcDesc.Position, ipcDesc.Size))))
byte[] temp = new byte[ipcDesc.Size];
context.Memory.Read((ulong)ipcDesc.Position, temp);
using (BinaryReader bufferReader = new BinaryReader(new MemoryStream(temp)))
{
return bufferReader.ReadStruct<ClockSnapshot>();
}
@ -418,7 +422,7 @@ namespace Ryujinx.HLE.HOS.Services.Time
bufferWriter.WriteStruct(clockSnapshot);
}
context.Memory.WriteBytes(ipcDesc.Position, memory.ToArray());
context.Memory.Write((ulong)ipcDesc.Position, memory.ToArray());
memory.Dispose();
}
}

View file

@ -123,7 +123,11 @@ namespace Ryujinx.HLE.HOS.Services.Time
(long bufferPosition, long bufferSize) = context.Request.GetBufferType0x21();
using (MemoryStream timeZoneBinaryStream = new MemoryStream(context.Memory.ReadBytes(bufferPosition, bufferSize)))
byte[] temp = new byte[bufferSize];
context.Memory.Read((ulong)bufferPosition, temp);
using (MemoryStream timeZoneBinaryStream = new MemoryStream(temp))
{
_timeManager.SetupTimeZoneManager(locationName, timeZoneUpdateTimePoint, totalLocationNameCount, timeZoneRuleVersion, timeZoneBinaryStream);
}

View file

@ -1,6 +1,5 @@
using ARMeilleure.Memory;
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Services.Time.TimeZone;
using System;
using System.Text;
@ -71,7 +70,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService
return ResultCode.LocationNameTooLong;
}
context.Memory.WriteBytes(bufferPosition + offset, Encoding.ASCII.GetBytes(locationName));
context.Memory.Write((ulong)bufferPosition + offset, Encoding.ASCII.GetBytes(locationName));
MemoryHelper.FillWithZeros(context.Memory, bufferPosition + offset + locationName.Length, padding);
offset += 0x24;

View file

@ -1,6 +1,6 @@
using ARMeilleure.Memory;
using Ryujinx.Common;
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Services.Time.Clock;
using Ryujinx.HLE.HOS.Services.Time.TimeZone;
using Ryujinx.HLE.Utilities;
@ -129,7 +129,11 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService
ResultCode result;
using (MemoryStream timeZoneBinaryStream = new MemoryStream(context.Memory.ReadBytes(bufferPosition, bufferSize)))
byte[] temp = new byte[bufferSize];
context.Memory.Read((ulong)bufferPosition, temp);
using (MemoryStream timeZoneBinaryStream = new MemoryStream(temp))
{
result = _timeZoneManager.SetDeviceLocationNameWithTimeZoneRule(locationName, timeZoneBinaryStream);
}
@ -156,7 +160,11 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService
ResultCode result;
using (MemoryStream timeZoneBinaryStream = new MemoryStream(context.Memory.ReadBytes(bufferPosition, bufferSize)))
byte[] temp = new byte[bufferSize];
context.Memory.Read((ulong)bufferPosition, temp);
using (MemoryStream timeZoneBinaryStream = new MemoryStream(temp))
{
result = _timeZoneManager.ParseTimeZoneRuleBinary(out TimeZoneRule timeZoneRule, timeZoneBinaryStream);
@ -246,7 +254,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService
long outBufferPosition = context.Request.RecvListBuff[0].Position;
long outBufferSize = context.Request.RecvListBuff[0].Size;
context.Memory.WriteInt64(outBufferPosition, posixTime);
context.Memory.Write((ulong)outBufferPosition, posixTime);
context.ResponseData.Write(1);
}
@ -266,7 +274,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService
long outBufferPosition = context.Request.RecvListBuff[0].Position;
long outBufferSize = context.Request.RecvListBuff[0].Size;
context.Memory.WriteInt64(outBufferPosition, posixTime);
context.Memory.Write((ulong)outBufferPosition, posixTime);
// There could be only one result on one calendar as leap seconds aren't supported.
context.ResponseData.Write(1);

View file

@ -55,7 +55,7 @@ namespace Ryujinx.HLE.HOS.Services.Time
EphemeralClockContextWriter = new EphemeralNetworkSystemClockContextWriter();
}
public void Initialize(Switch device, Horizon system, KSharedMemory sharedMemory, long timeSharedMemoryAddress, int timeSharedMemorySize)
public void Initialize(Switch device, Horizon system, KSharedMemory sharedMemory, ulong timeSharedMemoryAddress, int timeSharedMemorySize)
{
SharedMemory.Initialize(device, sharedMemory, timeSharedMemoryAddress, timeSharedMemorySize);

View file

@ -1,4 +1,5 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using Ryujinx.HLE.HOS.Kernel.Memory;
@ -13,7 +14,7 @@ namespace Ryujinx.HLE.HOS.Services.Time
{
private Switch _device;
private KSharedMemory _sharedMemory;
private long _timeSharedMemoryAddress;
private ulong _timeSharedMemoryAddress;
private int _timeSharedMemorySize;
private const uint SteadyClockContextOffset = 0x00;
@ -21,7 +22,7 @@ namespace Ryujinx.HLE.HOS.Services.Time
private const uint NetworkSystemClockContextOffset = 0x80;
private const uint AutomaticCorrectionEnabledOffset = 0xC8;
public void Initialize(Switch device, KSharedMemory sharedMemory, long timeSharedMemoryAddress, int timeSharedMemorySize)
public void Initialize(Switch device, KSharedMemory sharedMemory, ulong timeSharedMemoryAddress, int timeSharedMemorySize)
{
_device = device;
_sharedMemory = sharedMemory;
@ -29,7 +30,7 @@ namespace Ryujinx.HLE.HOS.Services.Time
_timeSharedMemorySize = timeSharedMemorySize;
// Clean the shared memory
_device.Memory.FillWithZeros(_timeSharedMemoryAddress, _timeSharedMemorySize);
_device.Memory.ZeroFill(_timeSharedMemoryAddress, (ulong)_timeSharedMemorySize);
}
public KSharedMemory GetSharedMemory()
@ -86,9 +87,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
WriteObjectToSharedMemory(NetworkSystemClockContextOffset, 4, context);
}
private T ReadObjectFromSharedMemory<T>(long offset, long padding)
private T ReadObjectFromSharedMemory<T>(ulong offset, ulong padding) where T : unmanaged
{
long indexOffset = _timeSharedMemoryAddress + offset;
ulong indexOffset = _timeSharedMemoryAddress + offset;
T result;
uint index;
@ -96,31 +97,31 @@ namespace Ryujinx.HLE.HOS.Services.Time
do
{
index = _device.Memory.ReadUInt32(indexOffset);
index = _device.Memory.Read<uint>(indexOffset);
long objectOffset = indexOffset + 4 + padding + (index & 1) * Marshal.SizeOf<T>();
ulong objectOffset = indexOffset + 4 + padding + (ulong)((index & 1) * Unsafe.SizeOf<T>());
result = _device.Memory.ReadStruct<T>(objectOffset);
result = _device.Memory.Read<T>(objectOffset);
Thread.MemoryBarrier();
possiblyNewIndex = _device.Memory.ReadUInt32(indexOffset);
possiblyNewIndex = _device.Memory.Read<uint>(indexOffset);
} while (index != possiblyNewIndex);
return result;
}
private void WriteObjectToSharedMemory<T>(long offset, long padding, T value)
private void WriteObjectToSharedMemory<T>(ulong offset, ulong padding, T value) where T : unmanaged
{
long indexOffset = _timeSharedMemoryAddress + offset;
uint newIndex = _device.Memory.ReadUInt32(indexOffset) + 1;
long objectOffset = indexOffset + 4 + padding + (newIndex & 1) * Marshal.SizeOf<T>();
ulong indexOffset = _timeSharedMemoryAddress + offset;
uint newIndex = _device.Memory.Read<uint>(indexOffset) + 1;
ulong objectOffset = indexOffset + 4 + padding + (ulong)((newIndex & 1) * Unsafe.SizeOf<T>());
_device.Memory.WriteStruct(objectOffset, value);
_device.Memory.Write(objectOffset, value);
Thread.MemoryBarrier();
_device.Memory.WriteUInt32(indexOffset, newIndex);
_device.Memory.Write(indexOffset, newIndex);
}
}
}

View file

@ -1,4 +1,4 @@
using ARMeilleure.Memory;
using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Services.SurfaceFlinger;
@ -62,11 +62,11 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService
MemoryHelper.FillWithZeros(context.Memory, recBuffPtr, 0x60);
// Add only the default display to buffer
context.Memory.WriteBytes(recBuffPtr, Encoding.ASCII.GetBytes("Default"));
context.Memory.WriteInt64(recBuffPtr + 0x40, 0x1L);
context.Memory.WriteInt64(recBuffPtr + 0x48, 0x1L);
context.Memory.WriteInt64(recBuffPtr + 0x50, 1280L);
context.Memory.WriteInt64(recBuffPtr + 0x58, 720L);
context.Memory.Write((ulong)recBuffPtr, Encoding.ASCII.GetBytes("Default"));
context.Memory.Write((ulong)recBuffPtr + 0x40, 0x1L);
context.Memory.Write((ulong)recBuffPtr + 0x48, 0x1L);
context.Memory.Write((ulong)recBuffPtr + 0x50, 1280L);
context.Memory.Write((ulong)recBuffPtr + 0x58, 720L);
context.ResponseData.Write(1L);
@ -128,7 +128,7 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService
ReadOnlySpan<byte> parcelData = parcel.Finish();
context.Memory.WriteBytes(parcelPtr, parcelData.ToArray());
context.Memory.Write((ulong)parcelPtr, parcelData);
context.ResponseData.Write((long)parcelData.Length);
@ -166,7 +166,7 @@ namespace Ryujinx.HLE.HOS.Services.Vi.RootService
ReadOnlySpan<byte> parcelData = parcel.Finish();
context.Memory.WriteBytes(parcelPtr, parcelData.ToArray());
context.Memory.Write((ulong)parcelPtr, parcelData);
context.ResponseData.Write(layerId);
context.ResponseData.Write((long)parcelData.Length);