2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-01-30 10:40:49 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "core/hle/kernel/k_light_condition_variable.h"
|
|
|
|
#include "core/hle/kernel/k_light_lock.h"
|
|
|
|
|
2022-06-26 05:44:19 +02:00
|
|
|
union Result;
|
2021-01-30 10:40:49 +01:00
|
|
|
|
2021-04-14 06:40:33 +02:00
|
|
|
namespace Core::Timing {
|
|
|
|
class CoreTiming;
|
2021-01-30 10:40:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
class KernelCore;
|
2022-11-03 15:22:05 +01:00
|
|
|
|
|
|
|
using LimitableResource = Svc::LimitableResource;
|
2021-01-30 10:40:49 +01:00
|
|
|
|
|
|
|
constexpr bool IsValidResourceType(LimitableResource type) {
|
|
|
|
return type < LimitableResource::Count;
|
|
|
|
}
|
|
|
|
|
2021-04-21 06:28:11 +02:00
|
|
|
class KResourceLimit final
|
|
|
|
: public KAutoObjectWithSlabHeapAndContainer<KResourceLimit, KAutoObjectWithList> {
|
|
|
|
KERNEL_AUTOOBJECT_TRAITS(KResourceLimit, KAutoObject);
|
|
|
|
|
2021-01-30 10:40:49 +01:00
|
|
|
public:
|
2023-03-07 16:58:51 +01:00
|
|
|
explicit KResourceLimit(KernelCore& kernel);
|
2021-05-29 08:49:07 +02:00
|
|
|
~KResourceLimit() override;
|
2021-04-21 06:28:11 +02:00
|
|
|
|
2023-08-15 00:12:06 +02:00
|
|
|
void Initialize();
|
2021-05-29 08:49:07 +02:00
|
|
|
void Finalize() override;
|
2021-01-30 10:40:49 +01:00
|
|
|
|
|
|
|
s64 GetLimitValue(LimitableResource which) const;
|
|
|
|
s64 GetCurrentValue(LimitableResource which) const;
|
|
|
|
s64 GetPeakValue(LimitableResource which) const;
|
|
|
|
s64 GetFreeValue(LimitableResource which) const;
|
|
|
|
|
2022-06-26 05:44:19 +02:00
|
|
|
Result SetLimitValue(LimitableResource which, s64 value);
|
2021-01-30 10:40:49 +01:00
|
|
|
|
|
|
|
bool Reserve(LimitableResource which, s64 value);
|
|
|
|
bool Reserve(LimitableResource which, s64 value, s64 timeout);
|
|
|
|
void Release(LimitableResource which, s64 value);
|
|
|
|
void Release(LimitableResource which, s64 value, s64 hint);
|
|
|
|
|
2023-03-07 15:25:12 +01:00
|
|
|
static void PostDestroy(uintptr_t arg) {}
|
2021-04-21 06:28:11 +02:00
|
|
|
|
2021-01-30 10:40:49 +01:00
|
|
|
private:
|
2021-02-02 03:23:00 +01:00
|
|
|
using ResourceArray = std::array<s64, static_cast<std::size_t>(LimitableResource::Count)>;
|
2023-03-07 16:58:51 +01:00
|
|
|
ResourceArray m_limit_values{};
|
|
|
|
ResourceArray m_current_values{};
|
|
|
|
ResourceArray m_current_hints{};
|
|
|
|
ResourceArray m_peak_values{};
|
|
|
|
mutable KLightLock m_lock;
|
|
|
|
s32 m_waiter_count{};
|
|
|
|
KLightConditionVariable m_cond_var;
|
2021-01-30 10:40:49 +01:00
|
|
|
};
|
2022-02-21 21:29:19 +01:00
|
|
|
|
|
|
|
KResourceLimit* CreateResourceLimitForProcess(Core::System& system, s64 physical_memory_size);
|
|
|
|
|
2021-01-30 10:40:49 +01:00
|
|
|
} // namespace Kernel
|