Commit graph

48 commits

Author SHA1 Message Date
Andreas Kling 10fa72d451 Kernel: Use AK::Time for InodeMetadata timestamps instead of time_t
Before this change, we were truncating the nanosecond part of file
timestamps in many different places.
2022-11-24 16:56:27 +01:00
Liav A dc5b28e26c Kernel/ProcFS: Remove all unnecessary components
Now that all global nodes are located in the /sys/kernel directory, we
can safely drop the global nodes in /proc, which includes both /proc/net
and /proc/sys directories as well.
This in fact leaves the ProcFS to only have subdirectories for processes
and the "self" symbolic link to reflect the current process being run.
2022-10-25 15:33:34 -06:00
Andreas Kling 280694bb46 Kernel: Update atime/ctime/mtime timestamps atomically
Instead of having three separate APIs (one for each timestamp),
there's now only Inode::update_timestamps() and it takes 3x optional
timestamps. The non-empty timestamps are updated while holding the inode
mutex, and the outside world no longer has to look at intermediate
timestamp states.
2022-08-22 17:56:03 +02:00
Andreas Kling 11eee67b85 Kernel: Make self-contained locking smart pointers their own classes
Until now, our kernel has reimplemented a number of AK classes to
provide automatic internal locking:

- RefPtr
- NonnullRefPtr
- WeakPtr
- Weakable

This patch renames the Kernel classes so that they can coexist with
the original AK classes:

- RefPtr => LockRefPtr
- NonnullRefPtr => NonnullLockRefPtr
- WeakPtr => LockWeakPtr
- Weakable => LockWeakable

The goal here is to eventually get rid of the Lock* classes in favor of
using external locking.
2022-08-20 17:20:43 +02:00
Andreas Kling e475263113 AK+Kernel: Add AK::AtomicRefCounted and use everywhere in the kernel
Instead of having two separate implementations of AK::RefCounted, one
for userspace and one for kernelspace, there is now RefCounted and
AtomicRefCounted.
2022-08-20 17:15:52 +02:00
Liav A 38bf7863d0 Kernel: Remove PCI information node from ProcFS
The SystemMonitor program was the last client to utilize this node, and
now it is not using this node anymore, we can simply remove this for
good.
2022-07-30 23:29:07 +02:00
sin-ack 3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
Andrew Kaster 940be19259 Kernel: Create /proc/pid/cmdline to expose process arguments in procfs
In typical serenity style, they are just a JSON array
2022-06-19 09:05:35 +02:00
MacDue d951e2ca97 Kernel: Add /proc/{pid}/children to ProcFS
This exposes the child processes for a process as a directory
of symlinks to the respective /proc entries for each child.

This makes for an easier and possibly more efficient way
to find and count a process's children. Previously the only
method was to parse the entire /proc/all JSON file.
2022-05-06 02:12:51 +04:30
Idan Horowitz 086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Liav A b5ef900ccd Kernel: Don't assume paths of TTYs and pseudo terminals anymore
The obsolete ttyname and ptsname syscalls are removed.
LibC doesn't rely on these anymore, and it helps simplifying the Kernel
in many places, so it's an overall an improvement.

In addition to that, /proc/PID/tty node is removed too as it is not
needed anymore by userspace to get the attached TTY of a process, as
/dev/tty (which is already a character device) represents that as well.
2022-03-22 20:26:05 +01:00
Liav A b849e4f907 Kernel/PCI: Don't create /proc/pci if PCI is disabled
Reading from /proc/pci assumes we have PCI enabled and also enumerated.
However, if PCI is disabled for some reason, we can't allow the user to
read from it as there's no valuable data we can supply.
2022-03-02 18:41:54 +01:00
Andreas Kling 3845c90e08 Kernel: Remove unnecessary includes from Thread.h
...and deal with the fallout by adding missing includes everywhere.
2022-01-30 16:21:59 +01:00
Daniel Bertalan 8dd11ae717 Kernel+SystemServer: Add /dev/tty
This file refers to the controlling terminal associated with the current
process. It's specified by POSIX, and is used by ports like openssh to
interface with the terminal even if the standard input/output is
redirected to somewhere else.

Our implementation leverages ProcFS's existing facilities to create
process-specific symbolic links. In our setup, `/dev/tty` is a symbolic
link to `/proc/self/tty`, which itself is a symlink to the appropriate
`/dev/pts` entry. If no TTY is attached, `/dev/tty` is left dangling.
2021-12-12 22:32:35 +01:00
Hendiadyoin1 e34eb3e36d Kernel: Remove unused String.h includes
This makes searching for not yet OOM safe interfaces a bit easier.
2021-12-11 13:15:26 -08:00
James Mintram 8350b44ebd Kernel: Add an x86 include check+error in x86/CPU.h 2021-12-01 11:22:04 -08:00
Andreas Kling e08d213830 Kernel: Use DistinctNumeric for filesystem ID's
This patch adds the FileSystemID type, which is a distinct u32.
This prevents accidental conversion from arbitrary integers.
2021-11-18 21:11:30 +01:00
Andrew Kaster eb1181b898 Kernel: Convert Process-related const member functions to static
Process::get_syscall_path_argument() and
ProcFSExposedComponent::modified_time() both are independent of this.
2021-11-14 22:52:35 +01:00
Andreas Kling 5ce753b74d Kernel: Make Inode::traverse_as_directory() callback return ErrorOr
This allows us to propagate errors from inside the callback with TRY().
2021-11-10 21:58:58 +01:00
Andreas Kling 79fa9765ca Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace!
This was a slightly tedious refactoring that took a long time, so it's
not unlikely that some bugs crept in.

Nevertheless, it does pass basic functionality testing, and it's just
real nice to finally see the same pattern in all contexts. :^)
2021-11-08 01:10:53 +01:00
SeekingBlues 3d174e3ad2 Kernel/ProcFS: Provide a way to write to ProcFS inodes
ProcFSGlobalInode now calls `write_bytes()`, `truncate()` and
`set_mtime()` on its associated component. This allows us to write 0 or
1 to a ProcFSSystemBoolean component to toggle a boolean value.
2021-10-17 14:46:59 +02:00
Andreas Kling 4a9c18afb9 Kernel: Rename FileDescription => OpenFileDescription
Dr. POSIX really calls these "open file description", not just
"file description", so let's call them exactly that. :^)
2021-09-07 13:53:14 +02:00
Andreas Kling 9db8a14264 Kernel: Make SysFS and ProcFS generator functions return KResult
This allows us to propagate a whole bunch of KBufferBuilder errors.
2021-09-06 18:56:51 +02:00
Andreas Kling 2065ced8f6 Kernel: Make KBufferBuilder::append() & friends return KResult
This allows callers to react to a failed append (due to OOM.)
2021-09-06 18:56:51 +02:00
sin-ack 566c5d1e99 AK+Kernel: Move KResult.h to Kernel/API for userspace access
This commit moves the KResult and KResultOr objects to Kernel/API to
signify that they may now be freely used by userspace code at points
where a syscall-related error result is to be expected. It also exposes
KResult and KResultOr to the global namespace to make it nicer to use
for userspace code.
2021-09-05 12:54:48 +02:00
Andreas Kling 8ebf08b6c8 Kernel: Make all ProcFS and SysFS files zero-sized
There is no value in exposing particular sizes for these files.
2021-08-29 01:09:19 +02:00
Andreas Kling ae197deb6b Kernel: Strongly typed user & group ID's
Prior to this change, both uid_t and gid_t were typedef'ed to `u32`.
This made it easy to use them interchangeably. Let's not allow that.

This patch adds UserID and GroupID using the AK::DistinctNumeric
mechanism we've already been employing for pid_t/ProcessID.
2021-08-29 01:09:19 +02:00
Andreas Kling 1b739a72c2 Kernel+Userland: Remove chroot functionality
We are not using this for anything and it's just been sitting there
gathering dust for well over a year, so let's stop carrying all this
complexity around for no good reason.
2021-08-15 12:44:35 +02:00
sin-ack 748938ea59 Kernel: Handle allocation failure in ProcFS and friends
There were many places in which allocation failure was noticed but
ignored.
2021-08-15 02:27:13 +02:00
Liav A 7ba991dc37 Kernel: Steer away from heap allocations for ProcFS process data
Instead, use more static patterns to acquire that sort of data.
2021-08-12 20:57:32 +02:00
Andreas Kling 07141434e0 Kernel/ProcFS: Make various things superuser-only once again
File and directory permissions regressed with the recent ProcFS changes.
This patch restores the superuser-only permissions where appropriate.
2021-07-28 18:59:53 +02:00
Andreas Kling a3063dfd33 Kernel: Simplify ProcFS generated buffer caching
Use a Mutex instead of a SpinLock to protect the per-FileDescription
generated data cache. This allows processes to go to sleep while
waiting their turn.

Also don't try to be clever by reusing existing cache buffers.
Just allocate KBuffers as needed (and make sure to surface failures.)
2021-07-20 18:05:05 +02:00
Andreas Kling b975a74a1d Kernel/USB: Move USB bus information from /proc to /sys
This patch moves all the USB data from /proc/bus/usb to /sys/bus/usb.
2021-07-18 00:55:16 +02:00
Andreas Kling 6fae2a5f9e Kernel/ProcFS: Remove unused ProcFSExposedComponent::entries_count() 2021-07-17 23:50:01 +02:00
Andreas Kling 2da0581fd2 Kernel: Replace "folder" => "directory" everywhere
Folders are a GUI concept. File systems have directories.
2021-07-17 23:50:00 +02:00
Andreas Kling cee9528168 Kernel: Rename Lock to Mutex
Let's be explicit about what kind of lock this is meant to be.
2021-07-17 21:10:32 +02:00
Liav A bee75c1f24 Kernel/ProcFS: Allow a process directory to have a null Process pointer
In case we are about to delete the PID directory, we clear the Process
pointer. If someone still holds a reference to the PID directory (by
opening it), we still need to delete the process, but we can't delete
the directory, so we will keep it alive, but any operation on it will
fail by propogating the error to userspace about that the Process was
deleted and therefore there's no meaning to trying to do operations on
the directory.

Fixes #8576.
2021-07-14 13:40:01 +02:00
Andreas Kling 98080497d2 Kernel: Use Forward.h headers more 2021-07-11 14:14:51 +02:00
Andreas Kling fa9111ac46 Kernel: Rename ProcFSComponentsRegistrar => ProcFSComponentRegistry
This matches the formatting used in SysFS.
2021-07-11 01:40:26 +02:00
Andreas Kling c1143e1bae Kernel: Remove friend classes from ProcFSComponentsRegistrar 2021-07-11 01:39:51 +02:00
Andreas Kling 805319ed30 Kernel: Replace "Folder" => "Directory" everywhere
Folders are a GUI concept, file systems have directories. :^)
2021-07-11 01:33:40 +02:00
Andreas Kling d53d9d3677 Kernel: Rename FS => FileSystem
This matches our common naming style better.
2021-07-11 00:20:38 +02:00
Ralf Donau 6113fe4747 Kernel: Pledge promises accessible via /proc/PID/pledge 2021-07-08 01:16:26 +02:00
Liav A 32a4a4ac19 Kernel/ProcFS: Lazily allocate all sub components of a PID folder 2021-07-02 13:16:12 +02:00
Liav A 3344f91fc4 Kernel/ProcFS: Clean dead processes properly
Now we use WeakPtrs to break Ref-counting cycle. Also, we call the
prepare_for_deletion method to ensure deleted objects are ready for
deletion. This is necessary to ensure we don't keep dead processes,
which would become zombies.

In addition to that, add some debug prints to aid debug in the future.
2021-07-02 13:16:12 +02:00
Andreas Kling fd06b8b713 Kernel: ProcFS and SysFS component indices should be InodeIndex
This fixes the x86_64 kernel build. :^)
2021-06-29 23:07:02 +02:00
Liav A 1f98d7d638 Kernel/ProcFS: Tighten modified time value across the filesystem objects
It didn't make any sense to hardcode the modified time of all created
inodes with "mepoch", so we should query the procfs "backend" to get
the modified time value.
Since ProcFS is dynamically changed all the time, the modified time
equals to the querying time.
This could be changed if desired, by making the modified_time()
method virtual and overriding it in different procfs-backed objects :)
2021-06-29 20:53:59 +02:00
Liav A 12b6e69150 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.
2021-06-29 20:53:59 +02:00