Commit graph

7723 commits

Author SHA1 Message Date
Ben Wiederhake c2a900b853 Everywhere: Remove unused includes of AK/StdLibExtras.h
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-02 20:27:20 -05:00
Ben Wiederhake 6fd478b6ce Everywhere: Remove unused includes of AK/Format.h
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-02 20:27:20 -05:00
Ben Wiederhake 143a64f9a2 Kernel: Remove unused includes of Kernel/Debug.h
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-02 20:27:20 -05:00
kleines Filmröllchen a6a439243f Kernel: Turn lock ranks into template parameters
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-02 18:15:27 -05:00
Ben Wiederhake 3334cf675a AK+Kernel: Eliminate UB (signed overflow) from days_since_epoch 2023-01-02 16:19:35 -05:00
Lenny Maiorani e0ab7763da AK: Combine SinglyLinkedList and SinglyLinkedListWithCount
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-02 20:13:24 +00:00
Ben Wiederhake a8391d5a60 Everywhere: Remove unused includes of AK/Array.h
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-02 20:08:35 +00:00
Ben Wiederhake add6be4c64 Kernel: Remove unused includes 2023-01-02 11:06:15 -05:00
Liav A cf3b75e2e6 Kernel: Propagate properly errors from PCI IDE Controller initialization 2023-01-02 04:59:23 -07:00
Liav A 735aa01b58 Kernel: Remove stale detect_disks method from PCI IDE controller class 2023-01-02 04:59:23 -07:00
Andreas Kling 1b4baaed56 Kernel/x86_64: *Restore* interrupt flag in page fault handler
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-01 15:14:35 +01:00
Andreas Kling 16f934474f Kernel+Tests: Allow deleting someone else's file in my sticky directory
This should be allowed according to Dr. POSIX. :^)
2023-01-01 10:09:02 +01:00
Andreas Kling 47b9e8e651 Kernel: Annotate VirtualFileSystem::rmdir() errors with spec comments 2023-01-01 10:09:02 +01:00
Andreas Kling 8619f2c6f3 Kernel+Tests: Remove inaccurate FIXME in sys$rmdir()
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-01 10:09:02 +01:00
Andreas Kling 8d781d0216 Kernel+Tests: Make sys$rmdir() fail with EINVAL if basename is "."
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. :^)
2023-01-01 10:09:02 +01:00
Liav A 883b0f1390 Kernel/Graphics: Restore VirtIO GPU framebuffer console functionality
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-31 05:13:21 -07:00
Liav A e598f22768 Kernel: Disallow executing SUID binaries if process is jailed
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-30 15:49:37 -05:00
kleines Filmröllchen 5d00e21852 Kernel/aarch64: Implement wait_cycles as a pause loop
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-30 08:32:46 -07:00
kleines Filmröllchen 984348ed0d Kernel/aarch64: Implement Processor::pause and Processor::wait_check
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-30 08:32:46 -07:00
kleines Filmröllchen 4d475588bb Kernel/aarch64: Declare TrapFrame as struct
Clang doesn't like misdeclaring classes and structs.
2022-12-30 08:32:46 -07:00
Timon Kruiper 51b69be970 Kernel/aarch64: Move ifdef in StorageManagement.cpp
The recent changes of removing i386 broke the aarch64 build, and moving
the ifdef fixes the aarch64 build.
2022-12-29 19:32:20 -07:00
Timon Kruiper e9b4e07b0a Kernel/aarch64: Start and initialize Scheduler and run multiple threads
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-29 19:32:20 -07:00
Timon Kruiper a5e98d3644 Kernel/aarch64: Add implementation of Processor::switch_context
This initial implementation makes it possible to actually context switch
between different kernel threads! :^)
2022-12-29 19:32:20 -07:00
Timon Kruiper 0b95d8cd24 Kernel/aarch64: Implement thread_context_first_enter
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-29 19:32:20 -07:00
Timon Kruiper 262309d9bf Kernel/aarch64: Implement Processor::initialize_context_switching
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-29 19:32:20 -07:00
Timon Kruiper 892f81b01a Kernel/aarch64: Add initial implementation of Processor::init_context
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.
2022-12-29 19:32:20 -07:00
Timon Kruiper 9554e5ca48 Kernel/aarch64: Add Saved Program Status Register EL1 (SPSR_EL1) 2022-12-29 19:32:20 -07:00
Timon Kruiper fb803e8025 Kernel/aarch64: Stub Processor::smp_wake_n_idle_processors 2022-12-29 19:32:20 -07:00
Timon Kruiper 1da84c2a2c Kernel: Factor out setting Thread entry function
This adds ThreadRegisters::set_entry_function, and also implements it
for aarch64.
2022-12-29 19:32:20 -07:00
Timon Kruiper a6f78b895f Kernel/aarch64: Stub Processor::clean_fpu_state() instead of crashing
Also print a message to the debug output, such that developers know that
the current implementation is not actually correct.
2022-12-29 19:32:20 -07:00
Timon Kruiper a3cbaa3449 Kernel: Move ThreadRegisters into arch-specific directory
These are architecture-specific anyway, so they belong in the Arch
directory. This commit also adds ThreadRegisters::set_initial_state to
factor out the logic in Thread.cpp.
2022-12-29 19:32:20 -07:00
Timon Kruiper 0d2dffb95b Kernel: Put x86_64 specific VERIFY in PageDirectory.cpp behind ifdef
This makes it possible to run this code on aarch64.
2022-12-29 19:32:20 -07:00
Timon Kruiper 5a5fa10046 Kernel/aarch64: Add FIXME debug messages to PageDirectory
These are added to make clear that the current memory situation in the
aarch64 kernel is not complete yet.
2022-12-29 19:32:20 -07:00
Timon Kruiper 21deb603de Kernel/aarch64: Implement stub for asm_signal_trampoline
This get us further into the boot process, since Process::initialize
does not crash anymore.
2022-12-29 19:32:20 -07:00
Timon Kruiper 1cc06b9985 Kernel/aarch64: Correctly implement Processor::is_initialized() 2022-12-29 19:32:20 -07:00
Timon Kruiper 27b384e073 Kernel/aarch64: Remove copy constructor from Processor
I can't think of a reason why copying the Processor class makes sense,
so lets make sure it's not possible to do it by accident by declaring
the copy constructor as deleted.
2022-12-29 19:32:20 -07:00
Timon Kruiper fbfe669f6d Kernel/aarch64: Implement Processor::{clear,restore}_critical() 2022-12-29 19:32:20 -07:00
Timon Kruiper 993b7495ba Kernel/aarch64: Implement Processor::check_invoke_scheduler() 2022-12-29 19:32:20 -07:00
Timon Kruiper f6f43fd65e Kernel: Add Processor::wait_for_interrupt and use it in Scheduler
This removes the x86 specific hlt instruction from the scheduler, and
allows us to run the scheduler code for aarch64 by implementing
Processor::wait_for_interrupt for aarch64.
2022-12-29 19:32:20 -07:00
Timon Kruiper f232133f65 Kernel/aarch64: Implement Processor::{enter,exit}_trap
And use them in interrupt handling.
2022-12-29 19:32:20 -07:00
Timon Kruiper ee883b839c Kernel/aarch64: Implement dbgput{str,char} in kprintf.cpp
Also changes the implementation of kernelearlyputstr to call
kernelputstr, to deduplicate some logic.
2022-12-29 19:32:20 -07:00
Timon Kruiper b991cff60f Kernel/aarch64: Add function to convert DFSC to StringView
This is useful for debugging, when hitting a data abort.
2022-12-29 19:32:20 -07:00
Timon Kruiper 5b06925b8a Kernel: Remove debug printing of code segment
This allows us to use the same code for aarch64.
2022-12-29 19:32:20 -07:00
Timon Kruiper ac788a2c8e Kernel: Remove duplicate Processor::restore_in_critical
There is already Processor::restore_critical, which does exactly the
same thing.
2022-12-29 19:32:20 -07:00
Timon Kruiper b18a7297c5 Kernel: Move ScopedCritical.cpp to Kernel base directory
This file does not contain any architecture specific implementations,
so we can move it to the Kernel base directory. Also update the relevant
include paths.
2022-12-29 19:32:20 -07:00
Timon Kruiper 496a3cdcd3 Kernel/aarch64: Fix typo in RegisterState.h
We are actually storing tpidr_el0, as can be seen in vector_table.S, but
the RegisterState.h incorrectly had tpidr_el1. This will probably save
some annoying debugging later on.
2022-12-29 19:32:20 -07:00
Andreas Kling 97dde51a9b Kernel: Add missing x86_64 files to CMakeLists.txt 2022-12-28 11:53:41 +01:00
Andreas Kling fb09661420 Kernel: Add missing Random.h include in x86_64/Processor.cpp 2022-12-28 11:53:41 +01:00
Andreas Kling 7b9ea3efde Kernel+Userland: Remove uses of the __i386__ compiler macro 2022-12-28 11:53:41 +01:00
Andreas Kling d6fa42dd5c Kernel: Remove the two remaining ARCH(I386) checks 2022-12-28 11:53:41 +01:00