From 633006926fd26eba7116526c760d2ab7d2a55fe3 Mon Sep 17 00:00:00 2001 From: Liav A Date: Thu, 12 Jan 2023 22:06:51 +0200 Subject: Kernel: Make the Jails' internal design a lot more sane This is done with 2 major steps: 1. Remove JailManagement singleton and use a structure that resembles what we have with the Process object. This is required later for the second step in this commit, but on its own, is a major change that removes this clunky singleton that had no real usage by itself. 2. Use IntrusiveLists to keep references to Process objects in the same Jail so it will be much more straightforward to iterate on this kind of objects when needed. Previously we locked the entire Process list and we did a simple pointer comparison to check if the checked Process we iterate on is in the same Jail or not, which required taking multiple Spinlocks in a very clumsy and heavyweight way. --- Kernel/Jail.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'Kernel/Jail.h') diff --git a/Kernel/Jail.h b/Kernel/Jail.h index bfbc6c833a..355c15c4ab 100644 --- a/Kernel/Jail.h +++ b/Kernel/Jail.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Liav A. + * Copyright (c) 2022-2023, Liav A. * * SPDX-License-Identifier: BSD-2-Clause */ @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -16,19 +17,21 @@ #include #include #include -#include namespace Kernel { -class JailManagement; +class ProcessList; AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, JailIndex); class Jail : public RefCounted { - friend class JailManagement; public: - static ErrorOr> create(Badge, NonnullOwnPtr, JailIndex); + NonnullRefPtr process_list(); + + static LockRefPtr find_by_index(JailIndex); + static ErrorOr> create(NonnullOwnPtr name); + static ErrorOr for_each_when_process_is_not_jailed(Function(Jail const&)> callback); StringView name() const { return m_name->view(); } JailIndex index() const { return m_index; } @@ -37,12 +40,19 @@ public: SpinlockProtected& attach_count() { return m_attach_count; } private: - Jail(NonnullOwnPtr, JailIndex); + Jail(NonnullOwnPtr, JailIndex, NonnullRefPtr); NonnullOwnPtr m_name; JailIndex const m_index; - IntrusiveListNode> m_jail_list_node; + IntrusiveListNode> m_list_node; + +public: + using List = IntrusiveListRelaxedConst<&Jail::m_list_node>; + +private: + NonnullRefPtr m_process_list; + SpinlockProtected m_attach_count { 0 }; }; -- cgit v1.2.3