Commit graph

6822 commits

Author SHA1 Message Date
Lenny Maiorani 2844f7c333 Everywhere: Switch from EnableIf to requires
C++20 provides the `requires` clause which simplifies the ability to
limit overload resolution. Prefer it over `EnableIf`

With all uses of `EnableIf` being removed, also remove the
implementation so future devs are not tempted.
2022-03-17 22:15:42 -07:00
Lenny Maiorani 2548ee4149 Kernel: Make number of RTL8168 rx/tx descriptors constexpr 2022-03-17 13:36:17 -07:00
Lenny Maiorani 190cf1507b Kernel: Use default constructors/destructors
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-17 00:51:36 -07:00
Linus Groh 9882848e0b Kernel: Define IF_NAMESIZE in net/if.h
This makes the _socket module from the Python port build. :^)
2022-03-16 18:03:25 +00:00
Daniel Bertalan e3eb68dd58 AK+Kernel: Avoid double memory clearing of HashTable buckets
Since the allocated memory is going to be zeroed immediately anyway,
let's avoid redundantly scrubbing it with MALLOC_SCRUB_BYTE just before
that.

The latest versions of gcc and Clang can automatically do this malloc +
memset -> calloc optimization, but I've seen a couple of places where it
failed to be done.

This commit also adds a naive kcalloc function to the kernel that
doesn't (yet) eliminate the redundancy like the userland does.
2022-03-15 11:56:46 +01:00
Hendiadyoin1 1a739b5d6e Kernel: Try to reuse empty slabheaps before expanding the kmalloc-heap 2022-03-14 23:30:08 +01:00
Hendiadyoin1 05381753c2 Kernel: Bail out earlier from Process::lookup_stacks_directory 2022-03-14 23:28:35 +01:00
Liav A 428d4ae337 Kernel/PCI: Break early of controller iteration over devices in OOM case
This is mainly useful when adding an HostController but due to OOM
condition, we abort temporary Vector insertion of a DeviceIdentifier
and then exit the iteration loop to report back the error if occured.
2022-03-14 22:39:09 +01:00
Liav A 3fb289e27d Kernel/PCI: Don't hold spinlocks when doing fast device enumeration
Instead, hold the lock while we copy the contents to a stack-based
Vector then iterate on it without any locking.

Because we rely on heap allocations, we need to propagate errors back
in case of OOM condition, therefore, both PCI::enumerate API function
and PCI::Access::add_host_controller_and_enumerate_attached_devices use
now a ErrorOr<void> return value to propagate errors. OOM Error can only
occur when enumerating the m_device_identifiers vector under a spinlock
and trying to expand the temporary Vector which will be used locklessly
to actually iterate over the PCI::DeviceIdentifiers objects.
2022-03-14 22:39:09 +01:00
Brian Gianforcaro c0ed656c94 Kernel: Fix buffer overflow in VirtIOGPU create_3d_resource(..)
This code attempts to copy the `Protocol::Resource3DSpecification`
struct into request, starting at `Protocol::ResourceCreate3D::target`
member of the `Protocol::ResourceCreate3D` struct.

The problem is that the `Protocol::Resource3DSpecification` struct
does not having the trailing `u32 padding` that the `ResourceCreate3D`
struct has. Leading to memcopy overrunning the struct and corrupting
32 bits of data trailing the struct.

Found by SonarCloud:
 - Memory copy function overflows the destination buffer.
2022-03-14 22:30:22 +01:00
Sahan Fernando 683de841e5 Kernel: Sandbox each GPU3DDevice file description into own host context 2022-03-14 17:38:18 +03:30
Brian Gianforcaro 03342876b8 Revert "Kernel: Use an ArmedScopeGuard to revert changes after failed mmap"
This reverts commit 790d620b39.
2022-03-12 21:45:57 -08:00
Brian Gianforcaro 3b39e16e8f Revert "Kernel: Don't override FramebufferDevice's memory regions on mmap"
This reverts commit 85ba70d86f.
2022-03-12 21:45:57 -08:00
Jakub V. Flasar 6d2c298b66 Kernel: Move aarch64 Prekernel into Kernel
As there is no need for a Prekernel on aarch64, the Prekernel code was
moved into Kernel itself. The functionality remains the same.

SERENITY_KERNEL_AND_INITRD in run.sh specifies a kernel and an inital
ramdisk to be used by the emulator. This is needed because aarch64
does not need a Prekernel and the other ones do.
2022-03-12 14:54:12 -08:00
Jakub V. Flasar f94293f121 Kernel: Create a stub mcontext for aarch64
The struct only has a stub integer so that the size is the same for C
and C++. Something caught by CLion.

This commit was made with mrkct's help!
2022-03-12 14:54:12 -08:00
Andreas Kling 7b3642d08c Kernel: Mark sys$lseek() as not needing the big lock
This syscall doesn't access any data that was implicitly protected by
the big lock.
2022-03-09 16:43:00 +01:00
Andreas Kling 09e644f0ba Kernel: Mark sys$emuctl() as not needing the big lock
This syscall doesn't do anything at all, and definitely doesn't need the
big lock. :^)
2022-03-09 16:43:00 +01:00
Andreas Kling b4fefedd1d Kernel: Mark sys$chmod() as not needing the big lock
This syscall doesn't access any data that was implicitly protected by
the big lock.
2022-03-09 16:43:00 +01:00
Andreas Kling aa381c4a67 Kernel: Mark sys$fchmod() as not needing the big lock
This syscall doesn't access any data that was implicitly protected by
the big lock.
2022-03-09 16:43:00 +01:00
Andreas Kling d074aae422 Kernel: Mark sys$dup2() as not needing the big lock
This syscall doesn't access any data that was implicitly protected by
the big lock.
2022-03-09 16:43:00 +01:00
Andreas Kling 8aad9e7448 Kernel: Mark sys$ftruncate() as not needing the big lock
This syscall doesn't access any data that was implicitly protected by
the big lock.
2022-03-09 16:43:00 +01:00
Andreas Kling 69a6a4d927 Kernel: Mark sys$fstatvfs() as not needing the big lock
This syscall doesn't access any data that was implicitly protected by
the big lock.
2022-03-09 16:43:00 +01:00
Sahan Fernando a2887dc157 Kernel: Disable GPU fencing for VirtIOGPU operations
These fences should not be needed, since we force the use of
synchronous operations through synchronous_virtio_gpu_command. The use
of these fences also causes severe lag when SERENITY_GL is enabled.
2022-03-09 14:58:48 +03:30
Sahan Fernando fd6a536c60 Kernel: Implement basic VirGL device
This commit flips VirtIOGPU back to using a Mutex for its operation
lock (instead of a spinlock). This is necessary for avoiding a few
system hangs when queuing actions on the driver from multiple
processes, which becomes much more of an issue when using VirGL from
multiple userspace process.

This does result in a few code paths where we inevitably have to grab
a mutex from inside a spinlock, the only way to fix both issues is to
move to issuing asynchronous virtio gpu commands.
2022-03-09 14:58:48 +03:30
Sahan Fernando 966989afe8 Kernel: Use AK::to_underlying instead of static_cast in VirtIOGPU 2022-03-09 14:58:48 +03:30
Sahan Fernando 0e57f80460 LibC: Add ioctls for VirGL 2022-03-09 14:58:48 +03:30
Tim Schumacher 5200cdac43 Kernel: Remove an unused fd_set.h import
The project appears to build just fine without it, and the explicit use
of `LibC` causes it to conflict with the system-wide `fd_set.h` when
building inside of Serenity.
2022-03-08 16:18:48 -08:00
Hendiadyoin1 85ba70d86f Kernel: Don't override FramebufferDevice's memory regions on mmap
This additionally refactors FramebufferDevice::try_to_initialize to not
leave the FramebufferDevice in an invalid state on errors.
This also unifies the logic between FramebufferDevice::mmap and
FramebufferDevice::try_to_initialize.
This comes with the drawback of removing the UNMAP_AFTER_INIT attribute
from this function, which wasn't honoured by IntelNativeGraphicsAdapter
anyway.
2022-03-08 15:58:51 -08:00
Hendiadyoin1 790d620b39 Kernel: Use an ArmedScopeGuard to revert changes after failed mmap 2022-03-08 15:58:51 -08:00
Daniel Bertalan 70ccdb300b Kernel: Panic if the init process dies
If init crashes, all other userspace processes exit too, thus rendering
the system unusable. Previously, the kernel would still keep running
even without a userland, showing just a black screen without any
indication of the issue.

We now panic the kernel, which shows a message on the console. In the
case of the CI runners, it shuts down the virtual machine, so we don't
have to wait for the 1 hour timeout if an issue arises with
SystemServer.
2022-03-08 23:30:47 +01:00
Liav A ed5623f40f Kernel/Graphics: Override first byte of the EDID in Intel Native driver 2022-03-08 21:56:14 +01:00
Liav A 7aa63ddd00 Kernel/Graphics: Print contents of offending EDID in Intel Native driver 2022-03-08 21:56:14 +01:00
Liav A f8df21c7e7 Kernel: Expose PCI BAR addresses in sysfs
Regardless of whether we use those BARs or not, expose them so userland
can use these values for its usage.
2022-03-08 21:52:10 +01:00
Andreas Kling 6354a9a030 Kernel: Mark sys$fsync() as not needing the big lock
This syscall doesn't access any data that was implicitly protected by
the big lock.
2022-03-08 00:19:49 +01:00
Andreas Kling ef45ff4703 Kernel: Mark sys$readlink() as not needing the big lock
This syscall doesn't access any data that was implicitly protected by
the big lock.
2022-03-08 00:19:49 +01:00
Andreas Kling 2688ee28ff Kernel: Mark sys$stat() as not needing the big lock
This syscall doesn't access any data that was implicitly protected by
the big lock.
2022-03-08 00:19:49 +01:00
Andreas Kling be7ec52ed0 Kernel: Mark sys$fstat() as not needing the big lock
This syscall doesn't access any data that was implicitly protected by
the big lock.
2022-03-08 00:19:49 +01:00
Andreas Kling 23822febd2 Kernel: Mark sys$fchdir() as not needing the big lock
This syscall doesn't access any data that was implicitly protected by
the big lock.
2022-03-08 00:19:49 +01:00
Andreas Kling 156ab0c47d Kernel: Mark sys$chdir() as not needing the big lock
This syscall doesn't access any data that was implicitly protected by
the big lock.
2022-03-08 00:19:49 +01:00
Andreas Kling 7597bef771 Kernel: Mark sys$getcwd() as not needing the big lock
This syscall doesn't access any data that was implicitly protected by
the big lock.
2022-03-08 00:19:49 +01:00
Andreas Kling f630d0f095 Kernel: Mark sys$realpath() as not needing the big lock
This syscall doesn't access any data that was implicitly protected by
the big lock.
2022-03-08 00:19:49 +01:00
Andreas Kling 580d89f093 Kernel: Put Process unveil state in a SpinlockProtected container
This makes path resolution safe to perform without holding the big lock.
2022-03-08 00:19:49 +01:00
Andreas Kling 24f02bd421 Kernel: Put Process's current directory in a SpinlockProtected
Also let's call it "current_directory" instead of "cwd" everywhere.
2022-03-08 00:19:49 +01:00
Andreas Kling 71792e4b3f Kernel: Make SpinlockProtected constructor forward all arguments
This allows you to instantiate SpinlockProtected<T> where T requires
constructor arguments.
2022-03-08 00:19:49 +01:00
Andreas Kling 7543c34d07 Kernel: Mark sys$anon_create() as not needing the big lock
This syscall is already safe for no-big-lock since it doesn't access any
unprotected data.
2022-03-08 00:19:49 +01:00
Idan Horowitz 29eee390ec Kernel: Implement kmalloc_good_size for the new kmalloc
This lets kmalloc-aware data structures like Vector and HashTable use
up the extra wasted space we allocate in the slab heaps & heap chunks.
2022-03-08 00:46:25 +02:00
Andreas Kling baa6ff5649 Kernel: Wrap HIDManagement keymap data in SpinlockProtected
This serializes access to the current keymap data everywhere in the
kernel, allowing to mark sys$setkeymap() as not needing the big lock.
2022-03-07 16:35:23 +01:00
Ali Mohammad Pur 6608812e4b Kernel: Over-align the FPUState on the stack in sigreturn
The stack is misaligned at this point for some reason, this is a hack
that makes the resulting object "correctly" aligned, thus avoiding a
KUBSAN error.
2022-03-04 20:07:05 +01:00
Ali Mohammad Pur 23f6a00162 Kernel: Fix silly unintentional use of operator,
Everyone's favourite activity, copy pasta, has produced yet another
confusing use of operator,; fix this and make it less confusing.
2022-03-04 20:07:05 +01:00
Ali Mohammad Pur 88d7bf7362 Kernel: Save and restore FPU state on signal dispatch on i386/x86_64 2022-03-04 20:07:05 +01:00