summaryrefslogtreecommitdiff
path: root/Kernel/init.cpp
AgeCommit message (Collapse)Author
2021-12-18Kernel: Use ksyms in-place instead of duplicating them into eternal heapAndreas Kling
We can leave the .ksyms section mapped-but-read-only and then have the symbols index simply point into it. Note that we manually insert null-terminators into the symbols section while parsing it. This gets rid of ~950 KiB of kmalloc_eternal() at startup. :^)
2021-12-14Kernel: Allow switching to IOAPIC mode even without enabling SMPLiav A
This small change allows to use the IOAPIC by default without to enable SMP mode, which emulates Uni-Processor setup with IOAPIC instead of using the PIC. This opens the opportunity to utilize other types of interrupts like MSI and MSI-X interrupts.
2021-12-05Kernel: Mark kernel smart-pointer classes as [[nodiscard]]Sam Atkins
And cast the unused return values to void.
2021-11-23Kernel: Implement AC97 audio device driverJelle Raaijmakers
2021-11-23Kernel: Teach DeviceManagement to handle multiple audio devicesJelle Raaijmakers
2021-11-23Kernel: Move SB16 to Audio subdirectoryJelle Raaijmakers
2021-10-17Everywhere: Make some symbols `__attribute__((used))` for LTODaniel Bertalan
With these changes, the userland builds correctly with Clang's ThinLTO enabled.
2021-10-14Kernel: Add per platform Processor.h headersJames Mintram
The platform independent Processor.h file includes the shared processor code and includes the specific platform header file. All references to the Arch/x86/Processor.h file have been replaced with a reference to Arch/Processor.h.
2021-09-17Kernel/Devices: Use try_create_device helper for SB16Liav A
2021-09-17Kernel/Devices: Use try_create_device helper for ConsoleDeviceLiav A
2021-09-17Kernel: Introduce the DeviceManagement singletonLiav A
This singleton simplifies many aspects that we struggled with before: 1. There's no need to make derived classes of Device expose the constructor as public anymore. The singleton is a friend of them, so he can call the constructor. This solves the issue with try_create_device helper neatly, hopefully for good. 2. Getting a reference of the NullDevice is now being done from this singleton, which means that NullDevice no longer needs to use its own singleton, and we can apply the try_create_device helper on it too :) 3. We can now defer registration completely after the Device constructor which means the Device constructor is merely assigning the major and minor numbers of the Device, and the try_create_device helper ensures it calls the after_inserting method immediately after construction. This creates a great opportunity to make registration more OOM-safe.
2021-09-12Kernel: Unify BIOS and ACPI components in the SysFS firmware directoryLiav A
Both should reside in the SysFS firmware directory which is normally located in /sys/firmware. Also, apply some OOM-safety patterns when creating the BIOS and ACPI directories.
2021-09-12Kernel: Move ACPI and BIOS code into the new Firmware directoryLiav A
This will somwhat help unify them also under the same SysFS directory in the commit. Also, it feels much more like this change reflects the reality that both ACPI and the BIOS are part of the firmware on x86 computers.
2021-09-10Kernel/ACPI: Simplify parser initializationLiav A
Let's remove the DynamicParser class, as it really did nothing yet in the Kernel. Instead, when we add support for AML parsing, we can figure out how to do it properly without the need of a derived class that just complicates everything for no good reason.
2021-09-08Kernel/Storage: Implement basic AHCI hotplug supportLiav A
This is really a basic support for AHCI hotplug events, so we know how to add a node representing the device in /sys/dev/block and removing it according to the event type (insertion/removal). This change doesn't take into account what happens if the device was mounted or a read/write operation is being handled. For this to work correctly, StorageManagement now uses the Singleton container, as it might be accessed simultaneously from many CPUs for hotplug events. DiskPartition holds a WeakPtr instead of a RefPtr, to allow removal of a StorageDevice object from the heap. StorageDevices are now stored and being referenced to via an IntrusiveList to make it easier to remove them on hotplug event. In future changes, all of the stated above might change, but for now, this commit represents the least amount of changes to make everything to work correctly.
2021-09-08Kernel: Expose device presence in /sys/dev/char and /sys/dev/blockLiav A
These files are not marked as block devices or character devices so they are not meant to be used as device nodes. The filenames are formatted to the pattern "major:minor", but a Userland program need to call the parse these format and inspect the the major and minor numbers and create the real device nodes in /dev. Later on, it might be a good idea to ensure we don't create new SysFSComponents on the heap for each Device, but rather generate them only when required (and preferably to not create a SysFSComponent at all if possible).
2021-09-07Kernel: Store process names as KStringAndreas Kling
2021-09-05Kernel: Tidy up VirtualFileSystem::mount_root() a little bitAndreas Kling
- Return KResult instead of bool - Use TRY()
2021-09-04Kernel: Tidy up Process::try_create_user_process()Andreas Kling
This function is currently only ever used to create the init process (SystemServer). It had a few idiosyncratic things about it that this patch cleans up: - Errors were returned in an int& out-param. - It had a path for non-0 process PIDs which was never taken.
2021-08-31Kernel/VirtIO: Remove redundant VirtIO word from filenamesLiav A
Now that all related VirtIO classes are in the VirtIO namespace, let's just remove the redundant VirtIO word from filenames.
2021-08-29Kernel: Strongly typed user & group ID'sAndreas Kling
Prior to this change, both uid_t and gid_t were typedef'ed to `u32`. This made it easy to use them interchangeably. Let's not allow that. This patch adds UserID and GroupID using the AK::DistinctNumeric mechanism we've already been employing for pid_t/ProcessID.
2021-08-19Kernel: Make Process::current() return a Process& instead of Process*Idan Horowitz
This has several benefits: 1) We no longer just blindly derefence a null pointer in various places 2) We will get nicer runtime error messages if the current process does turn out to be null in the call location 3) GCC no longer complains about possible nullptr dereferences when compiling without KUBSAN
2021-08-15Kernel: Lock thread list while in Thread::unref()Andreas Kling
This patch does three things: - Convert the global thread list from a HashMap to an IntrusiveList - Combine the thread list and its lock into a SpinLockProtectedValue - Customize Thread::unref() so it locks the list while unreffing This closes the same race window for Thread as @sin-ack's recent changes did for Process. Note that the HashMap->IntrusiveList conversion means that we lose O(1) lookups, but the majority of clients of this list are doing traversal, not lookup. Once we have an intrusive hashing solution, we should port this to use that, but for now, this gets rid of heap allocations during a sensitive time.
2021-08-15Kernel+Userland: Remove chroot functionalityAndreas Kling
We are not using this for anything and it's just been sitting there gathering dust for well over a year, so let's stop carrying all this complexity around for no good reason.
2021-08-13Kernel: Move VirtIO code into the Bus source folderLiav A
The VirtIO code handles functionality related to the VirtIO bus, so it really should be in the Bus folder.
2021-08-09Kernel/USB: Create controller base class and introduce USBManagementLuke
This removes Pipes dependency on the UHCIController by introducing a controller base class. This will be used to implement other controllers such as OHCI. Additionally, there can be multiple instances of a UHCI controller. For example, multiple UHCI instances can be required for systems with EHCI controllers. EHCI relies on using multiple of either UHCI or OHCI controllers to drive USB 1.x devices. This means UHCIController can no longer be a singleton. Multiple instances of it can now be created and passed to the device and then to the pipe. To handle finding and creating these instances, USBManagement has been introduced. It has the same pattern as the other management classes such as NetworkManagement.
2021-08-08Kernel: Fix deprecated array comparisonDaniel Bertalan
The Clang error message reads like this (`-Wdeprecated-array-compare`): > error: comparison between two arrays is deprecated; to compare > array addresses, use unary '+' to decay operands to pointers.
2021-08-07Kernel: Fix boot profiling after big process lock separation regressionBrian Gianforcaro
When I laid down the foundation for the start of the big process lock separation, I added asserts to all system call implementations to validate we hold the big process lock in the locations we think we should be. Adding that assert to sys$profiling_enable broke boot time profiling as we were never holding the lock on boot. Even though it's not technically required, lets make sure to hold the lock while enabling to appease the assert.
2021-08-06Kernel: Move Kernel/Memory/ code into Kernel::Memory namespaceAndreas Kling
2021-08-06Kernel: Rename Kernel/VM/ to Kernel/Memory/Andreas Kling
This directory isn't just about virtual memory, it's about all kinds of memory management.
2021-07-27Kernel: Mark the stack check guard as READONLY_AFTER_INITAndreas Kling
This makes it harder for an exploit to replace the kernel's randomized canary value since the memory containing it will be mapped read-only.
2021-07-27Kernel: Support loading the kernel at almost arbitrary virtual addressesGunnar Beutner
This enables further work on implementing KASLR by adding relocation support to the pre-kernel and updating the kernel to be less dependent on specific virtual memory layouts.
2021-07-27Prekernel: Export some multiboot parameters in our own BootInfo structGunnar Beutner
This allows us to specify virtual addresses for things the kernel should access via virtual addresses later on. By doing this we can make the kernel independent from specific physical addresses.
2021-07-27Kernel: Make the kernel independent from specific physical addressesGunnar Beutner
Previously the kernel relied on a fixed offset between virtual and physical addresses based on the kernel's load address. This allows us to specify an independent offset.
2021-07-26Kernel: Add option to build with coverage instrumentation and KCOVPatrick Meyer
GCC and Clang allow us to inject a call to a function named __sanitizer_cov_trace_pc on every edge. This function has to be defined by us. By noting down the caller in that function we can trace the code we have encountered during execution. Such information is used by coverage guided fuzzers like AFL and LibFuzzer to determine if a new input resulted in a new code path. This makes fuzzing much more effective. Additionally this adds a basic KCOV implementation. KCOV is an API that allows user space to request the kernel to start collecting coverage information for a given user space thread. Furthermore KCOV then exposes the collected program counters to user space via a BlockDevice which can be mmaped from user space. This work is required to add effective support for fuzzing SerenityOS to the Syzkaller syscall fuzzer. :^) :^)
2021-07-23Kernel: Mark a few more things as READONLY_AFTER_INITGunnar Beutner
2021-07-23Kernel: Annotate kernel_base and friends as READONLY_AFTER_INITBrian Gianforcaro
We don't want kernel_base to be modifiable by an attacker or a stray memory scribbler bug, so lets mark it as READONLY_AFTER_INIT.
2021-07-22Kernel: Fix the variable declaration for some linker script symbolsGunnar Beutner
Despite what the declaration would have us believe these are not "u8*". If they were we wouldn't have to use the & operator to get the address of them and then cast them to "u8*"/FlatPtr afterwards.
2021-07-20Kernel: Rename .boot_bss to .super_pages to better reflect what it isGunnar Beutner
This also removes the section attribute for kernel_base which had no effect because the section wasn't included in the linker script.
2021-07-20Prekernel: Use physical addresses for some of the BootInfo parametersGunnar Beutner
The kernel would just turn those virtual addresses into physical addresses later on, so let's just use physical addresses right from the start.
2021-07-20Kernel: Move boot info declarations to a header fileGunnar Beutner
Instead of manually redeclaring those variables in various files this now adds a header file for them.
2021-07-20Kernel: Initialize serial debug after setting kernel command-lineGunnar Beutner
2021-07-18Kernel: Rename bootloader to prekernelGunnar Beutner
There are a few occurrences of the old name that slipped through.
2021-07-18Kernel: Introduce basic pre-kernel environmentGunnar Beutner
This implements a simple bootloader that is capable of loading ELF64 kernel images. It does this by using QEMU/GRUB to load the kernel image from disk and pass it to our bootloader as a Multiboot module. The bootloader then parses the ELF image and sets it up appropriately. The kernel's entry point is a C++ function with architecture-native code. Co-authored-by: Liav A <liavalb@gmail.com>
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: 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-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-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-12Kernel: Initialize threading and process management earlierTom
This re-arranges the order of how things are initialized so that we try to initialize process and thread management earlier. This is neccessary because a lot of the code uses the Lock class, which really needs to have a running scheduler in place so that we can properly preempt. This also enables us to potentially initialize some things in parallel.
2021-07-11Kernel: Rename ProcFSComponentsRegistrar => ProcFSComponentRegistryAndreas Kling
This matches the formatting used in SysFS.