2019-12-22 17:49:51 -05:00
|
|
|
// Copyright 2019 yuzu emulator team
|
2018-01-14 21:42:23 -05:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
2018-01-17 13:33:38 -06:00
|
|
|
#include "common/logging/log.h"
|
2019-02-14 12:42:58 -05:00
|
|
|
#include "core/core.h"
|
2018-01-24 23:52:21 -05:00
|
|
|
#include "core/core_timing.h"
|
2020-02-11 19:56:24 -04:00
|
|
|
#include "core/hardware_properties.h"
|
2018-01-17 13:33:38 -06:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
2020-10-12 18:09:15 -07:00
|
|
|
#include "core/hle/kernel/kernel.h"
|
2018-01-14 21:42:23 -05:00
|
|
|
#include "core/hle/service/time/time.h"
|
2021-07-14 00:52:17 -04:00
|
|
|
#include "core/hle/service/time/time_interface.h"
|
2021-10-07 13:29:33 -04:00
|
|
|
#include "core/hle/service/time/time_manager.h"
|
2019-06-26 00:45:53 +10:00
|
|
|
#include "core/hle/service/time/time_sharedmemory.h"
|
2019-12-22 17:49:51 -05:00
|
|
|
#include "core/hle/service/time/time_zone_service.h"
|
2018-01-14 21:42:23 -05:00
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
namespace Service::Time {
|
2018-01-14 21:42:23 -05:00
|
|
|
|
2018-01-17 13:33:38 -06:00
|
|
|
class ISystemClock final : public ServiceFramework<ISystemClock> {
|
|
|
|
|
public:
|
2020-11-26 15:19:08 -05:00
|
|
|
explicit ISystemClock(Clock::SystemClockCore& clock_core_, Core::System& system_)
|
|
|
|
|
: ServiceFramework{system_, "ISystemClock"}, clock_core{clock_core_} {
|
2019-11-12 08:54:58 -05:00
|
|
|
// clang-format off
|
2018-01-17 13:33:38 -06:00
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
|
{0, &ISystemClock::GetCurrentTime, "GetCurrentTime"},
|
2018-04-17 18:37:43 +03:00
|
|
|
{1, nullptr, "SetCurrentTime"},
|
2019-12-22 17:49:51 -05:00
|
|
|
{2, &ISystemClock::GetSystemClockContext, "GetSystemClockContext"},
|
2018-04-17 18:37:43 +03:00
|
|
|
{3, nullptr, "SetSystemClockContext"},
|
2019-11-12 08:54:58 -05:00
|
|
|
{4, nullptr, "GetOperationEventReadableHandle"},
|
2018-04-17 18:37:43 +03:00
|
|
|
};
|
2019-11-12 08:54:58 -05:00
|
|
|
// clang-format on
|
2019-06-26 00:45:53 +10:00
|
|
|
|
2019-11-12 08:54:58 -05:00
|
|
|
RegisterHandlers(functions);
|
2018-01-17 13:33:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void GetCurrentTime(Kernel::HLERequestContext& ctx) {
|
2018-07-02 10:13:26 -06:00
|
|
|
LOG_DEBUG(Service_Time, "called");
|
2018-11-26 17:06:13 +11:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
if (!clock_core.IsInitialized()) {
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
|
rb.Push(ERROR_UNINITIALIZED_CLOCK);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s64 posix_time{};
|
2020-04-19 16:26:35 -04:00
|
|
|
if (const ResultCode result{clock_core.GetCurrentTime(system, posix_time)};
|
|
|
|
|
result.IsError()) {
|
2019-12-22 17:49:51 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
|
rb.Push(result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2019-12-22 17:49:51 -05:00
|
|
|
rb.Push<s64>(posix_time);
|
2018-01-23 22:02:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetSystemClockContext(Kernel::HLERequestContext& ctx) {
|
2019-12-22 17:49:51 -05:00
|
|
|
LOG_DEBUG(Service_Time, "called");
|
2018-11-26 17:06:13 +11:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
if (!clock_core.IsInitialized()) {
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
|
rb.Push(ERROR_UNINITIALIZED_CLOCK);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-06-26 00:45:53 +10:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
Clock::SystemClockContext system_clock_context{};
|
2020-04-19 16:26:35 -04:00
|
|
|
if (const ResultCode result{clock_core.GetClockContext(system, system_clock_context)};
|
|
|
|
|
result.IsError()) {
|
2019-12-22 17:49:51 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
|
rb.Push(result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, sizeof(Clock::SystemClockContext) / 4 + 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2019-06-26 00:45:53 +10:00
|
|
|
rb.PushRaw(system_clock_context);
|
2018-01-17 13:33:38 -06:00
|
|
|
}
|
2019-06-26 00:45:53 +10:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
Clock::SystemClockCore& clock_core;
|
2018-01-17 13:33:38 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ISteadyClock final : public ServiceFramework<ISteadyClock> {
|
|
|
|
|
public:
|
2020-11-26 15:19:08 -05:00
|
|
|
explicit ISteadyClock(Clock::SteadyClockCore& clock_core_, Core::System& system_)
|
|
|
|
|
: ServiceFramework{system_, "ISteadyClock"}, clock_core{clock_core_} {
|
2018-01-24 23:52:21 -05:00
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
|
{0, &ISteadyClock::GetCurrentTimePoint, "GetCurrentTimePoint"},
|
2020-06-29 04:01:34 +02:00
|
|
|
{2, nullptr, "GetTestOffset"},
|
|
|
|
|
{3, nullptr, "SetTestOffset"},
|
|
|
|
|
{100, nullptr, "GetRtcValue"},
|
|
|
|
|
{101, nullptr, "IsRtcResetDetected"},
|
|
|
|
|
{102, nullptr, "GetSetupResultValue"},
|
|
|
|
|
{200, nullptr, "GetInternalOffset"},
|
|
|
|
|
{201, nullptr, "SetInternalOffset"},
|
2018-01-24 23:52:21 -05:00
|
|
|
};
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void GetCurrentTimePoint(Kernel::HLERequestContext& ctx) {
|
2018-07-02 10:13:26 -06:00
|
|
|
LOG_DEBUG(Service_Time, "called");
|
2018-11-26 17:06:13 +11:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
if (!clock_core.IsInitialized()) {
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
|
rb.Push(ERROR_UNINITIALIZED_CLOCK);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-06-26 00:45:53 +10:00
|
|
|
|
2020-04-19 16:26:35 -04:00
|
|
|
const Clock::SteadyClockTimePoint time_point{clock_core.GetCurrentTimePoint(system)};
|
2019-12-22 17:49:51 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, (sizeof(Clock::SteadyClockTimePoint) / 4) + 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2019-06-26 00:45:53 +10:00
|
|
|
rb.PushRaw(time_point);
|
2018-01-24 23:52:21 -05:00
|
|
|
}
|
2019-06-26 00:45:53 +10:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
Clock::SteadyClockCore& clock_core;
|
2018-01-17 13:33:38 -06:00
|
|
|
};
|
|
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
ResultCode Module::Interface::GetClockSnapshotFromSystemClockContextInternal(
|
2020-12-30 23:01:08 -08:00
|
|
|
Kernel::KThread* thread, Clock::SystemClockContext user_context,
|
2021-04-08 13:26:38 -04:00
|
|
|
Clock::SystemClockContext network_context, Clock::TimeType type,
|
|
|
|
|
Clock::ClockSnapshot& clock_snapshot) {
|
2018-01-17 13:33:38 -06:00
|
|
|
|
2020-10-12 18:09:15 -07:00
|
|
|
auto& time_manager{system.GetTimeManager()};
|
2018-05-31 15:33:30 +03:00
|
|
|
|
2021-04-08 13:26:38 -04:00
|
|
|
clock_snapshot.steady_clock_time_point =
|
|
|
|
|
time_manager.GetStandardSteadyClockCore().GetCurrentTimePoint(system);
|
2019-12-22 17:49:51 -05:00
|
|
|
clock_snapshot.is_automatic_correction_enabled =
|
|
|
|
|
time_manager.GetStandardUserSystemClockCore().IsAutomaticCorrectionEnabled();
|
2021-04-08 13:26:38 -04:00
|
|
|
clock_snapshot.type = type;
|
2018-11-26 17:06:13 +11:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
if (const ResultCode result{
|
|
|
|
|
time_manager.GetTimeZoneContentManager().GetTimeZoneManager().GetDeviceLocationName(
|
|
|
|
|
clock_snapshot.location_name)};
|
2021-05-21 01:05:04 -04:00
|
|
|
result != ResultSuccess) {
|
2019-12-22 17:49:51 -05:00
|
|
|
return result;
|
2018-01-18 00:57:11 -05:00
|
|
|
}
|
|
|
|
|
|
2021-04-08 13:26:38 -04:00
|
|
|
clock_snapshot.user_context = user_context;
|
2021-03-10 11:40:51 -05:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
if (const ResultCode result{Clock::ClockSnapshot::GetCurrentTime(
|
2021-04-08 13:26:38 -04:00
|
|
|
clock_snapshot.user_time, clock_snapshot.steady_clock_time_point,
|
|
|
|
|
clock_snapshot.user_context)};
|
2021-05-21 01:05:04 -04:00
|
|
|
result != ResultSuccess) {
|
2019-12-22 17:49:51 -05:00
|
|
|
return result;
|
2018-01-17 13:33:38 -06:00
|
|
|
}
|
|
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
TimeZone::CalendarInfo userCalendarInfo{};
|
|
|
|
|
if (const ResultCode result{
|
|
|
|
|
time_manager.GetTimeZoneContentManager().GetTimeZoneManager().ToCalendarTimeWithMyRules(
|
|
|
|
|
clock_snapshot.user_time, userCalendarInfo)};
|
2021-05-21 01:05:04 -04:00
|
|
|
result != ResultSuccess) {
|
2019-12-22 17:49:51 -05:00
|
|
|
return result;
|
2018-02-07 15:11:17 +03:00
|
|
|
}
|
|
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
clock_snapshot.user_calendar_time = userCalendarInfo.time;
|
2021-04-08 13:26:38 -04:00
|
|
|
clock_snapshot.user_calendar_additional_time = userCalendarInfo.additional_info;
|
2018-05-31 15:33:30 +03:00
|
|
|
|
2021-04-08 13:26:38 -04:00
|
|
|
clock_snapshot.network_context = network_context;
|
|
|
|
|
|
|
|
|
|
if (Clock::ClockSnapshot::GetCurrentTime(clock_snapshot.network_time,
|
|
|
|
|
clock_snapshot.steady_clock_time_point,
|
2021-05-21 01:05:04 -04:00
|
|
|
clock_snapshot.network_context) != ResultSuccess) {
|
2019-12-22 17:49:51 -05:00
|
|
|
clock_snapshot.network_time = 0;
|
2018-05-31 15:33:30 +03:00
|
|
|
}
|
|
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
TimeZone::CalendarInfo networkCalendarInfo{};
|
|
|
|
|
if (const ResultCode result{
|
|
|
|
|
time_manager.GetTimeZoneContentManager().GetTimeZoneManager().ToCalendarTimeWithMyRules(
|
|
|
|
|
clock_snapshot.network_time, networkCalendarInfo)};
|
2021-05-21 01:05:04 -04:00
|
|
|
result != ResultSuccess) {
|
2019-12-22 17:49:51 -05:00
|
|
|
return result;
|
2018-11-10 17:41:57 +11:00
|
|
|
}
|
|
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
clock_snapshot.network_calendar_time = networkCalendarInfo.time;
|
2021-04-08 13:26:38 -04:00
|
|
|
clock_snapshot.network_calendar_additional_time = networkCalendarInfo.additional_info;
|
2018-11-26 17:06:13 +11:00
|
|
|
|
2021-05-21 01:05:04 -04:00
|
|
|
return ResultSuccess;
|
2019-12-22 17:49:51 -05:00
|
|
|
}
|
2018-01-17 13:33:38 -06:00
|
|
|
|
2018-01-18 10:58:29 -06:00
|
|
|
void Module::Interface::GetStandardUserSystemClock(Kernel::HLERequestContext& ctx) {
|
2018-11-26 17:06:13 +11:00
|
|
|
LOG_DEBUG(Service_Time, "called");
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-10-12 18:09:15 -07:00
|
|
|
rb.PushIpcInterface<ISystemClock>(system.GetTimeManager().GetStandardUserSystemClockCore(),
|
2020-04-19 16:26:35 -04:00
|
|
|
system);
|
2018-01-17 13:33:38 -06:00
|
|
|
}
|
|
|
|
|
|
2018-01-18 10:58:29 -06:00
|
|
|
void Module::Interface::GetStandardNetworkSystemClock(Kernel::HLERequestContext& ctx) {
|
2018-11-26 17:06:13 +11:00
|
|
|
LOG_DEBUG(Service_Time, "called");
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-10-12 18:09:15 -07:00
|
|
|
rb.PushIpcInterface<ISystemClock>(system.GetTimeManager().GetStandardNetworkSystemClockCore(),
|
2020-04-19 16:26:35 -04:00
|
|
|
system);
|
2018-01-17 13:33:38 -06:00
|
|
|
}
|
|
|
|
|
|
2018-01-18 10:58:29 -06:00
|
|
|
void Module::Interface::GetStandardSteadyClock(Kernel::HLERequestContext& ctx) {
|
2018-11-26 17:06:13 +11:00
|
|
|
LOG_DEBUG(Service_Time, "called");
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-10-12 18:09:15 -07:00
|
|
|
rb.PushIpcInterface<ISteadyClock>(system.GetTimeManager().GetStandardSteadyClockCore(), system);
|
2018-01-17 13:33:38 -06:00
|
|
|
}
|
|
|
|
|
|
2018-01-18 10:58:29 -06:00
|
|
|
void Module::Interface::GetTimeZoneService(Kernel::HLERequestContext& ctx) {
|
2018-11-26 17:06:13 +11:00
|
|
|
LOG_DEBUG(Service_Time, "called");
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-11-26 15:19:08 -05:00
|
|
|
rb.PushIpcInterface<ITimeZoneService>(system,
|
|
|
|
|
system.GetTimeManager().GetTimeZoneContentManager());
|
2018-01-17 13:33:38 -06:00
|
|
|
}
|
|
|
|
|
|
2020-01-04 22:18:54 -05:00
|
|
|
void Module::Interface::GetStandardLocalSystemClock(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
LOG_DEBUG(Service_Time, "called");
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-10-12 18:09:15 -07:00
|
|
|
rb.PushIpcInterface<ISystemClock>(system.GetTimeManager().GetStandardLocalSystemClockCore(),
|
2020-04-19 16:26:35 -04:00
|
|
|
system);
|
2020-01-04 22:18:54 -05:00
|
|
|
}
|
|
|
|
|
|
2019-12-22 18:10:59 -05:00
|
|
|
void Module::Interface::IsStandardNetworkSystemClockAccuracySufficient(
|
|
|
|
|
Kernel::HLERequestContext& ctx) {
|
|
|
|
|
LOG_DEBUG(Service_Time, "called");
|
2020-10-12 18:09:15 -07:00
|
|
|
auto& clock_core{system.GetTimeManager().GetStandardNetworkSystemClockCore()};
|
2019-12-22 18:10:59 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2019-12-22 18:10:59 -05:00
|
|
|
rb.Push<u32>(clock_core.IsStandardNetworkSystemClockAccuracySufficient(system));
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
void Module::Interface::CalculateMonotonicSystemClockBaseTimePoint(Kernel::HLERequestContext& ctx) {
|
2018-11-26 17:06:13 +11:00
|
|
|
LOG_DEBUG(Service_Time, "called");
|
|
|
|
|
|
2020-10-12 18:09:15 -07:00
|
|
|
auto& steady_clock_core{system.GetTimeManager().GetStandardSteadyClockCore()};
|
2019-12-22 17:49:51 -05:00
|
|
|
if (!steady_clock_core.IsInitialized()) {
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
|
rb.Push(ERROR_UNINITIALIZED_CLOCK);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
const auto context{rp.PopRaw<Clock::SystemClockContext>()};
|
2020-04-19 16:26:35 -04:00
|
|
|
const auto current_time_point{steady_clock_core.GetCurrentTimePoint(system)};
|
2019-12-22 17:49:51 -05:00
|
|
|
|
|
|
|
|
if (current_time_point.clock_source_id == context.steady_time_point.clock_source_id) {
|
2020-02-24 22:04:12 -04:00
|
|
|
const auto ticks{Clock::TimeSpanType::FromTicks(system.CoreTiming().GetClockTicks(),
|
|
|
|
|
Core::Hardware::CNTFREQ)};
|
2019-12-22 17:49:51 -05:00
|
|
|
const s64 base_time_point{context.offset + current_time_point.time_point -
|
|
|
|
|
ticks.ToSeconds()};
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, (sizeof(s64) / 4) + 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2019-12-22 17:49:51 -05:00
|
|
|
rb.PushRaw(base_time_point);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
|
rb.Push(ERROR_TIME_MISMATCH);
|
2018-02-21 18:43:05 -07:00
|
|
|
}
|
|
|
|
|
|
2018-11-10 01:25:56 +11:00
|
|
|
void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
2021-04-08 13:26:38 -04:00
|
|
|
const auto type{rp.PopEnum<Clock::TimeType>()};
|
|
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_Time, "called, type={}", type);
|
2018-11-10 01:25:56 +11:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
Clock::SystemClockContext user_context{};
|
|
|
|
|
if (const ResultCode result{
|
2020-10-12 18:09:15 -07:00
|
|
|
system.GetTimeManager().GetStandardUserSystemClockCore().GetClockContext(system,
|
|
|
|
|
user_context)};
|
2020-04-19 16:26:35 -04:00
|
|
|
result.IsError()) {
|
2018-11-10 01:25:56 +11:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2019-12-22 17:49:51 -05:00
|
|
|
rb.Push(result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-04-08 13:26:38 -04:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
Clock::SystemClockContext network_context{};
|
|
|
|
|
if (const ResultCode result{
|
2020-10-12 18:09:15 -07:00
|
|
|
system.GetTimeManager().GetStandardNetworkSystemClockCore().GetClockContext(
|
2020-04-19 16:26:35 -04:00
|
|
|
system, network_context)};
|
|
|
|
|
result.IsError()) {
|
2019-12-22 17:49:51 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
|
rb.Push(result);
|
2018-11-10 01:25:56 +11:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
Clock::ClockSnapshot clock_snapshot{};
|
|
|
|
|
if (const ResultCode result{GetClockSnapshotFromSystemClockContextInternal(
|
|
|
|
|
&ctx.GetThread(), user_context, network_context, type, clock_snapshot)};
|
2020-04-19 16:26:35 -04:00
|
|
|
result.IsError()) {
|
2019-12-22 17:49:51 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
|
rb.Push(result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-12-29 18:29:57 -05:00
|
|
|
|
2021-04-19 12:09:18 -04:00
|
|
|
ctx.WriteBuffer(clock_snapshot);
|
|
|
|
|
|
2018-11-10 01:25:56 +11:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-11-17 14:01:16 +11:00
|
|
|
}
|
|
|
|
|
|
2020-01-03 22:34:57 -05:00
|
|
|
void Module::Interface::GetClockSnapshotFromSystemClockContext(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
2021-04-08 13:26:38 -04:00
|
|
|
const auto type{rp.PopEnum<Clock::TimeType>()};
|
|
|
|
|
|
2021-04-19 11:17:47 -04:00
|
|
|
rp.Skip(1, false);
|
2020-01-03 22:34:57 -05:00
|
|
|
|
|
|
|
|
const Clock::SystemClockContext user_context{rp.PopRaw<Clock::SystemClockContext>()};
|
|
|
|
|
const Clock::SystemClockContext network_context{rp.PopRaw<Clock::SystemClockContext>()};
|
|
|
|
|
|
2021-04-08 13:26:38 -04:00
|
|
|
LOG_DEBUG(Service_Time, "called, type={}", type);
|
|
|
|
|
|
2020-01-03 22:34:57 -05:00
|
|
|
Clock::ClockSnapshot clock_snapshot{};
|
|
|
|
|
if (const ResultCode result{GetClockSnapshotFromSystemClockContextInternal(
|
|
|
|
|
&ctx.GetThread(), user_context, network_context, type, clock_snapshot)};
|
2021-05-21 01:05:04 -04:00
|
|
|
result != ResultSuccess) {
|
2020-01-03 22:34:57 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
|
rb.Push(result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-19 11:17:47 -04:00
|
|
|
ctx.WriteBuffer(clock_snapshot);
|
|
|
|
|
|
2020-01-03 22:34:57 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-01-03 22:34:57 -05:00
|
|
|
}
|
|
|
|
|
|
2020-04-14 22:28:41 -04:00
|
|
|
void Module::Interface::CalculateStandardUserSystemClockDifferenceByUser(
|
|
|
|
|
Kernel::HLERequestContext& ctx) {
|
|
|
|
|
LOG_DEBUG(Service_Time, "called");
|
|
|
|
|
|
2021-04-07 23:34:14 -04:00
|
|
|
Clock::ClockSnapshot snapshot_a;
|
|
|
|
|
Clock::ClockSnapshot snapshot_b;
|
|
|
|
|
|
|
|
|
|
const auto snapshot_a_data = ctx.ReadBuffer(0);
|
|
|
|
|
const auto snapshot_b_data = ctx.ReadBuffer(1);
|
|
|
|
|
|
|
|
|
|
std::memcpy(&snapshot_a, snapshot_a_data.data(), sizeof(Clock::ClockSnapshot));
|
|
|
|
|
std::memcpy(&snapshot_b, snapshot_b_data.data(), sizeof(Clock::ClockSnapshot));
|
2020-04-14 22:28:41 -04:00
|
|
|
|
|
|
|
|
auto time_span_type{Clock::TimeSpanType::FromSeconds(snapshot_b.user_context.offset -
|
|
|
|
|
snapshot_a.user_context.offset)};
|
|
|
|
|
|
|
|
|
|
if ((snapshot_b.user_context.steady_time_point.clock_source_id !=
|
|
|
|
|
snapshot_a.user_context.steady_time_point.clock_source_id) ||
|
|
|
|
|
(snapshot_b.is_automatic_correction_enabled &&
|
|
|
|
|
snapshot_a.is_automatic_correction_enabled)) {
|
|
|
|
|
time_span_type.nanoseconds = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, (sizeof(s64) / 4) + 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-04-14 22:28:41 -04:00
|
|
|
rb.PushRaw(time_span_type.nanoseconds);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-27 10:42:13 -04:00
|
|
|
void Module::Interface::CalculateSpanBetween(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
LOG_DEBUG(Service_Time, "called");
|
|
|
|
|
|
2021-03-10 11:15:05 -05:00
|
|
|
Clock::ClockSnapshot snapshot_a;
|
|
|
|
|
Clock::ClockSnapshot snapshot_b;
|
|
|
|
|
|
|
|
|
|
const auto snapshot_a_data = ctx.ReadBuffer(0);
|
|
|
|
|
const auto snapshot_b_data = ctx.ReadBuffer(1);
|
|
|
|
|
|
|
|
|
|
std::memcpy(&snapshot_a, snapshot_a_data.data(), sizeof(Clock::ClockSnapshot));
|
|
|
|
|
std::memcpy(&snapshot_b, snapshot_b_data.data(), sizeof(Clock::ClockSnapshot));
|
2020-03-27 10:42:13 -04:00
|
|
|
|
|
|
|
|
Clock::TimeSpanType time_span_type{};
|
|
|
|
|
s64 span{};
|
2021-03-10 11:15:05 -05:00
|
|
|
|
2020-03-27 10:42:13 -04:00
|
|
|
if (const ResultCode result{snapshot_a.steady_clock_time_point.GetSpanBetween(
|
|
|
|
|
snapshot_b.steady_clock_time_point, span)};
|
2021-05-21 01:05:04 -04:00
|
|
|
result != ResultSuccess) {
|
2020-03-27 10:42:13 -04:00
|
|
|
if (snapshot_a.network_time && snapshot_b.network_time) {
|
|
|
|
|
time_span_type =
|
|
|
|
|
Clock::TimeSpanType::FromSeconds(snapshot_b.network_time - snapshot_a.network_time);
|
|
|
|
|
} else {
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
|
rb.Push(ERROR_TIME_NOT_FOUND);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
time_span_type = Clock::TimeSpanType::FromSeconds(span);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, (sizeof(s64) / 4) + 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-03-27 10:42:13 -04:00
|
|
|
rb.PushRaw(time_span_type.nanoseconds);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-26 00:45:53 +10:00
|
|
|
void Module::Interface::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) {
|
|
|
|
|
LOG_DEBUG(Service_Time, "called");
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-04-03 21:21:22 -07:00
|
|
|
rb.PushCopyObjects(&system.Kernel().GetTimeSharedMem());
|
2019-06-26 00:45:53 +10:00
|
|
|
}
|
|
|
|
|
|
2020-11-26 15:19:08 -05:00
|
|
|
Module::Interface::Interface(std::shared_ptr<Module> module_, Core::System& system_,
|
|
|
|
|
const char* name)
|
|
|
|
|
: ServiceFramework{system_, name}, module{std::move(module_)} {}
|
2018-01-17 13:33:38 -06:00
|
|
|
|
2018-09-10 21:20:52 -04:00
|
|
|
Module::Interface::~Interface() = default;
|
|
|
|
|
|
2019-06-26 00:45:53 +10:00
|
|
|
void InstallInterfaces(Core::System& system) {
|
2020-10-12 18:09:15 -07:00
|
|
|
auto module{std::make_shared<Module>()};
|
2019-12-22 17:49:51 -05:00
|
|
|
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());
|
2018-01-14 21:42:23 -05:00
|
|
|
}
|
|
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
} // namespace Service::Time
|