summaryrefslogtreecommitdiff
path: root/Kernel/Syscall.cpp
AgeCommit message (Collapse)Author
2021-10-08Kernel: Fix -Wunreachable-code warnings from clangNico Weber
2021-10-02Kernel: Access MemoryManager static functions staticallyBrian Gianforcaro
SonarCloud flagged this "Code Smell", where we are accessing these static methods as if they are instance methods. While it is technically possible, it is very confusing to read when you realize they are static functions.
2021-09-05Kernel: Declare syscall handlers with "using" instead of "typedef"Brian Gianforcaro
Also use bit_cast to avoid -Wcast-function-type warning.
2021-08-29Kernel: Rename Spinlock::is_owned_by_current_thread()Andreas Kling
...to is_owned_by_current_processor(). As Tom pointed out, this is much more accurate. :^)
2021-08-29Kernel: {Mutex,Spinlock}::own_lock() => is_locked_by_current_thread()Andreas Kling
Rename these API's to make it more clear what they are checking.
2021-08-14Kernel: Stop allowing implicit conversion from KResult to intAndreas Kling
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-10Kernel: Add syscall performance event typeJean-Baptiste Boric
This allows tracing the syscalls made by a thread through the kernel's performance event framework, which is similar in principle to strace. Currently, this merely logs a stack backtrace to the current thread's performance event buffer whenever a syscall is made, if profiling is enabled. Future improvements could include tracing the arguments and the return value, for example.
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: 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-07-25Kernel+LibSystem: Add a 4th syscall argumentAndreas Kling
Let's allow passing 4 function arguments to a syscall. The 4th argument goes into ESI or RSI.
2021-07-23Kernel: Remove another ARCH ifdef using RegisterState::flags()Brian Gianforcaro
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: Conditionally acquire the big lock based on syscall metadataBrian Gianforcaro
2021-07-20Kernel: Move validate_syscall_preconditions outside of the big lockBrian Gianforcaro
Now that we hold the space lock for the duration of the validation it should be safe to move the validation outside the big lock.
2021-07-20Kernel: Move syscall precondition validates to MMBrian Gianforcaro
Move these to MM to simplify the flow of the syscall handler. While here, also make sure we hold the process space lock for the duration of the validation to avoid potential issues where another thread attempts to modify the process space during the validation. This will allow us to move the validation out of the big process lock scope in a future change. Additionally utilize the new no_lock variants of functions to avoid unnecessary recursive process space spinlock acquisitions.
2021-07-20Kernel: Instrument syscalls with their process big lock requirementsBrian Gianforcaro
Currently all syscalls run under the Process:m_big_lock, which is an obvious bottleneck. Long term we would like to remove the big lock and replace it with the required fine grained locking. To facilitate this goal we need a way of gradually decomposing the big lock into the all of the required fine grained locks. This commit introduces instrumentation to the syscall table, allowing the big lock requirement to be toggled on/off per syscall. Eventually when we are finished, no syscall will required the big lock, and we'll be able to remove all of this instrumentation.
2021-07-20Kernel: No lock validate_user_stack variant, switch to Space as argumentBrian Gianforcaro
The entire process is not needed, just require the user to pass in the Space. Also provide no_lock variant to use when you already have the VM/Space lock acquired, to avoid unnecessary recursive spinlock acquisitions.
2021-07-19Kernel: Push ARCH specific ifdef's down into RegisterState functionsBrian Gianforcaro
The non CPU specific code of the kernel shouldn't need to deal with architecture specific registers, and should instead deal with an abstract view of the machine. This allows us to remove a variety of architecture specific ifdefs and helps keep the code slightly more portable. We do this by exposing the abstract representation of instruction pointer, stack pointer, base pointer, return register, etc on the RegisterState struct.
2021-07-14Kernel: Ignore subsequent calls to Process::dieTom
It's possible that another thread might try to exit the process just about the same time another thread does the same, or a crash happens. Also, we may not be able to kill all other threads instantly as they may be blocked in the kernel (though in this case they would get killed before ever returning back to user mode. So keep track of whether Process::die was already called and ignore it on subsequent calls. Fixes #8485
2021-07-13Revert "Kernel: Make sure threads which don't do any syscalls are t..."Tom
This reverts commit 3c3a1726df847aff9db73862040d9f7a3b9fc907. We cannot blindly kill threads just because they're not executing in a system call. Being blocked (including in a page fault) needs proper unblocking and potentially kernel stack cleanup before we can mark a thread as Dying. Fixes #8691
2021-07-05Kernel: Replace raw asm functions with naked onesHendiadyoin1
2021-07-02Kernel: Use the GS segment for the per-CPU structGunnar Beutner
Right now we're using the FS segment for our per-CPU struct. On x86_64 there's an instruction to switch between a kernel and usermode GS segment (swapgs) which we could use. This patch doesn't update the rest of the code to use swapgs but it prepares for that by using the GS segment instead of the FS segment.
2021-06-30Kernel: Fix stack alignment on x86_64Gunnar Beutner
These were already properly aligned (as far as I can tell).
2021-06-28Kernel: Implement syscall entry for x86_64Gunnar Beutner
2021-06-27Kernel+Userland: Add x86_64 registers to RegisterState/PtraceRegistersGunnar Beutner
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-19Kernel: Make sure threads which don't do any syscalls are terminatedGunnar Beutner
Steps to reproduce: $ cat loop.c int main() { for (;;); } $ gcc -o loop loop.c $ ./loop Terminating this process wasn't previously possible because we only checked whether the thread should be terminated on syscall exit.
2021-06-09Meta: Disable -Wmaybe-uninitializedAli Mohammad Pur
It's prone to finding "technically uninitialized but can never happen" cases, particularly in Optional<T> and Variant<Ts...>. The general case seems to be that it cannot infer the dependency between Variant's index (or Optional's boolean state) and a particular alternative (or Optional's buffer) being untouched. So it can flag cases like this: ```c++ if (index == StaticIndexForF) new (new_buffer) F(move(*bit_cast<F*>(old_buffer))); ``` The code in that branch can _technically_ make a partially initialized `F`, but that path can never be taken since the buffer holding an object of type `F` and the condition being true are correlated, and so will never be taken _unless_ the buffer holds an object of type `F`. This commit also removed the various 'diagnostic ignored' pragmas used to work around this warning, as they no longer do anything.
2021-05-29Kernel: Make sure we free the thread stack on thread exitGunnar Beutner
This adds two new arguments to the thread_exit system call which let a thread unmap an arbitrary VM range on thread exit. LibPthread uses this functionality to unmap the thread stack. Fixes #7267.
2021-05-28Kernel: Allow building the kernel with -O0Gunnar Beutner
Unfortunately the kernel doesn't run with -O0 but at least it can be successfully built with this change.
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-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-20Kernel: Don't consider kernel memory regions for syscall origin checkAndreas Kling
We should never enter the syscall handler from a kernel address.
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-14Kernel: Suppress maybe-uninitialized' warning s_syscall_table in gcc-10.3.0Brian Gianforcaro
2021-04-12Kernel: Mark s_syscall_table const so it ends up in ro_data.Brian Gianforcaro
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-15Kernel: Don't return -EFOO when return type is KResultOr<...>Andreas Kling
2021-03-12Kernel: Convert klog() => AK::Format in a handful of placesAndreas Kling
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: Use RDTSC instead of get_fast_random() for syscall stack noiseAndreas Kling
This was the original approach before we switched to get_fast_random() which wasn't fast enough, so we added a buffer. Unfortunately that buffer is racy and we can actually skid past the end of it and continue fetching "random" offsets from the adjacent memory for a while, until we run out of kernel data segment and trip a fault. Instead of making this even more convoluted, let's just go back to the pleasantly simple (RDTSC & 0xff) approach. :^) Fixes #4912.
2021-03-01Kernel: Oops, SC_abort was actually calling sys$exit_thread()Andreas Kling
2021-03-01Kernel: Detach any attached thread tracer on sys$abort()Andreas Kling
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-25Kernel: Don't disable interrupts while exiting a thread or processAndreas Kling
This was another vestige from a long time ago, when exiting a thread would mutate global data structures that were only protected by the interrupt flag.
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-20Kernel: Slap a handful more things with UNMAP_AFTER_INITAndreas Kling
2021-02-14Kernel: Fix TOCTOU in syscall entry region validationAndreas Kling
We were doing stack and syscall-origin region validations before taking the big process lock. There was a window of time where those regions could then be unmapped/remapped by another thread before we proceed with our syscall. This patch closes that window, and makes sys$get_stack_bounds() rely on the fact that we now know the userspace stack pointer to be valid. Thanks to @BenWiederhake for spotting this! :^)
2021-02-14Kernel: Mark handle_crash() as [[noreturn]]Andreas Kling