diff options
author | Thomas Guillemard <me@thog.eu> | 2019-10-08 05:48:49 +0200 |
---|---|---|
committer | jduncanator <1518948+jduncanator@users.noreply.github.com> | 2019-10-08 14:48:49 +1100 |
commit | 1aba033ba7868d29f5f840c99ee11dd29d689972 (patch) | |
tree | a11692bbf3ba7d8f7d2780193356f112cfbb3356 /Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs | |
parent | 16869402bf81716ba3d1410621a3b1847bee389c (diff) |
Update time implementation to 9.0.0 (#783)
* Fix 9.0.0 related services bindings
This was wrong because of a mistake on switchbrew.
* Fix wronog cmdid for ISteadyClock::GetTestOffset/SetTestOffset
* Update ClockCore logics to 9.0.0
Also apply 9.0.0 permissions and comment time:u, and time:a (as those
are going to be moved)
* Move every clocks instances + timezone to a global manager
* Start implementing time:m
Also prepare the skeleton of the shared memory
* Implement SystemClockContextUpdateCallback and co
* Update StaticService to 9.0.0
* Update ISystemClock to 9.0.0
* Rename IStaticService and add glue's IStaticService
* Implement psc's ITimeZoneService
* Integrate psc layer into glue for TimeZoneService
* Rename TimeZoneManagerForPsc => TimeZoneManager
* Use correct TimeZoneService interface for both StaticService implementations
* Accurately implement time shared memory operations
* Fix two critical flaws in TimeZone logic
The first one was the month range being different fron Nintendo one
(0-11 instead of 1-12)
The other flaw was a bad incrementation order during days & months
computation.
* Follow Nintendo's abort logic for TimeManager
* Avoid crashing when timezone sysarchive isn't present
* Update Readme
* Address comments
* Correctly align fields in ISystemClock
* Fix code style and some typos
* Improve timezone system archive warning/error messages
* Rearrange using definitions in Horizon.cs
* Address comments
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs')
-rw-r--r-- | Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs | 91 |
1 files changed, 54 insertions, 37 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs b/Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs index 0d866177..d5b21f8c 100644 --- a/Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs +++ b/Ryujinx.HLE/HOS/Services/Time/StaticService/ISystemClock.cs @@ -1,5 +1,9 @@ using Ryujinx.Common; +using Ryujinx.HLE.HOS.Ipc; +using Ryujinx.HLE.HOS.Kernel.Common; +using Ryujinx.HLE.HOS.Kernel.Threading; using Ryujinx.HLE.HOS.Services.Time.Clock; +using System; namespace Ryujinx.HLE.HOS.Services.Time.StaticService { @@ -7,34 +11,31 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService { private SystemClockCore _clockCore; private bool _writePermission; + private bool _bypassUninitializedClock; + private int _operationEventReadableHandle; - public ISystemClock(SystemClockCore clockCore, bool writePermission) + public ISystemClock(SystemClockCore clockCore, bool writePermission, bool bypassUninitializedClock) { - _clockCore = clockCore; - _writePermission = writePermission; + _clockCore = clockCore; + _writePermission = writePermission; + _bypassUninitializedClock = bypassUninitializedClock; + _operationEventReadableHandle = 0; } [Command(0)] // GetCurrentTime() -> nn::time::PosixTime public ResultCode GetCurrentTime(ServiceCtx context) { - SteadyClockCore steadyClockCore = _clockCore.GetSteadyClockCore(); - SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(context.Thread); + if (!_bypassUninitializedClock && !_clockCore.IsInitialized()) + { + return ResultCode.UninitializedClock; + } - ResultCode result = _clockCore.GetSystemClockContext(context.Thread, out SystemClockContext clockContext); + ResultCode result = _clockCore.GetCurrentTime(context.Thread, out long posixTime); if (result == ResultCode.Success) { - result = ResultCode.TimeMismatch; - - if (currentTimePoint.ClockSourceId == clockContext.SteadyTimePoint.ClockSourceId) - { - long posixTime = clockContext.Offset + currentTimePoint.TimePoint; - - context.ResponseData.Write(posixTime); - - result = 0; - } + context.ResponseData.Write(posixTime); } return result; @@ -49,31 +50,26 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService return ResultCode.PermissionDenied; } - long posixTime = context.RequestData.ReadInt64(); - SteadyClockCore steadyClockCore = _clockCore.GetSteadyClockCore(); - SteadyClockTimePoint currentTimePoint = steadyClockCore.GetCurrentTimePoint(context.Thread); - - SystemClockContext clockContext = new SystemClockContext() + if (!_bypassUninitializedClock && !_clockCore.IsInitialized()) { - Offset = posixTime - currentTimePoint.TimePoint, - SteadyTimePoint = currentTimePoint - }; - - ResultCode result = _clockCore.SetSystemClockContext(clockContext); - - if (result == ResultCode.Success) - { - result = _clockCore.Flush(clockContext); + return ResultCode.UninitializedClock; } - return result; + long posixTime = context.RequestData.ReadInt64(); + + return _clockCore.SetCurrentTime(context.Thread, posixTime); } [Command(2)] - // GetSystemClockContext() -> nn::time::SystemClockContext + // GetClockContext() -> nn::time::SystemClockContext public ResultCode GetSystemClockContext(ServiceCtx context) { - ResultCode result = _clockCore.GetSystemClockContext(context.Thread, out SystemClockContext clockContext); + if (!_bypassUninitializedClock && !_clockCore.IsInitialized()) + { + return ResultCode.UninitializedClock; + } + + ResultCode result = _clockCore.GetClockContext(context.Thread, out SystemClockContext clockContext); if (result == ResultCode.Success) { @@ -84,7 +80,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService } [Command(3)] - // SetSystemClockContext(nn::time::SystemClockContext) + // SetClockContext(nn::time::SystemClockContext) public ResultCode SetSystemClockContext(ServiceCtx context) { if (!_writePermission) @@ -92,16 +88,37 @@ namespace Ryujinx.HLE.HOS.Services.Time.StaticService return ResultCode.PermissionDenied; } + if (!_bypassUninitializedClock && !_clockCore.IsInitialized()) + { + return ResultCode.UninitializedClock; + } + SystemClockContext clockContext = context.RequestData.ReadStruct<SystemClockContext>(); ResultCode result = _clockCore.SetSystemClockContext(clockContext); - if (result == ResultCode.Success) + return result; + } + + [Command(4)] // 9.0.0+ + // GetOperationEventReadableHandle() -> handle<copy> + public ResultCode GetOperationEventReadableHandle(ServiceCtx context) + { + if (_operationEventReadableHandle == 0) { - result = _clockCore.Flush(clockContext); + KEvent kEvent = new KEvent(context.Device.System); + + _clockCore.RegisterOperationEvent(kEvent.WritableEvent); + + if (context.Process.HandleTable.GenerateHandle(kEvent.ReadableEvent, out _operationEventReadableHandle) != KernelResult.Success) + { + throw new InvalidOperationException("Out of handles!"); + } } - return result; + context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_operationEventReadableHandle); + + return ResultCode.Success; } } }
\ No newline at end of file |