mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
vapours: add time primitives, fix result name
This commit is contained in:
parent
ef3da6cb51
commit
c6d1579265
13 changed files with 238 additions and 18 deletions
|
@ -79,7 +79,7 @@ namespace ams::kern {
|
|||
|
||||
/* Convenience definitions. */
|
||||
constexpr s32 DpcManagerThreadPriority = 3;
|
||||
constexpr s64 DpcManagerTimeout = 192'000ll; /* TODO: Constexpr conversion from 10ms */
|
||||
constexpr s64 DpcManagerTimeout = ams::svc::Tick(TimeSpan::FromMilliSeconds(10));
|
||||
|
||||
/* Globals. */
|
||||
s64 g_preemption_priorities[cpu::NumCores];
|
||||
|
|
|
@ -17,6 +17,12 @@
|
|||
|
||||
namespace ams::kern {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr s64 DefaultTimeout = ams::svc::Tick(TimeSpan::FromSeconds(10));
|
||||
|
||||
}
|
||||
|
||||
void KResourceLimit::Initialize() {
|
||||
/* This should be unnecessary for us, because our constructor will clear all fields. */
|
||||
/* The following is analagous to what Nintendo's implementation (no constexpr constructor) would do, though. */
|
||||
|
@ -91,8 +97,7 @@ namespace ams::kern {
|
|||
}
|
||||
|
||||
bool KResourceLimit::Reserve(ams::svc::LimitableResource which, s64 value) {
|
||||
/* TODO: constexpr definition for this default timeout (it's 10 seconds) */
|
||||
return this->Reserve(which, value, KHardwareTimer::GetTick() + 192'000'000);
|
||||
return this->Reserve(which, value, KHardwareTimer::GetTick() + DefaultTimeout);
|
||||
}
|
||||
|
||||
bool KResourceLimit::Reserve(ams::svc::LimitableResource which, s64 value, s64 timeout) {
|
||||
|
|
|
@ -100,7 +100,7 @@ namespace ams::map {
|
|||
|
||||
MappedCodeMemory tmp_mcm(process_handle, try_address, base_address, size);
|
||||
R_TRY_CATCH(tmp_mcm.GetResult()) {
|
||||
R_CATCH(svc::ResultInvalidCurrentMemoryState) { continue; }
|
||||
R_CATCH(svc::ResultInvalidCurrentMemory) { continue; }
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
if (!CanAddGuardRegionsInProcess(process_handle, try_address, size)) {
|
||||
|
@ -136,7 +136,7 @@ namespace ams::map {
|
|||
|
||||
MappedCodeMemory tmp_mcm(process_handle, try_address, base_address, size);
|
||||
R_TRY_CATCH(tmp_mcm.GetResult()) {
|
||||
R_CATCH(svc::ResultInvalidCurrentMemoryState) { continue; }
|
||||
R_CATCH(svc::ResultInvalidCurrentMemory) { continue; }
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
if (!CanAddGuardRegionsInProcess(process_handle, try_address, size)) {
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "vapours/defines.hpp"
|
||||
#include "vapours/literals.hpp"
|
||||
|
||||
#include "vapours/timespan.hpp"
|
||||
|
||||
#include "vapours/util.hpp"
|
||||
#include "vapours/results.hpp"
|
||||
#include "vapours/svc.hpp"
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace ams::svc {
|
|||
R_DEFINE_ERROR_RESULT(OutOfResource, 103);
|
||||
R_DEFINE_ERROR_RESULT(OutOfMemory, 104);
|
||||
R_DEFINE_ERROR_RESULT(OutOfHandles, 105);
|
||||
R_DEFINE_ERROR_RESULT(InvalidCurrentMemoryState, 106);
|
||||
R_DEFINE_ERROR_RESULT(InvalidCurrentMemory, 106);
|
||||
|
||||
R_DEFINE_ERROR_RESULT(InvalidNewMemoryPermissions, 108);
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#pragma once
|
||||
#include <vapours/svc/svc_types_common.hpp>
|
||||
|
||||
namespace ams::svc {
|
||||
namespace ams::svc::board::nintendo_switch {
|
||||
|
||||
enum DeviceName {
|
||||
DeviceName_Afi = 0,
|
||||
|
@ -62,4 +62,4 @@ namespace ams::svc {
|
|||
DeviceName_Count,
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
#include <vapours/svc/svc_types_common.hpp>
|
||||
|
||||
namespace ams::svc::board::nintendo_switch {
|
||||
|
||||
constexpr inline const s64 TicksPerSecond = 19'200'000;
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "svc_common.hpp"
|
||||
|
||||
#if defined(ATMOSPHERE_BOARD_NINTENDO_SWITCH)
|
||||
|
||||
#include "board/nintendo/switch/svc_device_name.hpp"
|
||||
namespace ams::svc {
|
||||
using namespace ams::svc::board::nintendo_switch;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#error "Unknown board for svc::DeviceName"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "svc_common.hpp"
|
||||
|
||||
#if defined(ATMOSPHERE_BOARD_NINTENDO_SWITCH)
|
||||
|
||||
#include "board/nintendo/switch/svc_hardware_constants.hpp"
|
||||
namespace ams::svc {
|
||||
using namespace ams::svc::board::nintendo_switch;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#error "Unknown board for svc::DeviceName"
|
||||
|
||||
#endif
|
72
libraries/libvapours/include/vapours/svc/svc_tick.hpp
Normal file
72
libraries/libvapours/include/vapours/svc/svc_tick.hpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "svc_common.hpp"
|
||||
#include "svc_select_hardware_constants.hpp"
|
||||
|
||||
namespace ams::svc {
|
||||
|
||||
class Tick {
|
||||
public:
|
||||
static constexpr s64 TicksPerSecond = ::ams::svc::TicksPerSecond;
|
||||
static constexpr s64 GetTicksPerSecond() { return TicksPerSecond; }
|
||||
private:
|
||||
s64 tick;
|
||||
private:
|
||||
static constexpr s64 NanoSecondsPerSecond = INT64_C(1'000'000'000);
|
||||
|
||||
static constexpr void DivNs(s64 &out, const s64 value) {
|
||||
out = value / NanoSecondsPerSecond;
|
||||
}
|
||||
|
||||
static constexpr void DivModNs(s64 &out_div, s64 &out_mod, const s64 value) {
|
||||
out_div = value / NanoSecondsPerSecond;
|
||||
out_mod = value % NanoSecondsPerSecond;
|
||||
}
|
||||
|
||||
static constexpr s64 ConvertTimeSpanToTickImpl(TimeSpan ts) {
|
||||
/* Split up timespan and ticks-per-second by ns. */
|
||||
s64 ts_div = 0, ts_mod = 0;
|
||||
s64 tick_div = 0, tick_mod = 0;
|
||||
DivModNs(ts_div, ts_mod, ts.GetNanoSeconds());
|
||||
DivModNs(tick_div, tick_mod, TicksPerSecond);
|
||||
|
||||
/* Convert the timespan into a tick count. */
|
||||
s64 value = 0;
|
||||
DivNs(value, ts_mod * tick_mod + NanoSecondsPerSecond - 1);
|
||||
|
||||
return (ts_div * tick_div) * NanoSecondsPerSecond + ts_div * tick_mod + ts_mod * tick_div + value;
|
||||
}
|
||||
public:
|
||||
constexpr explicit Tick(s64 t = 0) : tick(t) { /* ... */ }
|
||||
constexpr Tick(TimeSpan ts) : tick(ConvertTimeSpanToTickImpl(ts)) { /* ... */ }
|
||||
|
||||
constexpr operator s64() const { return this->tick; }
|
||||
|
||||
/* Tick arithmetic. */
|
||||
constexpr Tick &operator+=(Tick rhs) { this->tick += rhs.tick; return *this; }
|
||||
constexpr Tick &operator-=(Tick rhs) { this->tick -= rhs.tick; return *this; }
|
||||
constexpr Tick operator+(Tick rhs) const { Tick r(*this); return r += rhs; }
|
||||
constexpr Tick operator-(Tick rhs) const { Tick r(*this); return r -= rhs; }
|
||||
|
||||
constexpr Tick &operator+=(TimeSpan rhs) { this->tick += Tick(rhs).tick; return *this; }
|
||||
constexpr Tick &operator-=(TimeSpan rhs) { this->tick -= Tick(rhs).tick; return *this; }
|
||||
constexpr Tick operator+(TimeSpan rhs) const { Tick r(*this); return r += rhs; }
|
||||
constexpr Tick operator-(TimeSpan rhs) const { Tick r(*this); return r -= rhs; }
|
||||
};
|
||||
|
||||
}
|
|
@ -16,6 +16,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "svc_common.hpp"
|
||||
#include "svc_tick.hpp"
|
||||
#include "svc_types_common.hpp"
|
||||
#include "svc_types_base.hpp"
|
||||
#include "svc_types_dd.hpp"
|
||||
|
|
|
@ -15,16 +15,8 @@
|
|||
*/
|
||||
#pragma once
|
||||
#include "svc_types_common.hpp"
|
||||
|
||||
#ifdef ATMOSPHERE_BOARD_NINTENDO_SWITCH
|
||||
|
||||
#include "board/nintendo/switch/svc_device_name.hpp"
|
||||
|
||||
#else
|
||||
|
||||
#error "Unknown board for svc::DeviceName"
|
||||
|
||||
#endif
|
||||
#include "svc_select_hardware_constants.hpp"
|
||||
#include "svc_select_device_name.hpp"
|
||||
|
||||
namespace ams::svc {
|
||||
|
||||
|
|
63
libraries/libvapours/include/vapours/timespan.hpp
Normal file
63
libraries/libvapours/include/vapours/timespan.hpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "defines.hpp"
|
||||
#include <chrono>
|
||||
|
||||
namespace ams {
|
||||
|
||||
class TimeSpan {
|
||||
private:
|
||||
s64 ns;
|
||||
private:
|
||||
constexpr explicit ALWAYS_INLINE TimeSpan(s64 v) : ns(v) { /* ... */ }
|
||||
public:
|
||||
constexpr explicit ALWAYS_INLINE TimeSpan() : TimeSpan(0) { /* ... */ }
|
||||
|
||||
static constexpr ALWAYS_INLINE TimeSpan FromNanoSeconds(s64 ns) { return TimeSpan(ns); }
|
||||
static constexpr ALWAYS_INLINE TimeSpan FromMicroSeconds(s64 ms) { return FromNanoSeconds(ms * INT64_C(1000)); }
|
||||
static constexpr ALWAYS_INLINE TimeSpan FromMilliSeconds(s64 ms) { return FromMicroSeconds(ms * INT64_C(1000)); }
|
||||
static constexpr ALWAYS_INLINE TimeSpan FromSeconds(s64 s) { return FromMilliSeconds(s * INT64_C(1000)); }
|
||||
static constexpr ALWAYS_INLINE TimeSpan FromMinutes(s64 m) { return FromSeconds(m * INT64_C(60)); }
|
||||
static constexpr ALWAYS_INLINE TimeSpan FromHours(s64 h) { return FromMinutes(h * INT64_C(60)); }
|
||||
static constexpr ALWAYS_INLINE TimeSpan FromDays(s64 d) { return FromMinutes(d * INT64_C(24)); }
|
||||
|
||||
template<typename R, typename P>
|
||||
constexpr explicit ALWAYS_INLINE TimeSpan(const std::chrono::duration<R, P>& c) : TimeSpan(static_cast<std::chrono::nanoseconds>(c).count()) { /* ... */ }
|
||||
public:
|
||||
constexpr ALWAYS_INLINE s64 GetNanoSeconds() const { return this->ns; }
|
||||
constexpr ALWAYS_INLINE s64 GetMicroSeconds() const { return this->GetNanoSeconds() / (INT64_C(1000)); }
|
||||
constexpr ALWAYS_INLINE s64 GetMilliSeconds() const { return this->GetNanoSeconds() / (INT64_C(1000) * INT64_C(1000)); }
|
||||
constexpr ALWAYS_INLINE s64 GetSeconds() const { return this->GetNanoSeconds() / (INT64_C(1000) * INT64_C(1000) * INT64_C(1000)); }
|
||||
constexpr ALWAYS_INLINE s64 GetMinutes() const { return this->GetNanoSeconds() / (INT64_C(1000) * INT64_C(1000) * INT64_C(1000) * INT64_C( 60)); }
|
||||
constexpr ALWAYS_INLINE s64 GetHours() const { return this->GetNanoSeconds() / (INT64_C(1000) * INT64_C(1000) * INT64_C(1000) * INT64_C( 60) * INT64_C( 60)); }
|
||||
constexpr ALWAYS_INLINE s64 GetDays() const { return this->GetNanoSeconds() / (INT64_C(1000) * INT64_C(1000) * INT64_C(1000) * INT64_C( 60) * INT64_C( 60) * INT64_C( 24)); }
|
||||
|
||||
constexpr ALWAYS_INLINE bool operator==(const TimeSpan &rhs) const { return this->ns == rhs.ns; }
|
||||
constexpr ALWAYS_INLINE bool operator!=(const TimeSpan &rhs) const { return this->ns != rhs.ns; }
|
||||
constexpr ALWAYS_INLINE bool operator<=(const TimeSpan &rhs) const { return this->ns <= rhs.ns; }
|
||||
constexpr ALWAYS_INLINE bool operator>=(const TimeSpan &rhs) const { return this->ns >= rhs.ns; }
|
||||
constexpr ALWAYS_INLINE bool operator< (const TimeSpan &rhs) const { return this->ns < rhs.ns; }
|
||||
constexpr ALWAYS_INLINE bool operator> (const TimeSpan &rhs) const { return this->ns > rhs.ns; }
|
||||
|
||||
constexpr ALWAYS_INLINE TimeSpan &operator+=(TimeSpan rhs) { this->ns += rhs.ns; return *this; }
|
||||
constexpr ALWAYS_INLINE TimeSpan &operator-=(TimeSpan rhs) { this->ns -= rhs.ns; return *this; }
|
||||
constexpr ALWAYS_INLINE TimeSpan operator+(TimeSpan rhs) const { TimeSpan r(*this); return r += rhs; }
|
||||
constexpr ALWAYS_INLINE TimeSpan operator-(TimeSpan rhs) const { TimeSpan r(*this); return r -= rhs; }
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue