Add time:* permissions
This commit is contained in:
parent
b3e53f7a23
commit
69dbde450c
3 changed files with 45 additions and 9 deletions
|
@ -5,22 +5,40 @@ using System;
|
||||||
|
|
||||||
namespace Ryujinx.HLE.HOS.Services.Time
|
namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
{
|
{
|
||||||
[Service("time:a")]
|
[Flags]
|
||||||
[Service("time:s")]
|
enum TimePermissions
|
||||||
[Service("time:u")]
|
{
|
||||||
|
LocalSystemClockWritableMask = 0x1,
|
||||||
|
UserSystemClockWritableMask = 0x2,
|
||||||
|
NetworkSystemClockWritableMask = 0x4,
|
||||||
|
UnknwonPermissionMask = 0x8,
|
||||||
|
|
||||||
|
User = 0,
|
||||||
|
Applet = LocalSystemClockWritableMask | UserSystemClockWritableMask | UnknwonPermissionMask,
|
||||||
|
System = NetworkSystemClockWritableMask
|
||||||
|
}
|
||||||
|
|
||||||
|
[Service("time:a", TimePermissions.Applet)]
|
||||||
|
[Service("time:s", TimePermissions.System)]
|
||||||
|
[Service("time:u", TimePermissions.User)]
|
||||||
class IStaticService : IpcService
|
class IStaticService : IpcService
|
||||||
{
|
{
|
||||||
|
private TimePermissions _permissions;
|
||||||
|
|
||||||
private int _timeSharedMemoryNativeHandle = 0;
|
private int _timeSharedMemoryNativeHandle = 0;
|
||||||
|
|
||||||
private static readonly DateTime StartupDate = DateTime.UtcNow;
|
private static readonly DateTime StartupDate = DateTime.UtcNow;
|
||||||
|
|
||||||
public IStaticService(ServiceCtx context) { }
|
public IStaticService(ServiceCtx context, TimePermissions permissions)
|
||||||
|
{
|
||||||
|
_permissions = permissions;
|
||||||
|
}
|
||||||
|
|
||||||
[Command(0)]
|
[Command(0)]
|
||||||
// GetStandardUserSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
|
// GetStandardUserSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
|
||||||
public ResultCode GetStandardUserSystemClock(ServiceCtx context)
|
public ResultCode GetStandardUserSystemClock(ServiceCtx context)
|
||||||
{
|
{
|
||||||
MakeObject(context, new ISystemClock(StandardUserSystemClockCore.Instance));
|
MakeObject(context, new ISystemClock(StandardUserSystemClockCore.Instance, (_permissions & TimePermissions.UserSystemClockWritableMask) != 0));
|
||||||
|
|
||||||
return ResultCode.Success;
|
return ResultCode.Success;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +47,7 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
// GetStandardNetworkSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
|
// GetStandardNetworkSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
|
||||||
public ResultCode GetStandardNetworkSystemClock(ServiceCtx context)
|
public ResultCode GetStandardNetworkSystemClock(ServiceCtx context)
|
||||||
{
|
{
|
||||||
MakeObject(context, new ISystemClock(StandardNetworkSystemClockCore.Instance));
|
MakeObject(context, new ISystemClock(StandardNetworkSystemClockCore.Instance, (_permissions & TimePermissions.NetworkSystemClockWritableMask) != 0));
|
||||||
|
|
||||||
return ResultCode.Success;
|
return ResultCode.Success;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +74,7 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
// GetStandardLocalSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
|
// GetStandardLocalSystemClock() -> object<nn::timesrv::detail::service::ISystemClock>
|
||||||
public ResultCode GetStandardLocalSystemClock(ServiceCtx context)
|
public ResultCode GetStandardLocalSystemClock(ServiceCtx context)
|
||||||
{
|
{
|
||||||
MakeObject(context, new ISystemClock(StandardLocalSystemClockCore.Instance));
|
MakeObject(context, new ISystemClock(StandardLocalSystemClockCore.Instance, (_permissions & TimePermissions.LocalSystemClockWritableMask) != 0));
|
||||||
|
|
||||||
return ResultCode.Success;
|
return ResultCode.Success;
|
||||||
}
|
}
|
||||||
|
@ -91,6 +109,11 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
// SetStandardUserSystemClockAutomaticCorrectionEnabled(b8)
|
// SetStandardUserSystemClockAutomaticCorrectionEnabled(b8)
|
||||||
public ResultCode SetStandardUserSystemClockAutomaticCorrectionEnabled(ServiceCtx context)
|
public ResultCode SetStandardUserSystemClockAutomaticCorrectionEnabled(ServiceCtx context)
|
||||||
{
|
{
|
||||||
|
if ((_permissions & TimePermissions.UserSystemClockWritableMask) == 0)
|
||||||
|
{
|
||||||
|
return ResultCode.PermissionDenied;
|
||||||
|
}
|
||||||
|
|
||||||
bool autoCorrectionEnabled = context.RequestData.ReadBoolean();
|
bool autoCorrectionEnabled = context.RequestData.ReadBoolean();
|
||||||
|
|
||||||
return StandardUserSystemClockCore.Instance.SetAutomaticCorrectionEnabled(context.Thread, autoCorrectionEnabled);
|
return StandardUserSystemClockCore.Instance.SetAutomaticCorrectionEnabled(context.Thread, autoCorrectionEnabled);
|
||||||
|
|
|
@ -6,10 +6,12 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
class ISystemClock : IpcService
|
class ISystemClock : IpcService
|
||||||
{
|
{
|
||||||
private SystemClockCore _clockCore;
|
private SystemClockCore _clockCore;
|
||||||
|
private bool _writePermission;
|
||||||
|
|
||||||
public ISystemClock(SystemClockCore clockCore)
|
public ISystemClock(SystemClockCore clockCore, bool writePermission)
|
||||||
{
|
{
|
||||||
_clockCore = clockCore;
|
_clockCore = clockCore;
|
||||||
|
_writePermission = writePermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command(0)]
|
[Command(0)]
|
||||||
|
@ -43,6 +45,11 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
// SetCurrentTime(nn::time::PosixTime)
|
// SetCurrentTime(nn::time::PosixTime)
|
||||||
public ResultCode SetCurrentTime(ServiceCtx context)
|
public ResultCode SetCurrentTime(ServiceCtx context)
|
||||||
{
|
{
|
||||||
|
if (!_writePermission)
|
||||||
|
{
|
||||||
|
return ResultCode.PermissionDenied;
|
||||||
|
}
|
||||||
|
|
||||||
ulong posixTime = context.RequestData.ReadUInt64();
|
ulong posixTime = context.RequestData.ReadUInt64();
|
||||||
|
|
||||||
SteadyClockCore steadyClockCore = _clockCore.GetSteadyClockCore();
|
SteadyClockCore steadyClockCore = _clockCore.GetSteadyClockCore();
|
||||||
|
@ -83,6 +90,11 @@ namespace Ryujinx.HLE.HOS.Services.Time
|
||||||
// SetSystemClockContext(nn::time::SystemClockContext)
|
// SetSystemClockContext(nn::time::SystemClockContext)
|
||||||
public ResultCode SetSystemClockContext(ServiceCtx context)
|
public ResultCode SetSystemClockContext(ServiceCtx context)
|
||||||
{
|
{
|
||||||
|
if (!_writePermission)
|
||||||
|
{
|
||||||
|
return ResultCode.PermissionDenied;
|
||||||
|
}
|
||||||
|
|
||||||
SystemClockContext clockContext = context.RequestData.ReadStruct<SystemClockContext>();
|
SystemClockContext clockContext = context.RequestData.ReadStruct<SystemClockContext>();
|
||||||
|
|
||||||
ResultCode result = _clockCore.SetSystemClockContext(clockContext);
|
ResultCode result = _clockCore.SetSystemClockContext(clockContext);
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
Success = 0,
|
Success = 0,
|
||||||
|
|
||||||
|
PermissionDenied = (1 << ErrorCodeShift) | ModuleId,
|
||||||
TimeMismatch = (102 << ErrorCodeShift) | ModuleId,
|
TimeMismatch = (102 << ErrorCodeShift) | ModuleId,
|
||||||
TimeNotFound = (200 << ErrorCodeShift) | ModuleId,
|
TimeNotFound = (200 << ErrorCodeShift) | ModuleId,
|
||||||
Overflow = (201 << ErrorCodeShift) | ModuleId,
|
Overflow = (201 << ErrorCodeShift) | ModuleId,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue