summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2020-01-20LibGUI: Use clamp() is various placesAndreas Kling
2020-01-20SB16: Map the DMA buffer in kernelspace so we can write to itAndreas Kling
This broke with the >3GB paging overhaul. It's no longer possible to write directly to physical addresses below the 8MB mark. Physical pages need to be mapped into kernel VM by using a Region. Fixes #1099.
2020-01-20Add AnonymousVMObject::create_with_physical_page()Andreas Kling
This can be used to create a VMObject for a single PhysicalPage.
2020-01-20Kernel: Write-only regions should still be mapped as presentAndreas Kling
There is no real "read protection" on x86, so we have no choice but to map write-only pages simply as "present & read/write". If we get a read page fault in a non-readable region, that's still a correctness issue, so we crash the process. It's by no means a complete protection against invalid reads, since it's trivial to fool the kernel by first causing a write fault in the same region.
2020-01-20Kernel: Remove some unnecessary casts to uintptr_tAndreas Kling
VirtualAddress is constructible from uintptr_t and const void*. PhysicalAddress is constructible from uintptr_t but not const void*.
2020-01-20Use uintptr_t instead of u32 when storing pointers as integersAndreas Kling
uintptr_t is 32-bit or 64-bit depending on the target platform. This will help us write pointer size agnostic code so that when the day comes that we want to do a 64-bit port, we'll be in better shape.
2020-01-20Kernel+AK: Add/fix uintptr_t and intptr_t definitionsAndreas Kling
We should move towards using uintptr_t instead of u32 for pointers everywhere, to prepare for an eventual 64-bit port.
2020-01-20WindowServer: Simplify WSMenu MouseWheel eventShannon Booth
A mouse move event needs to do a bit more work than what a mouse wheel event does. Mouse wheel just needs to update the hovered item, and update for a new hovered item. This also stops us from calling redraw() twice on a wheel event.
2020-01-20WindowServer: Stop infinite menu movement cycleShannon Booth
While I really enjoyed having an infinite cycle when I implemented menu keys (and seeing it wizz around and around :D), menu key movement should be consistent between menus - and an inifinite cycle does not make much sense for a scrollable menu.
2020-01-20AK: Add clamp() functionShannon Booth
This function can be used to more cleanly write the common operation of clamping a value between two values.
2020-01-19WindowServer: Allow scrolling of menus that don't fit on screenAndreas Kling
Menus now have a scroll offset (index based, not pixel based) which is controlled either with the mouse wheel or with the up/down arrow keys. This finally allows us to browse all of the fonts that @xTibor has made avilable through his serenity-fontdev project: https://github.com/xTibor/serenity-fontdev I'm not completely sure about the up/down arrows. They feel like maybe they occupy a bit too much vertical space. Also FIXME: this mechanism probably won't look completely right for menus that have separators in them. Fixes #1043.
2020-01-19Kernel: Add fast-path for sys$gettid()Andreas Kling
The userspace locks are very aggressively calling sys$gettid() to find out which thread ID they have. Since syscalls are quite heavy, this can get very expensive for some programs. This patch adds a fast-path for sys$gettid(), which makes it skip all of the usual syscall validation and just return the thread ID right away. This cuts Kernel/Process.cpp compile time by ~18%, from ~29 to ~24 sec.
2020-01-19Kernel: Add a 1-deep cache to Process::region_from_range()Andreas Kling
This simple cache gets hit over 70% of the time on "g++ Process.cpp" and shaves ~3% off the runtime.
2020-01-19Kernel: Add a Process::add_region() helperAndreas Kling
This is a private helper for adding a Region to Process::m_regions. It's just for convenience since it's a bit cumbersome to do this.
2020-01-19Kernel: Simplify PageDirectory swapping in sys$execve()Andreas Kling
Swap out both the PageDirectory and the Region list at the same time, instead of doing the Region list slightly later.
2020-01-19AK: Add NonnullOwnPtr::swap() as well for symmetryAndreas Kling
2020-01-19Kernel: Oops, fix bad sort order of available VM rangesAndreas Kling
This made the allocator perform worse, so here's another second off of the Kernel/Process.cpp compile time from a simple bugfix! (31s to 30s)
2020-01-19TmpFS: Grow the underlying inode buffer with 2x factor when written toAndreas Kling
Before this, we would end up in memcpy() churn hell when a program was doing repeated write() calls to a file in /tmp. An even better solution will be to only grow the VM allocation of the underlying buffer and keep using the same physical pages. This would eliminate all the memcpy() work. I've benchmarked this using g++ to compile Kernel/Process.cpp. With these changes, compilation goes from ~35 sec to ~31 sec. :^)
2020-01-19Kernel: Limit Thread::raw_backtrace() to the max profiler stack sizeAndreas Kling
Let's avoid walking overly long stacks here, since kmalloc() is finite.
2020-01-19Shell: Don't crash when stdout is not a TTYAndreas Kling
Let's just pretend we have 80 columns while running non-interactively. There are definitely nicer solutions here, and we should find them.
2020-01-19Kernel: Make ProcessPagingScope restore CR3 properlyAndreas Kling
Instead of restoring CR3 to the current process's paging scope when a ProcessPagingScope goes out of scope, we now restore exactly whatever the CR3 value was when we created the ProcessPagingScope. This fixes breakage in situations where a process ends up with nested ProcessPagingScopes. This was making profiling very fragile, and with this change it's now possible to profile g++! :^)
2020-01-19Kernel: Optimize VM range deallocation a bitAndreas Kling
Previously, when deallocating a range of VM, we would sort and merge the range list. This was quite slow for large processes. This patch optimizes VM deallocation in the following ways: - Use binary search instead of linear scan to find the place to insert the deallocated range. - Insert at the right place immediately, removing the need to sort. - Merge the inserted range with any adjacent range(s) in-line instead of doing a separate merge pass into a list copy. - Add Traits<Range> to inform Vector that Range objects are trivial and can be moved using memmove(). I've also added an assertion that deallocated ranges are actually part of the RangeAllocator's initial address range. I've benchmarked this using g++ to compile Kernel/Process.cpp. With these changes, compilation goes from ~41 sec to ~35 sec.
2020-01-19AK: Teach Vector::insert() to use memmove() for trivial typesAndreas Kling
2020-01-19AK: Support '+' qualifier in printf() to force sign for positive %d'sAndreas Kling
2020-01-19AK: Make it possible to swap() a NonnullRefPtr with itselfAndreas Kling
The generic swap() is not able to swap a NonnullRefPtr with itself, due to its use of a temporary and NonnullRefPtr asserting when trying to move() from an already move()'d instance.
2020-01-19AK: Add some missing "inline" keywords in StdLibExtras.hAndreas Kling
2020-01-19Kernel: Use copy_from_user() when appropriate during thread backtracingAndreas Kling
2020-01-19Kernel: Always switch to own page tables when crashing/assertingAndreas Kling
I noticed this while debugging a crash in backtrace generation. If a process would crash while temporarily inspecting another process's address space, the crashing thread would still use the other process's page tables while handling the crash, causing all kinds of confusion when trying to walk the stack of the crashing thread.
2020-01-19Kernel: Assert that copy_to/from_user() are called with user addressesAndreas Kling
This will panic the kernel immediately if these functions are misused so we can catch it and fix the misuse. This patch fixes a couple of misuses: - create_signal_trampolines() writes to a user-accessible page above the 3GB address mark. We should really get rid of this page but that's a whole other thing. - CoW faults need to use copy_from_user rather than copy_to_user since it's the *source* pointer that points to user memory. - Inode faults need to use memcpy rather than copy_to_user since we're copying a kernel stack buffer into a quickmapped page. This should make the copy_to/from_user() functions slightly less useful for exploitation. Before this, they were essentially just glorified memcpy() with SMAP disabled. :^)
2020-01-19Kernel: Let's say that everything < 3GB is user virtual memoryAndreas Kling
Technically the bottom 2MB is still identity-mapped for the kernel and not made available to userspace at all, but for simplicity's sake we can just ignore that and make "address < 0xc0000000" the canonical check for user/kernel.
2020-01-19Kernel: Only require "stdio" pledge for sending signals to selfAndreas Kling
This should match what OpenBSD does. Sending a signal to yourself seems basically harmless.
2020-01-19WindowServer: More natural mouse menu navigationShannon Booth
Use an imaginary triangle between the top and bottom of the submenu of a hovered item to determine whether the mouse is moving towards the submenu. If it is, we do not update the hovered item. This allows the submenu to stay open, making for much easier menu navigation. Closes #1094
2020-01-19LibDraw: Add beginnings of a triangle classShannon Booth
Currently the points of a triangle do not need to be initialised in a certain orientation. Currently, the only real method in the class is `contains`. However we can continue extending the class if and when we need more functionality.
2020-01-18Kernel: Do not return ENOENT for unresolved symbolsSergey Bugaev
ENOENT means "no such file or directory", not "no such symbol". Return EINVAL instead, as we already do in other cases.
2020-01-18Kernel: Move setting file flags and r/w mode to VFS::open()Sergey Bugaev
Previously, VFS::open() would only use the passed flags for permission checking purposes, and Process::sys$open() would set them on the created FileDescription explicitly. Now, they should be set by VFS::open() on any files being opened, including files that the kernel opens internally. This also lets us get rid of the explicit check for whether or not the returned FileDescription was a preopen fd, and in fact, fixes a bug where a read-only preopen fd without any other flags would be considered freshly opened (due to O_RDONLY being indistinguishable from 0) and granted a new set of flags.
2020-01-18Kernel: Do not open stdio fds for kernel processesSergey Bugaev
Kernel processes just do not need them. This also avoids touching the file (sub)system early in the boot process when initializing the colonel process.
2020-01-18Kernel: Pass correct permission flags when opening filesSergey Bugaev
Right now, permission flags passed to VFS::open() are effectively ignored, but that is going to change. * O_RDONLY is 0, but it's still nicer to pass it explicitly * POSIX says that binding a Unix socket to a symlink shall fail with EADDRINUSE
2020-01-18Kernel: Fix identifier casingSergey Bugaev
2020-01-18WindowServer: Print the error when failing to open /dev/fb0Sergey Bugaev
2020-01-18Kernel: Enforce W^X between sys$mmap() and sys$execve()Andreas Kling
It's now an error to sys$mmap() a file as writable if it's currently mapped executable by anyone else. It's also an error to sys$execve() a file that's currently mapped writable by anyone else. This fixes a race condition vulnerability where one program could make modifications to an executable while another process was in the kernel, in the middle of exec'ing the same executable. Test: Kernel/elf-execve-mmap-race.cpp
2020-01-18AK: NonnullRefPtr should allow assigning owner to owneeAndreas Kling
Given the following situation: struct Object : public RefCounted<Object> { RefPtr<Object> parent; } NonnullRefPtr<Object> object = get_some_object(); object = *object->parent; We would previously crash if 'object' was the only strongly referencing pointer to 'parent'. This happened because NonnullRefPtr would unref the outgoing pointee before reffing the incoming pointee. This patch fixes that by implementing NonnullRefPtr assignments using pointer swaps, just like RefPtr already did.
2020-01-18Kernel: Symbolicate kernel EIP on process crashAndreas Kling
Process::crash() was assuming that EIP was always inside the ELF binary of the program, but it could also be in the kernel.
2020-01-18Kernel: Validate the requested range in allocate_region_with_vmobject()Andreas Kling
2020-01-18Kernel: Use get_syscall_path_argument() in sys$execve()Andreas Kling
Paths passed to sys$execve() should certainly be subject to all the usual path validation checks.
2020-01-18LibC: Use the templated type consistently in strtol_impl<T>Andreas Kling
2020-01-18Kernel: Disallow mmap names longer than PATH_MAXAndreas Kling
2020-01-18Kernel: Stop flushing GDT/IDT registers all the timeAndreas Kling
2020-01-18Kernel: Clean up and reorganize init.cppAndreas Kling
This is where we first enter into the kernel, so we should make at least some effort to keep things nice and understandable.
2020-01-18Kernel: Move all CPU feature initialization into cpu_setup()Andreas Kling
..and do it very very early in boot.
2020-01-18ACPI: Re-enable ACPI initialization after paging changesAndreas Kling