summaryrefslogtreecommitdiff
path: root/Kernel/Process.cpp
AgeCommit message (Collapse)Author
2022-07-27Everywhere: Make the codebase more architecture awareUndefine
2022-07-22Kernel+LibC: Don't hardcode the maximum signal number everywhereTim Schumacher
2022-07-12Everywhere: Add sv suffix to strings relying on StringView(char const*)sin-ack
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-05Kernel: Copy signal handlers when forkingTim Schumacher
2022-06-02Kernel: Implement InterruptDisabler using generic Processor functionsTimon Kruiper
Now that the code does not use architectural specific code, it is moved to the generic Arch directory and the paths are modified accordingly.
2022-04-09Kernel: Remove big lock from `sys$set_coredump_metadata`Luke Wilde
The only requirement for this syscall is to make Process::m_coredump_properties SpinlockProtected.
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-08Kernel: Panic if the init process diesDaniel Bertalan
If init crashes, all other userspace processes exit too, thus rendering the system unusable. Previously, the kernel would still keep running even without a userland, showing just a black screen without any indication of the issue. We now panic the kernel, which shows a message on the console. In the case of the CI runners, it shuts down the virtual machine, so we don't have to wait for the 1 hour timeout if an issue arises with SystemServer.
2022-03-08Kernel: Put Process unveil state in a SpinlockProtected containerAndreas Kling
This makes path resolution safe to perform without holding the big lock.
2022-03-08Kernel: Put Process's current directory in a SpinlockProtectedAndreas Kling
Also let's call it "current_directory" instead of "cwd" everywhere.
2022-03-04Kernel: Save and restore FPU state on signal dispatch on i386/x86_64Ali Mohammad Pur
2022-03-04Kernel: Add support for SA_SIGINFOAli Mohammad Pur
We currently don't really populate most of the fields, but that can wait :^)
2022-03-04Kernel: Comment the living daylights out of signal trampoline/sigreturnAli Mohammad Pur
Mere mortals like myself cannot understand more than two lines of assembly without a million comments explaining what's happening, so do that and make sure no one has to go on a wild stack state chase when hacking on these.
2022-03-04Kernel: Move signal handlers from being thread state to process stateAli Mohammad Pur
POSIX requires that sigaction() and friends set a _process-wide_ signal handler, so move signal handlers and flags inside Process. This also fixes a "pid/tid confusion" FIXME, as we can now send the signal to the process and let that decide which thread should get the signal (which is the thread with tid==pid, but that's now the Process's problem). Note that each thread still retains its signal mask, as that is local to each thread.
2022-02-27Kernel: Add OpenFileDescriptions::try_enumerate for fallible iterationIdan Horowitz
This API will allow users to short circuit iteration and properly propagate errors.
2022-02-21Kernel: VERIFY that signals are not sent to Kernel processesIdan Horowitz
Kernel processes can't handle signals, nor should they ever receive any
2022-02-21Kernel: Stop sending SIGCHLD to kernel parent processesIdan Horowitz
Kernel processes cannot handle signals.
2022-02-16AK+Kernel: Specialize Trie for NNOP<KString> and use it in UnveilNodeIdan Horowitz
This let's us avoid the infallible String allocations.
2022-02-15AK+Kernel: OOM-harden most parts of TrieAli Mohammad Pur
The only part of Unveil that can't handle OOM gracefully is the String::formatted() use in the node metadata.
2022-02-13Kernel: Use try_make_weak_ptr() instead of make_weak_ptr()Idan Horowitz
2022-01-30Kernel: Remove unnecessary includes from Thread.hAndreas Kling
...and deal with the fallout by adding missing includes everywhere.
2022-01-29Kernel: Stop using HashMap in MutexIdan Horowitz
This commit removes the usage of HashMap in Mutex, thereby making Mutex be allocation-free. In order to achieve this several simplifications were made to Mutex, removing unused code-paths and extra VERIFYs: * We no longer support 'upgrading' a shared lock holder to an exclusive holder when it is the only shared holder and it did not unlock the lock before relocking it as exclusive. NOTE: Unlike the rest of these changes, this scenario is not VERIFY-able in an allocation-free way, as a result the new LOCK_SHARED_UPGRADE_DEBUG debug flag was added, this flag lets Mutex allocate in order to detect such cases when debugging a deadlock. * We no longer support checking if a Mutex is locked by the current thread when the Mutex was not locked exclusively, the shared version of this check was not used anywhere. * We no longer support force unlocking/relocking a Mutex if the Mutex was not locked exclusively, the shared version of these functions was not used anywhere.
2022-01-29Kernel: Switch process file descriptor table from spinlock to mutexAndreas Kling
There's no reason for this to use a spinlock. Instead, let's allow threads to block if someone else is using the descriptor table.
2022-01-29Kernel: Convert process file descriptor table to a SpinlockProtectedAndreas Kling
Instead of manually locking in the various member functions of Process::OpenFileDescriptions, simply wrap it in a SpinlockProtected.
2022-01-27Kernel: Don't mess with thread state in Process::do_exec()Andreas Kling
We were marking the execing thread as Runnable near the end of Process::do_exec(). This was necessary for exec in processes that had never been scheduled yet, which is a specific edge case that only applies to the very first userspace process (normally SystemServer). At this point, such threads are in the Invalid state. In the common case (normal userspace-initiated exec), making the current thread Runnable meant that we switched away from its current state: Running. As the thread is indeed running, that's a bogus change! This created a short time window in which the thread state was bogus, and any attempt to block the thread would panic the kernel (due to a bogus thread state in Thread::block() leading to VERIFY_NOT_REACHED().) Fix this by not touching the thread state in Process::do_exec() and instead make the first userspace thread Runnable directly after calling Process::exec() on it in try_create_userspace_process(). It's unfortunate that exec() can be called both on the current thread, and on a new thread that has never been scheduled. It would be good to not have the latter edge case, but fixing that will require larger architectural changes outside the scope of this fix.
2022-01-26Kernel: Ignore allocation failures when appending threads to coredumpIdan Horowitz
We shouldn't panic due to a failure in coredump generation
2022-01-13Kernel: Perform exec-into-new-image directly in sys$execve()Andreas Kling
This ensures that everything allocated on the stack in Process::exec() gets cleaned up. We had a few leaks related to the parsing of shebang (#!) executables that get fixed by this.
2022-01-13Kernel: Convert hostname to KStringIdan Horowitz
2022-01-13Kernel: Make Process::dump_perfcore OOM-fallible using KStringIdan Horowitz
2022-01-12Kernel: Make PerformanceEventBuffer::add_process fallible with ErrorOrIdan Horowitz
2022-01-07Everywhere: Fix many spelling errorsmjz19910
2021-12-30Kernel: Tighten String-related includesDaniel Bertalan
2021-12-29Kernel: Add verification promise violations are propagated properlyBrian Gianforcaro
This change adds a thread member variable to track if we have a pending promise violation on a kernel thread. This ensures that all code properly propagates promise violations up to the syscall handler. Suggested-by: Andreas Kling <kling@serenityos.org>
2021-12-29Kernel: Handle promise violations in the syscall handlerBrian Gianforcaro
Previously we would crash the process immediately when a promise violation was found during a syscall. This is error prone, as we don't unwind the stack. This means that in certain cases we can leak resources, like an OwnPtr / RefPtr tracked on the stack. Or even leak a lock acquired in a ScopeLockLocker. To remedy this situation we move the promise violation handling to the syscall handler, right before we return to user space. This allows the code to follow the normal unwind path, and grantees there is no longer any cleanup that needs to occur. The Process::require_promise() and Process::require_no_promises() functions were modified to return ErrorOr<void> so we enforce that the errors are always propagated by the caller.
2021-12-29Kernel: Port Process to ListedRefCountedIdan Horowitz
2021-12-29Kernel: Remove Process::all_processes()Idan Horowitz
This was only used in ProcFS, which can use the `processes()` list just as well, so let's remove it.
2021-12-19Kernel: Make perfcore files owned by UID=0, GID=0Andreas Kling
Since perfcore files can be generated during process finalization, we can't just allow them to contain sensitive kernel information if they're gonna be owned by the process's own UID+GID. So instead, perfcores are now owned by 0:0. This is not the most ergonomic solution, but I'm not sure what we could do to make it nicer. We'll have to think more about that. In the meantime, this patches up a kernel info leak. :^)
2021-12-16Kernel+LibC: Move errno definitions to Kernel/API/POSIXsin-ack
This fixes at least half of our LibC includes in the kernel. The source of truth for errno codes and their description strings now lives in Kernel/API/POSIX/errno.h as an enumeration, which LibC includes.
2021-11-30Kernel: Surface errors when generating a process core dump :^)Brian Gianforcaro
2021-11-28Kernel: Log when a process exits with an unlocked veilSam Atkins
This catches applications that make use of `unveil()`, but then do not lock the veil with `unveil(nullptr, nullptr)`.
2021-11-14Kernel: Convert Process-related const member functions to staticAndrew Kaster
Process::get_syscall_path_argument() and ProcFSExposedComponent::modified_time() both are independent of this.
2021-11-14Kernel: Make OpenFileDescriptions::max_open() static and constexprAndrew Kaster
This method was just returning a static constexpr member variable verbatim, so there's no point requiring a member function to observe its value.
2021-11-14Kernel: Resolve clang-tidy readability-qualified-auto warningAndrew Kaster
... In files included by Kernel/Process.cpp or Kernel/Thread.cpp
2021-11-14Kernel: Resolve clang-tidy readability-make-member-function-constAndrew Kaster
... In files included from Kernel/Thread.cpp or Kernel/Process.cpp Some places the warning is suppressed, because we do not want a const object do have non-const access to the returned sub-object.
2021-11-14Kernel: Resolve clang-tidy readability-implicit-bool-conversion warningsAndrew Kaster
... In files included from Kernel/Process.cpp and Kernel/Thread.cpp
2021-11-10AK: Make Vector::try_* functions return ErrorOr<void>Andreas Kling
Instead of signalling allocation failure with a bool return value (false), we now use ErrorOr<void> and return ENOMEM as appropriate. This allows us to use TRY() and MUST() with Vector. :^)
2021-11-08Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>Andreas Kling
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-10-31Kernel: Do not try opening the same file when dumping perfcoreSeekingBlues
Dumping perfcore would always fail with EEXIST. This regressed in #10707 because of an incorrect indentation in the for loop.
2021-10-31Kernel: Avoid OpenFileDescription::absolute_pathBen Wiederhake
2021-10-08Kernel: Fix -Wunreachable-code warnings from clangNico Weber