core: hle: kernel: KEvent: Pass in owner KProcess on event creation.

- This is necessary to ensure resource limits are freed from the right process.
This commit is contained in:
bunnei 2022-02-21 12:31:23 -08:00
parent c7019db6f4
commit 57ebcbf2c4
4 changed files with 8 additions and 12 deletions

View File

@ -14,7 +14,7 @@ KEvent::KEvent(KernelCore& kernel_)
KEvent::~KEvent() = default; KEvent::~KEvent() = default;
void KEvent::Initialize(std::string&& name_) { void KEvent::Initialize(std::string&& name_, KProcess* owner_) {
// Increment reference count. // Increment reference count.
// Because reference count is one on creation, this will result // Because reference count is one on creation, this will result
// in a reference count of two. Thus, when both readable and // in a reference count of two. Thus, when both readable and
@ -30,10 +30,8 @@ void KEvent::Initialize(std::string&& name_) {
writable_event.Initialize(this, name_ + ":Writable"); writable_event.Initialize(this, name_ + ":Writable");
// Set our owner process. // Set our owner process.
owner = kernel.CurrentProcess(); owner = owner_;
if (owner) {
owner->Open(); owner->Open();
}
// Mark initialized. // Mark initialized.
name = std::move(name_); name = std::move(name_);
@ -47,10 +45,8 @@ void KEvent::Finalize() {
void KEvent::PostDestroy(uintptr_t arg) { void KEvent::PostDestroy(uintptr_t arg) {
// Release the event count resource the owner process holds. // Release the event count resource the owner process holds.
KProcess* owner = reinterpret_cast<KProcess*>(arg); KProcess* owner = reinterpret_cast<KProcess*>(arg);
if (owner) {
owner->GetResourceLimit()->Release(LimitableResource::Events, 1); owner->GetResourceLimit()->Release(LimitableResource::Events, 1);
owner->Close(); owner->Close();
} }
}
} // namespace Kernel } // namespace Kernel

View File

@ -22,7 +22,7 @@ public:
explicit KEvent(KernelCore& kernel_); explicit KEvent(KernelCore& kernel_);
~KEvent() override; ~KEvent() override;
void Initialize(std::string&& name); void Initialize(std::string&& name, KProcess* owner_);
void Finalize() override; void Finalize() override;

View File

@ -2332,7 +2332,7 @@ static ResultCode CreateEvent(Core::System& system, Handle* out_write, Handle* o
R_UNLESS(event != nullptr, ResultOutOfResource); R_UNLESS(event != nullptr, ResultOutOfResource);
// Initialize the event. // Initialize the event.
event->Initialize("CreateEvent"); event->Initialize("CreateEvent", kernel.CurrentProcess());
// Commit the thread reservation. // Commit the thread reservation.
event_reservation.Commit(); event_reservation.Commit();

View File

@ -43,7 +43,7 @@ Kernel::KEvent* ServiceContext::CreateEvent(std::string&& name) {
} }
// Initialize the event. // Initialize the event.
event->Initialize(std::move(name)); event->Initialize(std::move(name), process);
// Commit the thread reservation. // Commit the thread reservation.
event_reservation.Commit(); event_reservation.Commit();