From a4e840181c1e704a49e37c802ff36344ac18ca10 Mon Sep 17 00:00:00 2001
From: bunnei <bunneidev@gmail.com>
Date: Fri, 3 Jan 2020 22:34:57 -0500
Subject: [PATCH] service: time: Implement
 GetClockSnapshotFromSystemClockContext.

---
 src/core/hle/service/time/interface.cpp |  2 +-
 src/core/hle/service/time/time.cpp      | 27 +++++++++++++++++++++++--
 src/core/hle/service/time/time.h        |  1 +
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/core/hle/service/time/interface.cpp b/src/core/hle/service/time/interface.cpp
index 0bc90b1838..6423a6c37e 100644
--- a/src/core/hle/service/time/interface.cpp
+++ b/src/core/hle/service/time/interface.cpp
@@ -28,7 +28,7 @@ Time::Time(std::shared_ptr<Module> module, Core::System& system, const char* nam
         {201, nullptr, "GetStandardUserSystemClockAutomaticCorrectionUpdatedTime"},
         {300, &Time::CalculateMonotonicSystemClockBaseTimePoint, "CalculateMonotonicSystemClockBaseTimePoint"},
         {400, &Time::GetClockSnapshot, "GetClockSnapshot"},
-        {401, nullptr, "GetClockSnapshotFromSystemClockContext"},
+        {401, &Time::GetClockSnapshotFromSystemClockContext, "GetClockSnapshotFromSystemClockContext"},
         {500, nullptr, "CalculateStandardUserSystemClockDifferenceByUser"},
         {501, nullptr, "CalculateSpanBetween"},
     };
diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp
index 2053fa0789..6b13578135 100644
--- a/src/core/hle/service/time/time.cpp
+++ b/src/core/hle/service/time/time.cpp
@@ -242,7 +242,7 @@ void Module::Interface::CalculateMonotonicSystemClockBaseTimePoint(Kernel::HLERe
 void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) {
     LOG_DEBUG(Service_Time, "called");
     IPC::RequestParser rp{ctx};
-    const auto type = rp.PopRaw<u8>();
+    const auto type{rp.PopRaw<u8>()};
 
     Clock::SystemClockContext user_context{};
     if (const ResultCode result{
@@ -277,6 +277,29 @@ void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) {
     ctx.WriteBuffer(&clock_snapshot, sizeof(Clock::ClockSnapshot));
 }
 
+void Module::Interface::GetClockSnapshotFromSystemClockContext(Kernel::HLERequestContext& ctx) {
+    LOG_DEBUG(Service_Time, "called");
+    IPC::RequestParser rp{ctx};
+    const auto type{rp.PopRaw<u8>()};
+    rp.AlignWithPadding();
+
+    const Clock::SystemClockContext user_context{rp.PopRaw<Clock::SystemClockContext>()};
+    const Clock::SystemClockContext network_context{rp.PopRaw<Clock::SystemClockContext>()};
+
+    Clock::ClockSnapshot clock_snapshot{};
+    if (const ResultCode result{GetClockSnapshotFromSystemClockContextInternal(
+            &ctx.GetThread(), user_context, network_context, type, clock_snapshot)};
+        result != RESULT_SUCCESS) {
+        IPC::ResponseBuilder rb{ctx, 2};
+        rb.Push(result);
+        return;
+    }
+
+    IPC::ResponseBuilder rb{ctx, 2};
+    rb.Push(RESULT_SUCCESS);
+    ctx.WriteBuffer(&clock_snapshot, sizeof(Clock::ClockSnapshot));
+}
+
 void Module::Interface::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) {
     LOG_DEBUG(Service_Time, "called");
     IPC::ResponseBuilder rb{ctx, 2, 1};
@@ -290,7 +313,7 @@ Module::Interface::Interface(std::shared_ptr<Module> module, Core::System& syste
 Module::Interface::~Interface() = default;
 
 void InstallInterfaces(Core::System& system) {
-    auto module = std::make_shared<Module>(system);
+    auto module{std::make_shared<Module>(system)};
     std::make_shared<Time>(module, system, "time:a")->InstallAsService(system.ServiceManager());
     std::make_shared<Time>(module, system, "time:s")->InstallAsService(system.ServiceManager());
     std::make_shared<Time>(module, system, "time:u")->InstallAsService(system.ServiceManager());
diff --git a/src/core/hle/service/time/time.h b/src/core/hle/service/time/time.h
index 0b3cda6aa3..2a216701c3 100644
--- a/src/core/hle/service/time/time.h
+++ b/src/core/hle/service/time/time.h
@@ -30,6 +30,7 @@ public:
         void IsStandardNetworkSystemClockAccuracySufficient(Kernel::HLERequestContext& ctx);
         void CalculateMonotonicSystemClockBaseTimePoint(Kernel::HLERequestContext& ctx);
         void GetClockSnapshot(Kernel::HLERequestContext& ctx);
+        void GetClockSnapshotFromSystemClockContext(Kernel::HLERequestContext& ctx);
         void GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx);
 
     private:
-- 
GitLab