Commit Graph

1084 Commits

Author SHA1 Message Date
Andreas Kling
a9204510a4 Kernel: Make file description lookup return KResultOr
Instead of checking it at every call site (to generate EBADF), we make
file_description(fd) return a KResultOr<NonnullRefPtr<FileDescription>>.

This allows us to wrap all the calls in TRY(). :^)

The only place that got a little bit messier from this is sys$mount(),
and there's a whole bunch of things there in need of cleanup.
2021-09-05 18:36:13 +02:00
Andreas Kling
83fed5b2de Kernel: Tidy up Memory::AddressSpace construction
- Return KResultOr<T> in places
- Propagate errors
- Use TRY()
2021-09-05 15:13:20 +02:00
Andreas Kling
ae885b188f Kernel: Use TRY() when creating first thread in a new process 2021-09-05 14:08:12 +02:00
Andreas Kling
2ab8fd89fc Kernel: Simplify Process::get_syscall_path_argument() 2021-09-05 14:08:12 +02:00
Andreas Kling
f30eae7e7a Kernel: Use TRY() in some Process functions 2021-09-05 14:08:12 +02:00
Andreas Kling
12f820eb08 Kernel: Make Process::try_create() propagate errors better 2021-09-04 23:11:04 +02:00
Andreas Kling
3b995c6d01 Kernel: Tidy up Process::try_create_user_process()
This function is currently only ever used to create the init process
(SystemServer). It had a few idiosyncratic things about it that this
patch cleans up:

- Errors were returned in an int& out-param.
- It had a path for non-0 process PIDs which was never taken.
2021-09-04 23:11:04 +02:00
Andreas Kling
ba1a6ca971 Kernel: Move pledge verification into Process member functions
REQUIRE_PROMISE and REQUIRE_NO_PROMISES were macros for some reason,
and used all over the place.

This patch adds require_promise(Pledge) and require_no_promises()
to Process and makes the macros call these on the current process
instead of inlining code everywhere.
2021-09-04 23:11:04 +02:00
Andreas Kling
5d5a3708c4 Kernel: Rename Thread::clone() => try_clone() and propagate errors 2021-09-04 23:11:04 +02:00
Andreas Kling
cfc1a628d5 Kernel: Add missing error check after Process::try_create()
As the name now suggests, this API can fail. :^)
2021-09-04 23:11:04 +02:00
Andreas Kling
5e2e17c38c Kernel: Rename Process::create() => try_create() 2021-09-04 23:11:03 +02:00
Andreas Kling
d065de1fcf Kernel: Add missing error check when opening TTY for a new process 2021-09-04 13:08:37 +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
Andrew Kaster
4f2520674c Kernel: Don't acquire Mutex for hostname() before scheduling is enabled
There's no reason to acquire the mutex for this resource before APs are
booted, before scheduling is enabled, and before interrupts are enabled.
2021-08-28 20:53:38 +02:00
Andrew Kaster
dea62fe93c Kernel: Guard the all processes list with a Spinlock rather than a Mutex
There are callers of processes().with or processes().for_each that
require interrupts to be disabled. Taking a Mutexe with interrupts
disabled is a recipe for deadlock, so convert this to a Spinlock.
2021-08-28 20:53:38 +02:00
Andreas Kling
e51a5e2d5d Kernel: Rename some BlockerSets to foo_blocker_set
Cleanup after renaming BlockCondition to BlockerSet.
2021-08-23 01:42:04 +02:00
Andreas Kling
85546af417 Kernel: Rename Thread::BlockCondition to BlockerSet
This class represents a set of Thread::Blocker objects attached to
something that those blockers are waiting on.
2021-08-23 00:02:09 +02:00
Andreas Kling
bcd2025311 Everywhere: Core dump => Coredump
We all know what a coredump is, and it feels more natural to refer to
it as a coredump (most code already does), so let's be consistent.
2021-08-23 00:02:09 +02:00
Andreas Kling
c922a7da09 Kernel: Rename ScopedSpinlock => SpinlockLocker
This matches MutexLocker, and doesn't sound like it's a lock itself.
2021-08-22 03:34:10 +02:00
Andreas Kling
55adace359 Kernel: Rename SpinLock => Spinlock 2021-08-22 03:34:10 +02:00
Andreas Kling
c2fc33becd Kernel: Rename ProtectedValue<T> => MutexProtected<T>
Let's make it obvious what we're protecting it with.
2021-08-22 03:34:09 +02:00
Idan Horowitz
cf271183b4 Kernel: Make Process::current() return a Process& instead of Process*
This has several benefits:
1) We no longer just blindly derefence a null pointer in various places
2) We will get nicer runtime error messages if the current process does
turn out to be null in the call location
3) GCC no longer complains about possible nullptr dereferences when
compiling without KUBSAN
2021-08-19 23:49:53 +02:00
Andreas Kling
961f727448 Kernel: Consolidate a bunch of i386/x86_64 code paths
Add some arch-specific getters and setters that allow us to merge blocks
that were previously specific to either ARCH(I386) or ARCH(X86_64).
2021-08-19 23:22:02 +02:00
Ali Mohammad Pur
e9feced041 Kernel: Add a Process::FileDescriptions::get_if_valid(index) API
Note that this is not the same as ::at(index), which has a different
precondition ("allocated" vs "valid").
2021-08-16 21:16:14 +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
98408b8920 Kernel: Don't hold the process list lock while destructing the process
Once we remove the process from the process list, we're free to do
whatever we want without any locks.
2021-08-15 12:17:29 +02:00
sin-ack
18f260b78b Kernel: Handle removal of Process from list before unref
This makes the following scenario impossible with an SMP setup:

1) CPU A enters unref() and decrements the link count to 0.
2) CPU B sees the process in the process list and ref()s it.
3) CPU A removes the process from the list and continues destructing.
4) CPU B is now holding a destructed Process object.

By holding the process list lock before doing anything with it, we
ensure that other CPUs can't find this process in the middle of it being
destructed.
2021-08-15 02:27:13 +02:00
sin-ack
2830a0ecda Kernel: Move ProcFS related overrides in Process to ProcessProcFSTraits
This allows us to 1) let go of the Process when an inode is ref'ing for
ProcFSExposedComponent related reasons, and 2) change our ref/unref
implementation.
2021-08-15 02:27:13 +02:00
Andreas Kling
7676edfb9b Kernel: Stop allowing implicit conversion from KResult to int
This patch removes KResult::operator int() and deals with the fallout.
This forces a lot of code to be more explicit in its handling of errors,
greatly improving readability.
2021-08-14 15:19:00 +02:00
Brian Gianforcaro
40a942d28b Kernel: Remove char* versions of path argument / kstring copy methods
The only two paths for copying strings in the kernel should be going
through the existing Userspace<char const*>, or StringArgument methods.

Lets enforce this by removing the option for using the raw cstring APIs
that were previously available.
2021-08-13 11:08:11 +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
Liav A
04c2addaa8 Kernel: Fail process creating earlier if can't create AddressSpace
It makes more sense to fail the Process creation earlier if we can't
create an AddressSpace for the new Process.
2021-08-12 20:57:32 +02:00
Liav A
01b79910b3 Kernel/Process: Move protected values to the end of the object
The compiler can re-order the structure (class) members if that's
necessary, so if we make Process to inherit from ProcFSExposedComponent,
even if the declaration is to inherit first from ProcessBase, then from
ProcFSExposedComponent and last from Weakable<Process>, the members of
class ProcFSExposedComponent (including the Ref-counted parts) are the
first members of the Process class.

This problem made it impossible to safely use the current toggling
method with the write-protection bit on the ProcessBase members, so
instead of inheriting from it, we make its members the last ones in the
Process class so we can safely locate and modify the corresponding page
write protection bit of these values.

We make sure that the Process class doesn't expand beyond 8192 bytes and
the protected values are always aligned on a page boundary.
2021-08-12 20:57:32 +02:00
Andreas Kling
5e27861c2e Kernel: Don't ask RTC for current time when generating coredumps
Use kgettimeofday() like everybody else. :^)
2021-08-11 12:34:55 +02:00
Andreas Kling
0910979dec Kernel: Remove unused Process::FileDescriptions::fd_flags() 2021-08-08 14:24:55 +02:00
Andreas Kling
db14092d8f Kernel: Remove unused Process::all_pids() 2021-08-08 14:24:54 +02:00
Andreas Kling
c94c15d45c Everywhere: Replace AK::Singleton => Singleton 2021-08-08 00:03:45 +02:00
Andreas Kling
15d033b486 Kernel: Remove unused Process pointer in Memory::AddressSpace
Nobody was using the back-pointer to the process, so let's lose it.
2021-08-08 00:03:45 +02:00
Andreas Kling
b197fc40a7 Kernel: Port process thread lists to SpinLockProtectedValue
I had to move the thread list out of the protected base area of Process
so that it could live with its lock (which needs to be mutable).
Ideally it would live in the protected area, so maybe we can figure out
a way to do that later.
2021-08-07 13:46:16 +02:00
Andreas Kling
d6667e4cb8 Kernel: Port process groups to SpinLockProtectedValue 2021-08-07 13:30:59 +02:00
Jean-Baptiste Boric
08891e82a5 Kernel: Migrate process list locking to ProtectedValue
The existing recursive spinlock is repurposed for profiling only, as it
was shared with the process list.
2021-08-07 11:48:00 +02:00
Jean-Baptiste Boric
8554b66d09 Kernel: Make process list a singleton 2021-08-07 11:48:00 +02:00
Jean-Baptiste Boric
626b99ce1c Kernel: Migrate hostname locking to ProtectedValue 2021-08-07 11:48:00 +02:00
Andreas Kling
2cd8b21974 Kernel: Add convenience values to the Memory::Region::Access enum
Instead of `Memory::Region::Access::Read | Memory::Region::AccessWrite`
you can now say `Memory::Region::Access::ReadWrite`.
2021-08-06 22:25:00 +02:00
Andreas Kling
208147c77c Kernel: Rename Process::space() => Process::address_space()
We commonly talk about "a process's address space" so let's nudge the
code towards matching how we talk about it. :^)
2021-08-06 14:05:58 +02:00
Andreas Kling
b7476d7a1b Kernel: Rename Memory::Space => Memory::AddressSpace 2021-08-06 14:05:58 +02:00
Andreas Kling
93d98d4976 Kernel: Move Kernel/Memory/ code into Kernel::Memory namespace 2021-08-06 14:05:58 +02:00
Andreas Kling
a1d7ebf85a Kernel: Rename Kernel/VM/ to Kernel/Memory/
This directory isn't just about virtual memory, it's about all kinds
of memory management.
2021-08-06 14:05:58 +02:00
Andreas Kling
33adc3a42d Kernel: Store coredump metadata properties as KStrings
This patch also replaces the HashMap previously used to store coredump
properties with a plain AK::Array.
2021-08-06 00:37:47 +02:00
Andreas Kling
d5d8fba579 Kernel: Store Thread name as a KString 2021-08-06 00:37:47 +02:00