summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/fork.cpp
AgeCommit message (Collapse)Author
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-14Kernel: Make master TLS region WeakPtr construction OOM-fallibleIdan Horowitz
2022-02-11Kernel: Set up Regions before adding them to a Process's AddressSpaceIdan Horowitz
This reduces the amount of time in which not fully-initialized Regions are present inside an AddressSpace's region tree.
2022-01-30Kernel: Remove unnecessary includes from Thread.hAndreas Kling
...and deal with the fallout by adding missing includes everywhere.
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.
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: Use Process::require_promise() instead of REQUIRE_PROMISE()Brian Gianforcaro
This change lays the foundation for making the require_promise return an error hand handling the process abort outside of the syscall implementations, to avoid cases where we would leak resources. It also has the advantage that it makes removes a gs pointer read to look up the current thread, then process for every syscall. We can instead go through the Process this pointer in most cases.
2021-12-12Kernel: Inherit alternative signal stack on fork(2)Idan Horowitz
A child process created via fork(2) inherits a copy of its parent's alternate signal stack settings.
2021-12-12Kernel: Preserve signal mask across fork(2) and execve(2)Idan Horowitz
A child created via fork(2) inherits a copy of its parent's signal mask; the signal mask is preserved across execve(2).
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-09-07Kernel: Rename FileDescription => OpenFileDescriptionAndreas Kling
Dr. POSIX really calls these "open file description", not just "file description", so let's call them exactly that. :^)
2021-09-07Kernel: Store process names as KStringAndreas Kling
2021-09-06Kernel: Make Memory::Region::map() return KResultAndreas Kling
..and use TRY() at the call sites to propagate errors. :^)
2021-09-06Kernel: Make AddressSpace::add_region() return KResultOr<Region*>Andreas Kling
This allows us to use TRY() in a few places.
2021-09-05Kernel: Use TRY() in sys$fork()Andreas Kling
There's a lot of work to do on improving error propagation in the fork system call. This just scratches the surface.
2021-09-04Kernel: Make Process::try_create() propagate errors betterAndreas Kling
2021-09-04Kernel: Rename Process::create() => try_create()Andreas Kling
2021-08-25Kernel: Always observe the return value of Region::map and remapBrian Gianforcaro
We have seen cases where the map fails, but we return the region to the caller, causing them to page fault later on when they touch the region. The fix is to always observe the return code of map/remap.
2021-08-23Kernel: Rename Thread::BlockCondition to BlockerSetAndreas Kling
This class represents a set of Thread::Blocker objects attached to something that those blockers are waiting on.
2021-08-22Kernel: Rename ScopedSpinlock => SpinlockLockerAndreas Kling
This matches MutexLocker, and doesn't sound like it's a lock itself.
2021-08-22Kernel: Rename SpinLock => SpinlockAndreas Kling
2021-08-15Kernel: Make Memory::Region allocation functions return KResultOrsin-ack
This makes for some nicer handling of errors compared to checking an OwnPtr for null state.
2021-08-15Kernel+Userland: Remove chroot functionalityAndreas Kling
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-13Kernel: Make cloning of FileDescriptions OOM safeBrian Gianforcaro
2021-08-12Kernel/Process: Move protected values to the end of the objectLiav A
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-06Kernel: Make Process's m_promises & m_execpromises fields atomicIdan Horowitz
This is essentially free on x86 and allows us to not hold the big process lock just to check the required promises for a syscall.
2021-08-06Kernel: Rename Process::space() => Process::address_space()Andreas Kling
We commonly talk about "a process's address space" so let's nudge the code towards matching how we talk about it. :^)
2021-08-06Kernel: Move Kernel/Memory/ code into Kernel::Memory namespaceAndreas Kling
2021-08-06Kernel: Rename Kernel/VM/ to Kernel/Memory/Andreas Kling
This directory isn't just about virtual memory, it's about all kinds of memory management.
2021-08-01Kernel: Remove unused header includesBrian Gianforcaro
2021-07-25Kernel: Remove unnecessary weak pointer from Region to owning ProcessAndreas Kling
This was previously used for a single debug logging statement during memory purging. There are no remaining users of this weak pointer, so let's get rid of it.
2021-07-22Everywhere: Prefix hexadecimal numbers with 0xGunnar Beutner
Depending on the values it might be difficult to figure out whether a value is decimal or hexadecimal. So let's make this more obvious. Also this allows copying and pasting those numbers into GNOME calculator and probably also other apps which auto-detect the base.
2021-07-20Kernel: Annotate all syscalls with VERIFY_PROCESS_BIG_LOCK_ACQUIREDBrian Gianforcaro
Before we start disabling acquisition of the big process lock for specific syscalls, make sure to document and assert that all the lock is held during all syscalls.
2021-07-15Kernel: Handle OOM when adding memory regions to Spaces :^)Idan Horowitz
2021-07-14Kernel: Fix Process use-after-free in Thread finalizationAndreas Kling
We leak a ref() onto every user process when constructing them, either via Process::create_user_process(), or via Process::sys$fork(). This ref() is balanced by a corresponding unref() in Thread::WaitBlockCondition::finalize(). Since kernel processes don't have a leaked ref() on them, this led to an extra Process::unref() on kernel processes during finalization. This happened during every boot, with the `init_stage2` process. Found by turning off kfree() scrubbing. :^)
2021-07-12Kernel: Move new process registration out of Space spinlock scopeBrian Gianforcaro
There appears to be no reason why the process registration needs to happen under the space spin lock. As the first thread is not started yet it should be completely uncontested, but it's still bad practice.
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: Add x86_64 support for fork()Gunnar Beutner
2021-06-28Kernel: Fix the return type for syscallsGunnar Beutner
The Process::Handler type has KResultOr<FlatPtr> as its return type. Using a different return type with an equally-sized template parameter sort of works but breaks once that condition is no longer true, e.g. for KResultOr<int> on x86_64. Ideally the syscall handlers would also take FlatPtrs as their args so we can get rid of the reinterpret_cast for the function pointer but I didn't quite feel like cleaning that up as well.
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-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-07Kernel: Switch Process to InstrusiveList from InlineLinkedListBrian Gianforcaro
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-07Kernel: Move process creation perf events to PerformanceManagerBrian Gianforcaro
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-12Kernel: Replace process' regions vector with a Red Black treeIdan Horowitz
This should provide some speed up, as currently searches for regions containing a given address were performed in O(n) complexity, while this container allows us to do those in O(logn).
2021-03-11Kernel: Inherit the dumpable flag on sys$fork()Andreas Kling
This regressed at some point recently. All children were non-dumpable until manually opting into it.