summaryrefslogtreecommitdiff
path: root/Kernel/Process.h
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2021-06-12 04:23:58 +0300
committerAndreas Kling <kling@serenityos.org>2021-06-29 20:53:59 +0200
commit12b6e6915034a0c0d1981caf419a35c0a8cd247e (patch)
treefa1836dceef4483c62c7c12f89fac94240d348da /Kernel/Process.h
parent1baa05d6b22916c4cfdf9834dec554dd685e8a09 (diff)
downloadserenity-12b6e6915034a0c0d1981caf419a35c0a8cd247e.zip
Kernel: Introduce the new ProcFS design
The new ProcFS design consists of two main parts: 1. The representative ProcFS class, which is derived from the FS class. The ProcFS and its inodes are much more lean - merely 3 classes to represent the common type of inodes - regular files, symbolic links and directories. They're backed by a ProcFSExposedComponent object, which is responsible for the functional operation behind the scenes. 2. The backend of the ProcFS - the ProcFSComponentsRegistrar class and all derived classes from the ProcFSExposedComponent class. These together form the entire backend and handle all the functions you can expect from the ProcFS. The ProcFSExposedComponent derived classes split to 3 types in the manner of lifetime in the kernel: 1. Persistent objects - this category includes all basic objects, like the root folder, /proc/bus folder, main blob files in the root folders, etc. These objects are persistent and cannot die ever. 2. Semi-persistent objects - this category includes all PID folders, and subdirectories to the PID folders. It also includes exposed objects like the unveil JSON'ed blob. These object are persistent as long as the the responsible process they represent is still alive. 3. Dynamic objects - this category includes files in the subdirectories of a PID folder, like /proc/PID/fd/* or /proc/PID/stacks/*. Essentially, these objects are always created dynamically and when no longer in need after being used, they're deallocated. Nevertheless, the new allocated backend objects and inodes try to use the same InodeIndex if possible - this might change only when a thread dies and a new thread is born with a new thread stack, or when a file descriptor is closed and a new one within the same file descriptor number is opened. This is needed to actually be able to do something useful with these objects. The new design assures that many ProcFS instances can be used at once, with one backend for usage for all instances.
Diffstat (limited to 'Kernel/Process.h')
-rw-r--r--Kernel/Process.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/Kernel/Process.h b/Kernel/Process.h
index 8359ed0171..5b1bc7bd65 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -17,6 +17,7 @@
#include <AK/WeakPtr.h>
#include <AK/Weakable.h>
#include <Kernel/API/Syscall.h>
+#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/FileSystem/InodeMetadata.h>
#include <Kernel/Forward.h>
#include <Kernel/FutexQueue.h>
@@ -129,6 +130,7 @@ class Process
friend class Thread;
friend class CoreDump;
+ friend class ProcFSProcessFileDescriptions;
// Helper class to temporarily unprotect a process's protected data so you can write to it.
class ProtectedDataMutationScope {
@@ -169,6 +171,7 @@ public:
static RefPtr<Process> create_kernel_process(RefPtr<Thread>& first_thread, String&& name, void (*entry)(void*), void* entry_data = nullptr, u32 affinity = THREAD_AFFINITY_DEFAULT);
static RefPtr<Process> create_user_process(RefPtr<Thread>& first_thread, const String& path, uid_t, gid_t, ProcessID ppid, int& error, Vector<String>&& arguments = Vector<String>(), Vector<String>&& environment = Vector<String>(), TTY* = nullptr);
+ static void register_new(Process&);
~Process();
static Vector<ProcessID> all_pids();
@@ -585,23 +588,41 @@ private:
static constexpr int m_max_open_file_descriptors { FD_SETSIZE };
+public:
class FileDescriptionAndFlags {
+ friend class FileDescriptionRegistrar;
+
public:
operator bool() const { return !!m_description; }
+ bool is_valid() const { return !m_description.is_null(); }
+
FileDescription* description() { return m_description; }
const FileDescription* description() const { return m_description; }
-
+ InodeIndex global_procfs_inode_index() const { return m_global_procfs_inode_index; }
u32 flags() const { return m_flags; }
void set_flags(u32 flags) { m_flags = flags; }
void clear();
void set(NonnullRefPtr<FileDescription>&&, u32 flags = 0);
+ void refresh_inode_index();
private:
RefPtr<FileDescription> m_description;
u32 m_flags { 0 };
+
+ // Note: This is needed so when we generate inodes for ProcFS, we know that
+ // we assigned a global Inode index to it so we can use it later
+ InodeIndex m_global_procfs_inode_index;
};
+
+ // FIXME: We create a copy when trying to iterate the Vector because
+ // we don't want to put lots of locking when accessing this Vector.
+ // Maybe try to encapsulate the Vector inside a protective class with locking
+ // mechanism.
+ Vector<FileDescriptionAndFlags> fds() const { return m_fds; }
+
+private:
Vector<FileDescriptionAndFlags> m_fds;
mutable RecursiveSpinLock m_thread_list_lock;
@@ -638,6 +659,7 @@ private:
FutexQueues m_futex_queues;
SpinLock<u8> m_futex_lock;
+ mutable SpinLock<u8> m_fds_lock;
// This member is used in the implementation of ptrace's PT_TRACEME flag.
// If it is set to true, the process will stop at the next execve syscall