timeGetCurrentTime: add shared memory support [6.0.0+]

This commit is contained in:
fincs 2020-04-11 00:13:53 +02:00
parent b0d96342e8
commit 39629f5a67
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60

View File

@ -177,7 +177,22 @@ Result timeGetStandardSteadyClockInternalOffset(s64 *out) {
return serviceDispatchOut(&g_timeSteadyClock, 200, *out);
}
static Result _timeReadClockFromSharedMem(size_t offset, u64 *out) {
TimeStandardSteadyClockTimePointType steady;
_timeReadSharedmemObj(&steady, 0x00, sizeof(steady));
TimeSystemClockContext context;
_timeReadSharedmemObj(&context, offset, sizeof(context));
if (memcmp(&context.timestamp.source_id, &steady.source_id, sizeof(Uuid)) != 0)
return MAKERESULT(116,102);
*out = context.offset + (steady.base_time + armTicksToNs(armGetSystemTick())) / 1000000000UL;
return 0;
}
Result timeGetCurrentTime(TimeType type, u64 *timestamp) {
if (!shmemGetAddr(&g_timeSharedmem)) {
Service *srv = timeGetServiceSession_SystemClock(type);
if (srv==NULL)
@ -186,6 +201,12 @@ Result timeGetCurrentTime(TimeType type, u64 *timestamp) {
return _timeCmdNoInOutU64(srv, timestamp, 0);
}
if (type != TimeType_NetworkSystemClock)
return _timeReadClockFromSharedMem(0x38, timestamp);
else
return _timeReadClockFromSharedMem(0x80, timestamp);
}
Result timeSetCurrentTime(TimeType type, u64 timestamp) {
Service *srv = timeGetServiceSession_SystemClock(type);