summaryrefslogtreecommitdiff
path: root/Kernel
AgeCommit message (Collapse)Author
2021-05-27Kernel+AK: Move UBSanitizer to AK, and to AK namespaceAndrew Kaster
In preparation for copying UBSanitizer to userspace, move the header to AK :^)
2021-05-27Kernel: Add ENABLE_EXTRA_KERNEL_DEBUG_SYMBOLS option to set Og and ggdb3Andrew Kaster
When debugging kernel code, it's necessary to set extra flags. Normal advice is to set -ggdb3. Sometimes that still doesn't provide enough debugging information for complex functions that still get optimized. Compiling with -Og gives the best optimizations for debugging, but can sometimes be broken by changes that are innocuous when the compiler gets more of a chance to look at them. The new CMake option enables both compile options for kernel code.
2021-05-27Kernel: Explicitly initialize bools in IOAPIC mappingAndrew Kaster
The compiler couldn't convince itself that these are always initialized when compiling with Og. They are always initialized before use, because the only branch where they weren't had VERIFY_NOT_REACHED.
2021-05-27Kernel: Pass trampolines instead of lambdas to create_kernel_processAndrew Kaster
With -Og, all calls to create_kernel_process were triggering -Wnonnull when creating these lambdas that get implicitly converted to function pointers. A different design of create_kernel_process to use AK::Function instead might avoid this awkward behavior.
2021-05-27Kernel: Let the user read/write more than one page from/to dev filesGunnar Beutner
Previously reads and writes to /dev/zero, /dev/full, /dev/null and /dev/random were limited to 4096 bytes. This removes that restriction so that users can enjoy more zero bytes in their buffers.
2021-05-26Kernel: Block when writing to TCP sockets when the send window is fullGunnar Beutner
Previously we'd just dump those packets into the network adapter's send queue and hope for the best. Instead we should wait until the peer has sent TCP ACK packets. Ideally this would parse the TCP window size option from the SYN or SYN|ACK packet, but for now we just assume the window size is 64 kB.
2021-05-26Kernel: Avoid allocations when sending IP packetsGunnar Beutner
Previously we'd allocate buffers when sending packets. This patch avoids these allocations by using the NetworkAdapter's packet queue. At the same time this also avoids copying partially constructed packets in order to prepend Ethernet and/or IPv4 headers. It also properly truncates UDP and raw IP packets.
2021-05-26Kernel: Move packet allocation into helper methodsGunnar Beutner
2021-05-26Kernel: Switch VMObject to IntrusiveList from InlineLinkedListBrian Gianforcaro
2021-05-26Kernel: Switch Region to IntrusiveList from InlineLinkedListBrian Gianforcaro
2021-05-26Kernel: Switch LocalSocket to IntrusiveList from InlineLinkedListBrian Gianforcaro
2021-05-26Kernel: Switch Inode to IntrusiveList from InlineLinkedListBrian Gianforcaro
2021-05-25Kernel: Don't try to send TCP packets larger than the MSSGunnar Beutner
Previously TCPSocket::send_tcp_packet() would try to send TCP packets which matched whatever size the userspace program specified. We'd try to break those packets up into smaller fragments, however a much better approach is to limit TCP packets to the maximum segment size and avoid fragmentation altogether.
2021-05-25Kernel: Validate we don't hold s_mm_lock during context switchBrian Gianforcaro
Since `s_mm_lock` is a RecursiveSpinlock, if a kernel thread gets preempted while accidentally hold the lock during switch_context, another thread running on the same processor could end up manipulating the state of the memory manager even though they should not be able to. It will just bump the recursion count and keep going. This appears to be the root cause of weird bugs like: #7359 Where page protection magically appears to be wrong during execution. To avoid these cases lets guard this specific unfortunate case and make sure it can never go unnoticed ever again. The assert was Tom's idea to help debug this, so I am going to tag him as co-author of this commit. Co-Authored-By: Tom <tomut@yahoo.com>
2021-05-25Kernel: Release the paging lock while reading from the diskTom
Because reading from the disk may preempt, we need to release the paging lock.
2021-05-25Kernel: Add ScopedLockRelease to temporarily release a LockTom
2021-05-24LibVT: Add Alternate Screen Buffer supportDaniel Bertalan
The Alternate Screen Buffer is used by full-screen terminal applications (like `vim` and `nano`). Its data is stored separately from the normal buffer, therefore after applications using it exit, everything looks like it was before, the bottom of their interfaces isn't visible. An interesting feature is that it does not support scrollback, so it consumes less memory by not having to allocate lines for history. Because of the need to save and restore state between the switches, some correctness issues relating to it were also fixed in this commit.
2021-05-24LibVT+Kernel: Add support for setting cursor stylesDaniel Bertalan
This commit introduces support for 3 new escape sequences: 1. Stop blinking cursor mode 2. `DECTCEM` mode (enable/disable cursor) 3. `DECSCUSR` (set cursor style) `TerminalWidget` now supports the following cursor types: block, underline and vertical bar. Each of these can blink or be steady. `VirtualConsole` ignores these (just as we were doing before).
2021-05-24Kernel: Disable profiling if setting up the buffer or timer failedGunnar Beutner
2021-05-24Kernel: Signal EOF/EOL characters properly in `TTY`Daniel Bertalan
I introduced a regression in #7184 where `TTY` would report 1 byte read in canonical mode even if we had no more characters left. This was caused by counting the '\0' that denotes EOF into the number of characters that were read. The fix was simple: exclude the EOF character from the number of bytes. This still wouldn't be correct by itself, as the EOF and EOL control characters could change between when the data was written to the TTY and when it is read. We fix this by signaling out-of-band whether something is a special character. End-of-file markers have a value of zero and have their special bits set. Any other bytes with a special flag are treated as line endings. This is possible, as POSIX doesn't allow special characters to be 0. Fixes #7419
2021-05-23Kernel: Make sure we only log profiling events when m_profiling is trueGunnar Beutner
Previously the process' m_profiling flag was ignored for all event types other than CPU samples. The kfree tracing code relies on temporarily disabling tracing during exec. This didn't work for per-process profiles and would instead panic. This updates the profiling code so that the m_profiling flag isn't ignored.
2021-05-22Kernel: Print a message to debug log after writing a perfcore fileAndreas Kling
2021-05-22Kernel/Net: Make interfaces to have persistent namesLiav A
There's no good reason to distinguish between network interfaces based on their model. It's probably a good idea to try keep the names more persistent so scripts written for a specific network interface will be useable after hotplug event (or after rebooting with new hardware setup).
2021-05-22Kernel: Remove an allocation from VFS::resolve_path_without_veil (#7287)Mart G
Use GenericLexer to replace a call to StringView::split() since that returns its result in a heap-allocating Vector.
2021-05-21Kernel/Commandline: Allow the user to specify an embedded stringLiav A
This is by default left empty, so people won't run the kernel in a mode which they didn't want to. The embedded string will override the supplied commandline from the bootloader, which is good for debugging sessions. This change seemed important for me, because I debug the kernel on bare metal with iPXE, and every change to the commandline meant that I needed rewrite a new iPXE USB image with a modified iPXE script.
2021-05-21Kernel/CPU: Fix awkward printing early on bootLiav A
This usage of the word "installing" seemed for me for a long time as a wrong thing, so let's make it better now.
2021-05-21Kernel: Print commandline after initializing itLiav A
2021-05-21Kernel/VirtualConsole: Fix grammar error in commentLiav A
2021-05-21Kernel: Ignore interfaces without an IP address when routing packagesGunnar Beutner
Let's not route packages through interfaces which don't have an address yet unless we're explicitly asked to (e.g. by DHCPClient).
2021-05-21Kernel: Make sure network adapters have unique namesGunnar Beutner
Previously we'd just slap 0 onto the adapter's basename. This ensures we actually end up with unique names.
2021-05-21Kernel/PCI: Fix support of multiple PCI host controllers enumerationLiav A
First scan PCI bus 0. Find any device on that bus, and if it's a PCI-to-PCI bridge, recursively scan it too. Then try to handle Multiple PCI host bridges on slot 0, device 0. If we happen to miss some PCI buses because they are not reachable through recursive PCI-to-PCI bridges scanning starting from bus 0, we might find them in this scanning.
2021-05-21Kernel/Graphics: Indicate initialization failed if no device was foundLiav A
2021-05-21Revert "Kernel: Avoid allocating under spinlock in ProcessGroup::find_or_create"Brian Gianforcaro
This reverts commit e95eb7a51d8295c96cddf20f116139deecbb69d4. This is causing some sort of list corruption, as evident by #7313 I haven't been able to figure it out yet, so lets revert this change until I can figure out what's going on.
2021-05-21Revert "Kernel: Fix regression, removing a ProcessGroup that not in the list"Brian Gianforcaro
This reverts commit bbe315d8c0e36368091806f7ba1860d848e9bca7. This is un-needed when reverting the parent commit.
2021-05-21Kernel: Fix type, dectivate_writes => deactivate_writesLiav A
2021-05-21Kernel/Graphics: Choose VMObject considering enabled state when mmapingLiav A
When mmaping a Framebuffer from userspace, we need to check whether the framebuffer device is actually enabled (e.g. graphical mode is being used) or a textual VirtualConsole is active. Considering the above state, we mmap the right VMObject to ensure we don't have graphical artifacts if we change the resolution from DisplaySettings, changed to textual mode and after the resolution change was reverted, we will see the Desktop reappearing even though we are still in textual mode.
2021-05-21Kernel: Fix framebuffer resolution modesetting after bootLiav A
If we tried to change the resolution before of this patch, we triggered a kernel crash due to mmaping the framebuffer device again. Therefore, on mmaping of the framebuffer device, we create an entire new set of VMObjects and Regions for the new settings. Then, when we change the resolution, the framebuffersconsole needs to be updated with the new resolution and also to be refreshed with the new settings. To ensure we handle both shrinking of the resolution and growth of it, we only copy the right amount of available data from the cells Region.
2021-05-21Kernel/TTY: Don't flush dirty lines if VirtualConsole is not activeLiav A
2021-05-21Kernel: Process request to change virtual console from the IO Work queueLiav A
Instead of processing the input after receiving an IRQ, we shift the responsibility to the io work queue to handle this for us, so if a page fault occurs when trying to switch the VirtualConsole, the kernel can handle that.
2021-05-20Kernel: Close a Thread tid lookup raceTom
There is a window between dropping a thread's last reference and it being removed from the list. Found in #5541
2021-05-20Kernel: Stop allocating the PS2KeyboardDevice in the eternal heapIdan Horowitz
The PS2KeyboardDevice can be free'd in try_to_initialize if the initialization failed, resulting in an assertion.
2021-05-20Meta: Make generate_state_machine() generate a proper targetAli Mohammad Pur
And use GENERATED_SOURCES (or add_dependencies) to make LibVT depend on that target. Fixes a FIXME.
2021-05-20Kernel: Fix regression, removing a ProcessGroup that not in the listBrian Gianforcaro
I introduced this bug in e95eb7a51, where it's possible that the ProcessGroup is created, but we never add it to the list. Make sure we check that we are in the list before removal. This only broke booting in self-test mode oddly enough. Reported-By: Andrew Kaster <andrewdkaster@gmail.com>
2021-05-20Kernel: Use the Function class for smp_broadcast()/smp_unicast()Gunnar Beutner
This avoids allocations for smp_broadcast() and smp_unicast() by using the Function class.
2021-05-20Kernel: Use the Function class for deferred_call_queue()Gunnar Beutner
This avoids allocations for deferred_call_queue().
2021-05-20Kernel: Remove an allocation when blocking a threadGunnar Beutner
When blocking a thread with a timeout we would previously allocate a Timer object. This removes the allocation for that Timer object.
2021-05-20Kernel: Avoid allocating under spinlock in ProcessGroup::find_or_createBrian Gianforcaro
Avoid allocating while holding the g_process_groups_lock spinlock, it's a pattern that has a negative effect on performance and scalability, especially given that it is a global lock, reachable by all processes.
2021-05-20Kernel: Make ProcessGroup::find_or_create API OOM safeBrian Gianforcaro
Make ProcessGroup::find_or_create & ProcessGroup::create OOM safe, by moving to adopt_ref_if_nonnull.
2021-05-20Kernel: Remove s_processor_lock by making s_processors statically sizedBrian Gianforcaro
Currently in SMP mode we hard code support for up to only 8 processors. There is no reason for this to be a dynamic allocation that needs to be guarded by a spinlock. Instead use a Array<T* with inline storage of 8, allowing each processor to initialize it self in place, avoiding all the need for locks.
2021-05-20Kernel: Do not allocate AnonymousVMObject's under spin lockBrian Gianforcaro
Spinlocks guard short regions, with hopefully no other locks being taken in the process. Violating constraints usually had detrimental effects on platform stability as well as performance and scalability. Allocating memory takes it own locks, and can in some cases even allocate new regions, and thus violates these tenants. Move the AnonymousVMObject creation outside of the spinlock as creation does not modify any shared state.