summaryrefslogtreecommitdiff
path: root/Kernel/Process.h
AgeCommit message (Collapse)Author
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-12Kernel: Implement multi-watch InodeWatcher :^)sin-ack
This patch modifies InodeWatcher to switch to a one watcher, multiple watches architecture. The following changes have been made: - The watch_file syscall is removed, and in its place the create_iwatcher, iwatcher_add_watch and iwatcher_remove_watch calls have been added. - InodeWatcher now holds multiple WatchDescriptions for each file that is being watched. - The InodeWatcher file descriptor can be read from to receive events on all watched files. Co-authored-by: Gunnar Beutner <gunnar@beutner.name>
2021-05-07Kernel: Add PerformanceManager static class, move perf event APIs thereBrian Gianforcaro
The current method of emitting performance events requires a bit of boiler plate at every invocation, as well as having to ignore the return code which isn't used outside of the perf event syscall. This change attempts to clean that up by exposing high level API's that can be used around the code base.
2021-04-30Kernel+LibELF: Support initializing values of TLS dataItamar
Previously, TLS data was always zero-initialized. To support initializing the values of TLS data, sys$allocate_tls now receives a buffer with the desired initial data, and copies it to the master TLS region of the process. The DynamicLinker gathers the initial TLS image and passes it to sys$allocate_tls. We also now require the size passed to sys$allocate_tls to be page-aligned, to make things easier. Note that this doesn't waste memory as the TLS data has to be allocated in separate pages anyway.
2021-04-30Kernel/LibC: Implement `setreuid`Jesse Buhagiar
2021-04-28Kernel+LibC: Implement the socketpair() syscallGunnar Beutner
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-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-18Kernel+LibC: Clean up how assertions work in the kernel and LibCGunnar Beutner
This also brings LibC's abort() function closer to the spec.
2021-04-18LibC+LibELF: Implement support for the dl_iterate_phdr helperGunnar Beutner
This helper is used by libgcc_s to figure out where the .eh_frame sections are located for all loaded shared objects.
2021-04-16AK+Kernel: Make IntrusiveList capable of holding non-raw pointersAnotherTest
This should allow creating intrusive lists that have smart pointers, while remaining free (compared to the impl before this commit) when holding raw pointers :^) As a sidenote, this also adds a `RawPtr<T>` type, which is just equivalent to `T*`. Note that this does not actually use such functionality, but is only expected to pave the way for #6369, to replace NonnullRefPtrVector<T> with intrusive lists. As it is with zero-cost things, this makes the interface a bit less nice by requiring the type name of what an `IntrusiveListNode` holds (and optionally its container, if not RawPtr), and also requiring the type of the container (normally `RawPtr`) on the `IntrusiveList` instance.
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-17LibC+Kernel: Switch off_t to 64 bitsJean-Baptiste Boric
2021-03-12Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)Andreas Kling
Good-bye LogStream. Long live AK::Format!
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: Move process signal trampoline address into protected dataAndreas Kling
2021-03-11Kernel: Move process umask into protected data :^)Andreas 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 pledge promises into protected dataAndreas Kling
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-09Kernel+UserspaceEmulator: Add sys$emuctl() system callAndreas Kling
This returns ENOSYS if you are running in the real kernel, and some other result if you are running in UserspaceEmulator. There are other ways we could check if we're inside an emulator, but it seemed easier to just ask. :^)
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-03-01Kernel: Use Userspace<T> in sys${munmap,mprotect,madvise,msyscall}()Andreas Kling
2021-03-01Kernel: Use Userspace<T> in sys$select()Andreas Kling
2021-03-01Kernel: Use Userspace<T> in sys$get_dir_entries()Andreas Kling
2021-03-01Kernel: Use Userspace<T> in sys$get_stack_bounds()Andreas Kling
2021-03-01Kernel: Use Userspace<T> in sys$write()Andreas Kling
2021-03-01Kernel: Use Userspace<T> in sys$sigaction()Andreas Kling
fuzz-syscalls found a bunch of unaligned accesses into struct sigaction via this syscall. This patch fixes that issue by porting the syscall to Userspace<T> which we should have done anyway. :^) Fixes #5500.
2021-03-01Kernel: Make all syscall functions return KResultOr<T>Andreas Kling
This makes it a lot easier to return errors since we no longer have to worry about negating EFOO errors and can just return them flat.
2021-02-26Everywhere: Remove a bunch of redundant 'AK::' namespace prefixesLinus Groh
This is basically just for consistency, it's quite strange to see multiple AK container types next to each other, some with and some without the namespace prefix - we're 'using AK::Foo;' a lot and should leverage that. :^)
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: Add "map_fixed" pledge promiseAndreas Kling
This is a new promise that guards access to mmap() with MAP_FIXED. Fixed-address mappings are rarely used, but can be useful if you are trying to groom the process address space for malicious purposes. None of our programs need this at the moment, as the only user of MAP_FIXED is DynamicLoader, but the fixed mappings are constructed before the process has had a chance to pledge anything.
2021-02-18Kernel: Use KResult a bit more in sys$execve()Andreas Kling
2021-02-15Kernel+LibC: Implement readvAnotherTest
We already had writev, so let's just add readv too.
2021-02-14Kernel+Userland: Give sys$recvfd() an options argument for O_CLOEXECAndreas Kling
@bugaevc pointed out that we shouldn't be setting this flag in userspace, and he's right of course.
2021-02-14Kernel: Map signal trampoline into each process's address spaceAndreas Kling
The signal trampoline was previously in kernelspace memory, but with a special exception to make it user-accessible. This patch moves it into each process's regular address space so we can stop supporting user-allowed memory above 0xc0000000.
2021-02-12Kernel: Move get_interpreter_load_offset() out of Process classAndreas Kling
This is only used inside the sys$execve() implementation so just make it a execve.cpp local function.
2021-02-08Kernel: Prevent execve/ptrace raceAndreas Kling
Add a per-process ptrace lock and use it to prevent ptrace access to a process after it decides to commit to a new executable in sys$execve(). Fixes #5230.
2021-02-08Kernel: Move ShouldAllocateTls enum from Process to execve.cppAndreas Kling
2021-02-08Kernel: Move memory statistics helpers from Process to SpaceAndreas Kling