summaryrefslogtreecommitdiff
path: root/Kernel/Process.cpp
AgeCommit message (Collapse)Author
2021-06-29Kernel: Don't copy a Vector<FileDescriptionAndFlags>Liav A
Instead of copying a Vector everytime we need to enumerate a Process' file descriptions, we can just temporarily lock so it won't change.
2021-06-29Kernel: Introduce the new ProcFS designLiav A
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-29Kernel: Implement signal handling for x86_64Gunnar Beutner
2021-06-28Kernel: Make and use KERNEL_BASEHendiadyoin1
This is to make the 0xc0000000 less a magic number, and will make it easier in the future to move the Kernel around
2021-06-28Kernel: Fix Process::crash assuming 32-bit modeHendiadyoin1
2021-06-28Kernel: Implement more x86_64 context switching functionalityGunnar Beutner
2021-06-27Kernel: Rename Thread::tss to Thread::regs and add x86_64 supportGunnar Beutner
We're using software context switches so calling this struct tss is somewhat misleading.
2021-06-26Kernel: Clean up create_signal_trampoline a bitGunnar Beutner
The types for asm_signal_trampoline and asm_signal_trampoline_end were incorrect. They both point into the text segment but they're not really functions.
2021-06-24Everywhere: Use nothrow new with `adopt_{ref,own}_if_nonnull`Daniel Bertalan
This commit converts naked `new`s to `AK::try_make` and `AK::try_create` wherever possible. If the called constructor is private, this can not be done, so we instead now use the standard-defined and compiler-agnostic `new (nothrow)`.
2021-06-24Kernel: Add stubs for missing x86_64 functionalityGunnar Beutner
This adds just enough stubs to make the kernel compile on x86_64. Obviously it won't do anything useful - in fact it won't even attempt to boot because Multiboot doesn't support ELF64 binaries - but it gets those compiler errors out of the way so more progress can be made getting all the missing functionality in place.
2021-06-24Kernel: Move special sections into Sections.hHendiadyoin1
This also removes a lot of CPU.h includes infavor for Sections.h
2021-06-24Kernel: Pull apart CPU.hHendiadyoin1
This does not add any functional changes
2021-06-14Kernel: Verify Process coredump threads are emptyJelle Raaijmakers
2021-06-07Kernel: Switch Process to InstrusiveList from InlineLinkedListBrian Gianforcaro
2021-06-07Kernel: Remove unnecessary cast to int during ensure capacityBrian Gianforcaro
2021-06-03Kernel: Switch ProcessGroup to IntrusiveList from InlineLinkedListBrian Gianforcaro
2021-05-29Kernel: Convert Process::get_syscall_path_argument() to KStringAndreas Kling
This API now returns a KResultOr<NonnullOwnPtr<KString>> and allocation failures should be propagated everywhere nicely. :^)
2021-05-22Kernel: Print a message to debug log after writing a perfcore fileAndreas Kling
2021-05-17Kernel: Disable profile timer when the process exitsGunnar Beutner
When profiling a single process we didn't disable the profile timer. enable_profile_timer()/disable_profiler_timer() support nested calls so no special care has to be taken here to only disable the timer when nobody else is using it.
2021-05-16AK+Kernel+LibELF: Remove the need for `IteratorDecision::Continue`Nicholas Baron
By constraining two implementations, the compiler will select the best fitting one. All this will require is duplicating the implementation and simplifying for the `void` case. This constraining also informs both the caller and compiler by passing the callback parameter types as part of the constraint (e.g.: `IterationFunction<int>`). Some `for_each` functions in LibELF only take functions which return `void`. This is a minimal correctness check, as it removes one way for a function to incompletely do something. There seems to be a possible idiom where inside a lambda, a `return;` is the same as `continue;` in a for-loop.
2021-05-15Kernel: Make Process creation APIs OOM safeBrian Gianforcaro
This change looks more involved than it actually is. This simply reshuffles the previous Process constructor and splits out the parts which can fail (resource allocation) into separate methods which can be called from a factory method. The factory is then used everywhere instead of the constructor.
2021-05-13Kernel: Make Process::start_tracing_from API OOM safeBrian Gianforcaro
Modify the API so it's possible to propagate error on OOM failure. NonnullOwnPtr<T> is not appropriate for the ThreadTracer::create() API, so switch to OwnPtr<T>, use adopt_own_if_nonnull() to handle creation.
2021-05-07Kernel: Move process exit perf events to PerformanceManagerBrian Gianforcaro
2021-05-01Kernel: Harden Process Vector usage against OOM.Brian Gianforcaro
2021-04-29Kernel: Enable building the kernel with -fltoGunnar Beutner
GCC with -flto is more aggressive when it comes to inlining and discarding functions which is why we must mark some of the functions as NEVER_INLINE (because they contain asm labels which would be duplicated in the object files if the compiler decides to inline the function elsewhere) and __attribute__((used)) for others so that GCC doesn't discard them.
2021-04-26Kernel+Profiler: Improve profiling subsystemGunnar Beutner
This turns the perfcore format into more a log than it was before, which lets us properly log process, thread and region creation/destruction. This also makes it unnecessary to dump the process' regions every time it is scheduled like we did before. Incidentally this also fixes 'profile -c' because we previously ended up incorrectly dumping the parent's region map into the profile data. Log-based mmap support enables profiling shared libraries which are loaded at runtime, e.g. via dlopen(). This enables profiling both the parent and child process for programs which use execve(). Previously we'd discard the profiling data for the old process. The Profiler tool has been updated to not treat thread IDs as process IDs anymore. This enables support for processes with more than one thread. Also, there's a new widget to filter which process should be displayed.
2021-04-23AK: Rename adopt() to adopt_ref()Andreas Kling
This makes it more symmetrical with adopt_own() (which is used to create a NonnullOwnPtr from the result of a naked new.)
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-19Kernel: Add a syscall to clear the profiling bufferBrian Gianforcaro
While profiling all processes the profile buffer lives forever. Once you have copied the profile to disk, there's no need to keep it in memory. This syscall surfaces the ability to clear that buffer.
2021-04-04Kernel+CrashReporter: Add metadata about page faults to crash reportsAndreas Kling
Crash reports for page faults now tell you what kind of memory access failed and where. :^)
2021-03-21Kernel::CPU: Move headers into common directoryHendiadyoin1
Alot of code is shared between i386/i686/x86 and x86_64 and a lot probably will be used for compatability modes. So we start by moving the headers into one Directory. We will probalby be able to move some cpp files aswell.
2021-03-11Kernel: Always protect process data immediately after constructionAndreas Kling
2021-03-11Kernel: Move process termination status/signal into protected dataAndreas Kling
2021-03-11Kernel: Move process thread lists into protected dataAndreas Kling
2021-03-11Kernel: Don't keep protected Process data in a separate allocationAndreas Kling
The previous architecture had a huge flaw: the pointer to the protected data was itself unprotected, allowing you to overwrite it at any time. This patch reorganizes the protected data so it's part of the Process class itself. (Actually, it's a new ProcessBase helper class.) We use the first 4 KB of Process objects themselves as the new storage location for protected data. Then we make Process objects page-aligned using MAKE_ALIGNED_ALLOCATED. This allows us to easily turn on/off write-protection for everything in the ProcessBase portion of Process. :^) Thanks to @bugaevc for pointing out the flaw! This is still not perfect but it's an improvement.
2021-03-10Kernel: Move process "dumpable" flag into protected dataAndreas Kling
2021-03-10Kernel: Move process parent PID into protected data :^)Andreas Kling
2021-03-10Kernel: Move process extra_gids into protected data :^)Andreas Kling
2021-03-10Kernel: Move select Process members into protected memoryAndreas Kling
Process member variable like m_euid are very valuable targets for kernel exploits and until now they have been writable at all times. This patch moves m_euid along with a whole bunch of other members into a new Process::ProtectedData struct. This struct is remapped as read-only memory whenever we don't need to write to it. This means that a kernel write primitive is no longer enough to overwrite a process's effective UID, you must first unprotect the protected data where the UID is stored. :^)
2021-03-04Kernel: Make the kernel compile & link for x86_64Andreas Kling
It's now possible to build the whole kernel with an x86_64 toolchain. There's no bootstrap code so it doesn't work yet (obviously.)
2021-03-02Kernel+Profiler: Capture metadata about all profiled processesAndreas Kling
The perfcore file format was previously limited to a single process since the pid/executable/regions data was top-level in the JSON. This patch moves the process-specific data into a top-level array named "processes" and we now add entries for each process that has been sampled during the profile run. This makes it possible to see samples from multiple threads when viewing a perfcore file with Profiler. This is extremely cool! :^)
2021-03-02Kernel: Better handling of allocation failure in profilingAndreas Kling
If we can't allocate a PerformanceEventBuffer to store the profiling events, we now fail sys$profiling_enable() and sys$perf_event() with ENOMEM instead of carrying on with a broken buffer.
2021-03-02Kernel: Make kgettimeofday use AK::TimeBen Wiederhake
2021-03-02Kernel: Remove duplicative kgettimeofday(timeval&) functionBen Wiederhake
2021-03-02Kernel: Make TimeManagement use AK::Time internallyBen Wiederhake
I don't dare touch the multi-threading logic and locking mechanism, so it stays timespec for now. However, this could and should be changed to AK::Time, and I bet it will simplify the "increment_time_since_boot()" code.
2021-02-26Kernel: Detach the traced process on process exitcbsirb
Currently, when a process which has a tracee exits, nothing will happen, leaving the tracee unable to be attached again. This will call the stop_tracing function on any process which is traced by the exiting process and sending the SIGSTOP signal making the traced process wait for a SIGCONT (just as Linux does)
2021-02-25Kernel: Don't disable interrupts while dealing with a process crashAndreas Kling
This was necessary in the past when crash handling would modify various global things, but all that stuff is long gone so we can simplify crashes by leaving the interrupt flag alone.
2021-02-25Kernel: Take some baby steps towards x86_64Andreas Kling
Make more of the kernel compile in 64-bit mode, and make some things pointer-size-agnostic (by using FlatPtr.) There's a lot of work to do here before the kernel will even compile.
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-21Kernel: Use uniform initialization instead of memset for a few stack buffer.Brian Gianforcaro
Raw memset is relatively easy to mess up, avoid it when there are better alternatives provided by the compiler in modern C++.