summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2021-04-11 10:50:08 -0700
committerGravatar GitHub2021-04-11 10:50:08 -0700
commit0c19147e09a2ebbb64bc1735eb8fee1b5ee807d5 (patch)
treea55cd9991104cc241f86b29f7945d750539625c1
parentMerge pull request #6183 from MerryMage/dynarmic (diff)
parentservice: time: Setup the network clock with the local clock context (diff)
downloadyuzu-0c19147e09a2ebbb64bc1735eb8fee1b5ee807d5.tar.gz
yuzu-0c19147e09a2ebbb64bc1735eb8fee1b5ee807d5.tar.xz
yuzu-0c19147e09a2ebbb64bc1735eb8fee1b5ee807d5.zip
Merge pull request #6170 from Morph1984/more-time-fixes
service: time: Setup the network clock with the local clock context
-rw-r--r--src/core/hle/service/time/clock_types.h8
-rw-r--r--src/core/hle/service/time/time.cpp37
-rw-r--r--src/core/hle/service/time/time.h2
-rw-r--r--src/core/hle/service/time/time_manager.cpp6
-rw-r--r--src/core/hle/service/time/time_zone_manager.cpp2
-rw-r--r--src/core/hle/service/time/time_zone_types.h4
6 files changed, 38 insertions, 21 deletions
diff --git a/src/core/hle/service/time/clock_types.h b/src/core/hle/service/time/clock_types.h
index b78892223..a9cfe3eb0 100644
--- a/src/core/hle/service/time/clock_types.h
+++ b/src/core/hle/service/time/clock_types.h
@@ -12,6 +12,12 @@
12 12
13namespace Service::Time::Clock { 13namespace Service::Time::Clock {
14 14
15enum class TimeType : u8 {
16 UserSystemClock,
17 NetworkSystemClock,
18 LocalSystemClock,
19};
20
15/// https://switchbrew.org/wiki/Glue_services#SteadyClockTimePoint 21/// https://switchbrew.org/wiki/Glue_services#SteadyClockTimePoint
16struct SteadyClockTimePoint { 22struct SteadyClockTimePoint {
17 s64 time_point; 23 s64 time_point;
@@ -84,7 +90,7 @@ struct ClockSnapshot {
84 SteadyClockTimePoint steady_clock_time_point; 90 SteadyClockTimePoint steady_clock_time_point;
85 TimeZone::LocationName location_name; 91 TimeZone::LocationName location_name;
86 u8 is_automatic_correction_enabled; 92 u8 is_automatic_correction_enabled;
87 u8 type; 93 TimeType type;
88 INSERT_PADDING_BYTES_NOINIT(0x2); 94 INSERT_PADDING_BYTES_NOINIT(0x2);
89 95
90 static ResultCode GetCurrentTime(s64& current_time, 96 static ResultCode GetCurrentTime(s64& current_time,
diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp
index f6ff39789..63e0247de 100644
--- a/src/core/hle/service/time/time.cpp
+++ b/src/core/hle/service/time/time.cpp
@@ -122,14 +122,16 @@ private:
122 122
123ResultCode Module::Interface::GetClockSnapshotFromSystemClockContextInternal( 123ResultCode Module::Interface::GetClockSnapshotFromSystemClockContextInternal(
124 Kernel::KThread* thread, Clock::SystemClockContext user_context, 124 Kernel::KThread* thread, Clock::SystemClockContext user_context,
125 Clock::SystemClockContext network_context, u8 type, Clock::ClockSnapshot& clock_snapshot) { 125 Clock::SystemClockContext network_context, Clock::TimeType type,
126 Clock::ClockSnapshot& clock_snapshot) {
126 127
127 auto& time_manager{system.GetTimeManager()}; 128 auto& time_manager{system.GetTimeManager()};
128 129
130 clock_snapshot.steady_clock_time_point =
131 time_manager.GetStandardSteadyClockCore().GetCurrentTimePoint(system);
129 clock_snapshot.is_automatic_correction_enabled = 132 clock_snapshot.is_automatic_correction_enabled =
130 time_manager.GetStandardUserSystemClockCore().IsAutomaticCorrectionEnabled(); 133 time_manager.GetStandardUserSystemClockCore().IsAutomaticCorrectionEnabled();
131 clock_snapshot.user_context = user_context; 134 clock_snapshot.type = type;
132 clock_snapshot.network_context = network_context;
133 135
134 if (const ResultCode result{ 136 if (const ResultCode result{
135 time_manager.GetTimeZoneContentManager().GetTimeZoneManager().GetDeviceLocationName( 137 time_manager.GetTimeZoneContentManager().GetTimeZoneManager().GetDeviceLocationName(
@@ -138,12 +140,11 @@ ResultCode Module::Interface::GetClockSnapshotFromSystemClockContextInternal(
138 return result; 140 return result;
139 } 141 }
140 142
141 const auto current_time_point{ 143 clock_snapshot.user_context = user_context;
142 time_manager.GetStandardSteadyClockCore().GetCurrentTimePoint(system)};
143 clock_snapshot.steady_clock_time_point = current_time_point;
144 144
145 if (const ResultCode result{Clock::ClockSnapshot::GetCurrentTime( 145 if (const ResultCode result{Clock::ClockSnapshot::GetCurrentTime(
146 clock_snapshot.user_time, current_time_point, clock_snapshot.user_context)}; 146 clock_snapshot.user_time, clock_snapshot.steady_clock_time_point,
147 clock_snapshot.user_context)};
147 result != RESULT_SUCCESS) { 148 result != RESULT_SUCCESS) {
148 return result; 149 return result;
149 } 150 }
@@ -157,9 +158,12 @@ ResultCode Module::Interface::GetClockSnapshotFromSystemClockContextInternal(
157 } 158 }
158 159
159 clock_snapshot.user_calendar_time = userCalendarInfo.time; 160 clock_snapshot.user_calendar_time = userCalendarInfo.time;
160 clock_snapshot.user_calendar_additional_time = userCalendarInfo.additiona_info; 161 clock_snapshot.user_calendar_additional_time = userCalendarInfo.additional_info;
161 162
162 if (Clock::ClockSnapshot::GetCurrentTime(clock_snapshot.network_time, current_time_point, 163 clock_snapshot.network_context = network_context;
164
165 if (Clock::ClockSnapshot::GetCurrentTime(clock_snapshot.network_time,
166 clock_snapshot.steady_clock_time_point,
163 clock_snapshot.network_context) != RESULT_SUCCESS) { 167 clock_snapshot.network_context) != RESULT_SUCCESS) {
164 clock_snapshot.network_time = 0; 168 clock_snapshot.network_time = 0;
165 } 169 }
@@ -173,8 +177,7 @@ ResultCode Module::Interface::GetClockSnapshotFromSystemClockContextInternal(
173 } 177 }
174 178
175 clock_snapshot.network_calendar_time = networkCalendarInfo.time; 179 clock_snapshot.network_calendar_time = networkCalendarInfo.time;
176 clock_snapshot.network_calendar_additional_time = networkCalendarInfo.additiona_info; 180 clock_snapshot.network_calendar_additional_time = networkCalendarInfo.additional_info;
177 clock_snapshot.type = type;
178 181
179 return RESULT_SUCCESS; 182 return RESULT_SUCCESS;
180} 183}
@@ -257,9 +260,10 @@ void Module::Interface::CalculateMonotonicSystemClockBaseTimePoint(Kernel::HLERe
257} 260}
258 261
259void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) { 262void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) {
260 LOG_DEBUG(Service_Time, "called");
261 IPC::RequestParser rp{ctx}; 263 IPC::RequestParser rp{ctx};
262 const auto type{rp.PopRaw<u8>()}; 264 const auto type{rp.PopEnum<Clock::TimeType>()};
265
266 LOG_DEBUG(Service_Time, "called, type={}", type);
263 267
264 Clock::SystemClockContext user_context{}; 268 Clock::SystemClockContext user_context{};
265 if (const ResultCode result{ 269 if (const ResultCode result{
@@ -270,6 +274,7 @@ void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) {
270 rb.Push(result); 274 rb.Push(result);
271 return; 275 return;
272 } 276 }
277
273 Clock::SystemClockContext network_context{}; 278 Clock::SystemClockContext network_context{};
274 if (const ResultCode result{ 279 if (const ResultCode result{
275 system.GetTimeManager().GetStandardNetworkSystemClockCore().GetClockContext( 280 system.GetTimeManager().GetStandardNetworkSystemClockCore().GetClockContext(
@@ -295,14 +300,16 @@ void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) {
295} 300}
296 301
297void Module::Interface::GetClockSnapshotFromSystemClockContext(Kernel::HLERequestContext& ctx) { 302void Module::Interface::GetClockSnapshotFromSystemClockContext(Kernel::HLERequestContext& ctx) {
298 LOG_DEBUG(Service_Time, "called");
299 IPC::RequestParser rp{ctx}; 303 IPC::RequestParser rp{ctx};
300 const auto type{rp.PopRaw<u8>()}; 304 const auto type{rp.PopEnum<Clock::TimeType>()};
305
301 rp.AlignWithPadding(); 306 rp.AlignWithPadding();
302 307
303 const Clock::SystemClockContext user_context{rp.PopRaw<Clock::SystemClockContext>()}; 308 const Clock::SystemClockContext user_context{rp.PopRaw<Clock::SystemClockContext>()};
304 const Clock::SystemClockContext network_context{rp.PopRaw<Clock::SystemClockContext>()}; 309 const Clock::SystemClockContext network_context{rp.PopRaw<Clock::SystemClockContext>()};
305 310
311 LOG_DEBUG(Service_Time, "called, type={}", type);
312
306 Clock::ClockSnapshot clock_snapshot{}; 313 Clock::ClockSnapshot clock_snapshot{};
307 if (const ResultCode result{GetClockSnapshotFromSystemClockContextInternal( 314 if (const ResultCode result{GetClockSnapshotFromSystemClockContextInternal(
308 &ctx.GetThread(), user_context, network_context, type, clock_snapshot)}; 315 &ctx.GetThread(), user_context, network_context, type, clock_snapshot)};
diff --git a/src/core/hle/service/time/time.h b/src/core/hle/service/time/time.h
index 4154c7ee9..ce9c479c6 100644
--- a/src/core/hle/service/time/time.h
+++ b/src/core/hle/service/time/time.h
@@ -40,7 +40,7 @@ public:
40 private: 40 private:
41 ResultCode GetClockSnapshotFromSystemClockContextInternal( 41 ResultCode GetClockSnapshotFromSystemClockContextInternal(
42 Kernel::KThread* thread, Clock::SystemClockContext user_context, 42 Kernel::KThread* thread, Clock::SystemClockContext user_context,
43 Clock::SystemClockContext network_context, u8 type, 43 Clock::SystemClockContext network_context, Clock::TimeType type,
44 Clock::ClockSnapshot& cloc_snapshot); 44 Clock::ClockSnapshot& cloc_snapshot);
45 45
46 protected: 46 protected:
diff --git a/src/core/hle/service/time/time_manager.cpp b/src/core/hle/service/time/time_manager.cpp
index 1f7309f6b..51becd074 100644
--- a/src/core/hle/service/time/time_manager.cpp
+++ b/src/core/hle/service/time/time_manager.cpp
@@ -44,7 +44,11 @@ struct TimeManager::Impl final {
44 const auto system_time{Clock::TimeSpanType::FromSeconds(GetExternalRtcValue())}; 44 const auto system_time{Clock::TimeSpanType::FromSeconds(GetExternalRtcValue())};
45 SetupStandardSteadyClock(system, Common::UUID::Generate(), system_time, {}, {}); 45 SetupStandardSteadyClock(system, Common::UUID::Generate(), system_time, {}, {});
46 SetupStandardLocalSystemClock(system, {}, system_time.ToSeconds()); 46 SetupStandardLocalSystemClock(system, {}, system_time.ToSeconds());
47 SetupStandardNetworkSystemClock({}, standard_network_clock_accuracy); 47
48 Clock::SystemClockContext clock_context{};
49 standard_local_system_clock_core.GetClockContext(system, clock_context);
50
51 SetupStandardNetworkSystemClock(clock_context, standard_network_clock_accuracy);
48 SetupStandardUserSystemClock(system, {}, Clock::SteadyClockTimePoint::GetRandom()); 52 SetupStandardUserSystemClock(system, {}, Clock::SteadyClockTimePoint::GetRandom());
49 SetupEphemeralNetworkSystemClock(); 53 SetupEphemeralNetworkSystemClock();
50 } 54 }
diff --git a/src/core/hle/service/time/time_zone_manager.cpp b/src/core/hle/service/time/time_zone_manager.cpp
index bdf0439f2..3032ca193 100644
--- a/src/core/hle/service/time/time_zone_manager.cpp
+++ b/src/core/hle/service/time/time_zone_manager.cpp
@@ -818,7 +818,7 @@ static ResultCode ToCalendarTimeInternal(const TimeZoneRule& rules, s64 time,
818static ResultCode ToCalendarTimeImpl(const TimeZoneRule& rules, s64 time, CalendarInfo& calendar) { 818static ResultCode ToCalendarTimeImpl(const TimeZoneRule& rules, s64 time, CalendarInfo& calendar) {
819 CalendarTimeInternal calendar_time{}; 819 CalendarTimeInternal calendar_time{};
820 const ResultCode result{ 820 const ResultCode result{
821 ToCalendarTimeInternal(rules, time, calendar_time, calendar.additiona_info)}; 821 ToCalendarTimeInternal(rules, time, calendar_time, calendar.additional_info)};
822 calendar.time.year = static_cast<s16>(calendar_time.year); 822 calendar.time.year = static_cast<s16>(calendar_time.year);
823 823
824 // Internal impl. uses 0-indexed month 824 // Internal impl. uses 0-indexed month
diff --git a/src/core/hle/service/time/time_zone_types.h b/src/core/hle/service/time/time_zone_types.h
index 4a57e036d..d39103253 100644
--- a/src/core/hle/service/time/time_zone_types.h
+++ b/src/core/hle/service/time/time_zone_types.h
@@ -66,8 +66,8 @@ struct CalendarTime {
66static_assert(sizeof(CalendarTime) == 0x8, "CalendarTime is incorrect size"); 66static_assert(sizeof(CalendarTime) == 0x8, "CalendarTime is incorrect size");
67 67
68struct CalendarInfo { 68struct CalendarInfo {
69 CalendarTime time{}; 69 CalendarTime time;
70 CalendarAdditionalInfo additiona_info{}; 70 CalendarAdditionalInfo additional_info;
71}; 71};
72static_assert(sizeof(CalendarInfo) == 0x20, "CalendarInfo is incorrect size"); 72static_assert(sizeof(CalendarInfo) == 0x20, "CalendarInfo is incorrect size");
73 73