PatchworkOS  621ae6b
A non-POSIX operating system.
Loading...
Searching...
No Matches
procfs.h
Go to the documentation of this file.
1#pragma once
2
4#include <kernel/fs/cwd.h>
5#include <kernel/fs/devfs.h>
8#include <kernel/ipc/note.h>
9#include <kernel/mem/space.h>
10#include <kernel/proc/group.h>
11#include <kernel/sched/sched.h>
12#include <kernel/sched/wait.h>
13#include <kernel/sync/futex.h>
14#include <kernel/utils/ref.h>
15
16#include <stdatomic.h>
17
18/**
19 * @brief Process filesystem.
20 * @defgroup kernel_fs_procfs Process Filesystem
21 * @ingroup kernel_fs
22 *
23 * The "procfs" filesystem is used to expose process information and control interfaces to user space.
24 *
25 * Each process has its own directory whose name is the process ID and for convenience,
26 * `/self` is a dynamic symbolic link to the current process's directory.
27 *
28 * Unlike traditional UNIX systems, security is implemented such that a process can access all files of all processes
29 * that it could propagate mounts to, meaning any processes in its namespace or in child namespaces. If a process cant
30 * propagate mounts to a another process then certain entries will appear to not exist. This is implemented using the
31 * "revalidate()" dentry operation.
32 *
33 * @see kernel_fs_namespace
34 *
35 * Included below is a list of all entries found in each processes directory. All entries with restricted visibility
36 * will be marked with `(restricted)`.
37 *
38 * @note Anytime a file descriptor is referred to it is from the perspective of the target process unless otherwise
39 * stated.
40 *
41 * ## prio (restricted)
42 *
43 * A readable and writable file that contains the scheduling priority of the process.
44 *
45 * Format:
46 *
47 * ```
48 * %llu
49 * ```
50 *
51 * ## cwd (restricted)
52 *
53 * A readable and writable file that contains the current working directory of the process.
54 *
55 * Format:
56 *
57 * ```
58 * %s
59 * ```
60 *
61 * ## cmdline
62 *
63 * A readable file that contains the command line arguments of the process (argv).
64 *
65 * Format:
66 *
67 * ```
68 * %s\0%s\0...%s\0
69 * ```
70 *
71 * ## note (restricted)
72 *
73 * A writable file that sends notes to the process. Writing to this file will enqueue that data as a
74 * note in the note queue of one of the process's threads.
75 *
76 * @see kernel_ipc_note
77 *
78 * ## notegroup (restricted)
79 *
80 * A writeable file that sends notes to every process in the group of the target process.
81 *
82 * @see kernel_ipc_note
83 *
84 * ## group (restricted)
85 *
86 * Opening this file returns a file descriptor referring to the group. This file descriptor can be used with the
87 * `setgroup` command in the `ctl` file to switch groups.
88 *
89 * ## pid
90 *
91 * A readable file that contains the process ID.
92 *
93 * Format:
94 * ```
95 * %llu
96 * ```
97 *
98 * ## wait
99 *
100 * A readable and pollable file that can be used to wait for the process to exit. Reading
101 * from this file will block until the process has exited.
102 *
103 * The read value is the exit status of the process, usually either a integer exit code or a string describing the
104 * reason for termination often the note that caused it.
105 *
106 * Format:
107 *
108 * ```
109 * %s
110 * ```
111 *
112 * ## perf
113 *
114 * A readable file that contains performance statistics for the process.
115 *
116 * Format:
117 *
118 * ```
119 * user_clocks kernel_sched_clocks start_clocks user_pages thread_count
120 * %llu %llu %llu %llu %llu
121 * ```
122 *
123 * ## ns (restricted)
124 *
125 * Opening this file returns a file descriptor referring to the namespace. This file descriptor can be used with the
126 * `setns` command in the `ctl` file to switch namespaces.
127 *
128 * ## ctl (restricted)
129 *
130 * A writable file that can be used to control certain aspects of the process, such as closing file descriptors.
131 *
132 * Included is a list of all supported commands.
133 *
134 * ### close <fd>
135 *
136 * Closes the specified file descriptor in the process.
137 *
138 * ### close <minfd> <maxfd>
139 *
140 * Closes the range `[minfd, maxfd)` of file descriptors in the process.
141 *
142 * Note that specifying `-1` as `maxfd` will close all file descriptors from `minfd` to the maximum allowed file
143 * descriptor.
144 *
145 * ### dup2 <oldfd> <newfd>
146 *
147 * Duplicates the specified old file descriptor to the new file descriptor in the process.
148 *
149 * ### bind <target> <source>
150 *
151 * Bind a source path from the writing process to a target path in the processes namespace.
152 *
153 * Path flags for controlling the bind behaviour should to be specified in the target path.
154 *
155 * @see kernel_fs_path for information on path flags.
156 *
157 * ### mount <mountpoint> <fs> [device]
158 *
159 * Mounts a filesystem at the specified mountpoint in the process's namespace, optionally with a device.
160 *
161 * @see kernel_fs_path for information on path flags.
162 *
163 * ### touch <path>
164 *
165 * Open the specified path in the process and immediately close it.
166 *
167 * ### start
168 *
169 * Starts the process if it was previously suspended.
170 *
171 * ### kill [status]
172 *
173 * Sends a kill note to all threads in the process, effectively terminating it. The optional status will be set as the
174 * processes exit status.
175 *
176 * ### setns <fd>
177 *
178 * Sets the namespace of the process to the one referred to by the file descriptor.
179 *
180 * The file descriptor must be one that was opened from `/[pid]/ns`.
181 *
182 * ### setgroup <fd>
183 *
184 * Sets the group of the process to the one referred to by the file descriptor.
185 *
186 * The file descriptor must be one that was opened from `/[pid]/group`.
187 *
188 * ## env (restricted)
189 *
190 * A directory that contains the environment variables of the process. Each environment variable is represented as a
191 * readable and writable file whose name is the name of the variable and whose content is the value of the variable.
192 *
193 * To add or modify an environment variable, create or write to a file with the name of the variable. To remove an
194 * environment variable, delete the corresponding file.
195 *
196 * @{
197 */
198
199/**
200 * @brief Process filesystem name.
201 */
202#define PROCFS_NAME "procfs"
203
204/**
205 * @brief Register the procfs filesystem.
206 */
207void procfs_init(void);
208
209/** @} */
void procfs_init(void)
Register the procfs filesystem.
Definition procfs.c:1267