aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-12-12 00:06:20 -0300
committerGitHub <noreply@github.com>2020-12-12 14:06:20 +1100
commit74aa7b20be5ef924f3e8cbde699fcf4f8431f750 (patch)
tree173851ac0907333cf4b62467b1763fdbf9c8816a
parent06057a99a653b83389447a9c56d926c463317b47 (diff)
Rewrite size for fixed size buffers (#1808)
-rw-r--r--Ryujinx.Cpu/MemoryHelper.cs4
-rw-r--r--Ryujinx.HLE/HOS/Ipc/IpcPtrBuffDesc.cs5
-rw-r--r--Ryujinx.HLE/HOS/Services/Account/Acc/IManagerForApplication.cs4
-rw-r--r--Ryujinx.HLE/HOS/Services/Account/Acc/IProfile.cs2
-rw-r--r--Ryujinx.HLE/HOS/Services/Bcat/ServiceCreator/IDeliveryCacheProgressService.cs13
-rw-r--r--Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs2
-rw-r--r--Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs17
7 files changed, 26 insertions, 21 deletions
diff --git a/Ryujinx.Cpu/MemoryHelper.cs b/Ryujinx.Cpu/MemoryHelper.cs
index 8ef4bc66..7c400e91 100644
--- a/Ryujinx.Cpu/MemoryHelper.cs
+++ b/Ryujinx.Cpu/MemoryHelper.cs
@@ -37,7 +37,7 @@ namespace Ryujinx.Cpu
}
}
- public unsafe static void Write<T>(IVirtualMemoryManager memory, long position, T value) where T : struct
+ public unsafe static long Write<T>(IVirtualMemoryManager memory, long position, T value) where T : struct
{
long size = Marshal.SizeOf<T>();
@@ -49,6 +49,8 @@ namespace Ryujinx.Cpu
}
memory.Write((ulong)position, data);
+
+ return size;
}
public static string ReadAsciiString(IVirtualMemoryManager memory, long position, long maxSize = -1)
diff --git a/Ryujinx.HLE/HOS/Ipc/IpcPtrBuffDesc.cs b/Ryujinx.HLE/HOS/Ipc/IpcPtrBuffDesc.cs
index c17f248f..67cf17c9 100644
--- a/Ryujinx.HLE/HOS/Ipc/IpcPtrBuffDesc.cs
+++ b/Ryujinx.HLE/HOS/Ipc/IpcPtrBuffDesc.cs
@@ -30,6 +30,11 @@ namespace Ryujinx.HLE.HOS.Ipc
Size = (ushort)(word0 >> 16);
}
+ public IpcPtrBuffDesc WithSize(long size)
+ {
+ return new IpcPtrBuffDesc(Position, Index, size);
+ }
+
public uint GetWord0()
{
uint word0;
diff --git a/Ryujinx.HLE/HOS/Services/Account/Acc/IManagerForApplication.cs b/Ryujinx.HLE/HOS/Services/Account/Acc/IManagerForApplication.cs
index 7e2b5d4f..734366dc 100644
--- a/Ryujinx.HLE/HOS/Services/Account/Acc/IManagerForApplication.cs
+++ b/Ryujinx.HLE/HOS/Services/Account/Acc/IManagerForApplication.cs
@@ -41,7 +41,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
// GetAccountId() -> nn::account::NetworkServiceAccountId
public ResultCode GetAccountId(ServiceCtx context)
{
- // NOTE: This opens the file at "su/baas/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted
+ // NOTE: This opens the file at "su/baas/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted
// as "%08x-%04x-%04x-%02x%02x-%08x%04x") in the account:/ savedata.
// Then it searches the NetworkServiceAccountId related to the UserId in this file and returns it.
@@ -122,6 +122,8 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
context.ResponseData.Write(NetworkServiceAccountId);
+ context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(0L);
+
// TODO: determine and fill the two output IPC buffers.
return ResultCode.Success;
diff --git a/Ryujinx.HLE/HOS/Services/Account/Acc/IProfile.cs b/Ryujinx.HLE/HOS/Services/Account/Acc/IProfile.cs
index 32ee41d8..4b134c6f 100644
--- a/Ryujinx.HLE/HOS/Services/Account/Acc/IProfile.cs
+++ b/Ryujinx.HLE/HOS/Services/Account/Acc/IProfile.cs
@@ -24,6 +24,8 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
{
Logger.Stub?.PrintStub(LogClass.ServiceAcc);
+ context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(0x80L);
+
long position = context.Request.ReceiveBuff[0].Position;
MemoryHelper.FillWithZeros(context.Memory, position, 0x80);
diff --git a/Ryujinx.HLE/HOS/Services/Bcat/ServiceCreator/IDeliveryCacheProgressService.cs b/Ryujinx.HLE/HOS/Services/Bcat/ServiceCreator/IDeliveryCacheProgressService.cs
index 54b1a58a..741f3363 100644
--- a/Ryujinx.HLE/HOS/Services/Bcat/ServiceCreator/IDeliveryCacheProgressService.cs
+++ b/Ryujinx.HLE/HOS/Services/Bcat/ServiceCreator/IDeliveryCacheProgressService.cs
@@ -1,5 +1,6 @@
using Ryujinx.Common;
using Ryujinx.Common.Logging;
+using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
@@ -48,21 +49,17 @@ namespace Ryujinx.HLE.HOS.Services.Bcat.ServiceCreator
Result = 0
};
- WriteDeliveryCacheProgressImpl(context, context.Request.RecvListBuff[0], deliveryCacheProgress);
+ long dcpSize = WriteDeliveryCacheProgressImpl(context, context.Request.RecvListBuff[0], deliveryCacheProgress);
+ context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(dcpSize);
Logger.Stub?.PrintStub(LogClass.ServiceBcat);
return ResultCode.Success;
}
- private void WriteDeliveryCacheProgressImpl(ServiceCtx context, IpcRecvListBuffDesc ipcDesc, DeliveryCacheProgressImpl deliveryCacheProgress)
+ private long WriteDeliveryCacheProgressImpl(ServiceCtx context, IpcRecvListBuffDesc ipcDesc, DeliveryCacheProgressImpl deliveryCacheProgress)
{
- using (MemoryStream memory = new MemoryStream((int)ipcDesc.Size))
- using (BinaryWriter bufferWriter = new BinaryWriter(memory))
- {
- bufferWriter.WriteStruct(deliveryCacheProgress);
- context.Memory.Write((ulong)ipcDesc.Position, memory.ToArray());
- }
+ return MemoryHelper.Write(context.Memory, ipcDesc.Position, deliveryCacheProgress);
}
}
} \ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs b/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs
index 64ef5b2b..71502cda 100644
--- a/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs
+++ b/Ryujinx.HLE/HOS/Services/Friend/ServiceCreator/IFriendService.cs
@@ -221,6 +221,8 @@ namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator
bool unknownBool = context.RequestData.ReadBoolean();
UserId userId = context.RequestData.ReadStruct<UserId>();
+ context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(0x40L);
+
long bufferPosition = context.Request.RecvListBuff[0].Position;
if (userId.IsNull)
diff --git a/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs b/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs
index 8de3f726..dee3e476 100644
--- a/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs
+++ b/Ryujinx.HLE/HOS/Services/Time/IStaticServiceForPsc.cs
@@ -1,4 +1,5 @@
using Ryujinx.Common;
+using Ryujinx.Cpu;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.Kernel.Common;
using Ryujinx.HLE.HOS.Kernel.Threading;
@@ -245,6 +246,8 @@ namespace Ryujinx.HLE.HOS.Services.Time
{
byte type = context.RequestData.ReadByte();
+ context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(Marshal.SizeOf<ClockSnapshot>());
+
ResultCode result = _timeManager.StandardUserSystemClock.GetClockContext(context.Thread, out SystemClockContext userContext);
if (result == ResultCode.Success)
@@ -271,6 +274,8 @@ namespace Ryujinx.HLE.HOS.Services.Time
{
byte type = context.RequestData.ReadByte();
+ context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(Marshal.SizeOf<ClockSnapshot>());
+
context.RequestData.BaseStream.Position += 7;
SystemClockContext userContext = context.RequestData.ReadStruct<SystemClockContext>();
@@ -413,17 +418,7 @@ namespace Ryujinx.HLE.HOS.Services.Time
private void WriteClockSnapshotFromBuffer(ServiceCtx context, IpcRecvListBuffDesc ipcDesc, ClockSnapshot clockSnapshot)
{
- Debug.Assert(ipcDesc.Size == Marshal.SizeOf<ClockSnapshot>());
-
- MemoryStream memory = new MemoryStream((int)ipcDesc.Size);
-
- using (BinaryWriter bufferWriter = new BinaryWriter(memory))
- {
- bufferWriter.WriteStruct(clockSnapshot);
- }
-
- context.Memory.Write((ulong)ipcDesc.Position, memory.ToArray());
- memory.Dispose();
+ MemoryHelper.Write(context.Memory, ipcDesc.Position, clockSnapshot);
}
}
} \ No newline at end of file