kernel: fix resource limit imbalance

master
Liam 2023-12-18 15:38:50 +07:00
parent db7b2bc8f1
commit c57ae803a6
3 changed files with 7 additions and 8 deletions

@ -58,8 +58,8 @@ Result KClientPort::CreateSession(KClientSession** out) {
KSession* session{}; KSession* session{};
// Reserve a new session from the resource limit. // Reserve a new session from the resource limit.
KScopedResourceReservation session_reservation( KScopedResourceReservation session_reservation(GetCurrentProcessPointer(m_kernel),
GetCurrentProcessPointer(m_kernel)->GetResourceLimit(), LimitableResource::SessionCountMax); LimitableResource::SessionCountMax);
R_UNLESS(session_reservation.Succeeded(), ResultLimitReached); R_UNLESS(session_reservation.Succeeded(), ResultLimitReached);
// Allocate a session normally. // Allocate a session normally.

@ -151,8 +151,8 @@ public:
if (manager->IsDomain()) { if (manager->IsDomain()) {
context->AddDomainObject(std::move(iface)); context->AddDomainObject(std::move(iface));
} else { } else {
kernel.ApplicationProcess()->GetResourceLimit()->Reserve( ASSERT(Kernel::GetCurrentProcess(kernel).GetResourceLimit()->Reserve(
Kernel::LimitableResource::SessionCountMax, 1); Kernel::LimitableResource::SessionCountMax, 1));
auto* session = Kernel::KSession::Create(kernel); auto* session = Kernel::KSession::Create(kernel);
session->Initialize(nullptr, 0); session->Initialize(nullptr, 0);

@ -28,7 +28,6 @@ void Controller::ConvertCurrentObjectToDomain(HLERequestContext& ctx) {
void Controller::CloneCurrentObject(HLERequestContext& ctx) { void Controller::CloneCurrentObject(HLERequestContext& ctx) {
LOG_DEBUG(Service, "called"); LOG_DEBUG(Service, "called");
auto& process = *ctx.GetThread().GetOwnerProcess();
auto session_manager = ctx.GetManager(); auto session_manager = ctx.GetManager();
// FIXME: this is duplicated from the SVC, it should just call it instead // FIXME: this is duplicated from the SVC, it should just call it instead
@ -36,11 +35,11 @@ void Controller::CloneCurrentObject(HLERequestContext& ctx) {
// Reserve a new session from the process resource limit. // Reserve a new session from the process resource limit.
Kernel::KScopedResourceReservation session_reservation( Kernel::KScopedResourceReservation session_reservation(
&process, Kernel::LimitableResource::SessionCountMax); Kernel::GetCurrentProcessPointer(kernel), Kernel::LimitableResource::SessionCountMax);
ASSERT(session_reservation.Succeeded()); ASSERT(session_reservation.Succeeded());
// Create the session. // Create the session.
Kernel::KSession* session = Kernel::KSession::Create(system.Kernel()); Kernel::KSession* session = Kernel::KSession::Create(kernel);
ASSERT(session != nullptr); ASSERT(session != nullptr);
// Initialize the session. // Initialize the session.
@ -50,7 +49,7 @@ void Controller::CloneCurrentObject(HLERequestContext& ctx) {
session_reservation.Commit(); session_reservation.Commit();
// Register the session. // Register the session.
Kernel::KSession::Register(system.Kernel(), session); Kernel::KSession::Register(kernel, session);
// Register with server manager. // Register with server manager.
session_manager->GetServerManager().RegisterSession(&session->GetServerSession(), session_manager->GetServerManager().RegisterSession(&session->GetServerSession(),