summaryrefslogtreecommitdiff
path: root/Kernel/Arch
AgeCommit message (Collapse)Author
2020-03-06Kernel: Fix strange looking output on unhandled page faultAndreas Kling
2020-03-06CPU: Allow to use IRQs in range of 50 to 178Liav A
2020-03-02CPU: Change debug messages to fit the latest changesLiav A
2020-03-02Kernel: Use klog() instead of kprintf()Liav A
Also, duplicate data in dbg() and klog() calls were removed. In addition, leakage of virtual address to kernel log is prevented. This is done by replacing kprintf() calls to dbg() calls with the leaked data instead. Also, other kprintf() calls were replaced with klog().
2020-03-01Kernel: Remove some unnecessary .characters() when doing dbg()<<StringAndreas Kling
2020-02-29CPU: Simplify handle_interrupt() functionLiav A
2020-02-27CPU: Use dbg() instead of dbgprintf()Liav A
2020-02-24Kernel: Change get_sharing_devices_count() in GenericInterruptHandlerLiav A
The new method' name is sharing_devices_count(). The Serenity Coding Style tends to not accept the word "get" in methods' names if possible.
2020-02-24Kernel: Delete unused filesLiav A
2020-02-24CPU: Use the new interrupt componentsLiav A
Now we use the GenericInterruptHandler class instead of IRQHandler in the CPU functions. This commit adds an include to the ISR stub macros header file. Also, this commit adds support for IRQ sharing, so when an IRQHandler will try to register to already-assigned IRQ number, a SharedIRQHandler will be created to register both IRQHandlers.
2020-02-24CPU: Add 2 files with ISR stub macrosLiav A
2020-02-21Kernel: Don't trigger page faults during profiling stack walkAndreas Kling
The kernel sampling profiler will walk thread stacks during the timer tick handler. Since it's not safe to trigger page faults during IRQ's, we now avoid this by checking the page tables manually before accessing each stack location.
2020-02-21Kernel: Assert on page fault during IRQAndreas Kling
We're not equipped to deal with page faults during an IRQ handler, so add an assertion so we can immediately tell what's wrong. This is why profiling sometimes hangs the system -- walking the stack of the profiled thread causes a page fault and things fall apart.
2020-02-17Kernel: Replace "current" with Thread::current and Process::currentAndreas Kling
Suggested by Sergey. The currently running Thread and Process are now Thread::current and Process::current respectively. :^)
2020-02-16Kernel: Move all code into the Kernel namespaceAndreas Kling
2020-02-16Kernel: Rename RegisterDump => RegisterStateAndreas Kling
2020-02-10Kernel: Add getter and setter for the X86 CR3 registerAndreas Kling
This gets rid of a bunch of inline assembly.
2020-02-10Kernel: Remove more <LibBareMetal/Output/kstdio.h> includesAndreas Kling
2020-02-09Kernel: Use VirtualAddress & PhysicalAddress classes from LibBareMetalLiav A
2020-02-09Kernel: Apply changes to use LibBareMetal definitionsLiav A
2020-02-08x86: Simplify region unmapping a bitAndreas Kling
Add PageTableEntry::clear() to zero out a whole PTE, and use that for unmapping instead of clearing individual fields.
2020-02-01Kernel: Add memory scrubbing in slab_alloc() and slab_dealloc()Andreas Kling
These now scrub allocated and freed memory like kmalloc()/kfree() was already doing.
2020-02-01Kernel: Add crash logging heuristic for uninitialized kmalloc()/kfree()Andreas Kling
Since we scrub both kmalloc() and kfree() with predictable values, we can log a helpful message when hitting a crash that looks like it might be a dereference of such scrubbed data.
2020-01-22Revert "Kernel: Replace IRQHandler with the new InterruptHandler class"Andreas Kling
This reverts commit 6c72736b26a81a8f03d8dd47989bfffe26bb1c95. I am unable to boot on my home machine with this change in the tree.
2020-01-22Kernel: Replace IRQHandler with the new InterruptHandler classLiav A
System components that need an IRQ handling are now inheriting the InterruptHandler class. In addition to that, the initialization process of PATAChannel was changed to fit the changes. PATAChannel, E1000NetworkAdapter and RTL8139NetworkAdapter are now inheriting from PCI::Device instead of InterruptHandler directly.
2020-01-21Kernel: Remove map_for_kernel() in MemoryManagerLiav A
We don't need to have this method anymore. It was a hack that was used in many components in the system but currently we use better methods to create virtual memory mappings. To prevent any further use of this method it's best to just remove it completely. Also, the APIC code is disabled for now since it doesn't help booting the system, and is broken since it relies on identity mapping to exist in the first 1MB. Any call to the APIC code will result in assertion failed. In addition to that, the name of the method which is responsible to create an identity mapping between 1MB to 2MB was changed, to be more precise about its purpose.
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-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-18Kernel: Stop flushing GDT/IDT registers all the timeAndreas Kling
2020-01-18Kernel: Move all CPU feature initialization into cpu_setup()Andreas Kling
..and do it very very early in boot.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2020-01-18Kernel: Clean up MemoryManager initialization a bit moreAndreas Kling
Move the CPU feature enabling to functions in Arch/i386/CPU.cpp.
2020-01-17Kernel: Move kernel above the 3GB virtual address markAndreas Kling
The kernel and its static data structures are no longer identity-mapped in the bottom 8MB of the address space, but instead move above 3GB. The first 8MB above 3GB are pseudo-identity-mapped to the bottom 8MB of the physical address space. But things don't have to stay this way! Thanks to Jesse who made an earlier attempt at this, it was really easy to get device drivers working once the page tables were in place! :^) Fixes #734.
2020-01-14Kernel: Remove problematic memory mapping methodsLiav A
mmap() & mmap_region() methods are removed from ACPI & DMI components, and we replace them with the new MM.allocate_kernel_region() helper. Instead of doing a raw calculation for each VM address, from now on we can use helper functions to do perform those calculations in a neat, reusable and readable way.
2020-01-09Kernel: Rename {ss,esp}_if_crossRing to userspace_{ss,esp}Andreas Kling
These were always so awkwardly named.
2020-01-08Kernel: Enable SMAP protection on IRQ and exception entryAndreas Kling
It would be nice to do this in the assembly code, but we have to check if the feature is available before doing a CLAC, so I've put this in the C++ code for now.
2020-01-06Kernel: Fix SMAP violation when doing a crash dumpAndreas Kling
2020-01-05Kernel: Start implementing x86 SMAP supportAndreas Kling
Supervisor Mode Access Prevention (SMAP) is an x86 CPU feature that prevents the kernel from accessing userspace memory. With SMAP enabled, trying to read/write a userspace memory address while in the kernel will now generate a page fault. Since it's sometimes necessary to read/write userspace memory, there are two new instructions that quickly switch the protection on/off: STAC (disables protection) and CLAC (enables protection.) These are exposed in kernel code via the stac() and clac() helpers. There's also a SmapDisabler RAII object that can be used to ensure that you don't forget to re-enable protection before returning to userspace code. THis patch also adds copy_to_user(), copy_from_user() and memset_user() which are the "correct" way of doing things. These functions allow us to briefly disable protection for a specific purpose, and then turn it back on immediately after it's done. Going forward all kernel code should be moved to using these and all uses of SmapDisabler are to be considered FIXME's. Note that we're not realizing the full potential of this feature since I've used SmapDisabler quite liberally in this initial bring-up patch.
2020-01-03Kernel: Add a more expressive API for getting random bytesAndreas Kling
We now have these API's in <Kernel/Random.h>: - get_fast_random_bytes(u8* buffer, size_t buffer_size) - get_good_random_bytes(u8* buffer, size_t buffer_size) - get_fast_random<T>() - get_good_random<T>() Internally they both use x86 RDRAND if available, otherwise they fall back to the same LCG we had in RandomDevice all along. The main purpose of this patch is to give kernel code a way to better express its needs for random data. Randomness is something that will require a lot more work, but this is hopefully a step in the right direction.
2020-01-01Kernel: Add a random offset to kernel stacks upon syscall entryAndreas Kling
When entering the kernel from a syscall, we now insert a small bit of stack padding after the RegisterDump. This makes kernel stacks less deterministic across syscalls and may make some bugs harder to exploit. Inspired by Elena Reshetova's talk on kernel stack exploitation.
2020-01-01Kernel: Disable x86 RDTSC instruction in userspaceAndreas Kling
It's still possible to read the TSC via the read_tsc() syscall, but we will now clear some of the bottom bits for unprivileged users.
2020-01-01Kernel: Fix typo in Descriptor::set_limit()Andreas Kling
x86 descriptor limits are 20 bytes, not 24 bytes. This was already a 4-bit wide bitfield, so no damage done, but let's be correct.
2020-01-01Kernel: Switch to eagerly restoring x86 FPU state on context switchAndreas Kling
Lazy FPU restore is well known to be vulnerable to timing attacks, and eager restore is a lot simpler anyway, so let's just do it eagerly.
2020-01-01Kernel: Enable x86 UMIP (User Mode Instruction Prevention) if supportedAndreas Kling
This prevents code running outside of kernel mode from using the following instructions: * SGDT - Store Global Descriptor Table * SIDT - Store Interrupt Descriptor Table * SLDT - Store Local Descriptor Table * SMSW - Store Machine Status Word * STR - Store Task Register There's no need for userspace to be able to use these instructions so let's just disable them to prevent information leakage.
2020-01-01Kernel: Move CPU feature detection to Arch/x86/CPU.{cpp.h}Andreas Kling
We now refuse to boot on machines that don't support PAE since all of our paging code depends on it. Also let's only enable SSE and PGE support if the CPU advertises it.
2019-12-25Kernel: Interpret "reserved bit violation" page faults correctlyAndreas Kling
We don't actually react to these in any meaningful way other than crashing, but let's at least print the correct information. :^)
2019-12-25Kernel: Enable PAE (Physical Address Extension)Andreas Kling
Introduce one more (CPU) indirection layer in the paging code: the page directory pointer table (PDPT). Each PageDirectory now has 4 separate PageDirectoryEntry arrays, governing 1 GB of VM each. A really neat side-effect of this is that we can now share the physical page containing the >=3GB kernel-only address space metadata between all processes, instead of lazily cloning it on page faults. This will give us access to the NX (No eXecute) bit, allowing us to prevent execution of memory that's not supposed to be executed.
2019-12-25Kernel: Clean up CPU fault register dumpsAndreas Kling
These were looking a bit messy after we started using 32-bit fields to store segment registers in RegisterDumps.
2019-12-20Kernel: Remove AK_MAKE_NONCOPYABLE from PDE and PTE classesAndreas Kling
This avoids -Wclass-memaccess warnings exposed by the new Makefiles.