mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
![Liav A](/assets/img/avatar_default.png)
Our implementation for Jails resembles much of how FreeBSD jails are working - it's essentially only a matter of using a RefPtr in the Process class to a Jail object. Then, when we iterate over all processes in various cases, we could ensure if either the current process is in jail and therefore should be restricted what is visible in terms of PID isolation, and also to be able to expose metadata about Jails in /sys/kernel/jails node (which does not reveal anything to a process which is in jail). A lifetime model for the Jail object is currently plain simple - there's simpy no way to manually delete a Jail object once it was created. Such feature should be carefully designed to allow safe destruction of a Jail without the possibility of releasing a process which is in Jail from the actual jail. Each process which is attached into a Jail cannot leave it until the end of a Process (i.e. when finalizing a Process). All jails are kept being referenced in the JailManagement. When a last attached process is finalized, the Jail is automatically destroyed.
35 lines
745 B
C++
35 lines
745 B
C++
/*
|
|
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <Kernel/Jail.h>
|
|
|
|
namespace Kernel {
|
|
|
|
ErrorOr<NonnullLockRefPtr<Jail>> Jail::create(Badge<JailManagement>, NonnullOwnPtr<KString> name, JailIndex index)
|
|
{
|
|
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) Jail(move(name), index));
|
|
}
|
|
|
|
Jail::Jail(NonnullOwnPtr<KString> name, JailIndex index)
|
|
: m_name(move(name))
|
|
, m_index(index)
|
|
{
|
|
}
|
|
|
|
void Jail::detach(Badge<Process>)
|
|
{
|
|
VERIFY(ref_count() > 0);
|
|
m_attach_count.with([&](auto& my_attach_count) {
|
|
VERIFY(my_attach_count > 0);
|
|
my_attach_count--;
|
|
if (my_attach_count == 0) {
|
|
m_jail_list_node.remove();
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|