summaryrefslogtreecommitdiff
path: root/Kernel/Jail.h
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2023-01-12 22:06:51 +0200
committerAndrew Kaster <andrewdkaster@gmail.com>2023-03-12 10:21:59 -0600
commit633006926fd26eba7116526c760d2ab7d2a55fe3 (patch)
treece1671b7582463e28db9c6746a17414ddfb6573b /Kernel/Jail.h
parent9b297c634f82479f3b6851b77f9af9e1486c4546 (diff)
downloadserenity-633006926fd26eba7116526c760d2ab7d2a55fe3.zip
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.
Diffstat (limited to 'Kernel/Jail.h')
-rw-r--r--Kernel/Jail.h24
1 files changed, 17 insertions, 7 deletions
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. <liavalb@hotmail.co.il>
+ * Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -9,6 +9,7 @@
#include <AK/DistinctNumeric.h>
#include <AK/Error.h>
#include <AK/IntrusiveList.h>
+#include <AK/IntrusiveListRelaxedConst.h>
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Try.h>
@@ -16,19 +17,21 @@
#include <Kernel/KString.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Locking/SpinlockProtected.h>
-#include <Kernel/Process.h>
namespace Kernel {
-class JailManagement;
+class ProcessList;
AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, JailIndex);
class Jail : public RefCounted<Jail> {
- friend class JailManagement;
public:
- static ErrorOr<NonnullLockRefPtr<Jail>> create(Badge<JailManagement>, NonnullOwnPtr<KString>, JailIndex);
+ NonnullRefPtr<ProcessList> process_list();
+
+ static LockRefPtr<Jail> find_by_index(JailIndex);
+ static ErrorOr<NonnullLockRefPtr<Jail>> create(NonnullOwnPtr<KString> name);
+ static ErrorOr<void> for_each_when_process_is_not_jailed(Function<ErrorOr<void>(Jail const&)> callback);
StringView name() const { return m_name->view(); }
JailIndex index() const { return m_index; }
@@ -37,12 +40,19 @@ public:
SpinlockProtected<size_t, LockRank::None>& attach_count() { return m_attach_count; }
private:
- Jail(NonnullOwnPtr<KString>, JailIndex);
+ Jail(NonnullOwnPtr<KString>, JailIndex, NonnullRefPtr<ProcessList>);
NonnullOwnPtr<KString> m_name;
JailIndex const m_index;
- IntrusiveListNode<Jail, NonnullLockRefPtr<Jail>> m_jail_list_node;
+ IntrusiveListNode<Jail, NonnullLockRefPtr<Jail>> m_list_node;
+
+public:
+ using List = IntrusiveListRelaxedConst<&Jail::m_list_node>;
+
+private:
+ NonnullRefPtr<ProcessList> m_process_list;
+
SpinlockProtected<size_t, LockRank::None> m_attach_count { 0 };
};