mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-08 10:22:24 -04:00
kern: support dynamic resource expansion for system heaps/events/sessions.
This commit is contained in:
parent
dfd57b09a3
commit
f8fd072349
37 changed files with 856 additions and 328 deletions
|
@ -49,7 +49,8 @@ namespace ams::kern {
|
|||
KScopedLightLock lk(m_lock);
|
||||
value = m_limit_values[which];
|
||||
MESOSPHERE_ASSERT(value >= 0);
|
||||
MESOSPHERE_ASSERT(m_current_values[which] <= m_limit_values[which]);
|
||||
MESOSPHERE_ASSERT(m_current_values[which] <= m_peak_values[which]);
|
||||
MESOSPHERE_ASSERT(m_peak_values[which] <= m_limit_values[which]);
|
||||
MESOSPHERE_ASSERT(m_current_hints[which] <= m_current_values[which]);
|
||||
}
|
||||
|
||||
|
@ -64,7 +65,8 @@ namespace ams::kern {
|
|||
KScopedLightLock lk(m_lock);
|
||||
value = m_current_values[which];
|
||||
MESOSPHERE_ASSERT(value >= 0);
|
||||
MESOSPHERE_ASSERT(m_current_values[which] <= m_limit_values[which]);
|
||||
MESOSPHERE_ASSERT(m_current_values[which] <= m_peak_values[which]);
|
||||
MESOSPHERE_ASSERT(m_peak_values[which] <= m_limit_values[which]);
|
||||
MESOSPHERE_ASSERT(m_current_hints[which] <= m_current_values[which]);
|
||||
}
|
||||
|
||||
|
@ -79,7 +81,8 @@ namespace ams::kern {
|
|||
KScopedLightLock lk(m_lock);
|
||||
value = m_peak_values[which];
|
||||
MESOSPHERE_ASSERT(value >= 0);
|
||||
MESOSPHERE_ASSERT(m_current_values[which] <= m_limit_values[which]);
|
||||
MESOSPHERE_ASSERT(m_current_values[which] <= m_peak_values[which]);
|
||||
MESOSPHERE_ASSERT(m_peak_values[which] <= m_limit_values[which]);
|
||||
MESOSPHERE_ASSERT(m_current_hints[which] <= m_current_values[which]);
|
||||
}
|
||||
|
||||
|
@ -93,7 +96,8 @@ namespace ams::kern {
|
|||
{
|
||||
KScopedLightLock lk(m_lock);
|
||||
MESOSPHERE_ASSERT(m_current_values[which] >= 0);
|
||||
MESOSPHERE_ASSERT(m_current_values[which] <= m_limit_values[which]);
|
||||
MESOSPHERE_ASSERT(m_current_values[which] <= m_peak_values[which]);
|
||||
MESOSPHERE_ASSERT(m_peak_values[which] <= m_limit_values[which]);
|
||||
MESOSPHERE_ASSERT(m_current_hints[which] <= m_current_values[which]);
|
||||
value = m_limit_values[which] - m_current_values[which];
|
||||
}
|
||||
|
@ -113,6 +117,37 @@ namespace ams::kern {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
void KResourceLimit::Add(ams::svc::LimitableResource which, s64 value) {
|
||||
MESOSPHERE_ASSERT_THIS();
|
||||
MESOSPHERE_ASSERT(KTargetSystem::IsDynamicResourceLimitsEnabled());
|
||||
|
||||
KScopedLightLock lk(m_lock);
|
||||
|
||||
/* Check that this is a true increase. */
|
||||
MESOSPHERE_ABORT_UNLESS(value > 0);
|
||||
|
||||
/* Check that we can perform an increase. */
|
||||
MESOSPHERE_ABORT_UNLESS(m_current_values[which] <= m_peak_values[which]);
|
||||
MESOSPHERE_ABORT_UNLESS(m_peak_values[which] <= m_limit_values[which]);
|
||||
MESOSPHERE_ABORT_UNLESS(m_current_hints[which] <= m_current_values[which]);
|
||||
|
||||
/* Check that the increase doesn't cause an overflow. */
|
||||
const auto increased_limit = m_limit_values[which] + value;
|
||||
const auto increased_current = m_current_values[which] + value;
|
||||
const auto increased_hint = m_current_hints[which] + value;
|
||||
MESOSPHERE_ABORT_UNLESS(m_limit_values[which] < increased_limit);
|
||||
MESOSPHERE_ABORT_UNLESS(m_current_values[which] < increased_current);
|
||||
MESOSPHERE_ABORT_UNLESS(m_current_hints[which] < increased_hint);
|
||||
|
||||
/* Add the value. */
|
||||
m_limit_values[which] = increased_limit;
|
||||
m_current_values[which] = increased_current;
|
||||
m_current_hints[which] = increased_hint;
|
||||
|
||||
/* Update our peak. */
|
||||
m_peak_values[which] = std::max(m_peak_values[which], increased_current);
|
||||
}
|
||||
|
||||
bool KResourceLimit::Reserve(ams::svc::LimitableResource which, s64 value) {
|
||||
return this->Reserve(which, value, KHardwareTimer::GetTick() + DefaultTimeout);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue