summaryrefslogtreecommitdiff
path: root/Kernel
AgeCommit message (Collapse)Author
2020-09-17LibC: Convert SO_ constants to enumNico Weber
I want to add another entry to this list and don't want to have to think of a number for it.
2020-09-17Kernel: Plumb packet receive timestamp from NetworkAdapter to Socket::recvfromNico Weber
Since the receiving socket isn't yet known at packet receive time, keep timestamps for all packets. This is useful for keeping statistics about in-kernel queue latencies in the future, and it can be used to implement SO_TIMESTAMP.
2020-09-17Kernel+LibC+UserspaceEmulator: Mostly add recvmsg(), sendmsg()Nico Weber
The implementation only supports a single iovec for now. Some might say having more than one iovec is the main point of recvmsg() and sendmsg(), but I'm interested in the control message bits.
2020-09-17Kernel: Unbreak sys$pledge()Andreas Kling
We were dropping all the incoming pledge promise strings and parsing "" instead. Fixes #3519.
2020-09-16Kernel: Return ENOMEM in more placesLuke
There are plenty of places in the kernel that aren't checking if they actually got their allocation. This fixes some of them, but definitely not all. Fixes #3390 Fixes #3391 Also, let's make find_one_free_page() return nullptr if it doesn't get a free index. This stops the kernel crashing when out of memory and allows memory purging to take place again. Fixes #3487
2020-09-16Kernel: Fix kernel crash in get_dir_entries when buffer too small.asynts
Before e06362de9487806df92cf2360a42d3eed905b6bf this was a sneaky buffer overflow. BufferStream did not do range checking and continued to write past the allocated buffer (the size of which was controlled by the user.) The issue surfaced after my changes because OutputMemoryStream does range checking. Not sure how exploitable that bug was, directory entries are somewhat controllable by the user but the buffer was on the heap, so exploiting that should be tough.
2020-09-16Kernel: Handle Thread::State::Dead in sys$waitid()Andreas Kling
I'm not sure how it happened, but it looks like I caught a thread in this state so let's just handle it the same way we do Dying.
2020-09-15Kernel: Fix thread donation hanging the systemTom
Fixes two flaws in the thread donation logic: Scheduler::donate_to would never really donate, but just trigger a deferred yield. And that deferred yield never actually donated to the beneficiary. So, when we can't immediately donate, we need to save the beneficiary and use this information as soon as we can perform the deferred context switch. Fixes #3495
2020-09-15Kernel: Don't symbolicate stack traces in IRQ handlersTom
If we're capturing a stack trace in an IRQ handler, don't try to symbolicate it as we may not be able to access all pages.
2020-09-15FileSystem: Use OutputMemoryStream instead of BufferStream.asynts
2020-09-15Kernel: Use Userspace<> for sys$writevNico Weber
2020-09-14Kernel: Handle safe_memcpy/safe_memset/safe_strnlen faults in irq handlersTom
Fix gracefully failing these calls if used within IRQ handlers. If we're handling IRQs, we need to handle these failures first, because we can't really resolve page faults in a meaningful way. But if we know that it was one of these functions that failed, then we can gracefully handle the situation. This solves a crash where the Scheduler attempts to produce backtraces in the timer irq, some of which cause faults. Fixes #3492
2020-09-14Kernel: Stop back trace on a null base pointerTom
This silences some warnings trying to copy from null when capturing a stack trace.
2020-09-13Kernel: Make copy_to/from_user safe and remove unnecessary checksTom
Since the CPU already does almost all necessary validation steps for us, we don't really need to attempt to do this. Doing it ourselves doesn't really work very reliably, because we'd have to account for other processors modifying virtual memory, and we'd have to account for e.g. pages not being able to be allocated due to insufficient resources. So change the copy_to/from_user (and associated helper functions) to use the new safe_memcpy, which will return whether it succeeded or not. The only manual validation step needed (which the CPU can't perform for us) is making sure the pointers provided by user mode aren't pointing to kernel mappings. To make it easier to read/write from/to either kernel or user mode data add the UserOrKernelBuffer helper class, which will internally either use copy_from/to_user or directly memcpy, or pass the data through directly using a temporary buffer on the stack. Last but not least we need to keep syscall params trivial as we need to copy them from/to user mode using copy_from/to_user.
2020-09-13Kernel: Add safe_memcpy, safe_memset and safe_strnlenTom
These special functions can be used to safely copy/set memory or determine the length of a string, e.g. provided by user mode. In the event of a page fault, safe_memcpy/safe_memset will return false and safe_strnlen will return -1.
2020-09-12Kernel: Remove spurious ProcessInspectionHandleBen Wiederhake
The class was removed in 538b985487fd958a7e8663a32867ac39d6643d04.
2020-09-12Kernel: Fix various forward declarationsBen Wiederhake
I decided to modify MappedROM.h because all other entried in Forward.h are also classes, and this is visually more pleasing. Other than that, it just doesn't make any difference which way we resolve the conflicts.
2020-09-10Kernel: Rename Process::is_ring0/3 to Process::is_kernel/user_processTom
Since "rings" typically refer to code execution and user processes can also execute in ring 0, rename these functions to more accurately describe what they mean: kernel processes and user processes.
2020-09-10Kernel: Fix detecting in what ring a crash happenedTom
The ring is determined based on the CS register. This fixes crashes being handled as ring 3 crashes even though EIP/CS clearly showed that the crash happened in the kernel.
2020-09-10IPv4: Truncate raw socket reads past buffer lengthAvery
In addition to being the proper POSIX etiquette, it seems like a bad idea for issues like the one seen in #3428 to result in a kernel crash. This patch replaces the current behavior of failing on insufficient buffer size to truncating SOCK_RAW messages to the buffer size. This will have to change if/when MSG_PEEK is implemented, but for now this behavior is more compliant and logical than just bailing.
2020-09-09Kernel+LibC+UE: Introduce SIGINFO (generated with ^T)Andreas Kling
This signal is ignored by default, but can be caught to implement state reporting a la BSD. :^)
2020-09-09Kernel: Fix heap expansion loopTom
By being a bit too greedy and only allocating how much we need for the failing allocation, we can end up in an infinite loop trying to expand the heap further. That's because there are other allocations (e.g. logging, vmobjects, regions, ...) that happen before we finally retry the failed allocation request. Also fix allocating in page size increments, which lead to an assertion when the heap had to grow more than the 1 MiB backup.
2020-09-09Kernel: Optimize single physical page allocation and randomize returnsTom
Rather than trying to find a contiguous set of bits of size 1, just find one single available bit using a hint. Also, try to randomize returned physical pages a bit by placing them into a 256 entry queue rather than making them available immediately. Then, once the queue is filled, pick a random one, make it available again and use that slot for the latest page to be returned.
2020-09-09Kernel: Keep signal state in syncTom
In c3d231616c1d20309b2b568f383fbcb736887dad we added the atomic variable m_have_any_unmasked_pending_signals tracking the state of pending signals. Add helper functions that automatically update this variable as needed.
2020-09-08AK: Remove FixedArray class.asynts
2020-09-08Refactor: Replace usages of FixedArray with Vector.asynts
2020-09-08Refactor: Replace usages of FixedArray with Array.asynts
2020-09-07Kernel: Fix crash when delivering signal to barely created threadTom
We need to wait until a thread is fully set up and ready for running before attempting to deliver a signal. Otherwise we may not have a user stack yet. Also, remove the Skip0SchedulerPasses and Skip1SchedulerPass thread states that we don't really need anymore with software context switching. Fixes the kernel crash reported in #3419
2020-09-07Kernel: Let TimeManagement keep epoch time as timespecNico Weber
Previously, it was kept as just a time_t and the sub-second offset was inferred from the monotonic clock. This means that sub-second time adjustments were ignored. Now that `ntpquery -s` can pass in a time with sub-second precision, it makes sense to keep time at that granularity in the kernel. After this, `ntpquery -s` immediately followed by `ntpquery` shows an offset of 0.02s (that is, on the order of network roundtrip time) instead of up to 0.75s previously.
2020-09-06Kernel: Track time-of-last-write in SlavePTY and report it as mtimeAndreas Kling
2020-09-06Kernel: Make File weakableAndreas Kling
This will be useful for some things. This also removes the need for TCPSocket to be special about this.
2020-09-06Kernel: Virtualize the File::stat() operationAndreas Kling
Instead of FileDescriptor branching on the type of File it's wrapping, add a File::stat() function that can be overridden to provide custom behavior for the stat syscalls.
2020-09-06Kernel: Rename FileDescription::fstat() => stat()Andreas Kling
2020-09-06Kernel: Remove bogus FIXME in TTY::write()Andreas Kling
Failure to send SIGTTOU to the current process is not something that should cause write() to fail with -ESRCH.
2020-09-05Kernel/USB: Disable autodetection of UHCI controllers for nowAndreas Kling
Until this thing becomes stable, let's not bother everyone with it.
2020-09-05Kernel/USB: Start the UHCI controller after resetting itAndreas Kling
2020-09-04Kernel: Add a missing "#pragma once"Andreas Kling
2020-09-04Kernel/USB: Add a simple UHCIController::stop()Andreas Kling
This stops the controller and waits for it to complete.
2020-09-04Kernel/USB: Add some constants for the USBCMD and USBSTS bitsAndreas Kling
2020-09-04Kernel/USB: Start fleshing out a basic UHCI controller driver :^)Andreas Kling
Let's see if we can talk to some USB devices. We will now detect a UHCI controller if present on the PCI bus.
2020-09-03Kernel: Add PCI::get_programming_interface(PCI::Address)Andreas Kling
This returns the programming interface at a given PCI address. This is sometimes referred to as "prog-if" on other systems.
2020-09-02Kernel: Handle committing pages in regions more gracefullyTom
Sometimes a physical underlying page may be there, but we may be unable to allocate a page table that may be needed to map it. Bubble up such mapping errors so that they can be handled more appropriately.
2020-09-02Kernel: Use removed memory as backup if backup hasn't been allocatedTom
It may be impossible to allocate more backup memory after expanding the heap if memory is running low. In that case we wouldn't allocate backup memory until trying to expand the heap again. But we also wouldn't take advantage of using removed memory as backup, which means that no backup memory would be available when the heap needs to grow again, causing subsequent expansion to fail because there is no backup memory.
2020-09-02Kernel: Prevent recursive expansion or removing memory while expanding itTom
The process of expanding memory requires allocations and deallocations on the heap itself. So, while we're trying to expand the heap, don't remove memory just because we might briefly not need it. Also prevent recursive expansion attempts.
2020-09-01Kernel: Fix memory purge clobbering mapped page directory in ensure_pteTom
If allocating a page table triggers purging memory, we need to call quickmap_pd again to make sure the underlying physical page is remapped to the correct one. This is needed because purging itself may trigger calls to ensure_pte as well. Fixes #3370
2020-09-01Kernel: Remove assertion from Region::commitTom
We should be able to gracefully fail a commit in low-memory situations.
2020-09-01Kernel: Only remap regions if memory was purged from themTom
2020-09-01Kernel: Preserve internal state in cloned PurgeableVMObjectsAndreas Kling
When cloning a purgeable memory region (which happens on fork), we need to preserve the "was purged" and "volatile" state of the original region, or they will always appear as non-volatile and unpurged regions in the child process. Fixes #3374.
2020-09-01Build: Add some -Wno-unknown-warning-option flags to CXXFLAGSAndreas Kling
Patch from Anonymous.
2020-08-31Kernel: Fix Processor::features_string() stopping too early and detect more ↵Luke
features The exit condition for the loop was sizeof(m_features) * 8, which was 32. Presumably this was supposed to mean 32 bits, but it actually made it stop as soon as it reached the 6th bit. Also add detection for more SIMD CPU features.