summaryrefslogtreecommitdiff
path: root/Kernel
AgeCommit message (Collapse)Author
2021-07-17Kernel: Declare VM/RangeAllocator trivial destructor as defaultBrian Gianforcaro
This is a clang tidy recommendation.
2021-07-17Kernel: Remove stale include from VM/RangeAllocator.cppBrian Gianforcaro
This was left over after the latest big refactor of the VM subsystem.
2021-07-17Kernel: Convert RangeAllocator VERIFY to proper error handlingBrian Gianforcaro
If a user allocates above 0x0 and below the allowable usermode virtual address space, we need to return error instead of asserting. Fixes: #8484
2021-07-17LibC: Use 64-bit stack smash value for 64-bit modePeter Bindels
Otherwise it'll use the first 32 bits that happen to come after, leading to very weird bugs. Fixes #8601
2021-07-17Kernel: Make PAGE_MASK architecture independentHediadyoin1
2021-07-17Kernel: Initialize TimeManagement before using KernelRNGTom
We should initialize the timers before KernelRNG as the RNG may want to utilize system time as an entropy source. Fixes #8710
2021-07-17Kernel: Remove TimeManagement::initialized that wasn't implementedTom
2021-07-16Kernel+AK: Generate compile-time error for non-sized `delete`Daniel Bertalan
This is a much more ergonomic option than getting a `VERIFY_NOT_REACHED()` failure at run-time. I encountered this issue with Clang, where sized deallocation is not the default due to ABI breakage concerns. Note that we can't simply just not declare these functions, because the C++ standard states: > If this function with size parameter is defined, the program shall > also define the version without the size parameter.
2021-07-16Kernel: Implement aligned `operator new` and use itDaniel Bertalan
The compiler will use these to allocate objects that have alignment requirements greater than that of our normal `operator new` (4/8 byte aligned). This means we can now use smart pointers for over-aligned types. Fixes a FIXME.
2021-07-16Kernel: Tell the compiler about `operator new`'s alignmentDaniel Bertalan
By default, the compiler will assume that `operator new` returns pointers that are aligned correctly for every built-in type. This is not the case in the kernel on x64, since the assumed alignment is 16 (because of long double), but the kmalloc blocks are only `alignas(void*)`.
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-16Kernel: Release big lock when blocking on another lockTom
When blocking on a Lock other than the big lock and we're holding the big lock, we need to release the big lock first. This fixes some deadlocks where a thread blocks while holding the big lock, preventing other threads from getting the big lock in order to unblock the waiting thread.
2021-07-16Kernel: Fix some Lock problems and VERIFY statementsTom
When a Lock blocks (e.g. due to a mode mismatch or because someone else holds it) the lock mode will be updated to what was requested. There were also some cases where restoring locks may have not worked as intended as it may have been held already by the same thread. Fixes #8787
2021-07-16Kernel: Make the page table for the kernel image largerGunnar Beutner
Building the x86_64 kernel with ENABLE_EXTRA_KERNEL_DEBUG_SYMBOLS results in an image that is larger than 0x2000000 bytes.
2021-07-16Kernel: Make resizing the page tables for the kernel image easierGunnar Beutner
By using the KERNEL_PD_OFFSET constant we can avoid some of the hard-coded values in the boot code.
2021-07-16Kernel: Move end_of_kernel_image after the .ksyms sectionGunnar Beutner
Without this we won't be able to detect whether .ksyms overlaps the end of the page table we set up for the kernel image.
2021-07-16Kernel: Support specifying a 64-bit KERNEL_BASE addressGunnar Beutner
The kernel doesn't currently boot when using an address other than 0xc0000000 because the page tables aren't set up properly for that but this at least lets us build the kernel.
2021-07-16Kernel: Avoid unnecessary jump in the boot codeGunnar Beutner
The 32-bit boot code jumps to 0xc0000000 + entry address once page tables are set up. This is unnecessary for 64-bit mode because we'll do another far jump just moments later.
2021-07-16Kernel: Avoid hard-coding kernel virtual baseGunnar Beutner
2021-07-16Kernel: Remove stale forward declaration of BochsFramebufferDeviceLiav A
2021-07-16Kernel: Fix bogus check in Thread::WaitBlockCondition::finalize()Andreas Kling
I botched this in 859e5741ffd3c5be57a3c3ef4c08c6372e2ff35c, the check was supposed to be with Process::is_kernel_process(). This fixes an issue with zombie processes hanging around forever. Thanks tomuta for spotting it! :^)
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-16Kernel: Return ENOMEM on allocation failures in FramebufferDevice::mmapLuke
2021-07-16Kernel/Ext2FS: Don't hog inode lock in traverse_as_directory()Andreas Kling
Reimplement directory traversal in terms of read_bytes() instead of doing direct block access. This lets us avoid taking the inode lock while iterating over the directory contents.
2021-07-16Kernel/Ext2FS: Don't hog FS lock when calling base class flush_writes()Andreas Kling
Once we've finalized all the file system metadata in flush_writes(), we no longer need to hold the file system lock during the call to BlockBasedFileSystem::flush_writes().
2021-07-16Kernel/Ext2FS: Uncache unknown inode indices when flushing writesAndreas Kling
Ext2FS::get_inode() will remember unknown inode indices that it has been asked about and put them into the inode cache as null inodes. flush_writes() was not null-checking these while iterating, which was a bug I finally managed to hit. Flushing also seemed like a good time to drop unknown inodes from the cache, since there's no good reason to hold to them indefinitely.
2021-07-16Kernel: Don't hog file system lock when doing BlockBasedFileSystem I/OAndreas Kling
The file system lock is meant to protect the file system metadata (super blocks, bitmaps, etc.) Not protect processes from reading independent parts of the disk at once. This patch introduces a new lock to protect the *block cache* instead, which is the real thing that needs synchronization.
2021-07-16Kernel: Don't explicitly seek before I/O in BlockBasedFileSystemAndreas Kling
Use the new FileDescription APIs to avoid doing seek+read or seek+write as two separate operations.
2021-07-16Kernel: Add FileDescription read/write API that bypasses current offsetAndreas Kling
Forcing users of a FileDescription to seek before they can read/write makes it inherently racy. This patch adds variants of read/write that simply ignore the "current offset" of the description in favor of a caller-supplied offset.
2021-07-16Kernel/Ext2FS: Don't hog both locks in Ext2FSInode::lookup()Andreas Kling
This function was acquiring both the inode and file system locks (in that order) which could lead to deadlocks.
2021-07-15Kernel: Optionally dump scheduler state with stack tracesTom
This will dump stack traces of all threads when pressing Ctrl+Shift+Alt+F12
2021-07-15Kernel: Make new kernel build process work on macOSGunnar Beutner
Use objcopy from the toolchain so that the changes introduced in 7236584 will succeed on macOS. Fixes #8768.
2021-07-15Kernel: Convert RangeAllocator to using a RedBlackTree internallyAndreas Kling
This data structure is a much better fit for what is essentially a sorted list of non-overlapping ranges. Not using Vector means we no longer have to worry about Vector buffers getting huge. Only nice & small allocations from now on.
2021-07-15Kernel: Hoist VERIFY from a loop in RangeAllocator::allocate_specific()Andreas Kling
2021-07-15Kernel: Remove unnecessary locking in RangeAllocator::contains()Andreas Kling
The total range managed by a RangeAllocator doesn't change, so there's no need to take a spinlock while comparing against it.
2021-07-15Kernel: Convert RangeAllocator to east-const styleAndreas Kling
2021-07-15Kernel: Handle OOM when adding memory regions to Spaces :^)Idan Horowitz
2021-07-14Kernel: Make kernel symbols available much earlier in the boot processGunnar Beutner
This adds a new section .ksyms at the end of the linker map, reserves 5MiB for it (which are after end_of_kernel_image so they get re-used once MemoryManager is initialized) and then embeds the symbol map into the kernel binary with objcopy. This also shrinks the .ksyms section to the real size of the symbol file (around 900KiB at the moment). By doing this we can make the symbol map available much earlier in the boot process, i.e. even before VFS is available.
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-14Kernel: Detect and display CPUID Hyper-V dataJean-Baptiste Boric
2021-07-14Kernel: Detect and display CPUID hypervisor signatureJean-Baptiste Boric
2021-07-14Kernel: Add support for hypervisor CPUID featureJean-Baptiste Boric
2021-07-14Kernel/ProcFS: Allow a process directory to have a null Process pointerLiav A
In case we are about to delete the PID directory, we clear the Process pointer. If someone still holds a reference to the PID directory (by opening it), we still need to delete the process, but we can't delete the directory, so we will keep it alive, but any operation on it will fail by propogating the error to userspace about that the Process was deleted and therefore there's no meaning to trying to do operations on the directory. Fixes #8576.
2021-07-14Kernel: Convert MemoryManager to east-const styleAndreas Kling
2021-07-14Kernel: Don't mix AT&T and Intel ASM syntax in `boot.S`Daniel Bertalan
The rest of the file is in AT&T syntax, so for the time being, I'll switch these instructions to AT&T too to make Clang shut up.
2021-07-14Kernel: Allow passing null pointer to deleteDaniel Bertalan
The C++ standard says that it's legal to call the `delete` operator with a null pointer argument, in which case it should be a no-op. I encountered this issue when running a kernel that's compiled with Clang. I assume this fact was used for some kind of optimization.
2021-07-14Kernel: Fix inverted check in VirtIOConsolePortx-yl
We should really only try to open if we're closed. Oops :P
2021-07-14Kernel: Ignore subsequent calls to Process::dieTom
It's possible that another thread might try to exit the process just about the same time another thread does the same, or a crash happens. Also, we may not be able to kill all other threads instantly as they may be blocked in the kernel (though in this case they would get killed before ever returning back to user mode. So keep track of whether Process::die was already called and ignore it on subsequent calls. Fixes #8485
2021-07-14AK: Generalize ByteReaderHendiadyoin1
Also use it instead of CPU.h's possibly_unaligned_data interface
2021-07-14Kernel: Remove debug spam when PhysicalRegion::take_free_page() failsAndreas Kling
We can have multiple PhysicalRegions (often the case when there is a huge amount of RAM) so we really shouldn't print a debug message any time someone tries to allocate from one. They will move on to another region anyway.