summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls
AgeCommit message (Collapse)Author
2023-04-04Kernel: Stop using *LockRefPtr for ThreadAndreas Kling
These were stored in a bunch of places. The main one that's a bit iffy is the Mutex::m_holder one, which I'm going to simplify in a subsequent commit. In Plan9FS and WorkQueue, we can't make the NNRPs const due to initialization order problems. That's probably doable with further cleanup, but left as an exercise for our future selves. Before starting this, I expected the thread blockers to be a problem, but as it turns out they were super straightforward (for once!) as they don't mutate the thread after initiating a block, so they can just use simple const-ified NNRPs.
2023-04-04Kernel: Simplify Process factory functionsAndreas Kling
- Instead of taking the first new thread as an out-parameter, we now bundle the process and its first thread in a struct and use that as the return value. - Make all Process factory functions return ErrorOr. Use this to convert some places to more TRY(). - Drop the "try_" prefix on Process factory functions.
2023-04-04Kernel: Stop using *LockRefPtr for Process pointersAndreas Kling
The only persistent one of these was Thread::m_process and that never changes after initialization. Make it const to enforce this and switch everything over to RefPtr & NonnullRefPtr.
2023-04-04Kernel: Stop using *LockRefPtr for FileSystem pointersAndreas Kling
There was only one permanent storage location for these: as a member in the Mount class. That member is never modified after Mount initialization, so we don't need to worry about races there.
2023-04-03Kernel: Abstract Processor::assume_context flags using InterruptsStateIdan Horowitz
The details of the specific interrupt bits that must be turned on are irrelevant to the sys$execve implementation. Abstract it away to the Processor implementations using the InterruptsState enum.
2023-04-03Kernel: Add AArch64 support to sys$forkIdan Horowitz
2023-03-24Kernel/Syscalls: Use copy_n_to_user when applicablePankaj Raghav
copy_to_user() with bytes as the last argument could be changed to using copy_n_to_user() with a count.
2023-03-15Kernel: Merge {get,set}_process_name syscalls to the prctl syscallLiav A
It makes much more sense to have these actions being performed via the prctl syscall, as they both require 2 plain arguments to be passed to the syscall layer, and in contrast to most syscalls, we don't get in these removed syscalls an automatic representation of Userspace<T>, but two FlatPtr(s) to perform casting on them in the prctl syscall which is suited to what has been done in the removed syscalls. Also, it makes sense to have these actions in the prctl syscall, because they are strongly related to the process control concept of the prctl syscall.
2023-03-12Kernel: Make the Jails' internal design a lot more saneLiav A
This is done with 2 major steps: 1. Remove JailManagement singleton and use a structure that resembles what we have with the Process object. This is required later for the second step in this commit, but on its own, is a major change that removes this clunky singleton that had no real usage by itself. 2. Use IntrusiveLists to keep references to Process objects in the same Jail so it will be much more straightforward to iterate on this kind of objects when needed. Previously we locked the entire Process list and we did a simple pointer comparison to check if the checked Process we iterate on is in the same Jail or not, which required taking multiple Spinlocks in a very clumsy and heavyweight way.
2023-03-11Kernel: Add non standard value to sys$sysconfFabian Dellwing
Add `_SC_PHYS_PAGES` to sys$sysconf syscall. This value is needed for a port I'm working on.
2023-03-07Kernel: Use non-locking {Nonnull,}RefPtr for OpenFileDescriptionAndreas Kling
This patch switches away from {Nonnull,}LockRefPtr to the non-locking smart pointers throughout the kernel. I've looked at the handful of places where these were being persisted and I don't see any race situations. Note that the process file descriptor table (Process::m_fds) was already guarded via MutexProtected.
2023-03-06Kernel: Stop using NonnullLockRefPtrVectorAndreas Kling
2023-03-06Everywhere: Stop using NonnullOwnPtrVectorAndreas Kling
Same as NonnullRefPtrVector: weird semantics, questionable benefits.
2023-03-05Kernel: Move process coredump metadata modification to the prctl syscallLiav A
2023-03-05Kernel+Userland: Add support for using the PCSpeaker with various tonesLiav A
2023-03-01Kernel+LibC: Move the FD_SETSIZE declaration to API/POSIX/select.h fileLiav A
2023-02-25Kernel: Mark sys$prctl() as not needing the big lockLiav A
This syscall has sufficient locking and therefore it doesn't need the big lock being taken.
2023-02-24Kernel+Userland: Refine preventing syscall annotations of Regions optionLiav A
Instead of using a special case of the annotate_mapping syscall, let's introduce a new prctl option to disallow further annotations of Regions as new syscall Region(s).
2023-02-24Kernel: Do 2 validations in annotate_mapping syscall outside a spinlockLiav A
2023-02-24Kernel: Properly lock Process protected data in the prctl syscallLiav A
2023-02-24AK+Kernel: Add includes before removing Kernel/ProcessExposed.hLiav A
Apparently without this file, we won't be able to compile due to missing includes to TimeManagement and KBufferBuilder.
2023-02-24Kernel+Userland: Move prctl numbers header file to Kernel/API directoryLiav A
2023-02-21Kernel: Support more clocks in sys$clock_getres()Humberto Alves
Support all the available clocks in clock_getres(). Also, fix this function to use the actual ticks per second value, not the constant `_SC_CLK_TCK` (which is always equal to 8) and move the resolution computation logic to TimeManagement.
2023-02-19Kernel: Support sending filedescriptors with sendmsg(2) and SCM_RIGHTSPeter Elliott
This is necessary to support the wayland protocol. I also moved the CMSG_* macros to the kernel API since they are used in both kernel and userspace. this does not break ntpquery/SCM_TIMESTAMP.
2023-02-19Kernel: Support F_DUPFD_CLOEXEC command to fcntl(2)Peter Elliott
Specified by POSIX: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
2023-02-15Kernel/aarch64: Implement Thread Local StorageTimon Kruiper
This commit adds Processor::set_thread_specific_data, and this function is used to factor out architecture specific implementation of setting the thread specific data. This function is implemented for aarch64 and x86_64, and the callsites are changed to use this function instead.
2023-02-10Everywhere: Remove needless copies of Error / ErrorOr instancesTimothy Flynn
Either take the underlying objects with release_* methods or move() the instances around.
2023-02-08Kernel: Update registers in tracer when attaching to a stopped threadItamar
2023-02-08Kernel: Add optional userspace backtrace to Process::crashTimon Kruiper
This is very useful for debugging the initial userspace applications, as the CrashReporter is not yet running.
2023-02-06Kernel: Return ENAMETOOLONG when trying to set a too-long thread nameSam Atkins
2023-02-06Kernel: Protect Thread::m_name with a spinlockSam Atkins
This replaces manually grabbing the thread's main lock. This lets us remove the `get_thread_name` and `set_thread_name` syscalls from the big lock. :^)
2023-02-06Kernel: Protect Process::m_name with a spinlockSam Atkins
This also lets us remove the `get_process_name` and `set_process_name` syscalls from the big lock. :^)
2023-02-06Kernel: Remove create_inode_watcher syscall from the big lockSam Atkins
2023-02-06Kernel: Remove pledge syscall from the big lockSam Atkins
This already does all its dangerous work inside `with_mutable_protected_data()`.
2023-02-04Kernel+SystemServer+Base: Introduce the RAMFS filesystemLiav A
This filesystem is based on the code of the long-lived TmpFS. It differs from that filesystem in one keypoint - its root inode doesn't have a sticky bit on it. Therefore, we mount it on /dev, to ensure only root can modify files on that directory. In addition to that, /tmp is mounted directly in the SystemServer main (start) code, so it's no longer specified in the fstab file. We ensure that /tmp has a sticky bit and has the value 0777 for root directory permissions, which is certainly a special case when using RAM-backed (and in general other) filesystems. Because of these 2 changes, it's no longer needed to maintain the TmpFS filesystem, hence it's removed (renamed to RAMFS), because the RAMFS represents the purpose of this filesystem in a much better way - it relies on being backed by RAM "storage", and therefore it's easy to conclude it's temporary and volatile, so its content is gone on either system shutdown or unmounting of the filesystem.
2023-02-03Kernel: Fix usermode verification in ptrace with PT_SETREGSItamar
When doing PT_SETREGS, we want to verify that the debugged thread is executing in usermode. b2f7ccf refactored things and flipped the relevant check around, which broke things that use PT_SETREGS (for example, stepping over breakpoints with sdb).
2023-01-27Kernel: Add Syscalls/execve.cpp to aarch64 buildTimon Kruiper
2023-01-27Kernel: Add ThreadRegisters::set_exec_state and use it in execve.cppTimon Kruiper
Using this abstraction it is possible to compile this file for aarch64.
2023-01-27Kernel: Use InterruptsState abstraction in execve.cppTimon Kruiper
This was using the x86_64 specific cpu_flags abstraction, which is not compatible with aarch64.
2023-01-27Kernel: Add Syscalls/fork.cpp to aarch64 buildTimon Kruiper
2023-01-27Kernel: Add Syscalls/mmap.cpp to aarch64 buildTimon Kruiper
2023-01-27Kernel: Make Syscalls/ptrace.cpp buildable for aarch64Timon Kruiper
2023-01-27Kernel: Move Memory/PageDirectory.{cpp,h} to arch-specific directoryTimon Kruiper
The handling of page tables is very architecture specific, so belongs in the Arch directory. Some parts were already architecture-specific, however this commit moves the rest of the PageDirectory class into the Arch directory. While we're here the aarch64/PageDirectory.{h,cpp} files are updated to be aarch64 specific, by renaming some members and removing x86_64 specific code.
2023-01-27Kernel: Factor our PreviousMode into RegisterState::previous_modeTimon Kruiper
Various places in the kernel were manually checking the cs register for x86_64, however to share this with aarch64 a function in RegisterState is added, and the call-sites are updated. While we're here the PreviousMode enum is renamed to ExecutionMode.
2023-01-21Kernel+Userland: Move LibC/sys/ioctl_numbers to Kernel/API/Ioctl.hAndrew Kaster
This header has always been fundamentally a Kernel API file. Move it where it belongs. Include it directly in Kernel files, and make Userland applications include it via sys/ioctl.h rather than directly.
2023-01-21Kernel+LibC: Move name length constants to Kernel/API from limits.hAndrew Kaster
Reduce inclusion of limits.h as much as possible at the same time. This does mean that kmalloc.h is now including Kernel/API/POSIX/limits.h instead of LibC/limits.h, but the scope could be limited a lot more. Basically every file in the kernel includes kmalloc.h, and needs the limits.h include for PAGE_SIZE.
2023-01-14Meta: Fix copyright header in Kernel/Syscalls/jail.cpp fileLiav A
I wrote that file in 2022, not Andreas in 2018.
2023-01-13Kernel: Require "stdio" pledge promise when calling get_root_session_idLiav A
2023-01-10Kernel+LibCore: Make %sid path parsing not take agesAndreas Kling
Before this patch, Core::SessionManagement::parse_path_with_sid() would figure out the root session ID by sifting through /sys/kernel/processes. That file can take quite a while to generate (sometimes up to 40ms on my machine, which is a problem on its own!) and with no caching, many of our programs were effectively doing this multiple times on startup when unveiling something in /tmp/session/%sid/ While we should find ways to make generating /sys/kernel/processes fast again, this patch addresses the specific problem by introducing a new syscall: sys$get_root_session_id(). This extracts the root session ID by looking directly at the process table and takes <1ms instead of 40ms. This cuts WebContent process startup time by ~100ms on my machine. :^)
2023-01-07Kernel: Mark Process::jail() method as constLiav A
We really don't want callers of this function to accidentally change the jail, or even worse - remove the Process from an attached jail. To ensure this never happens, we can just declare this method as const so nobody can mutate it this way.