IStaticService.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using Ryujinx.HLE.HOS.Ipc;
  2. using Ryujinx.HLE.HOS.Kernel.Common;
  3. using System;
  4. namespace Ryujinx.HLE.HOS.Services.Time
  5. {
  6. [Service("time:a")]
  7. [Service("time:s")]
  8. [Service("time:u")]
  9. class IStaticService : IpcService
  10. {
  11. private int _timeSharedMemoryNativeHandle = 0;
  12. private static readonly DateTime StartupDate = DateTime.UtcNow;
  13. public IStaticService(ServiceCtx context) { }
  14. [Command(0)]
  15. // GetStandardUserSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
  16. public long GetStandardUserSystemClock(ServiceCtx context)
  17. {
  18. MakeObject(context, new ISystemClock(SystemClockType.User));
  19. return 0;
  20. }
  21. [Command(1)]
  22. // GetStandardNetworkSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
  23. public long GetStandardNetworkSystemClock(ServiceCtx context)
  24. {
  25. MakeObject(context, new ISystemClock(SystemClockType.Network));
  26. return 0;
  27. }
  28. [Command(2)]
  29. // GetStandardSteadyClock() -> object<nn::timesrv::detail::service::ISteadyClock>
  30. public long GetStandardSteadyClock(ServiceCtx context)
  31. {
  32. MakeObject(context, new ISteadyClock());
  33. return 0;
  34. }
  35. [Command(3)]
  36. // GetTimeZoneService() -> object<nn::timesrv::detail::service::ITimeZoneService>
  37. public long GetTimeZoneService(ServiceCtx context)
  38. {
  39. MakeObject(context, new ITimeZoneService());
  40. return 0;
  41. }
  42. [Command(4)]
  43. // GetStandardLocalSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
  44. public long GetStandardLocalSystemClock(ServiceCtx context)
  45. {
  46. MakeObject(context, new ISystemClock(SystemClockType.Local));
  47. return 0;
  48. }
  49. [Command(20)] // 6.0.0+
  50. // GetSharedMemoryNativeHandle() -> handle<copy>
  51. public long GetSharedMemoryNativeHandle(ServiceCtx context)
  52. {
  53. if (_timeSharedMemoryNativeHandle == 0)
  54. {
  55. if (context.Process.HandleTable.GenerateHandle(context.Device.System.TimeSharedMem, out _timeSharedMemoryNativeHandle) != KernelResult.Success)
  56. {
  57. throw new InvalidOperationException("Out of handles!");
  58. }
  59. }
  60. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_timeSharedMemoryNativeHandle);
  61. return 0;
  62. }
  63. [Command(300)] // 4.0.0+
  64. // CalculateMonotonicSystemClockBaseTimePoint(nn::time::SystemClockContext) -> u64
  65. public long CalculateMonotonicSystemClockBaseTimePoint(ServiceCtx context)
  66. {
  67. long timeOffset = (long)(DateTime.UtcNow - StartupDate).TotalSeconds;
  68. long systemClockContextEpoch = context.RequestData.ReadInt64();
  69. context.ResponseData.Write(timeOffset + systemClockContextEpoch);
  70. return 0;
  71. }
  72. }
  73. }