1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 22:28:11 +00:00

Kernel: Acquire reference to waitee before trying to block in sys$waitid

Previously, we would try to acquire a reference to the all processes
lock or other contended resources while holding both the scheduler lock
and the thread's blocker lock. This could lead to a deadlock if we
actually have to block on those other resources.
This commit is contained in:
Andrew Kaster 2021-08-22 22:01:04 -06:00 committed by Andreas Kling
parent dea62fe93c
commit 54161bf5b4
4 changed files with 43 additions and 66 deletions

View file

@ -15,6 +15,7 @@
#include <AK/String.h>
#include <AK/TemporaryChange.h>
#include <AK/Time.h>
#include <AK/Variant.h>
#include <AK/Vector.h>
#include <AK/WeakPtr.h>
#include <AK/Weakable.h>
@ -705,7 +706,7 @@ public:
Disowned
};
WaitBlocker(int wait_options, idtype_t id_type, pid_t id, KResultOr<siginfo_t>& result);
WaitBlocker(int wait_options, Variant<Empty, NonnullRefPtr<Process>, NonnullRefPtr<ProcessGroup>> waitee, KResultOr<siginfo_t>& result);
virtual StringView state_string() const override { return "Waiting"sv; }
virtual Type blocker_type() const override { return Type::Wait; }
virtual void will_unblock_immediately_without_blocking(UnblockImmediatelyReason) override;
@ -720,13 +721,9 @@ public:
void do_set_result(const siginfo_t&);
const int m_wait_options;
const idtype_t m_id_type;
const pid_t m_waitee_id;
KResultOr<siginfo_t>& m_result;
RefPtr<Process> m_waitee;
RefPtr<ProcessGroup> m_waitee_group;
Variant<Empty, NonnullRefPtr<Process>, NonnullRefPtr<ProcessGroup>> m_waitee;
bool m_did_unblock { false };
bool m_error { false };
bool m_got_sigchild { false };
};