blob: 2e9985762c35c942dee798d9ca8098f3a3778541 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
/*
* Copyright (c) 2022-2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#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>
#include <AK/Types.h>
#include <Kernel/KString.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Locking/SpinlockProtected.h>
#include <Kernel/Process.h>
namespace Kernel {
class ProcessList;
AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, JailIndex);
class Jail : public RefCounted<Jail> {
public:
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; }
void detach(Badge<Process>);
SpinlockProtected<size_t, LockRank::None>& attach_count() { return m_attach_count; }
private:
Jail(NonnullOwnPtr<KString>, JailIndex, NonnullRefPtr<ProcessList>);
NonnullOwnPtr<KString> m_name;
JailIndex const m_index;
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 };
};
}
|