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 14:33:38 -05: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"
|
2018-07-24 06:03:24 -04:00
|
|
|
#include "core/core_timing_util.h"
|
2020-02-11 18:56:24 -05:00
|
|
|
#include "core/hardware_properties.h"
|
2018-01-17 14:33:38 -05:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
|
|
|
#include "core/hle/kernel/client_port.h"
|
|
|
|
#include "core/hle/kernel/client_session.h"
|
2019-12-22 17:49:51 -05:00
|
|
|
#include "core/hle/kernel/scheduler.h"
|
2018-07-24 02:45:23 -04:00
|
|
|
#include "core/hle/service/time/interface.h"
|
2018-01-14 21:42:23 -05:00
|
|
|
#include "core/hle/service/time/time.h"
|
2019-06-25 10:45:53 -04: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 14:33:38 -05:00
|
|
|
class ISystemClock final : public ServiceFramework<ISystemClock> {
|
|
|
|
public:
|
2020-04-19 16:26:35 -04:00
|
|
|
explicit ISystemClock(Clock::SystemClockCore& clock_core, Core::System& system)
|
|
|
|
: ServiceFramework("ISystemClock"), clock_core{clock_core}, system{system} {
|
2019-11-12 08:54:58 -05:00
|
|
|
// clang-format off
|
2018-01-17 14:33:38 -05:00
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, &ISystemClock::GetCurrentTime, "GetCurrentTime"},
|
2018-04-17 11:37:43 -04:00
|
|
|
{1, nullptr, "SetCurrentTime"},
|
2019-12-22 17:49:51 -05:00
|
|
|
{2, &ISystemClock::GetSystemClockContext, "GetSystemClockContext"},
|
2018-04-17 11:37:43 -04:00
|
|
|
{3, nullptr, "SetSystemClockContext"},
|
2019-11-12 08:54:58 -05:00
|
|
|
{4, nullptr, "GetOperationEventReadableHandle"},
|
2018-04-17 11:37:43 -04:00
|
|
|
};
|
2019-11-12 08:54:58 -05:00
|
|
|
// clang-format on
|
2019-06-25 10:45:53 -04:00
|
|
|
|
2019-11-12 08:54:58 -05:00
|
|
|
RegisterHandlers(functions);
|
2018-01-17 14:33:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void GetCurrentTime(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_DEBUG(Service_Time, "called");
|
2018-11-26 01:06:13 -05: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};
|
2018-01-17 14:33:38 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
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 01:06:13 -05: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-25 10:45:53 -04: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};
|
2018-01-23 22:02:14 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2019-06-25 10:45:53 -04:00
|
|
|
rb.PushRaw(system_clock_context);
|
2018-01-17 14:33:38 -05:00
|
|
|
}
|
2019-06-25 10:45:53 -04:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
Clock::SystemClockCore& clock_core;
|
2020-04-19 16:26:35 -04:00
|
|
|
Core::System& system;
|
2018-01-17 14:33:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class ISteadyClock final : public ServiceFramework<ISteadyClock> {
|
|
|
|
public:
|
2020-04-19 16:26:35 -04:00
|
|
|
explicit ISteadyClock(Clock::SteadyClockCore& clock_core, Core::System& system)
|
|
|
|
: ServiceFramework("ISteadyClock"), clock_core{clock_core}, system{system} {
|
2018-01-24 23:52:21 -05:00
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, &ISteadyClock::GetCurrentTimePoint, "GetCurrentTimePoint"},
|
2020-06-28 22:01:34 -04: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 12:13:26 -04:00
|
|
|
LOG_DEBUG(Service_Time, "called");
|
2018-11-26 01:06:13 -05: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-25 10:45:53 -04: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};
|
2018-01-24 23:52:21 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2019-06-25 10:45:53 -04:00
|
|
|
rb.PushRaw(time_point);
|
2018-01-24 23:52:21 -05:00
|
|
|
}
|
2019-06-25 10:45:53 -04:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
Clock::SteadyClockCore& clock_core;
|
2020-04-19 16:26:35 -04:00
|
|
|
Core::System& system;
|
2018-01-17 14:33:38 -05:00
|
|
|
};
|
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
ResultCode Module::Interface::GetClockSnapshotFromSystemClockContextInternal(
|
|
|
|
Kernel::Thread* thread, Clock::SystemClockContext user_context,
|
|
|
|
Clock::SystemClockContext network_context, u8 type, Clock::ClockSnapshot& clock_snapshot) {
|
2018-01-17 14:33:38 -05:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
auto& time_manager{module->GetTimeManager()};
|
2018-05-31 08:33:30 -04:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
clock_snapshot.is_automatic_correction_enabled =
|
|
|
|
time_manager.GetStandardUserSystemClockCore().IsAutomaticCorrectionEnabled();
|
|
|
|
clock_snapshot.user_context = user_context;
|
|
|
|
clock_snapshot.network_context = network_context;
|
2018-11-26 01:06:13 -05:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
if (const ResultCode result{
|
|
|
|
time_manager.GetTimeZoneContentManager().GetTimeZoneManager().GetDeviceLocationName(
|
|
|
|
clock_snapshot.location_name)};
|
|
|
|
result != RESULT_SUCCESS) {
|
|
|
|
return result;
|
2018-01-18 00:57:11 -05:00
|
|
|
}
|
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
const auto current_time_point{
|
2020-04-19 16:26:35 -04:00
|
|
|
time_manager.GetStandardSteadyClockCore().GetCurrentTimePoint(system)};
|
2019-12-22 17:49:51 -05:00
|
|
|
if (const ResultCode result{Clock::ClockSnapshot::GetCurrentTime(
|
|
|
|
clock_snapshot.user_time, current_time_point, clock_snapshot.user_context)};
|
|
|
|
result != RESULT_SUCCESS) {
|
|
|
|
return result;
|
2018-01-17 14:33:38 -05: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)};
|
|
|
|
result != RESULT_SUCCESS) {
|
|
|
|
return result;
|
2018-02-07 07:11:17 -05:00
|
|
|
}
|
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
clock_snapshot.user_calendar_time = userCalendarInfo.time;
|
|
|
|
clock_snapshot.user_calendar_additional_time = userCalendarInfo.additiona_info;
|
2018-05-31 08:33:30 -04:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
if (Clock::ClockSnapshot::GetCurrentTime(clock_snapshot.network_time, current_time_point,
|
|
|
|
clock_snapshot.network_context) != RESULT_SUCCESS) {
|
|
|
|
clock_snapshot.network_time = 0;
|
2018-05-31 08:33:30 -04: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)};
|
|
|
|
result != RESULT_SUCCESS) {
|
|
|
|
return result;
|
2018-11-10 01:41:57 -05:00
|
|
|
}
|
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
clock_snapshot.network_calendar_time = networkCalendarInfo.time;
|
|
|
|
clock_snapshot.network_calendar_additional_time = networkCalendarInfo.additiona_info;
|
|
|
|
clock_snapshot.type = type;
|
2018-11-26 01:06:13 -05:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2018-01-17 14:33:38 -05:00
|
|
|
|
2018-01-18 11:58:29 -05:00
|
|
|
void Module::Interface::GetStandardUserSystemClock(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_Time, "called");
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2018-01-22 17:42:11 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2020-04-19 16:26:35 -04:00
|
|
|
rb.PushIpcInterface<ISystemClock>(module->GetTimeManager().GetStandardUserSystemClockCore(),
|
|
|
|
system);
|
2018-01-17 14:33:38 -05:00
|
|
|
}
|
|
|
|
|
2018-01-18 11:58:29 -05:00
|
|
|
void Module::Interface::GetStandardNetworkSystemClock(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_Time, "called");
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2018-01-22 17:42:11 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2020-04-19 16:26:35 -04:00
|
|
|
rb.PushIpcInterface<ISystemClock>(module->GetTimeManager().GetStandardNetworkSystemClockCore(),
|
|
|
|
system);
|
2018-01-17 14:33:38 -05:00
|
|
|
}
|
|
|
|
|
2018-01-18 11:58:29 -05:00
|
|
|
void Module::Interface::GetStandardSteadyClock(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_Time, "called");
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2018-01-22 17:42:11 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2020-04-19 16:26:35 -04:00
|
|
|
rb.PushIpcInterface<ISteadyClock>(module->GetTimeManager().GetStandardSteadyClockCore(),
|
|
|
|
system);
|
2018-01-17 14:33:38 -05:00
|
|
|
}
|
|
|
|
|
2018-01-18 11:58:29 -05:00
|
|
|
void Module::Interface::GetTimeZoneService(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_Time, "called");
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2018-01-17 14:33:38 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2019-12-22 17:49:51 -05:00
|
|
|
rb.PushIpcInterface<ITimeZoneService>(module->GetTimeManager().GetTimeZoneContentManager());
|
2018-01-17 14:33:38 -05: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};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2020-04-19 16:26:35 -04:00
|
|
|
rb.PushIpcInterface<ISystemClock>(module->GetTimeManager().GetStandardLocalSystemClockCore(),
|
|
|
|
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");
|
|
|
|
auto& clock_core{module->GetTimeManager().GetStandardNetworkSystemClockCore()};
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
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 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_Time, "called");
|
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
auto& steady_clock_core{module->GetTimeManager().GetStandardSteadyClockCore()};
|
|
|
|
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 21:04:12 -05: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};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushRaw(base_time_point);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERROR_TIME_MISMATCH);
|
2018-02-21 20:43:05 -05:00
|
|
|
}
|
|
|
|
|
2018-11-09 09:25:56 -05:00
|
|
|
void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_Time, "called");
|
|
|
|
IPC::RequestParser rp{ctx};
|
2020-01-03 22:34:57 -05:00
|
|
|
const auto type{rp.PopRaw<u8>()};
|
2018-11-09 09:25:56 -05:00
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
Clock::SystemClockContext user_context{};
|
|
|
|
if (const ResultCode result{
|
|
|
|
module->GetTimeManager().GetStandardUserSystemClockCore().GetClockContext(
|
2020-04-19 16:26:35 -04:00
|
|
|
system, user_context)};
|
|
|
|
result.IsError()) {
|
2018-11-09 09:25:56 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2019-12-22 17:49:51 -05:00
|
|
|
rb.Push(result);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Clock::SystemClockContext network_context{};
|
|
|
|
if (const ResultCode result{
|
|
|
|
module->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-09 09:25:56 -05: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
|
|
|
|
2018-11-09 09:25:56 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2020-08-03 07:28:54 -04:00
|
|
|
ctx.WriteBuffer(clock_snapshot);
|
2018-11-16 22:01:16 -05:00
|
|
|
}
|
|
|
|
|
2020-01-03 22:34:57 -05:00
|
|
|
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);
|
2020-08-03 07:28:54 -04:00
|
|
|
ctx.WriteBuffer(clock_snapshot);
|
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");
|
|
|
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto snapshot_a = rp.PopRaw<Clock::ClockSnapshot>();
|
|
|
|
const auto snapshot_b = rp.PopRaw<Clock::ClockSnapshot>();
|
|
|
|
|
|
|
|
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};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
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");
|
|
|
|
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto snapshot_a = rp.PopRaw<Clock::ClockSnapshot>();
|
|
|
|
const auto snapshot_b = rp.PopRaw<Clock::ClockSnapshot>();
|
|
|
|
|
|
|
|
Clock::TimeSpanType time_span_type{};
|
|
|
|
s64 span{};
|
|
|
|
if (const ResultCode result{snapshot_a.steady_clock_time_point.GetSpanBetween(
|
|
|
|
snapshot_b.steady_clock_time_point, span)};
|
|
|
|
result != RESULT_SUCCESS) {
|
|
|
|
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};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushRaw(time_span_type.nanoseconds);
|
|
|
|
}
|
|
|
|
|
2019-06-25 10:45:53 -04:00
|
|
|
void Module::Interface::GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_Time, "called");
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2019-12-22 17:49:51 -05:00
|
|
|
rb.PushCopyObjects(module->GetTimeManager().GetSharedMemory().GetSharedMemoryHolder());
|
2019-06-25 10:45:53 -04:00
|
|
|
}
|
|
|
|
|
2019-12-22 17:49:51 -05:00
|
|
|
Module::Interface::Interface(std::shared_ptr<Module> module, Core::System& system, const char* name)
|
|
|
|
: ServiceFramework(name), module{std::move(module)}, system{system} {}
|
2018-01-17 14:33:38 -05:00
|
|
|
|
hle/service: Default constructors and destructors in the cpp file where applicable
When a destructor isn't defaulted into a cpp file, it can cause the use
of forward declarations to seemingly fail to compile for non-obvious
reasons. It also allows inlining of the construction/destruction logic
all over the place where a constructor or destructor is invoked, which
can lead to code bloat. This isn't so much a worry here, given the
services won't be created and destroyed frequently.
The cause of the above mentioned non-obvious errors can be demonstrated
as follows:
------- Demonstrative example, if you know how the described error happens, skip forwards -------
Assume we have the following in the header, which we'll call "thing.h":
\#include <memory>
// Forward declaration. For example purposes, assume the definition
// of Object is in some header named "object.h"
class Object;
class Thing {
public:
// assume no constructors or destructors are specified here,
// or the constructors/destructors are defined as:
//
// Thing() = default;
// ~Thing() = default;
//
// ... Some interface member functions would be defined here
private:
std::shared_ptr<Object> obj;
};
If this header is included in a cpp file, (which we'll call "main.cpp"),
this will result in a compilation error, because even though no
destructor is specified, the destructor will still need to be generated by
the compiler because std::shared_ptr's destructor is *not* trivial (in
other words, it does something other than nothing), as std::shared_ptr's
destructor needs to do two things:
1. Decrement the shared reference count of the object being pointed to,
and if the reference count decrements to zero,
2. Free the Object instance's memory (aka deallocate the memory it's
pointing to).
And so the compiler generates the code for the destructor doing this inside main.cpp.
Now, keep in mind, the Object forward declaration is not a complete type. All it
does is tell the compiler "a type named Object exists" and allows us to
use the name in certain situations to avoid a header dependency. So the
compiler needs to generate destruction code for Object, but the compiler
doesn't know *how* to destruct it. A forward declaration doesn't tell
the compiler anything about Object's constructor or destructor. So, the
compiler will issue an error in this case because it's undefined
behavior to try and deallocate (or construct) an incomplete type and
std::shared_ptr and std::unique_ptr make sure this isn't the case
internally.
Now, if we had defaulted the destructor in "thing.cpp", where we also
include "object.h", this would never be an issue, as the destructor
would only have its code generated in one place, and it would be in a
place where the full class definition of Object would be visible to the
compiler.
---------------------- End example ----------------------------
Given these service classes are more than certainly going to change in
the future, this defaults the constructors and destructors into the
relevant cpp files to make the construction and destruction of all of
the services consistent and unlikely to run into cases where forward
declarations are indirectly causing compilation errors. It also has the
plus of avoiding the need to rebuild several services if destruction
logic changes, since it would only be necessary to recompile the single
cpp file.
2018-09-10 21:20:52 -04:00
|
|
|
Module::Interface::~Interface() = default;
|
|
|
|
|
2019-06-25 10:45:53 -04:00
|
|
|
void InstallInterfaces(Core::System& system) {
|
2020-01-03 22:34:57 -05:00
|
|
|
auto module{std::make_shared<Module>(system)};
|
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
|