summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls
AgeCommit message (Collapse)Author
2021-04-03Kernel: Introduce a new HID subsystemLiav A
The end goal of this commit is to allow to boot on bare metal with no PS/2 device connected to the system. It turned out that the original code relied on the existence of the PS/2 keyboard, so VirtualConsole called it even though ACPI indicated the there's no i8042 controller on my real machine because I didn't plug any PS/2 device. The code is much more flexible, so adding HID support for other type of hardware (e.g. USB HID) could be much simpler. Briefly describing the change, we have a new singleton called HIDManagement, which is responsible to initialize the i8042 controller if exists, and to enumerate its devices. I also abstracted a bit things, so now every Human interface device is represented with the HIDDevice class. Then, there are 2 types of it - the MouseDevice and KeyboardDevice classes; both are responsible to handle the interface in the DevFS. PS2KeyboardDevice, PS2MouseDevice and VMWareMouseDevice classes are responsible for handling the hardware-specific interface they are assigned to. Therefore, they are inheriting from the IRQHandler class.
2021-03-29Kernel: Support write() after setting O_APPEND on a non-seekable fileItamar
Previously, Process::do_write would error if the O_APPEND flag was set on a non-seekable file. Other systems (such as Linux) seem to be OK with doing this, so we now do not attempt to seek to the end the file if it's not seekable.
2021-03-29Kernel: Let's also not reverse the blocking flag for FIONBIO..Andreas Kling
2021-03-29Kernel: Let's allow unsetting non-blocking mode with FIONBIO as wellAndreas Kling
Thanks to almightyhydra for pointing this out! :^)
2021-03-28Kernel+LibC: Implement sys$ioctl() FIONBIOAndreas Kling
This is another (older) way of making a file descriptor non-blocking.
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-19Kernel: Set TLS-related members of Process after loading static programItamar
We previously ignored these values in the return value of load_elf_object, which causes us to not allocate a TLS region for statically-linked programs.
2021-03-19Kernel: Make FileDescription::seek() return KResultOr<off_t>Andreas Kling
This exposed a bunch of places where errors were not propagated, so this patch is forced to deal with them as well.
2021-03-19Kernel: Refactor storage stack with u64 as mmap offsetJean-Baptiste Boric
2021-03-17LibC+Kernel: Switch off_t to 64 bitsJean-Baptiste Boric
2021-03-16Kernel: sysconf(_SC_CLK_TCK): Use TimeManagement::ticks_per_second()thatdutchguy
2021-03-16Kernel: Add _SC_CLK_TCK to sysconf.thatdutchguy
Unbreaks the hatari port.
2021-03-15Kernel: Don't return -EFOO when return type is KResultOr<...>Andreas Kling
2021-03-13Kernel: Make munmap more posix compliantHendiadyoin1
In case someone tries to unmap a not mapped region (fallback) we should not return an error, but silently do nothing
2021-03-13Kernel: munmap multiple regions at a timeHendiadyoin1
This implements a fallback to munmap that unmaps multiple regions at a time, with splitting some when needed. The way it is implemented is possibly not optimal, due to it searching without looking into the cache
2021-03-12Kernel: Fix rounding of PT_LOAD mappings in sys$execve()Andreas Kling
We were not rounding the mappings down/up correctly, which could lead to executables missing the last 4 KB of text and/or data.
2021-03-12Kernel: Convert klog() => AK::Format in a handful of placesAndreas Kling
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.
2021-03-11Kernel: Move process termination status/signal 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 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-08Kernel: Add bitwise operators for Thread::FileBlocker::BlockFlags enumBrian Gianforcaro
Switch to using type-safe bitwise operators for the BlockFlags class, this cleans up a lot of boilerplate casts which are necessary when the enum is declared as `enum class`.
2021-03-07Kernel: Fix pointer over/underflow in create_threadBen Wiederhake
The expression (u8*)params.m_stack_location + stack_size … causes UBSan to spit out the warning KUBSAN: addition of unsigned offset to 0x00000002 overflowed to 0xb0000003 … even though there is no actual overflow happening here. This can be reproduced by running: $ syscall create_thread 0 [ 0 0 0 0 0xb0000001 2 ] Technically, this is a true-positive: The C++-reference is incredibly strict about pointer-arithmetic: > A pointer to non-array object is treated as a pointer to the first element > of an array with size 1. […] [A]ttempts to generate a pointer that isn't > pointing at an element of the same array or one past the end invoke > undefined behavior. https://en.cppreference.com/w/cpp/language/operator_arithmetic Frankly, this feels silly. So let's just use FlatPtr instead. Found by fuzz-syscalls. Undocumented bug. Note that FlatPtr is an unsigned type, so user_esp.value() - 4 is defined even if we end up with a user_esp of 0 (this can happen for example when params.m_stack_size = 0 and params.m_stack_location = 0). The result would be a Kernelspace-pointer, which would then be immediately flagged by 'MM.validate_user_stack' as invalid, as intended.
2021-03-03Kernel: Skip TLB flushes while cloning regions in sys$fork()Andreas Kling
Since we know for sure that the virtual memory regions in the new process being created are not being used on any CPU, there's no need to do TLB flushes for every mapped page.
2021-03-03Kernel: Avoid transient kmalloc heap allocations in sys$select()Andreas Kling
Dynamic Vector allocations in sys$select() were showing up in the full-system profile and since there will never be more than FD_SETSIZE file descriptors to worry about, we can confidently add enough inline capacity to this Vector that it never has to kmalloc. To compensate for the increased stack usage, reduce the size of the FDInfo struct while we're here. :^)
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: Start work on full system profiling :^)Andreas Kling
The superuser can now call sys$profiling_enable() with PID -1 to enable profiling of all running threads in the system. The perf events are collected in a global PerformanceEventBuffer (currently 32 MiB in size.) The events can be accessed via /proc/profile
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 sockets use AK::TimeBen Wiederhake
2021-03-02Kernel: Make kgettimeofday use AK::TimeBen 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-02Kernel: Make Thread use AK::Time internallyBen Wiederhake
This commit is very invasive, because Thread likes to take a pointer and write to it. This means that translating between timespec/timeval/Time would have been more difficult than just changing everything that hands a raw pointer to Thread, in bulk.
2021-03-02Kernel: Sanitize all user-supplied timeval's/timespec'sBen Wiederhake
This also removes a bunch of unnecessary EINVAL. Most of them weren't even recommended by POSIX.
2021-03-01Kernel: Fix build with IO_DEBUGAndreas Kling
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-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-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: Move SMAP disabler RAII helper to its own fileAndreas Kling
Added this in a new directory called Kernel/Arch/x86/ where stuff that applies to both i386 and x86_64 can live.