summaryrefslogtreecommitdiff
path: root/Kernel
AgeCommit message (Collapse)Author
2023-01-07Kernel/Graphics: Introduce a new mechanism to initialize a PCI deviceLiav A
Instead of using a clunky switch-case paradigm, we now have all drivers being declaring two methods for their adapter class - create and probe. These methods are linked in each PCIGraphicsDriverInitializer structure, in a new s_initializers static list of them. Then, when we probe for a PCI device, we use each probe method and if there's a match, then the corresponding create method is called. As a result of this change, it's much more easy to add more drivers and the initialization code is more readable.
2023-01-07Kernel/Graphics: Allocate 16 MiB framebuffer if failed allocating largerLiav A
We try our best to ensure a DisplayConnector initialization succeeds, and this makes the Intel driver to work again, because if we can't allocate a Region for the whole PCI BAR mapped region, then we will try to allocate a Region with 16 MiB window size, so it doesn't eat the entire Kernel-allocated virtual memory space.
2023-01-07Kernel: Make Device::after_inserting to return ErrorOr<void>Liav A
Instead of just returning nothing, let's return Error or nothing. This would help later on with error propagation in case of failure during this method. This also makes us more paranoid about failure in this method, so when initializing a DisplayConnector we safely tear down the internal members of the object. This applies the same for a StorageDevice object, but its after_inserting method is much smaller compared to the DisplayConnector overriden method.
2023-01-07Kernel: Remove the RTL8139 PCI network adapter driverLiav A
Nobody tests this network card, and the driver has bugs (see the issue https://github.com/SerenityOS/serenity/issues/10198 for more details), so it's almost certain that this happened due to code being rotting when there's simply no testing of it. Essentially this has been determined to be dead-code so this is the most important reason to drop this code. Another good reason to do so is because the RTL8139 only supports Fast Ethernet connections (10/100 Megabits per second), and is considered obsolete even for bare metal setups.
2023-01-07Kernel/Net: Introduce a new mechanism to initialize a PCI deviceLiav A
Instead of using a clunky if-statement paradigm, we now have all drivers being declaring two methods for their adapter class - create and probe. These methods are linked in each PCINetworkDriverInitializer structure, in a new s_initializers static list of them. Then, when we probe for a PCI device, we use each probe method and if there's a match, then the corresponding create method is called. After the adapter instance is created, we call the virtual initialize method on it, because many drivers actually require a sort of post-construction initialization sequence to ensure the network adapter can properly function. As a result of this change, it's much more easy to add more drivers and the initialization code is more readable and it's easier to understand when and where things could fail in the whole initialization sequence.
2023-01-07Kernel/Net: Allocate regions before invoking the RTL8139 constructorLiav A
Instead of allocating those regions in the constructor, which makes it impossible to fail in case of OOM condition, allocate them in the static factory method so we could propagate errors in case of failure.
2023-01-07Kernel/Net: Allocate regions before invoking Intel driver constructorsLiav A
Instead of allocating after the construction point ensure that all Intel drivers are allocating necessary buffer regions and then pass them to the constructors. This could let us fail early in case of OOM, so we don't touch a network adapter before we ensure we have all the appropriate mappings in place.
2023-01-07Kernel: Mark Process::jail() method as constLiav A
We really don't want callers of this function to accidentally change the jail, or even worse - remove the Process from an attached jail. To ensure this never happens, we can just declare this method as const so nobody can mutate it this way.
2023-01-06Kernel: Add helper function to check if a Process is in jailLiav A
Use this helper function in various places to replace the old code of acquiring the SpinlockProtected<RefPtr<Jail>> of a Process to do that validation.
2023-01-06Kernel: Restore setting i8042 scan code set to scan code set 2 sequenceLiav A
This seems to work perfectly OK on my ICH7 test machine and also it works on QEMU, so it is probably OK to restore this. This will ensure we always get scan code set 1 input, because we enable scan code set 2 and PS/2 translation on the first (keyboard) port.
2023-01-06Kernel: Make i8042 controller initialization sequence more robustLiav A
The setting of scan code set sequence is removed, as it's buggy and could lead the controller to fail immediately when doing self-test afterwards. We will restore it when we understand how to do so safely. Allow the user to determine a preferred detection path with a new kernel command line argument. The defualt option is to check i8042 presence with an ACPI check and if necessary - an "aggressive" test to determine i8042 existence in the system. Also, keep the i8042 controller pointer on the stack, so don't assign m_i8042_controller member pointer if it does not exist.
2023-01-05Kernel/SysFS: Don't refresh/set-values inside the Jail spinlock scopeLiav A
Only do so after a brief check if we are in a Jail or not. This fixes SMP, because apparently it is crashing when calling try_generate() from the SysFSGlobalInformation::refresh_data method, so the fix for this is to simply not do that inside the Process' Jail spinlock scope, because otherwise we will simply have a possible flow of taking multiple conflicting Spinlocks (in the wrong order multiple times), for the SysFSOverallProcesses generation code: Process::current().jail(), and then Process::for_each_in_same_jail being called, we take Process::all_instances(), and Process::current().jail() again. Therefore, we should at the very least eliminate the first taking of the Process::current().jail() spinlock, in the refresh_data method of the SysFSGlobalInformation class.
2023-01-05Kernel: Repair build for aarch64Ben Wiederhake
This broke in 6fd478b6ce6e717132a5e9a9a907d0e56916701f due to insufficient testing on my part. Sorry!
2023-01-05Kernel/aarch64: Remove counterproductive `volatile`Nico Weber
Should not be needed, and triggers -Wvolatile in gcc. See discussion on #16790.
2023-01-05Kernel: Convert 2 instances of `dbgln` to `dmesgln_pci` in AC'97Jelle Raaijmakers
2023-01-05Kernel: Add dmesgln_pci logging for Kernel::PCIEvan Smal
A virtual method named device_name() was added to Kernel::PCI to support logging the PCI::Device name and address using dmesgln_pci. Previously, PCI::Device did not store the device name. All devices inheriting from PCI::Device now use dmesgln_pci where they previously used dmesgln.
2023-01-04Everywhere: Make global `inline` functions not `static`Nico Weber
`inline` already assigns vague linkage, so there's no need to also assign per-TU linkage. Allows the linker to dedup these functions across TUs (and is almost always just the Right Thing to do in C++ -- this ain't C).
2023-01-04Everywhere: Remove some redundant `inline` keywordsNico Weber
Functions defined inside class bodies (including static functions) are implicitly inline, no need to type it out.
2023-01-04Kernel/FileSystem: Fix handling of FAT names that don't fill an entryTaj Morton
* Fix bug where last character of a filename or extension would be truncated (HELLO.TXT -> HELL.TX). * Fix bug where additional NULL characters would be added to long filenames that did not completely fill one of the Long Filename Entry character fields.
2023-01-04Kernel/FileSystem: Remove FIXME about old/new path being the sameTaj Morton
Added comment after confirming that Linux and OpenBSD implenment the same behavior.
2023-01-03Kernel: Allow sending `SIGCONT` to processes in the same groupyyny
Allow sending `SIGCONT` to processes that share the same `pgid`. This is allowed in Linux aswell. Also fixes a FIXME :^)
2023-01-03Kernel: Add `sid` and `pgid` to `Credentials`yyny
There are places in the kernel that would like to have access to `pgid` credentials in certain circumstances. I haven't found any use cases for `sid` yet, but `sid` and `pgid` are both changed with `sys$setpgid`, so it seemed sensical to add it. In Linux, `man 7 credentials` also mentions both the session id and process group id, so this isn't unprecedented.
2023-01-02Everywhere: Remove unused includes of AK/Memory.hBen Wiederhake
These instances were detected by searching for files that include AK/Memory.h, but don't match the regex: \\b(fast_u32_copy|fast_u32_fill|secure_zero|timing_safe_compare)\\b This regex is pessimistic, so there might be more files that don't actually use any memory function. In theory, one might use LibCPP to detect things like this automatically, but let's do this one step after another.
2023-01-02Everywhere: Remove unused includes of AK/Concepts.hBen Wiederhake
These instances were detected by searching for files that include AK/Concepts.h, but don't match the regex: \\b(AnyString|Arithmetic|ArrayLike|DerivedFrom|Enum|FallibleFunction|Flo atingPoint|Fundamental|HashCompatible|Indexable|Integral|IterableContain er|IteratorFunction|IteratorPairWith|OneOf|OneOfIgnoringCV|SameAs|Signed |SpecializationOf|Unsigned|VoidFunction)\\b (Without the linebreaks.) This regex is pessimistic, so there might be more files that don't actually use any concepts. In theory, one might use LibCPP to detect things like this automatically, but let's do this one step after another.
2023-01-02Everywhere: Remove unused includes of AK/StdLibExtras.hBen Wiederhake
These instances were detected by searching for files that include AK/StdLibExtras.h, but don't match the regex: \\b(abs|AK_REPLACED_STD_NAMESPACE|array_size|ceil_div|clamp|exchange|for ward|is_constant_evaluated|is_power_of_two|max|min|mix|move|_RawPtr|RawP tr|round_up_to_power_of_two|swap|to_underlying)\\b (Without the linebreaks.) This regex is pessimistic, so there might be more files that don't actually use any "extra stdlib" functions. In theory, one might use LibCPP to detect things like this automatically, but let's do this one step after another.
2023-01-02Everywhere: Remove unused includes of AK/Format.hBen Wiederhake
These instances were detected by searching for files that include AK/Format.h, but don't match the regex: \\b(CheckedFormatString|critical_dmesgln|dbgln|dbgln_if|dmesgln|FormatBu ilder|__FormatIfSupported|FormatIfSupported|FormatParser|FormatString|Fo rmattable|Formatter|__format_value|HasFormatter|max_format_arguments|out |outln|set_debug_enabled|StandardFormatter|TypeErasedFormatParams|TypeEr asedParameter|VariadicFormatParams|v_critical_dmesgln|vdbgln|vdmesgln|vf ormat|vout|warn|warnln|warnln_if)\\b (Without the linebreaks.) This regex is pessimistic, so there might be more files that don't actually use any formatting functions. Observe that this revealed that Userland/Libraries/LibC/signal.cpp is missing an include. In theory, one might use LibCPP to detect things like this automatically, but let's do this one step after another.
2023-01-02Kernel: Remove unused includes of Kernel/Debug.hBen Wiederhake
These instances were detected by searching for files that include Kernel/Debug.h, but don't match the regex: \\bdbgln_if\(|_DEBUG\\b This regex is pessimistic, so there might be more files that don't check for any real *_DEBUG macro. There seem to be no corner cases anyway. In theory, one might use LibCPP to detect things like this automatically, but let's do this one step after another.
2023-01-02Kernel: Turn lock ranks into template parameterskleines Filmröllchen
This step would ideally not have been necessary (increases amount of refactoring and templates necessary, which in turn increases build times), but it gives us a couple of nice properties: - SpinlockProtected inside Singleton (a very common combination) can now obtain any lock rank just via the template parameter. It was not previously possible to do this with SingletonInstanceCreator magic. - SpinlockProtected's lock rank is now mandatory; this is the majority of cases and allows us to see where we're still missing proper ranks. - The type already informs us what lock rank a lock has, which aids code readability and (possibly, if gdb cooperates) lock mismatch debugging. - The rank of a lock can no longer be dynamic, which is not something we wanted in the first place (or made use of). Locks randomly changing their rank sounds like a disaster waiting to happen. - In some places, we might be able to statically check that locks are taken in the right order (with the right lock rank checking implementation) as rank information is fully statically known. This refactoring even more exposes the fact that Mutex has no lock rank capabilites, which is not fixed here.
2023-01-02AK+Kernel: Eliminate UB (signed overflow) from days_since_epochBen Wiederhake
2023-01-02AK: Combine SinglyLinkedList and SinglyLinkedListWithCountLenny Maiorani
Using policy based design `SinglyLinkedList` and `SinglyLinkedListWithCount` can be combined into one class which takes a policy to determine how to keep track of the size of the list. The default policy is to use list iteration to count the items in the list each time. The `WithCount` form is a different policy which tracks the size, but comes with the overhead of storing the count and incrementing/decrementing on each modification. This model is extensible to have other forms of counting by implementing only a new policy instead of implementing a totally new type.
2023-01-02Everywhere: Remove unused includes of AK/Array.hBen Wiederhake
These instances were detected by searching for files that include Array.h, but don't match the regex: \\b(Array(?!\.h>)|iota_array|integer_sequence_generate_array)\\b These are the three symbols defined by Array.h. In theory, one might use LibCPP to detect things like this automatically, but let's do this one step after another.
2023-01-02Kernel: Remove unused includesBen Wiederhake
2023-01-02Kernel: Propagate properly errors from PCI IDE Controller initializationLiav A
2023-01-02Kernel: Remove stale detect_disks method from PCI IDE controller classLiav A
2023-01-01Kernel/x86_64: *Restore* interrupt flag in page fault handlerAndreas Kling
If a page fault occurs while interrupts are disabled, we were wrongly enabling interrupts right away in the page fault handler. Instead, we should only do this if interrupts were enabled when the page fault occurred.
2023-01-01Kernel+Tests: Allow deleting someone else's file in my sticky directoryAndreas Kling
This should be allowed according to Dr. POSIX. :^)
2023-01-01Kernel: Annotate VirtualFileSystem::rmdir() errors with spec commentsAndreas Kling
2023-01-01Kernel+Tests: Remove inaccurate FIXME in sys$rmdir()Andreas Kling
We were already handling the rmdir("..") case by refusing to remove directories that were not empty. This patch removes a FIXME from January 2019 and adds a test. :^)
2023-01-01Kernel+Tests: Make sys$rmdir() fail with EINVAL if basename is "."Andreas Kling
Dr. POSIX says that we should reject attempts to rmdir() the file named "." so this patch does exactly that. We also add a test. This solves a FIXME from January 2019. :^)
2022-12-31Kernel/Graphics: Restore VirtIO GPU framebuffer console functionalityLiav A
This has been done in multiple ways: - Each time we modeset the resolution via the VirtIOGPU DisplayConnector we ensure that the framebuffer is updated with the new resolution. - Each time the cursor is updated we ensure that the framebuffer console is marked dirty so the IO Work Queue task which is scheduled to check if it is dirty, will flush the surface. - We only initialize a framebuffer console after we ensure that at the very least a DisplayConnector has being set with a known resolution. - We only call GenericFramebufferConsole::enable() when enabling the console after the important variables of the console (m_width, m_pitch and m_height) have been set.
2022-12-30Kernel: Disallow executing SUID binaries if process is jailedLiav A
Check if the process we are currently running is in a jail, and if that is the case, fail early with the EPERM error code. Also, as Brian noted, we should also disallow attaching to a jail in case of already running within a setid executable, as this leaves the user with false thinking of being secure (because you can't exec new setid binaries), but the current program is still marked setid, which means that at the very least we gained permissions while we didn't expect it, so let's block it.
2022-12-30Kernel/aarch64: Implement wait_cycles as a pause loopkleines Filmröllchen
The hand-written assembly does not compile under Clang due to register size mismatches. Using a loop is slower (~6 instructions on O2 as opposed to 2 with hand-written assembly), but using the pause instruction makes this more efficient even under TCG.
2022-12-30Kernel/aarch64: Implement Processor::pause and Processor::wait_checkkleines Filmröllchen
For pause we use isb sy which will put the processor to sleep while the pipeline is being flushed. This instruction is also used by Rust in spin loops and found to be more efficient, as well as being a rough equivalent to the x86 pause instruction which we also use here. For wait_check we use yield, which is a hinted nop that is faster to execute, and I leave a FIXME for processing SMP messages once we support SMP. These two changes probably make spin loops work on aarch64 :^)
2022-12-30Kernel/aarch64: Declare TrapFrame as structkleines Filmröllchen
Clang doesn't like misdeclaring classes and structs.
2022-12-29Kernel/aarch64: Move ifdef in StorageManagement.cppTimon Kruiper
The recent changes of removing i386 broke the aarch64 build, and moving the ifdef fixes the aarch64 build.
2022-12-29Kernel/aarch64: Start and initialize Scheduler and run multiple threadsTimon Kruiper
This commit changes the init.cpp file to start and initialize the Scheduler, and actually runs init_stage2. To show that it actually works, another thread is spawned and executed simultaneously, by context switching between the two!
2022-12-29Kernel/aarch64: Add implementation of Processor::switch_contextTimon Kruiper
This initial implementation makes it possible to actually context switch between different kernel threads! :^)
2022-12-29Kernel/aarch64: Implement thread_context_first_enterTimon Kruiper
This requires two new functions, context_first_init and restore_context_and_eret. With this code in place, we are now running the first idle thread! :^)
2022-12-29Kernel/aarch64: Implement Processor::initialize_context_switchingTimon Kruiper
This changes the stack pointer to the initial_thread stack pointer, and pushes two pointers onto the stack that point to the initial_thread. The function then jumps to the ip of the initial_thread, which will be thread_context_first_enter, and hangs there because that function is not yet implemented.
2022-12-29Kernel/aarch64: Add initial implementation of Processor::init_contextTimon Kruiper
This does not handle everything correctly yet, such as setting the correct state for running userspace applications, however this should be enough to get kernel scheduling to work.