summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls
AgeCommit message (Collapse)Author
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-25Kernel: Remove unused madvise(MADV_GET_VOLATILE)Andreas Kling
This was used to query the volatile state of a memory region, however nothing ever actually used it.
2021-07-25Kernel: Make purgeable memory a VMObject level concept (again)Andreas Kling
This patch changes the semantics of purgeable memory. - AnonymousVMObject now has a "purgeable" flag. It can only be set when constructing the object. (Previously, all anonymous memory was effectively purgeable.) - AnonymousVMObject now has a "volatile" flag. It covers the entire range of physical pages. (Previously, we tracked ranges of volatile pages, effectively making it a page-level concept.) - Non-volatile objects maintain a physical page reservation via the committed pages mechanism, to ensure full coverage for page faults. - When an object is made volatile, it relinquishes any unused committed pages immediately. If later made non-volatile again, we then attempt to make a new committed pages reservation. If this fails, we return ENOMEM to userspace. mmap() now creates purgeable objects if passed the MAP_PURGEABLE option together with MAP_ANONYMOUS. anon_create() memory is always purgeable.
2021-07-23Kernel: Use StringView when parsing pledges in sys$pledge(..)Brian Gianforcaro
This ensures no potential allocation as in some cases the pledge char* could be promoted to AK::String by the compiler to execute the comparison.
2021-07-23Kernel: Fix bug where we half apply pledges in sys$pledge(..)Brian Gianforcaro
This bug manifests it self when the caller to sys$pledge() passes valid promises, but invalid execpromises. The code would apply the promises and then return an error for the execpromises. This leaves the user in a confusing state, as the promises were silently applied, but we return an error suggesting the operation has failed. Avoid this situation by tweaking the implementation to only apply the promises / execpromises after all validation has occurred.
2021-07-23Kernel: Migrate sys$pledge to use the KString APIBrian Gianforcaro
This avoids potential unhandled OOM that's possible with the old copy_string_from_user API.
2021-07-23Kernel: Migrate sys$unveil to use the KString APIBrian Gianforcaro
This avoids potential unhandled OOM that's possible with the old copy_string_from_user API.
2021-07-23Kernel: Use StringView literals for fs_type match in sys$mount(..)Brian Gianforcaro
2021-07-23Kernel: Simplify VMObject locking & page fault handlersAndreas Kling
This patch greatly simplifies VMObject locking by doing two things: 1. Giving VMObject an IntrusiveList of all its mapping Region objects. 2. Removing VMObject::m_paging_lock in favor of VMObject::m_lock Before (1), VMObject::for_each_region() was forced to acquire the global MM lock (since it worked by walking MemoryManager's list of all regions and checking for regions that pointed to itself.) With each VMObject having its own list of Regions, VMObject's own m_lock is all we need. Before (2), page fault handlers used a separate mutex for preventing overlapping work. This design required multiple temporary unlocks and was generally extremely hard to reason about. Instead, page fault handlers now use VMObject's own m_lock as well.
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+LibC: Implement fcntl(2) advisory locksPeter Elliott
Advisory locks don't actually prevent other processes from writing to the file, but they do prevent other processes looking to acquire and advisory lock on the file. This implementation currently only adds non-blocking locks, which are all I need for now.
2021-07-20Kernel: Disable big process lock for sys$yield()Brian Gianforcaro
2021-07-20Kernel: Disable big process lock for sys$gettid()Brian Gianforcaro
This syscall reads a read only value from the current thread, and hence has no need for the big process lock.
2021-07-20Kernel: Disable big process lock for sys$getpid()Brian Gianforcaro
2021-07-20Kernel: Disable big process lock for sys$uname()Brian Gianforcaro
2021-07-20Kernel: Disable big process lock in sys$gethostname() sys$sethostname()Brian Gianforcaro
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-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-18Kernel: Rename Locker => MutexLockerAndreas Kling
2021-07-17Kernel: Rename Lock to MutexAndreas Kling
Let's be explicit about what kind of lock this is meant to be.
2021-07-17Kernel: Remove double RedBlackTree lookup in VM/Space region removalBrian Gianforcaro
We should never request a regions removal that we don't currently own. We currently assert this everywhere else by all callers. Instead lets just push the assert down into the RedBlackTree removal and assume that we will always successfully remove the region.
2021-07-16Kernel: Rename functions to be less confusingTom
Thread::yield_and_release_relock_big_lock releases the big lock, yields and then relocks the big lock. Thread::yield_assuming_not_holding_big_lock yields assuming the big lock is not being held.
2021-07-16AK+Kernel: Implement and use EnumBits has_any_flag()Timothy
This duplicates the old functionality of has_flag and will return true when any flags present in the mask are also in the value.
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-07-11Kernel: Make Region splitting OOM-safeAndreas Kling
Region allocation failures during splitting are now propagated all the way out to where we can return ENOMEM for them.
2021-07-11Kernel: Rename various *VMObject::create*() => try_create()Andreas Kling
try_*() implies that it can fail (and they all return RefPtr with nullptr signalling failure.)
2021-07-11Kernel: Make SharedInodeVMObject allocation OOM-safeAndreas Kling
2021-07-11Kernel: Make VirtualFileSystem::sync() staticAndreas Kling
2021-07-11Kernel: Rename VFS => VirtualFileSystemAndreas Kling
2021-07-11Kernel: Rename FS => FileSystemAndreas Kling
This matches our common naming style better.
2021-07-10Kernel: Logic fix in the pledge syscallRalf Donau
Pledge should check m_has_promises. Calling pledge("", nullptr) does not fail on an already pledged process anymore.
2021-07-10Kernel+Userland: Make the stack alignment comply with the System V ABIGunnar Beutner
The System V ABI for both x86 and x86_64 requires that the stack pointer is 16-byte aligned on entry. Previously we did not align the stack pointer properly. As far as "main" was concerned the stack alignment was correct even without this patch due to how the C++ _start function and the kernel interacted, i.e. the kernel misaligned the stack as far as the ABI was concerned but that misalignment (read: it was properly aligned for a regular function call - but misaligned in terms of what the ABI dictates) was actually expected by our _start function.
2021-07-09LibPthread+Kernel: Add pthread_kill() and the thread_kill syscallAli Mohammad Pur
2021-07-07Kernel: Map non-page-aligned text segments correctlyDaniel Bertalan
`.text` segments with non-aligned offsets had their lengths applied to the first page's base address. This meant that in some cases the last PAGE_SIZE - 1 bytes weren't mapped. Previously, it did not cause any problems as the GNU ld insists on aligning everything; but that's not the case with the LLVM toolchain.
2021-07-07Kernel: Custody::absolute_path() => try_create_absolute_path()Max Wipfli
This converts most users of Custody::absolute_path() to use the new try_create_absolute_path() API, and return ENOMEM if the KString allocation fails.
2021-07-07Kernel: Replace usage of LexicalPath with KLexicalPathMax Wipfli
This replaces all uses of LexicalPath in the Kernel with the functions from KLexicalPath. This also allows the Kernel to stop including AK::LexicalPath.
2021-07-07Kernel+KeyboardSettings: Remove numlock syscall and implement ioctlEdwin Hoksberg
2021-07-07Kernel: Do not hold spinlock while touching user mode futex valuesTom
The user_atomic_* functions are subject to the same rules as copy_from/to/user, which may require preemption.
2021-07-07Kernel: Fix futex race that could lead to thread waiting foreverTom
There is a race condition where we would remove a FutexQueue from our futex map and in the meanwhile another thread started to queue itself into that very same futex, leading to that thread to wait forever as no other wake operation could discover that removed FutexQueue. This fixes the problem by: * Tracking imminent waits, which prevents a new FutexQueue from being deleted that a thread will wait on momentarily * Atomically marking a FutexQueue as removed, which prevents a thread from waiting on it before it is actually removed from the futex map.
2021-07-05Kernel+LibC: Remove sys$donate()Andreas Kling
This was an old SerenityOS-specific syscall for donating the remainder of the calling thread's time-slice to another thread within the same process. Now that Threading::Lock uses a pthread_mutex_t internally, we no longer need this syscall, which allows us to get rid of a surprising amount of unnecessary scheduler logic. :^)
2021-07-05KeyboardSettings+Kernel: Setting to enable Num Lock on loginForLoveOfCats
2021-07-04Everywhere: Fix incorrect usages of AK::CheckedIdan Horowitz
Specifically, explicitly specify the checked type, use the resulting value instead of doing the same calculation twice, and break down calculations to discrete operations to ensure no intermediary overflows are missed.
2021-07-04Kernel: Implement TLS support for x86_64Gunnar Beutner
2021-07-04Kernel: Don't allow allocate_tls() if the process has multiple threadsGunnar Beutner
We can't safely update the other threads' FS selector. This shouldn't be a problem in practice because allocate_tls() is only used by the loader.
2021-07-03Everywhere: Fix some alignment issuesDaniel Bertalan
When creating uninitialized storage for variables, we need to make sure that the alignment is correct. Fixes a KUBSAN failure when running kernels compiled with Clang. In `Syscalls/socket.cpp`, we can simply use local variables, as `sockaddr_un` is a POD type. Along with moving the `alignas` specifier to the correct member, `AK::Optional`'s internal buffer has been made non-zeroed by default. GCC emitted bogus uninitialized memory access warnings, so we now use `__builtin_launder` to tell the compiler that we know what we are doing. This might disable some optimizations, but judging by how GCC failed to notice that the memory's initialization is dependent on `m_has_value`, I'm not sure that's a bad thing.
2021-07-01Kernel+LibPthread: Add support for usermode threads on x86_64Gunnar Beutner
2021-07-01Kernel+LibPthread: Remove m_ prefix for public membersGunnar Beutner