Address comment
This commit is contained in:
parent
0b3bfe4b6f
commit
9d937ab93c
10 changed files with 70 additions and 76 deletions
|
@ -759,19 +759,6 @@ namespace ChocolArm64.Memory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe T ReadStruct<T>(long position)
|
|
||||||
where T : struct
|
|
||||||
{
|
|
||||||
int size = Marshal.SizeOf<T>();
|
|
||||||
|
|
||||||
byte[] data = ReadBytes(position, size);
|
|
||||||
|
|
||||||
fixed (byte* ptr = data)
|
|
||||||
{
|
|
||||||
return Marshal.PtrToStructure<T>((IntPtr)ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WriteSByte(long position, sbyte value)
|
public void WriteSByte(long position, sbyte value)
|
||||||
{
|
{
|
||||||
WriteByte(position, (byte)value);
|
WriteByte(position, (byte)value);
|
||||||
|
@ -965,21 +952,6 @@ namespace ChocolArm64.Memory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe void WriteStruct<T>(long position, T value)
|
|
||||||
where T : struct
|
|
||||||
{
|
|
||||||
long size = Marshal.SizeOf<T>();
|
|
||||||
|
|
||||||
byte[] data = new byte[size];
|
|
||||||
|
|
||||||
fixed (byte* ptr = data)
|
|
||||||
{
|
|
||||||
Marshal.StructureToPtr<T>(value, (IntPtr)ptr, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
WriteBytes(position, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CopyBytes(long src, long dst, long size)
|
public void CopyBytes(long src, long dst, long size)
|
||||||
{
|
{
|
||||||
// Note: This will be moved later.
|
// Note: This will be moved later.
|
||||||
|
|
|
@ -7,6 +7,8 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
struct TimeSpanType
|
struct TimeSpanType
|
||||||
{
|
{
|
||||||
|
private const long NanoSecondsPerSecond = 1000000000;
|
||||||
|
|
||||||
public long NanoSeconds;
|
public long NanoSeconds;
|
||||||
|
|
||||||
public TimeSpanType(long nanoSeconds)
|
public TimeSpanType(long nanoSeconds)
|
||||||
|
@ -16,12 +18,12 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||||
|
|
||||||
public long ToSeconds()
|
public long ToSeconds()
|
||||||
{
|
{
|
||||||
return NanoSeconds / 1000000000;
|
return NanoSeconds / NanoSecondsPerSecond;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TimeSpanType FromSeconds(long seconds)
|
public static TimeSpanType FromSeconds(long seconds)
|
||||||
{
|
{
|
||||||
return new TimeSpanType(seconds * 1000000000);
|
return new TimeSpanType(seconds * NanoSecondsPerSecond);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TimeSpanType FromTicks(ulong ticks, ulong frequency)
|
public static TimeSpanType FromTicks(ulong ticks, ulong frequency)
|
||||||
|
@ -65,7 +67,6 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||||
public SteadyClockTimePoint SteadyTimePoint;
|
public SteadyClockTimePoint SteadyTimePoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, Size = 0xD0)]
|
[StructLayout(LayoutKind.Sequential, Size = 0xD0)]
|
||||||
struct ClockSnapshot
|
struct ClockSnapshot
|
||||||
{
|
{
|
||||||
|
@ -87,7 +88,6 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||||
public byte Type;
|
public byte Type;
|
||||||
public ushort Unknown;
|
public ushort Unknown;
|
||||||
|
|
||||||
|
|
||||||
public static ResultCode GetCurrentTime(out long currentTime, SteadyClockTimePoint steadyClockTimePoint, SystemClockContext context)
|
public static ResultCode GetCurrentTime(out long currentTime, SteadyClockTimePoint steadyClockTimePoint, SystemClockContext context)
|
||||||
{
|
{
|
||||||
currentTime = 0;
|
currentTime = 0;
|
||||||
|
|
|
@ -2,18 +2,18 @@
|
||||||
{
|
{
|
||||||
class EphemeralNetworkSystemClockCore : SystemClockCore
|
class EphemeralNetworkSystemClockCore : SystemClockCore
|
||||||
{
|
{
|
||||||
private static EphemeralNetworkSystemClockCore instance;
|
private static EphemeralNetworkSystemClockCore _instance;
|
||||||
|
|
||||||
public static EphemeralNetworkSystemClockCore Instance
|
public static EphemeralNetworkSystemClockCore Instance
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (_instance == null)
|
||||||
{
|
{
|
||||||
instance = new EphemeralNetworkSystemClockCore(TickBasedSteadyClockCore.Instance);
|
_instance = new EphemeralNetworkSystemClockCore(TickBasedSteadyClockCore.Instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,18 +2,18 @@
|
||||||
{
|
{
|
||||||
class StandardLocalSystemClockCore : SystemClockCore
|
class StandardLocalSystemClockCore : SystemClockCore
|
||||||
{
|
{
|
||||||
private static StandardLocalSystemClockCore instance;
|
private static StandardLocalSystemClockCore _instance;
|
||||||
|
|
||||||
public static StandardLocalSystemClockCore Instance
|
public static StandardLocalSystemClockCore Instance
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (_instance == null)
|
||||||
{
|
{
|
||||||
instance = new StandardLocalSystemClockCore(StandardSteadyClockCore.Instance);
|
_instance = new StandardLocalSystemClockCore(StandardSteadyClockCore.Instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,18 +6,18 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||||
{
|
{
|
||||||
private TimeSpanType _standardNetworkClockSufficientAccuracy;
|
private TimeSpanType _standardNetworkClockSufficientAccuracy;
|
||||||
|
|
||||||
private static StandardNetworkSystemClockCore instance;
|
private static StandardNetworkSystemClockCore _instance;
|
||||||
|
|
||||||
public static StandardNetworkSystemClockCore Instance
|
public static StandardNetworkSystemClockCore Instance
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (_instance == null)
|
||||||
{
|
{
|
||||||
instance = new StandardNetworkSystemClockCore(StandardSteadyClockCore.Instance);
|
_instance = new StandardNetworkSystemClockCore(StandardSteadyClockCore.Instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,18 +11,18 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||||
private TimeSpanType _testOffset;
|
private TimeSpanType _testOffset;
|
||||||
private TimeSpanType _internalOffset;
|
private TimeSpanType _internalOffset;
|
||||||
|
|
||||||
private static StandardSteadyClockCore instance;
|
private static StandardSteadyClockCore _instance;
|
||||||
|
|
||||||
public static StandardSteadyClockCore Instance
|
public static StandardSteadyClockCore Instance
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (_instance == null)
|
||||||
{
|
{
|
||||||
instance = new StandardSteadyClockCore();
|
_instance = new StandardSteadyClockCore();
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,18 +8,18 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||||
private StandardNetworkSystemClockCore _networkSystemClockCore;
|
private StandardNetworkSystemClockCore _networkSystemClockCore;
|
||||||
private bool _autoCorrectionEnabled;
|
private bool _autoCorrectionEnabled;
|
||||||
|
|
||||||
private static StandardUserSystemClockCore instance;
|
private static StandardUserSystemClockCore _instance;
|
||||||
|
|
||||||
public static StandardUserSystemClockCore Instance
|
public static StandardUserSystemClockCore Instance
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (_instance == null)
|
||||||
{
|
{
|
||||||
instance = new StandardUserSystemClockCore(StandardLocalSystemClockCore.Instance, StandardNetworkSystemClockCore.Instance);
|
_instance = new StandardUserSystemClockCore(StandardLocalSystemClockCore.Instance, StandardNetworkSystemClockCore.Instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,18 +5,18 @@ namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
||||||
{
|
{
|
||||||
class TickBasedSteadyClockCore : SteadyClockCore
|
class TickBasedSteadyClockCore : SteadyClockCore
|
||||||
{
|
{
|
||||||
private static TickBasedSteadyClockCore instance;
|
private static TickBasedSteadyClockCore _instance;
|
||||||
|
|
||||||
public static TickBasedSteadyClockCore Instance
|
public static TickBasedSteadyClockCore Instance
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (_instance == null)
|
||||||
{
|
{
|
||||||
instance = new TickBasedSteadyClockCore();
|
_instance = new TickBasedSteadyClockCore();
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,9 @@ using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||||
using Ryujinx.HLE.HOS.Services.Time.Clock;
|
using Ryujinx.HLE.HOS.Services.Time.Clock;
|
||||||
using Ryujinx.HLE.HOS.Services.Time.TimeZone;
|
using Ryujinx.HLE.HOS.Services.Time.TimeZone;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace Ryujinx.HLE.HOS.Services.Time
|
namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
{
|
{
|
||||||
|
@ -132,7 +135,6 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
public ResultCode CalculateMonotonicSystemClockBaseTimePoint(ServiceCtx context)
|
public ResultCode CalculateMonotonicSystemClockBaseTimePoint(ServiceCtx context)
|
||||||
{
|
{
|
||||||
SystemClockContext otherContext = context.RequestData.ReadStruct<SystemClockContext>();
|
SystemClockContext otherContext = context.RequestData.ReadStruct<SystemClockContext>();
|
||||||
|
|
||||||
SteadyClockTimePoint currentTimePoint = StandardSteadyClockCore.Instance.GetCurrentTimePoint(context.Thread);
|
SteadyClockTimePoint currentTimePoint = StandardSteadyClockCore.Instance.GetCurrentTimePoint(context.Thread);
|
||||||
|
|
||||||
ResultCode result = ResultCode.TimeMismatch;
|
ResultCode result = ResultCode.TimeMismatch;
|
||||||
|
@ -140,7 +142,6 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
if (currentTimePoint.ClockSourceId == otherContext.SteadyTimePoint.ClockSourceId)
|
if (currentTimePoint.ClockSourceId == otherContext.SteadyTimePoint.ClockSourceId)
|
||||||
{
|
{
|
||||||
TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(context.Thread.Context.ThreadState.CntpctEl0, context.Thread.Context.ThreadState.CntfrqEl0);
|
TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(context.Thread.Context.ThreadState.CntpctEl0, context.Thread.Context.ThreadState.CntfrqEl0);
|
||||||
|
|
||||||
long baseTimePoint = otherContext.Offset + currentTimePoint.TimePoint - ticksTimeSpan.ToSeconds();
|
long baseTimePoint = otherContext.Offset + currentTimePoint.TimePoint - ticksTimeSpan.ToSeconds();
|
||||||
|
|
||||||
context.ResponseData.Write(baseTimePoint);
|
context.ResponseData.Write(baseTimePoint);
|
||||||
|
@ -157,9 +158,6 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
{
|
{
|
||||||
byte type = context.RequestData.ReadByte();
|
byte type = context.RequestData.ReadByte();
|
||||||
|
|
||||||
long bufferPosition = context.Request.RecvListBuff[0].Position;
|
|
||||||
long bufferSize = context.Request.RecvListBuff[0].Size;
|
|
||||||
|
|
||||||
ResultCode result = StandardUserSystemClockCore.Instance.GetSystemClockContext(context.Thread, out SystemClockContext userContext);
|
ResultCode result = StandardUserSystemClockCore.Instance.GetSystemClockContext(context.Thread, out SystemClockContext userContext);
|
||||||
|
|
||||||
if (result == ResultCode.Success)
|
if (result == ResultCode.Success)
|
||||||
|
@ -172,7 +170,7 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
|
|
||||||
if (result == ResultCode.Success)
|
if (result == ResultCode.Success)
|
||||||
{
|
{
|
||||||
context.Memory.WriteStruct(bufferPosition, clockSnapshot);
|
WriteClockSnapshotFromBuffer(context, context.Request.RecvListBuff[0], clockSnapshot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,18 +183,17 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
public ResultCode GetClockSnapshotFromSystemClockContext(ServiceCtx context)
|
public ResultCode GetClockSnapshotFromSystemClockContext(ServiceCtx context)
|
||||||
{
|
{
|
||||||
byte type = context.RequestData.ReadByte();
|
byte type = context.RequestData.ReadByte();
|
||||||
|
|
||||||
context.RequestData.BaseStream.Position += 7;
|
context.RequestData.BaseStream.Position += 7;
|
||||||
|
|
||||||
SystemClockContext userContext = context.RequestData.ReadStruct<SystemClockContext>();
|
SystemClockContext userContext = context.RequestData.ReadStruct<SystemClockContext>();
|
||||||
SystemClockContext networkContext = context.RequestData.ReadStruct<SystemClockContext>();
|
SystemClockContext networkContext = context.RequestData.ReadStruct<SystemClockContext>();
|
||||||
long bufferPosition = context.Request.RecvListBuff[0].Position;
|
|
||||||
long bufferSize = context.Request.RecvListBuff[0].Size;
|
|
||||||
|
|
||||||
ResultCode result = GetClockSnapshotFromSystemClockContextInternal(context.Thread, userContext, networkContext, type, out ClockSnapshot clockSnapshot);
|
ResultCode result = GetClockSnapshotFromSystemClockContextInternal(context.Thread, userContext, networkContext, type, out ClockSnapshot clockSnapshot);
|
||||||
|
|
||||||
if (result == ResultCode.Success)
|
if (result == ResultCode.Success)
|
||||||
{
|
{
|
||||||
context.Memory.WriteStruct(bufferPosition, clockSnapshot);
|
WriteClockSnapshotFromBuffer(context, context.Request.RecvListBuff[0], clockSnapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -206,8 +203,9 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
// CalculateStandardUserSystemClockDifferenceByUser(buffer<nn::time::sf::ClockSnapshot, 0x19>, buffer<nn::time::sf::ClockSnapshot, 0x19>) -> nn::TimeSpanType
|
// CalculateStandardUserSystemClockDifferenceByUser(buffer<nn::time::sf::ClockSnapshot, 0x19>, buffer<nn::time::sf::ClockSnapshot, 0x19>) -> nn::TimeSpanType
|
||||||
public ResultCode CalculateStandardUserSystemClockDifferenceByUser(ServiceCtx context)
|
public ResultCode CalculateStandardUserSystemClockDifferenceByUser(ServiceCtx context)
|
||||||
{
|
{
|
||||||
ClockSnapshot clockSnapshotA = context.Memory.ReadStruct<ClockSnapshot>(context.Request.ExchangeBuff[0].Position);
|
|
||||||
ClockSnapshot clockSnapshotB = context.Memory.ReadStruct<ClockSnapshot>(context.Request.ExchangeBuff[1].Position);
|
ClockSnapshot clockSnapshotA = ReadClockSnapshotFromBuffer(context, context.Request.ExchangeBuff[0]);
|
||||||
|
ClockSnapshot clockSnapshotB = ReadClockSnapshotFromBuffer(context, context.Request.ExchangeBuff[1]);
|
||||||
TimeSpanType difference = TimeSpanType.FromSeconds(clockSnapshotB.UserContext.Offset - clockSnapshotA.UserContext.Offset);
|
TimeSpanType difference = TimeSpanType.FromSeconds(clockSnapshotB.UserContext.Offset - clockSnapshotA.UserContext.Offset);
|
||||||
|
|
||||||
if (clockSnapshotB.UserContext.SteadyTimePoint.ClockSourceId != clockSnapshotA.UserContext.SteadyTimePoint.ClockSourceId || (clockSnapshotB.IsAutomaticCorrectionEnabled && clockSnapshotA.IsAutomaticCorrectionEnabled))
|
if (clockSnapshotB.UserContext.SteadyTimePoint.ClockSourceId != clockSnapshotA.UserContext.SteadyTimePoint.ClockSourceId || (clockSnapshotB.IsAutomaticCorrectionEnabled && clockSnapshotA.IsAutomaticCorrectionEnabled))
|
||||||
|
@ -224,8 +222,8 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
// CalculateSpanBetween(buffer<nn::time::sf::ClockSnapshot, 0x19>, buffer<nn::time::sf::ClockSnapshot, 0x19>) -> nn::TimeSpanType
|
// CalculateSpanBetween(buffer<nn::time::sf::ClockSnapshot, 0x19>, buffer<nn::time::sf::ClockSnapshot, 0x19>) -> nn::TimeSpanType
|
||||||
public ResultCode CalculateSpanBetween(ServiceCtx context)
|
public ResultCode CalculateSpanBetween(ServiceCtx context)
|
||||||
{
|
{
|
||||||
ClockSnapshot clockSnapshotA = context.Memory.ReadStruct<ClockSnapshot>(context.Request.ExchangeBuff[0].Position);
|
ClockSnapshot clockSnapshotA = ReadClockSnapshotFromBuffer(context, context.Request.ExchangeBuff[0]);
|
||||||
ClockSnapshot clockSnapshotB = context.Memory.ReadStruct<ClockSnapshot>(context.Request.ExchangeBuff[1].Position);
|
ClockSnapshot clockSnapshotB = ReadClockSnapshotFromBuffer(context, context.Request.ExchangeBuff[1]);
|
||||||
|
|
||||||
TimeSpanType result;
|
TimeSpanType result;
|
||||||
|
|
||||||
|
@ -260,7 +258,6 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
clockSnapshot = new ClockSnapshot();
|
clockSnapshot = new ClockSnapshot();
|
||||||
|
|
||||||
SteadyClockCore steadyClockCore = StandardSteadyClockCore.Instance;
|
SteadyClockCore steadyClockCore = StandardSteadyClockCore.Instance;
|
||||||
|
|
||||||
SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(thread);
|
SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(thread);
|
||||||
|
|
||||||
clockSnapshot.IsAutomaticCorrectionEnabled = StandardUserSystemClockCore.Instance.IsAutomaticCorrectionEnabled();
|
clockSnapshot.IsAutomaticCorrectionEnabled = StandardUserSystemClockCore.Instance.IsAutomaticCorrectionEnabled();
|
||||||
|
@ -306,5 +303,30 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ClockSnapshot ReadClockSnapshotFromBuffer(ServiceCtx context, IpcBuffDesc ipcDesc)
|
||||||
|
{
|
||||||
|
Debug.Assert(ipcDesc.Size == Marshal.SizeOf<ClockSnapshot>());
|
||||||
|
|
||||||
|
using (BinaryReader bufferReader = new BinaryReader(new MemoryStream(context.Memory.ReadBytes(ipcDesc.Position, ipcDesc.Size))))
|
||||||
|
{
|
||||||
|
return bufferReader.ReadStruct<ClockSnapshot>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.WriteBytes(ipcDesc.Position, memory.ToArray());
|
||||||
|
memory.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue