Commit graph

7684 commits

Author SHA1 Message Date
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
Liav A
91db482ad3 Kernel: Reorganize Arch/x86 directory to Arch/x86_64 after i686 removal
No functional change.
2022-12-28 11:53:41 +01:00
Liav A
5ff318cf3a Kernel: Remove i686 support 2022-12-28 11:53:41 +01:00
Liav A
92da98822a LibC: Remove i686 support 2022-12-28 11:53:41 +01:00
Liav A
85b453c2e4 Kernel+Userland: Remove dependency on i386-specific registers 2022-12-28 11:53:41 +01:00
konrad
88d0d0d90d Kernel: Add PMCCNTR_EL0, Performance Monitors Cycle Count Register 2022-12-26 14:11:27 +01:00
konrad
e1c3bf0ec0 Kernel: Add NZCV, Condition Flags 2022-12-26 14:11:27 +01:00
konrad
e7d4bbcde8 Kernel: Add MIDR_EL1, Main ID Register
This register is already provided in a separate class
but will be migrated here for uniform access
2022-12-26 14:11:27 +01:00
konrad
d0b73352cc Kernel: Add CNTFRQ_EL0, Counter-timer Frequency Register 2022-12-26 14:11:27 +01:00
konrad
91c3d7199f Kernel: Add MPIDR_EL1, Multiprocessor Affinity Register 2022-12-26 14:11:27 +01:00
konrad
d80d7744b6 Kernel: Add ID_AA64ISAR0_EL1, Instruction Set Attribute Register 0 2022-12-26 14:11:27 +01:00
Stephan Unverwerth
07053d32dd Kernel/Graphics: Increase VirtIO GPU transfer buffer size to 4MiB
This is necessary to allow transferring frame buffers larger than
~500x500 pixels back to user space. Until the buffer management is
improved this allows us to at least test the existing game ports.
2022-12-26 09:39:20 +01:00
Sam Atkins
29733e65f8 AK+Everywhere: Replace all Bitmap::must_create() uses with ::create()
Well, *someone* has to add some more FIXMEs to keep FIXME Roulette
going. :^)
2022-12-22 15:48:53 +01:00
Sam Atkins
bed5961fc2 AK: Rename Bitmap::try_create() to ::create()
This is step 1 to removing `must_create()`.
2022-12-22 15:48:53 +01:00
Liav A
2e710de2f4 Kernel/FileSystem: Prevent symlink creation in veiled directory paths
Also, try to resolve the target path and check if it is allowed to be
accessed under the unveil rules.
2022-12-21 09:17:09 +00:00
Timon Kruiper
a473cfd71b Kernel/aarch64: Add -mstrict-align flag to Kernel build
The ARM CPU is set up to trap on unaligned accesses, however the
compiler will still generate them if this flag is not set. We also need
the -Wno-cast-align as there are some files in AK that don't build
without the flag.
2022-12-21 08:35:14 +00:00
Timon Kruiper
0226390b21 Kernel/aarch64: Add Fault Address Register (FAR_EL1)
And use it for printing the virtual address when an exception has
happened that set the register, such as data aborts and instruction
aborts.
2022-12-21 08:35:14 +00:00
Timon Kruiper
344ffda8cb Kernel: Use AK::is_power_of_two instead of AK::popcount in kmalloc_impl
AK::popcount will use floating-point instructions, which in the aarch64
kernel are not allowed, and will result in an exception.
2022-12-21 08:35:14 +00:00
Timon Kruiper
81571bdac9 Kernel/aarch64: Add function to convert Exception Class to StringView
This is useful when printing information about the type of exception
that happened.
2022-12-21 08:35:14 +00:00
Liav A
efae6e2270 Kernel/Graphics: Propagate errors properly around in the VirtIO driver
This happens to be a sad truth for the VirtIOGPU driver - it lacked any
error propagation measures and generally relied on clunky assumptions
that most operations with the GPU device are infallible, although in
reality much of them could fail, so we do need to handle errors.

To fix this, synchronous GPU commands no longer rely on the wait queue
mechanism anymore, so instead we introduce a timeout-based mechanism,
similar to how other Kernel drivers use a polling based mechanism with
the assumption that hardware could get stuck in an error state and we
could abort gracefully.

Then, we change most of the VirtIOGraphicsAdapter methods to propagate
errors properly to the original callers, to ensure that if a synchronous
GPU command failed, either the Kernel or userspace could do something
meaningful about this situation.
2022-12-19 10:19:57 +00:00
Liav A
12d4bbbd11 Kernel/Graphics: Disable double buffering for the VirtIO driver
The performance that we achieve from this technique is visually worse
compared to turning off this feature, so let's not use this until we
figure out why it happens.
2022-12-19 10:19:57 +00:00
Liav A
bb491a681d Kernel: Properly propagate errors in VirtIOGPU 3D device initialization 2022-12-19 10:19:57 +00:00
Lenny Maiorani
f2336d0144 AK+Everywhere: Move custom deleter capability to OwnPtr
`OwnPtrWithCustomDeleter` was a decorator which provided the ability
to add a custom deleter to `OwnPtr` by wrapping and taking the deleter
as a run-time argument to the constructor. This solution means that no
additional space is needed for the `OwnPtr` because it doesn't need to
store a pointer to the deleter, but comes at the cost of having an
extra type that stores a pointer for every instance.

This logic is moved directly into `OwnPtr` by adding a template
argument that is defaulted to the default deleter for the type. This
means that the type itself stores the pointer to the deleter instead
of every instance and adds some type safety by encoding the deleter in
the type itself instead of taking a run-time argument.
2022-12-17 16:00:08 -05:00
Baitinq
0f2ca95b5e Kernel: Propagate errors in E1000NetworkAdapter
We now move the ErrorOr returning functions in the constructor to the
try_to_initialize() factory,  which allows us to handle the errors and
removes two FIXME's :))
2022-12-17 18:34:57 +01:00
Freakness109
1f1e58ed75 Kernel/Plan9FS: Propagate errors in Plan9FSMessage::append_data 2022-12-17 09:37:04 +00:00
Liav A
d94f3b902c Kernel: Propagate properly errors from ISAIDEController initialization 2022-12-16 10:00:31 +01:00
Liav A
8585b2dc23 Kernel/Memory: Add option to annotate region mapping as immutable
We add this basic functionality to the Kernel so Userspace can request a
particular virtual memory mapping to be immutable. This will be useful
later on in the DynamicLoader code.

The annotation of a particular Kernel Region as immutable implies that
the following restrictions apply, so these features are prohibited:
- Changing the region's protection bits
- Unmapping the region
- Annotating the region with other virtual memory flags
- Applying further memory advises on the region
- Changing the region name
- Re-mapping the region
2022-12-16 01:02:00 -07:00
Liav A
6c0486277e Kernel: Reintroduce the msyscall syscall as the annotate_mapping syscall
This syscall will be used later on to ensure we can declare virtual
memory mappings as immutable (which means that the underlying Region is
basically immutable for both future annotations or changing the
protection bits of it).
2022-12-16 01:02:00 -07:00
Sam Atkins
1b5a565e55 Kernel: Allocate VirtIOGPU context IDs from a bitmap, with ErrorOr
As is, we never *deallocate* them, so we will run out eventually.

Creating a context, or allocating a context ID, now returns ErrorOr if
there are no available free context IDs.

`number_of_fixmes--;` :^)
2022-12-15 22:04:28 +00:00
Sam Atkins
6d67cb516a Kernel: Remove unimplemented VirGL adapter's edid_feature_accepted() 2022-12-15 22:04:28 +00:00
Sam Atkins
3597f4a490 Kernel: Remove Badged VirtIOGraphicsAdapter::allocate_FOO_id() methods
These are unused, so let's remove them. `number_of_fixmes--;` :^)
2022-12-15 22:04:28 +00:00
implicitfield
9665f41979 Kernel: Ignore an invalid QEMU multiboot entry
This was introduced in the QEMU commit 8504f12 and was causing the
kernel to fail to boot on the q35 machine.

Fixes #14952.
2022-12-14 17:05:06 +00:00
Tim Schumacher
2577bb8416 Kernel: Start implementing kmalloc_aligned more efficiently
This now only requires `size + alignment` bytes while searching for a
free memory location. For the actual allocation, the memory area is
properly trimmed to the required alignment.
2022-12-14 15:18:31 +00:00
Tim Schumacher
30a553ef80 Kernel: Check against TCP packet size overflows in checksum calculation 2022-12-14 15:17:05 +00:00
Tim Schumacher
24f956c739 Kernel: Convert TCP pseudo-headers through a union
This keeps us from tripping strict aliasing, which previously made TCP
connections inoperable when building without `-fsanitize=undefined` or
`-fno-strict-aliasing`.
2022-12-14 15:17:05 +00:00
Agustin Gianni
ac40090583 Kernel: Add the auxiliary vector to the stack size validation
This patch validates that the size of the auxiliary vector does not
exceed `Process::max_auxiliary_size`. The auxiliary vector is a range
of memory in userspace stack where the kernel can pass information to
the process that will be created via `Process:do_exec`.

The reason the kernel needs to validate its size is that the about to
be created process needs to have remaining space on the stack.
Previously only `argv` and `envp` were taken into account for the
size validation, with this patch, the size of `auxv` is also
checked. All three elements contain values that a user (or an
attacker) can specify.

This patch adds the constant `Process::max_auxiliary_size` which is
defined to be one eight of the user-space stack size. This is the
approach taken by `Process:max_arguments_size` and
`Process::max_environment_size` which are used to check the sizes
of `argv` and `envp`.
2022-12-14 15:09:28 +00:00
Ali Mohammad Pur
f96a3c002a Everywhere: Stop shoving things into ::std and mentioning them as such
Note that this still keeps the old behaviour of putting things in std by
default on serenity so the tools can be happy, but if USING_AK_GLOBALLY
is unset, AK behaves like a good citizen and doesn't try to put things
in the ::std namespace.

std::nothrow_t and its friends get to stay because I'm being told that
compilers assume things about them and I can't yeet them into a
different namespace...for now.
2022-12-14 11:44:32 +01:00
Andreas Kling
30d3f2789e Kernel: Propagate errors during network adapter detection/initialization
When scanning for network adapters, we give each driver a chance to
claim the PCI device and whoever claims it first gets to keep it.
Before this patch, the driver API returned a LockRefPtr<AdapterType>,
which made it impossible to propagate errors that occurred during
detection and/or initialization.

This patch changes the API so that errors can bubble all the way out
the PCI enumeration in NetworkingManagement::initialize() where we
perform all the network adapter auto-detection on boot.

When we eventually start to support hot-plugging network adapter in the
future, it will be even more important to propagate errors instead of
swallowing them.

Importantly, before this patch, some errors were "handled" by panicking
the kernel. This is no longer the case.

7 FIXMEs were killed in the making of this commit. :^)
2022-12-13 11:20:11 +01:00
Tim Schumacher
1ca0898b1c Kernel: Use size_t to keep track of the number of pages in a region
We were previously using a 32-bit unsigned integer for this, which
caused us to start truncating region sizes when multiplied with
`PAGE_SIZE` on hardware with a lot of memory.
2022-12-12 15:14:07 +00:00
sin-ack
d9e1a6c566 Kernel: Bump maximum pthread stack size to 32MiB
The Zig compiler asks for this much stack on its main thread via the use
of PT_GNU_STACK.
2022-12-11 19:55:37 -07:00