Commit Graph

8166 Commits

Author SHA1 Message Date
Marco Cutecchia
1b04c43690 Kernel: Initialize DiskCache's buffer before the dirty&clean lists
This commit fixes a kernel panic that happened when unmounting
a disk due to an invalid memory access.
This was because `DiskCache` initializes two linked lists that use
an argument `KBuffer` as the storage for their elements.
Since the member `KBuffer` was declared after the two lists,
when `DiskCache`'s destructor was called, then `KBuffer`'s destructor
was called before the ones of the two lists, causing a page fault in
the kernel.
2023-04-02 12:43:17 -06:00
Liav A
07b83cf3fa Kernel/HID: Don't update the remapped Ctrl modifier unconditionally
Instead, only update it when the Caps Lock key event is generated and
remapping to the Ctrl key is enabled.

This fixes a bug that when enabling remapping Caps Lock key to the Ctrl
key, the original Ctrl key is no longer usable.
2023-03-31 12:45:12 -04:00
Jelle Raaijmakers
dd8fa73da1 Kernel: Add support for Intel HDA
This is an implementation that tries to follow the spec as closely as
possible, and works with Qemu's Intel HDA and some bare metal HDA
controllers out there. Compiling with `INTEL_HDA_DEBUG=on` will provide
a lot of detailed information that could help us getting this to work
on more bare metal controllers as well :^)

Output format is limited to `i16` samples for now.
2023-03-25 21:27:03 +01:00
Jelle Raaijmakers
c530f74e2f Kernel: Mention right parent class for AC'97's device_name 2023-03-25 21:27:03 +01:00
Marco Cutecchia
36c5afdfb2 Revert "Revert "Kernel/Storage: Remove the ramdisk implementation""
This reverts commit 187723776a.

This was reverted because it was needed until the aarch64 port
got an SD card driver

Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
2023-03-25 16:50:36 +00:00
Marco Cutecchia
d09852642c Revert "Kernel/aarch64: Embed disk image into kernel binary"
This reverts commit 3b65fd64fc.

This is no longer needed as we don't use the ramdisk anymore

Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
2023-03-25 16:50:36 +00:00
Marco Cutecchia
c91db6ec97 Kernel: Add an SD card driver for the aarch64 port
Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
2023-03-25 16:50:36 +00:00
Marco Cutecchia
bb8092d6a1 Kernel: Allow enabling high level detection on GPIOs
Co-authored-by: Timon Kruiper <timonkruiper@gmail.com>
Co-authored-by: Ollrogge <nils-ollrogge@outlook.de>
2023-03-25 16:50:36 +00:00
Marco Cutecchia
28acf25035 Kernel: Use u64 instead of int for the bitfields of CPACR_EL1
This fixes the Clang build of the aarch64 port
2023-03-25 16:50:36 +00:00
Marco Cutecchia
d0403d24d4 Kernel: Add missing include to Jail.h 2023-03-25 16:50:36 +00:00
Liav A
59a76b1279 Kernel: Remove 2 duplicated listings of cpp files in CMakeLists.txt file 2023-03-25 08:46:54 +00:00
Pankaj Raghav
d0ac24ddbf Kernel/Syscalls: Use copy_n_to_user when applicable
copy_to_user() with bytes as the last argument could be changed to using
copy_n_to_user() with a count.
2023-03-24 18:25:12 +01:00
Pankaj Raghav
f32fde6152 Kernel/StdLib: Change try_copy_n_to_user to copy_n_to_user
Let us keep the naming consistent between copy_n_from_user() and
copy_n_to_user()
2023-03-24 18:25:12 +01:00
Liav A
fdab8a24f5 Kernel/Graphics: Use longer timeout settings in VirtIO GPU commands
It appeared that we sometimes failed to invoke synchronous commands on
the GPU. To temporarily fix this, wait 10 milliseconds for commands to
complete before failing.
2023-03-19 00:19:06 +00:00
Liav A
3337a5722a Kernel: Simplify VirtIOGPU attach_physical_range_to_framebuffer method
According to the specification, modesetting can be invoked with no need
for flushing the framebuffer nor with DMA to transfer the framebuffer
rendering.
2023-03-19 00:19:06 +00:00
Liav A
657bc71247 Kernel/VirtIO: Ignore the VIRTIO_PCI_CAP_PCI_CFG configuration type
This configuration exposes a suboptimal mechanism to access other
VirtIO device configurations. It is also the only configuration to use a
zero length for a configuration structure, and specify a valid BAR which
triggered a kernel panic when attaching a virtio-gpu-pci device before
95b15e4901 was applied.

The real solution for that problem is to ignore this configuration type
because we never actually use it. It means that we can VERIFY that all
other configuration types have a valid length, as being expected.
2023-03-19 00:19:06 +00:00
Julian Offenhäuser
f31a9e9374 Kernel: Refactor AHCIController to propagate more errors
Before, the mapping of our HBA region would be done in the constructor.
Since this can fail, I moved it into initialize().

Additionally, we now use the TypedMapping helper for mapping the HBA
instead of doing it manually. This actually uncovered a bug where we
would ignore any possible offset into the page we were mapping, which
caused us to miss the mapped registers entirely.
2023-03-16 09:55:15 +01:00
Julian Offenhäuser
5541dfd9f8 Kernel: Allow AHCIController::initialize() to fail
If we fail to initialize an AHCI controller, we now skip adding it to
the list of storage controllers in StorageManagement.
2023-03-16 09:55:15 +01:00
Julian Offenhäuser
d1e88a5141 Kernel: Propagate errors in StorageController reset() and shutdown()
These used to signal an error with a boolean return type. We now return
a sensible errno instead.
2023-03-16 09:55:15 +01:00
Liav A
d16d805d96 Kernel: Merge {get,set}_process_name syscalls to the prctl syscall
It makes much more sense to have these actions being performed via the
prctl syscall, as they both require 2 plain arguments to be passed to
the syscall layer, and in contrast to most syscalls, we don't get in
these removed syscalls an automatic representation of Userspace<T>, but
two FlatPtr(s) to perform casting on them in the prctl syscall which is
suited to what has been done in the removed syscalls.

Also, it makes sense to have these actions in the prctl syscall, because
they are strongly related to the process control concept of the prctl
syscall.
2023-03-15 20:10:48 +01:00
Pankaj Raghav
6ff85aa19a Kernel/Ramdisk: Propagate error during Ramdisk initialize
Use the same pattern for Ramdisk similar to other storage devices during
device initialization. This will propagate errors if the Ramdisk fails
to initialize.
2023-03-15 11:25:59 +01:00
Pankaj Raghav
b204da94b0 Kernel/Storage: Use NonnullRefPtr for storage controllers
Storage controllers are initialized during init and are never modified.
NonnullRefPtr can be safely used instead of the NonnullLockRefPtr. This
also fixes one of the UB issue that was there when using an NVMe device
because of NonnullLockRefPtr.

We can add proper locking when we need to modify the storage controllers
after init.
2023-03-15 11:25:59 +01:00
Tim Schumacher
ecd1862859 AK: Rename Stream::write_entire_buffer to Stream::write_until_depleted
No functional changes.
2023-03-13 15:16:20 +00:00
Andrew Kaster
6ce7257ad7 Kernel: Don't include Kernel/Arch/RegisterState from userspace
Any userspace cpp file that included <syscall.h> would end up with
a large glob of Kernel headers included, all the way down to
Kernel/Arch/x86_64/CPU.h and friends.

Only the kernel needs RegisterState, so hide it from userspace.
2023-03-13 07:23:53 +00:00
Liav A
633006926f Kernel: Make the Jails' internal design a lot more sane
This is done with 2 major steps:
1. Remove JailManagement singleton and use a structure that resembles
    what we have with the Process object. This is required later for the
    second step in this commit, but on its own, is a major change that
    removes this clunky singleton that had no real usage by itself.
2. Use IntrusiveLists to keep references to Process objects in the same
    Jail so it will be much more straightforward to iterate on this kind
    of objects when needed. Previously we locked the entire Process list
    and we did a simple pointer comparison to check if the checked
    Process we iterate on is in the same Jail or not, which required
    taking multiple Spinlocks in a very clumsy and heavyweight way.
2023-03-12 10:21:59 -06:00
Pankaj Raghav
f8b67e1596 Kernel/Storage+Base: Fix boot_device_addressing document for NVMe
The LUN.target_id parameter points to a NVMe Namespace which starts from
1 and not 0. Fix the document to reflect the same while addressing a
nvme device in the boot parameters
2023-03-11 13:15:00 +00:00
Fabian Dellwing
7c0b360881 Kernel: Add non standard value to sys$sysconf
Add `_SC_PHYS_PAGES` to sys$sysconf syscall. This value is needed
for a port I'm working on.
2023-03-11 13:06:36 +00:00
Julian Offenhäuser
c705afa43a Kernel: Fix variable shadowing issue in PCIIDELegacyModeController
In this specific else case, primary_base_io_window would not be assigned
in the outer scope, leading to a crash immediately after.
2023-03-11 06:06:01 -07:00
Andreas Kling
03cc45e5a2 Kernel: Use RefPtr instead of LockRefPtr for File and subclasses
This was mostly straightforward, as all the storage locations are
guarded by some related mutex.

The use of old-school associated mutexes instead of MutexProtected
is unfortunate, but the process to modernize such code is ongoing.
2023-03-10 13:15:44 +01:00
Andreas Kling
e6fc7b3ff7 Kernel: Switch LockRefPtr<Inode> to RefPtr<Inode>
The main place where this is a little iffy is in RAMFS where inodes
have a LockWeakPtr to their parent inode. I've left that as a
LockWeakPtr for now.
2023-03-09 21:54:59 +01:00
Marco Cutecchia
f61e65a609 Kernel: Add missing include that broke the AARCH64 build 2023-03-08 14:20:29 +01:00
Marco Cutecchia
a7144a47ab Kernel: Fix mispellings of AARCH64 that broke the build 2023-03-08 14:20:29 +01:00
Liav A
736f9f38ae Kernel/Storage: Remove indication for possible future support of ATAPI
There's no plan to support ATAPI in the foreseeable future. ATAPI is
considered mostly as an extension to pass SCSI commands over ATA-link
compatible channel (which could be a physical SATA or PATA).

ATAPI is mostly used for controlling optical drives which are considered
obsolete in 2023, and require an entire SCSI abstraction layer we don't
exhibit with bypassing ioctls for sending specific SCSI commands in many
control-flow sequences for actions being taken for such hardware.

Therefore, let's make it clear we don't support ATAPI (SCSI over ATA)
unless someone picks it up and proves otherwise that this can be done
cleanly and also in a relevant way to our project.
2023-03-08 01:41:51 +01:00
Liav A
db72467e31 Kernel: Remove ATAPI eject method from the AHCIPort class
We never actually used it. It never has been proved to work reliably,
therefore it should be removed.
2023-03-08 01:41:51 +01:00
Liav A
95b15e4901 Kernel/VirtIO: Ignore Configurations that have length of zero bytes
These configurations are simply invalid. Ignoring those allow us to boot
with the virtio-gpu-pci device (in addition to the already supported
virtio-vga PCI device).
2023-03-08 01:38:13 +01:00
Andreas Kling
d1371d66f7 Kernel: Use non-locking {Nonnull,}RefPtr for OpenFileDescription
This patch switches away from {Nonnull,}LockRefPtr to the non-locking
smart pointers throughout the kernel.

I've looked at the handful of places where these were being persisted
and I don't see any race situations.

Note that the process file descriptor table (Process::m_fds) was already
guarded via MutexProtected.
2023-03-07 00:30:12 +01:00
Andreas Kling
36b0ecfe9e Kernel: Remove two outdated FIXMEs about the file descriptor table mutex
These functions cannot be called without already holding the relevant
mutex these days, since m_fds is a MutexProtected object. :^)
2023-03-06 23:46:36 +01:00
Andreas Kling
5aa12da959 AK+Kernel: Remove all the Nonnull*PtrVector classes 2023-03-06 23:46:36 +01:00
Andreas Kling
7369d0ab5f Kernel: Stop using NonnullLockRefPtrVector 2023-03-06 23:46:36 +01:00
Andreas Kling
21db2b7b90 Everywhere: Remove NonnullOwnPtr.h includes 2023-03-06 23:46:35 +01:00
Andreas Kling
359d6e7b0b Everywhere: Stop using NonnullOwnPtrVector
Same as NonnullRefPtrVector: weird semantics, questionable benefits.
2023-03-06 23:46:35 +01:00
Andreas Kling
689ca370d4 Everywhere: Remove NonnullRefPtr.h includes 2023-03-06 23:46:35 +01:00
Andreas Kling
8a48246ed1 Everywhere: Stop using NonnullRefPtrVector
This class had slightly confusing semantics and the added weirdness
doesn't seem worth it just so we can say "." instead of "->" when
iterating over a vector of NNRPs.

This patch replaces NonnullRefPtrVector<T> with Vector<NNRP<T>>.
2023-03-06 23:46:35 +01:00
Liav A
be1d7c325a Kernel: Move process coredump metadata modification to the prctl syscall 2023-03-05 16:55:08 +01:00
Liav A
39de5b7f82 Kernel: Actually check Process unveil data when creating perfcore dump
Before of this patch, we looked at the unveil data of the FinalizerTask,
which naturally doesn't have any unveil restrictions, therefore allowing
an unveil bypass for a process that enabled performance coredumps.

To ensure we always check the dumped process unveil data, an option to
pass a Process& has been added to a couple of methods in the class of
VirtualFileSystem.
2023-03-05 15:15:55 +00:00
Liav A
11a7e21c2a Kernel+Userland: Add support for using the PCSpeaker with various tones 2023-03-05 08:38:29 +00:00
Liav A
6b849fc8b1 Kernel: Move TYPEDEF_* TTY macros to API/ttydefaults.h file
This allows us to get rid of an include to LibC/sys/ttydefaults.h in the
Kernel TTY implementation.

Also, move ttydefchars static const struct to another file called
Kernel/API/ttydefaultschars.h, so it could be used too in the Kernel TTY
implementation without the need to include anything from LibC.
2023-03-01 19:36:53 -07:00
Liav A
800e244ed9 Kernel+LibC: Move the FD_SETSIZE declaration to API/POSIX/select.h file 2023-03-01 19:36:53 -07:00
Liav A
77486a0d08 Kernel: Remove includes to LibC stdarg definitions
We don't actually need the va_list and other stdarg definitions in the
kernel, because we actually don't use the "pure" printf interface in any
kernel code at all, but we retain the snprintf declaration because the
libstdc++ library still need it to be declared and extern'ed.
2023-03-01 19:36:53 -07:00
Liav A
5416a37fde Kernel: Remove heuristics for detecting malformed malloc memory access
I never saw these kind of messages in any debug session I had, and it
helps us to remove an include to LibC/mallocdefs.h file.
2023-03-01 19:36:53 -07:00
Liav A
8a50c967b8 Kernel: Mark sys$prctl() as not needing the big lock
This syscall has sufficient locking and therefore it doesn't need the
big lock being taken.
2023-02-25 15:21:29 +01:00
Liav A
b27f88f61d Kernel+Userland: Refine preventing syscall annotations of Regions option
Instead of using a special case of the annotate_mapping syscall, let's
introduce a new prctl option to disallow further annotations of Regions
as new syscall Region(s).
2023-02-24 22:26:07 +01:00
Liav A
08de5abc6d Kernel: Do 2 validations in annotate_mapping syscall outside a spinlock 2023-02-24 22:26:07 +01:00
Liav A
bedd90b1f0 Kernel: Properly lock Process protected data in the prctl syscall 2023-02-24 22:26:07 +01:00
Liav A
c56e1c5378 Kernel/FileSystem: Simplify the ProcFS significantly
Since the ProcFS doesn't hold many global objects within it, the need
for a fully-structured design of backing components and a registry like
with the SysFS is no longer true.

To acommodate this, let's remove all backing store and components of the
ProcFS, so now it resembles what we had in the early days of ProcFS in
the project - a mostly-static filesystem, with very small amount of
kmalloc allocations needed.
We still use the inode index mechanism to understand the role of each
inode, but this is done in a much "static"ier way than before.
2023-02-24 22:14:18 +01:00
Liav A
9216caeec2 Kernel: Fix typo proccess => process in a name of Process method 2023-02-24 22:14:18 +01:00
Liav A
12b7328c22 AK+Kernel: Add includes before removing Kernel/ProcessExposed.h
Apparently without this file, we won't be able to compile due to missing
includes to TimeManagement and KBufferBuilder.
2023-02-24 22:14:18 +01:00
Liav A
8f3c343b88 Kernel+Userland: Unify declarations for KCOV in Kernel/API/kcov.h 2023-02-24 20:35:45 +01:00
Liav A
e7142c482a Kernel+Userland: Move prctl numbers header file to Kernel/API directory 2023-02-24 20:35:45 +01:00
Liav A
b19dc8a9b6 Kernel: Prevent out-of-bounds read/write in VirtIO GPU3DDevice::ioctl
Before doing a check if offset_in_region + num_bytes of the transfer
descriptor are together more than NUM_TRANSFER_REGION_PAGES * PAGE_SIZE,
check that addition of both of these parameters will not simply overflow
which could lead to out-of-bounds read/write.

Fixes #17518.
2023-02-23 09:33:54 +00:00
Humberto Alves
f6eb155167 Kernel: Support more clocks in sys$clock_getres()
Support all the available clocks in clock_getres(). Also, fix this
function to use the actual ticks per second value, not the constant
`_SC_CLK_TCK` (which is always equal to 8) and move the resolution
computation logic to TimeManagement.
2023-02-21 01:00:06 +01:00
Andreas Kling
0cdd227e9b Kernel: Fix const-correctness issue in StorageManagement
We have to take the StorageDevice as a mutable reference, otherwise
we can't perform any interesting I/O operations on it.
2023-02-21 00:54:04 +01:00
Andreas Kling
b5cef78e35 Kernel: Make NVMeQueue const-correct internally
Store the DMA R/W page PhysicalPage object as an NNRP<T const>.
2023-02-21 00:54:04 +01:00
Andreas Kling
68c9781299 Kernel: Fix const-correctness of PCI::DeviceIdentifier usage 2023-02-21 00:54:04 +01:00
Andreas Kling
8bf248a046 Kernel: Make NNRP<PhysicalPage const> possible
This wasn't possible before as ref() and unref() were non-const.
2023-02-21 00:54:04 +01:00
Liav A
ac4829cc50 Kernel/IntelGraphics: Move PLL handling code to a different file
Dealing with the specific details of how to program a PLL should be done
in a separate file to ensure we can easily expand it to support future
generations of the Intel graphics device.
2023-02-19 15:01:01 -07:00
Liav A
9eab59c42b Kernel/Graphics: Return ENODEV if there's no valid EDID to return
ENODEV better represents the fact that there might be no display device
(e.g. a monitor) connected to the connector, therefore we should return
this error.
Another reason to not use ENOTIMPL is that it's a requirement for all
DisplayConnectors to put a valid EDID in place even for a hardware we
don't currently support mode-setting in runtime.
2023-02-19 15:01:01 -07:00
Liav A
b2da5d3e62 Kernel/Graphics: Allow Intel DisplayConnector to not have console 2023-02-19 15:01:01 -07:00
Liav A
016fedbd20 Kernel/IntelGraphics: Move DisplayPlane enable code to derived classes
Instead of doing that on the IntelDisplayPlane class, let's have this in
derived classes so these classes can decide how to use the settings that
were provided before calling the enable method.
2023-02-19 15:01:01 -07:00
Liav A
e393071a9b Kernel/IntelGraphics: Add Generation enum to the Definitions file
This will be used to annotate which Generation is being used for each
Intel iGPU we discover.
2023-02-19 15:01:01 -07:00
Liav A
8042ae43c3 Kernel/IntelGraphics: Move pipe management to the Transcoder class
It became apparent to me that future generations of the Intel graphics
chipset utilize the same register set as part of the Transcoder register
set. Therefore, it should be included now in the Transcoder class.
2023-02-19 15:01:01 -07:00
Liav A
2def16a3d2 Kernel/Graphics: Introduce the IntelDisplayConnectorGroup class
In the real world, graphics hardware tend to have multiple display
connectors. However, usually the connectors share one register space but
still keeping different PLL timings and display lanes.
This new class should represent a group of multiple display connectors
working together in the same Intel graphics adapter. This opens an
opportunity to abstract the interface so we could support future Intel
iGPU generations.

This is also a preparation before the driver can support newer devices
and utilize their capabilities.
The mentioned preparation is applied in a these aspects:
1. The code is splitted into more classes to adjust to future expansion.
2 classes are introduced: IntelDisplayPlane and IntelDisplayTranscoder,
so the IntelDisplayPlane controls the plane registers and second class
controls the pipeline (transcoder, encoder) registers. On gen4 it's not
really useful because there are probably one plane and one encoder to
care about, but in future generations, there are likely to be multiple
transcoders and planes to accommodate multi head support.
2. The set_edid_bytes method in the DisplayConnector class can now be
told to not assume the provided EDID bytes are always invalid. Therefore
it can refrain from printing error messages if this flag parameter is
true. This is useful for supporting real hardware situation when on boot
not all ports are connected to a monitor, which can result in floating
bus condition (essentially all the bytes we read are 0xFF).
3. An IntelNativeDisplayConnector could now be set to flag other types
of connections such as eDP (embedded DisplayPort), Analog output, etc.
This is important because on the Intel gen4 graphics we could assume to
have one analog output connector, but on future generations this is very
likely to not be the case, as there might be no VGA outputs, but rather
only an eDP connector which is converted to VGA by a design choice of
the motherboard manufacturer.
4. Add ConnectorIndex to IntelNativeDisplayConnector class - Currently
this is used to verify we always handle the correct connector when doing
modesetting.
Later, it will be used to locate special settings needed when handling
connector requests.
5. Prepare to support more types of display planes. For example, the
Intel Skylake register set for display planes is a bit different, so
let's ensure we can properly support it in the near future.
2023-02-19 15:01:01 -07:00
Liav A
61f4914d6e Kernel+Userland: Add constants subdirectory at /sys/kernel directory
This subdirectory is meant to hold all constant data related to the
kernel. This means that this data is never meant to updated and is
relevant from system boot to system shutdown.
Move the inodes of "load_base", "cmdline" and "system_mode" to that
directory. All nodes under this new subdirectory are generated during
boot, and therefore don't require calling kmalloc each time we need to
read them. Locking is also not necessary, because these nodes and their
data are completely static once being generated.
2023-02-19 13:47:11 +01:00
Liav A
1acd679775 Kernel: Remove unnecessary include from SysFS PowerStateSwitch code
I added that include in 2e55956784 by a
mistake, so we should get rid of it as soon as possible.
2023-02-19 08:13:04 +00:00
Liav A
8266e40b35 Kernel/FileSystem: Don't assume flags for root filesystem mount flags
This is considered somewhat an abstraction layer violation, because we
should always let userspace to decide on the root filesystem mount flags
because it allows the user to configure the mount table to preferences
that they desire.
Now that SystemServer is modified to re-mount the root mount with the
desired flags, we can just mount the root filesystem without assuming
special flags.
2023-02-19 01:20:10 +01:00
Liav A
4a14138230 Kernel/FileSystem: Fix check of read offset for the RAMFSInode code
The check of ensuring we are not trying to read beyond the end of the
inode data buffer is already there, it's just that we need to disallow
further reading if the read offset equals to the inode data size.
2023-02-19 01:01:45 +01:00
Liav A
9790b81959 Kernel/FileSystem: Add check of read offset for the FATInode code
Apparently we lacked this important check from the beginning of this
piece of code. This check is crucial to ensure we only give back data
being related to the FATInode data buffer and nothing beyond it.
2023-02-19 01:01:45 +01:00
Peter Elliott
f20902deb3 Kernel: Support sending filedescriptors with sendmsg(2) and SCM_RIGHTS
This is necessary to support the wayland protocol.
I also moved the CMSG_* macros to the kernel API since they are used in
both kernel and userspace.
this does not break ntpquery/SCM_TIMESTAMP.
2023-02-19 00:37:37 +01:00
Peter Elliott
ae5d7f542c Kernel: Change polarity of weak ownership between Inode and LocalSocket
There was a bug in which bound Inodes would lose all their references
(because localsocket does not reference them), and they would be
deallocated, and clients would get ECONNREFUSED as a result. now
LocalSocket has a strong reference to inode so that the inode will live
as long as the socket, and Inode has a weak reference to the socket,
because if the socket stops being referenced anywhere it should not be
bound.

This still prevents the reference loop that
220b7dd779 was trying to fix.
2023-02-19 00:37:37 +01:00
Peter Elliott
2808b03764 Kernel: Support F_DUPFD_CLOEXEC command to fcntl(2)
Specified by POSIX:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
2023-02-19 00:37:37 +01:00
Undefine
ab298ca106 Kernel: Dont crash if power states gets set to an invalid value 2023-02-18 23:52:20 +01:00
Timon Kruiper
13f5aa81e3 Kernel/aarch64: Disable memory access alignment check
Even though we currently build all of Userland and the Kernel with the
-mstrict-align flag, the compiler will still emit unaligned memory
accesses. To work around this, we disable the check for now. See
https://github.com/SerenityOS/serenity/issues/17516 for the relevant
issue.
2023-02-18 19:17:21 +01:00
Timon Kruiper
5d587ea562 Kernel/aarch64: Call handle_crash on unknown exceptions
This is useful for debugging, as it will now print out a userspace
backtrace, and optionally also dump the memory regions of the process.
2023-02-18 19:17:21 +01:00
Andrew Kaster
3a01573350 Revert "Kernel: Migrate ‘main id registerʼ access in Aarch64 MMIO"
This patch needed more review than it got.

This reverts commit a6526cd90c.
2023-02-17 11:29:33 -07:00
Andrew Kaster
aac122ab17 Revert "Kernel: Remove old ‘main id register accessorʼ for Aarch64"
This patch needed more review than it got.

This reverts commit 84e8d5f418.
2023-02-17 11:29:33 -07:00
Ben Wiederhake
9a7b3c145f Everywhere: Change all XXX into FIXME or remove as appropriate 2023-02-15 23:33:25 +01:00
Timon Kruiper
cfd73e5d9f Kernel/aarch64: Implement Thread Local Storage
This commit adds Processor::set_thread_specific_data, and this function
is used to factor out architecture specific implementation of setting
the thread specific data. This function is implemented for
aarch64 and x86_64, and the callsites are changed to use this function
instead.
2023-02-15 22:53:19 +01:00
Timon Kruiper
7d0917f50b Kernel/aarch64: Remove tpidr_el0 from RegisterState
In the next commit, this register will be populated by directly writing
to it, instead of using the RegisterState mechanism.
2023-02-15 22:53:19 +01:00
Timon Kruiper
a98c0c3e51 Kernel/aarch64: Add implementations for safe_memset and safe_strnlen
They currently do not actually implement a safe memset or safe strnlen,
but this initial implementation works fine for now.
2023-02-15 22:53:19 +01:00
Timon Kruiper
d1eec20773 Kernel/aarch64: Implement storing and restoring floating-point registers 2023-02-15 22:53:19 +01:00
Timon Kruiper
e57d35ff53 Kernel/aarch64: Do not trap floating-point instructions
This requires setting the FPEN field of the Architectural Feature Access
Control Register (CPACR_EL1) to 0b11.
2023-02-15 22:53:19 +01:00
Timon Kruiper
d5262a540c Kernel/aarch64: Handle SVC exception by calling syscall_handler
The SVC (supervisor call) instruction is used in userland to do
syscalls, and this commit adds the handling of syscalls to
Interrupts.cpp.
2023-02-15 22:53:19 +01:00
Ollrogge
361df6eff8 AK: Add conversion functions for packed DOS time format
This also adjusts the FATFS code to use the new functions and removes
the now redundant old conversion functions.
2023-02-12 13:13:15 -07:00
konrad
84e8d5f418 Kernel: Remove old ‘main id register accessorʼ for Aarch64 2023-02-10 11:51:47 -07:00
konrad
a6526cd90c Kernel: Migrate ‘main id registerʼ access in Aarch64 MMIO 2023-02-10 11:51:47 -07:00
konrad
d6c620dc4f Kernel: Provide better types in MIDR register accessor for Aarch64
This avoids unnecessary and-masks during reading.
2023-02-10 11:51:47 -07:00
Liav A
ab27fce86f AK: Add a new method to propagate errno while printing errors in Kernel
This new method is meant to be used in both userspace and kernel code.
The idea is to allow printing of a verbose message and then returning an
errno code which is the proper mechanism for kernel code because we
should almost always assume that such error will be propagated back to
userspace in some way, so the userspace code could reasonably decode it.

For userspace code however, this new method is meant to be a simple
wrapper for Error::from_string_view, because for most invocations, it's
much more useful to have a verbose & literal error than a errno code, so
we simply ignore that errno code completely in such context.
2023-02-10 09:14:20 +00:00
Liav A
df72c9327b Kernel: Return proper errno codes from Coredump::write_regions method 2023-02-10 09:14:20 +00:00
Liav A
2d1719da73 Kernel/Net: Propagate proper errno codes from determine_network_device
Returning literal strings is not the proper action here, because we
should always assume that error could be propagated back to userland, so
we need to keep a valid errno when returning an Error.
2023-02-10 09:14:20 +00:00
Liav A
2715f91c92 Kernel/VirtIOGPU: Propagate proper errno codes from query_and_set_edid
Returning literal strings is not the proper action here, because we
should always assume that error could be propagated back to userland, so
we need to keep a valid errno when returning an Error.
2023-02-10 09:14:20 +00:00
Timothy Flynn
604d5f5bca AK+Everywhere: Do not implicitly copy variables in TRY macros
For example, consider cases where we want to propagate errors only in
specific instances:

    auto result = read_data(); // something like ErrorOr<ByteBuffer>
    if (result.is_error() && result.error().code() != EINTR)
        continue;
    auto bytes = TRY(result);

The TRY invocation will currently copy the byte buffer when the
expression (in this case, just a local variable) is stored into
_temporary_result.

This patch binds the expression to a reference to prevent such copies.
In less trival invocations (such as TRY(some_function()), this will
incur only temporary lifetime extensions, i.e. no functional change.
2023-02-10 09:08:52 +00:00
Timothy Flynn
4a916cd379 Everywhere: Remove needless copies of Error / ErrorOr instances
Either take the underlying objects with release_* methods or move() the
instances around.
2023-02-10 09:08:52 +00:00
Timothy Flynn
52687814ea Kernel: Explicitly copy Plan9FS read errors to registered delegates 2023-02-10 09:08:52 +00:00
Timothy Flynn
bd4bddf31b Kernel: Store socket errors as errno codes rather than ErrorOr values 2023-02-10 09:08:52 +00:00
MacDue
63b11030f0 Everywhere: Use ReadonlySpan<T> instead of Span<T const> 2023-02-08 19:15:45 +00:00
Tim Schumacher
81863eaf57 Kernel: Use AK::Stream to write packed binary data 2023-02-08 18:50:31 +00:00
Tim Schumacher
23e10a30ad Kernel: Modernize Error handling when serializing directory entries 2023-02-08 18:50:31 +00:00
Itamar
ddec9cb1f0 Kernel: Update stored registers in a thread's tracer on SIGSTOP
This is needed so we can retrieve the registers of a traced
thread that was attached to while it was running.

Attaching with ptrace to a running thread sends SIGSTOP to it.
2023-02-08 19:23:07 +01:00
Itamar
7544b35694 Kernel: Update registers in tracer when attaching to a stopped thread 2023-02-08 19:23:07 +01:00
Timon Kruiper
0f3e1668bb Kernel/aarch64: Execute first userspace process
This adds the necessary code to init.cpp to be able to execute the first
userspace process. To do this, first the filesystem code is initialized,
which will use the ramdisk embedded into the kernel image. Then the
first userspace process, /bin/SystemServer is executed. :^)

The ramdisk code is used as it is useful for the bring-up of the aarch64
port, however once the kernel has support for better ram-based
filesystems, the ramdisk code will be removed again.
2023-02-08 18:19:48 +00:00
Timon Kruiper
3b65fd64fc Kernel/aarch64: Embed disk image into kernel binary
This allows us to actually boot to userspace in the next commit! :^)
2023-02-08 18:19:48 +00:00
Timon Kruiper
da89cd948f Kernel/aarch64: Do not dump register state on every page fault
This became very spammy, and is not needed anymore since we now
correctly handle page faults.
2023-02-08 18:19:48 +00:00
Timon Kruiper
3106a72a72 Kernel/aarch64: Make register dump output a bit nicer 2023-02-08 18:19:48 +00:00
Timon Kruiper
cf5b02e3a4 Kernel/aarch64: Dump ESR_EL1 in dump_registers and remove backtracing 2023-02-08 18:19:48 +00:00
Timon Kruiper
3295137224 Kernel: Add optional userspace backtrace to Process::crash
This is very useful for debugging the initial userspace applications, as
the CrashReporter is not yet running.
2023-02-08 18:19:48 +00:00
Timon Kruiper
3611427ce2 Kernel/aarch64: Return correct values from RegisterState accessors 2023-02-08 18:19:48 +00:00
Timon Kruiper
5aba83e6ba Kernel/aarch64: Add TimeManagement fallback entropy source to Random.cpp
The emulated aarch64 CPU does not contain the RNG cpu feature, so the
random number generator was not seeded. This commit adds a fallback to
use TimeManagement as a entropy source, such that get_good_random_bytes
works, which is needed for running the first userspace application on
aarch64.
2023-02-08 18:19:48 +00:00
Timon Kruiper
5781d58fe8 Kernel/aarch64: Implement set_exec_state in ThreadRegisters
This sets up the correct ThreadRegisters state when a process is
exec'ed, which happens when the first userspace application is executed.
Also changes Processor.cpp to get the stack pointer from the
ThreadRegisters.
2023-02-08 18:19:48 +00:00
Timon Kruiper
8960662e57 Kernel/aarch64: Set exception origin mode to SP_EL0 for userspace thread 2023-02-08 18:19:48 +00:00
Timon Kruiper
3f05748c0c Kernel/aarch64: Store Saved Program Status Register in ThreadRegisters
This allows us to set the Mode field of the Saved Program Status
Register (EL1) to EL0t when a userspace process is created.
2023-02-08 18:19:48 +00:00
Timon Kruiper
816076f71a Kernel: Share CrashHandler.cpp between aarch64 and x86_64
This file contains no architecture specific code, so can be moved to the
Kernel/ directory, and thus shared between aarch64 and x86_64.
2023-02-08 18:19:48 +00:00
Timon Kruiper
7ba9bc6338 Kernel/aarch64: Remove static from dump_registers
This allows the function to be called from other translation units, in
particular this allows the CrashHandler.cpp file to be shared between
aarch64 and x86_64.
2023-02-08 18:19:48 +00:00
Timon Kruiper
5cb37038a3 Kernel/aarch64: Set kernel_load_base and correctly calculate symbol addr
Setting the kernel_load_base variable caused backtracking to regress, so
to have proper backtracing the calculation of the symbol address in
KSyms.cpp needs to keep into account that the aarch64 kernel is linked
at a high virtual memory address.
2023-02-08 18:19:48 +00:00
Timon Kruiper
c7802cef25 Kernel/aarch64: Handle exceptions from lower exception level (EL)
When we execute in userspace, the exception level is EL0, so to handle
exceptions, such as interrupts, and syscalls, we need to add handlers to
vector_table.S. For now we only support running userspace applications
in AArch64 mode, so this commit only adds the handlers for that mode.
2023-02-08 18:19:48 +00:00
Timon Kruiper
7be7324287 Kernel/aarch64: Set correct ExecutionMode of PageFault
Adds a helper to aarch64/Registers.h to factor out the exception class
encoding.
2023-02-08 18:19:48 +00:00
Timon Kruiper
ecf45e191e Kernel/aarch64: Handle instruction aborts
To detect instruction aborts, a helper to Registers.h is added, and used
in Interrupts.cpp. Additionally, the PageFault class gets a setter to
set the PageFaults m_is_instruction_fetch bool, and is also used in
Interrupts.cpp.
2023-02-08 18:19:48 +00:00
Timon Kruiper
163e3ac90b Kernel/aarch64: Set Access Permission EL0 bit for userspace mappings
This bit was not set, which was causing Permission Faults when executing
in userspace.
2023-02-08 18:19:48 +00:00
Timon Kruiper
187723776a Revert "Kernel/Storage: Remove the ramdisk implementation"
This reverts commit 4e0f85432a as the
ramdisk code is useful for the bring-up of the aarch64 port. Once the
kernel supports better ram-based filesystems, this code will be removed
again.
2023-02-08 18:19:48 +00:00
Sam Atkins
e249d751c8 Kernel: Return ENAMETOOLONG when trying to set a too-long thread name 2023-02-06 20:36:53 +01:00
Sam Atkins
1014aefe64 Kernel: Protect Thread::m_name with a spinlock
This replaces manually grabbing the thread's main lock.

This lets us remove the `get_thread_name` and `set_thread_name` syscalls
from the big lock. :^)
2023-02-06 20:36:53 +01:00
Sam Atkins
fe7b08dad7 Kernel: Protect Process::m_name with a spinlock
This also lets us remove the `get_process_name` and `set_process_name`
syscalls from the big lock. :^)
2023-02-06 20:36:53 +01:00
Sam Atkins
b26ecca970 Kernel: Remove create_inode_watcher syscall from the big lock 2023-02-06 20:36:53 +01:00
Sam Atkins
cc558d95f0 Kernel: Remove pledge syscall from the big lock
This already does all its dangerous work inside
`with_mutable_protected_data()`.
2023-02-06 20:36:53 +01:00
Iman Seyed
85feab4095 Kernel: Pass ipv4_packet_size to ipv4.set_length()
Instead of `sizeof(IPv4Packet) + payload_size` expression,
pass `ipv4_packet_size` to `ipv4.set_length()`
2023-02-05 22:14:14 +00:00
MacDue
83a59396c8 Kernel: Fix CPUInfo error propagation fixme
We can now propagate the errors directly from for_each_split_view(),
which I think counts as "Make this nicer" :^)
2023-02-05 19:31:21 +01:00
Liav A
ed67a877a3 Kernel+SystemServer+Base: Introduce the RAMFS filesystem
This filesystem is based on the code of the long-lived TmpFS. It differs
from that filesystem in one keypoint - its root inode doesn't have a
sticky bit on it.

Therefore, we mount it on /dev, to ensure only root can modify files on
that directory. In addition to that, /tmp is mounted directly in the
SystemServer main (start) code, so it's no longer specified in the fstab
file. We ensure that /tmp has a sticky bit and has the value 0777 for
root directory permissions, which is certainly a special case when using
RAM-backed (and in general other) filesystems.

Because of these 2 changes, it's no longer needed to maintain the TmpFS
filesystem, hence it's removed (renamed to RAMFS), because the RAMFS
represents the purpose of this filesystem in a much better way - it
relies on being backed by RAM "storage", and therefore it's easy to
conclude it's temporary and volatile, so its content is gone on either
system shutdown or unmounting of the filesystem.
2023-02-04 15:32:45 -07:00
Steffen Rusitschka
198f2945bf Kernel/aarch64: Include Error.h to fix aarch64 missing ErrorOr 2023-02-03 20:26:26 +01:00
Itamar
8fce807b10 Kernel: Fix usermode verification in ptrace with PT_SETREGS
When doing PT_SETREGS, we want to verify that the debugged thread is
executing in usermode.

b2f7ccf refactored things and flipped the relevant check around, which
broke things that use PT_SETREGS (for example, stepping over
breakpoints with sdb).
2023-02-03 17:39:13 +01:00
Liav A
cd3c51f29b Kernel/Graphics: Export DDC I2C address definition to global header file 2023-02-02 02:10:33 -07:00
Liav A
0c64abb5e3 Kernel: Split I2C functionality from IntelNativeDisplayConnector code
Splitting the I2C-related code lets the DisplayConnector code to utilize
I2C operations without caring about the specific details of the hardware
and allow future expansion of the driver to other newer generations
sharing the same GMBus code.

We should require a timeout for GMBus operations always, because faulty
hardware could let us just spin forever. Also, if nothing is listening
to the bus (which should result in a NAK), we could also spin forever.
2023-02-02 02:10:33 -07:00
Liav A
ddc5c41253 Kernel: Fix a long-standing problem with GMBus in Intel Grahpics code
Thanks to Andrew Kaster, which gave a review back in October, about a
big PR I opened (#15502), I managed to figure out why we always had a
problem with the first byte being read into the EDID buffer with the
GMBus code. It turns out that this simple invalid cast was making the
entire problem and using the correct AK::Array::data() method fixed this
notorious long standing problem for good.
2023-02-02 02:10:33 -07:00
Agustin Gianni
bfbb4bcd9b Kernel: Remove trap based syscall handling
This patch removes the x86 mechanism for calling syscalls, favoring
the more modern syscall instruction. It also moves architecture
dependent code from functions that are meant to be architecture
agnostic therefore paving the way for adding more architectures.
2023-02-02 01:52:52 -07:00
Agustin Gianni
e71c320154 Kernel: Change the way we call a syscall in signal_trampoline_dummy
The function signal_trampoline_dummy was using int 0x82 to call
SC_sigreturn. Since x86 is no longer supported, the correct way
to call a syscall is using the syscall instruction.

This paves the way to remove the syscall trap handling mechanism.
2023-02-02 01:52:52 -07:00
Tim Schumacher
ae64b68717 AK: Deprecate the old AK::Stream
This also removes a few cases where the respective header wasn't
actually required to be included.
2023-01-29 19:16:44 -07:00
Liav A
722ae35329 Kernel/FileSystem: Simplify the ProcFS inode code
This is done by merging all scattered pieces of derived classes from the
ProcFSInode class into that one class, so we don't use inheritance but
rather simplistic checks to determine the proper code for each ProcFS
inode with its specific characteristics.
2023-01-29 12:59:30 +01:00
Linus Groh
9c08bb9555 AK: Remove try_ prefix from FixedArray creation functions 2023-01-28 22:41:36 +01:00
Timon Kruiper
0d722b4111 Kernel/PCI: Pass DeviceIdentifier to get_BAR2 in BochsGraphicsAdapter
This change was forgotten in 1f9d3a3523
and broke the aarch64 build.
2023-01-27 20:47:08 +00:00
Timon Kruiper
58cfd46a5a Kernel: Add Syscall.cpp to aarch64 build 2023-01-27 20:47:08 +00:00
Timon Kruiper
b941bd55d9 Kernel: Add Syscalls/execve.cpp to aarch64 build 2023-01-27 20:47:08 +00:00
Timon Kruiper
1fbf562e7e Kernel: Add ThreadRegisters::set_exec_state and use it in execve.cpp
Using this abstraction it is possible to compile this file for aarch64.
2023-01-27 20:47:08 +00:00
Timon Kruiper
171a8ca478 Kernel/aarch64: Implement Processor::platform_string() 2023-01-27 20:47:08 +00:00
Timon Kruiper
12322670cb Kernel: Use InterruptsState abstraction in execve.cpp
This was using the x86_64 specific cpu_flags abstraction, which is not
compatible with aarch64.
2023-01-27 20:47:08 +00:00
Timon Kruiper
5ffd53e2f2 Kernel: Add Syscalls/fork.cpp to aarch64 build 2023-01-27 20:47:08 +00:00
Timon Kruiper
6ad87f9409 Kernel: Add Syscalls/sigaction.cpp to aarch64 build 2023-01-27 20:47:08 +00:00
Timon Kruiper
80b722081b Kernel: Add Syscalls/mmap.cpp to aarch64 build 2023-01-27 20:47:08 +00:00
Timon Kruiper
a146a19636 Kernel: Make Syscalls/ptrace.cpp buildable for aarch64 2023-01-27 20:47:08 +00:00
Timon Kruiper
cab725cdfb Kernel/aarch64: Implement set_return_reg and capture_syscall_params 2023-01-27 20:47:08 +00:00
Timon Kruiper
293ece6fad Kernel/aarch64: Add stub for copy_ptrace_registers_into_kernel_registers 2023-01-27 20:47:08 +00:00
Sam Atkins
3cbc0fdbb0 Kernel: Remove declarations for non-existent methods 2023-01-27 20:33:18 +00:00
Timon Kruiper
2896d7796d Kernel/aarch64: Set Access Permission (writable bit) on PageTableEntry
This will cause page faults to be generated. Since the previous commits
introduced the handling of page faults, we can now actually correctly
handle page faults.
2023-01-27 11:41:43 +01:00
Timon Kruiper
1d58663298 Kernel/aarch64: Implement switching page directories
The code in PageDirectory.cpp now keeps track of the registered page
directories, and actually sets the TTBR0_EL1 to the page table base of
the currently executing thread. When context switching, we now also
change the TTBR0_EL1 to the page table base of the thread that we
context switch into.
2023-01-27 11:41:43 +01:00
Timon Kruiper
1f30a5e4d9 Kernel/aarch64: Store and initialize TTBR0_EL1 in ThreadRegisters 2023-01-27 11:41:43 +01:00
Timon Kruiper
9e90932bfb Kernel/aarch64: Add helper to get the current TTBR0_EL1 2023-01-27 11:41:43 +01:00
Timon Kruiper
d9946c8e89 Kernel/aarch64: Keep track of root page table and kernel directory table 2023-01-27 11:41:43 +01:00
Timon Kruiper
697c5ca5e5 Kernel: Move Memory/PageDirectory.{cpp,h} to arch-specific directory
The handling of page tables is very architecture specific, so belongs
in the Arch directory. Some parts were already architecture-specific,
however this commit moves the rest of the PageDirectory class into the
Arch directory.

While we're here the aarch64/PageDirectory.{h,cpp} files are updated to
be aarch64 specific, by renaming some members and removing x86_64
specific code.
2023-01-27 11:41:43 +01:00
Timon Kruiper
55d756a813 Kernel/aarch64: Implement initial page fault handling
The shared code is moved to a common PageFault.cpp file.
2023-01-27 11:41:43 +01:00
Timon Kruiper
a532d28905 Kernel/aarch64: Add stub for handle_safe_access_fault 2023-01-27 11:41:43 +01:00
Timon Kruiper
ade27fa6b9 Kernel: Refactor PageFault for use in the aarch64 port
The class used to look at the x86_64 specific exception code to figure
out what kind of page fault happend, however this refactor allows
aarch64 to use the same class.
2023-01-27 11:41:43 +01:00
Timon Kruiper
fb10774862 Kernel: Factor our PreviousMode into RegisterState::previous_mode
Various places in the kernel were manually checking the cs register for
x86_64, however to share this with aarch64 a function in RegisterState
is added, and the call-sites are updated. While we're here the
PreviousMode enum is renamed to ExecutionMode.
2023-01-27 11:41:43 +01:00
Timon Kruiper
247109cee6 Kernel/aarch64: Execute kernel with SP_EL1 instead of SP_EL0
Until now the kernel was always executing with SP_EL0, as this made the
initial dropping to EL1 a bit easier. This commit changes this behaviour
to use the corresponding SP_ELx for each exception level.

To make sure that the execution of the C++ code can continue, the
current stack pointer is copied into the corresponding SP_ELx just
before dropping an exception level.
2023-01-27 11:41:43 +01:00
Timon Kruiper
05659debd1 Kernel/aarch64: Move exception handler to Interrupts.cpp
Also dump the registers in a nicer format.
2023-01-27 11:41:43 +01:00
Liav A
a7677f1d9b Kernel/PCI: Expose PCI option ROM data from the sysfs interface
For each exposed PCI device in sysfs, there's a new node called "rom"
and by reading it, it exposes the raw data of a PCI option ROM blob to
a user for examining the blob.
2023-01-26 23:04:26 +01:00
Liav A
1f9d3a3523 Kernel/PCI: Hold a reference to DeviceIdentifier in the Device class
There are now 2 separate classes for almost the same object type:
- EnumerableDeviceIdentifier, which is used in the enumeration code for
  all PCI host controller classes. This is allowed to be moved and
  copied, as it doesn't support ref-counting.
- DeviceIdentifier, which inherits from EnumerableDeviceIdentifier. This
  class uses ref-counting, and is not allowed to be copied. It has a
  spinlock member in its structure to allow safely executing complicated
  IO sequences on a PCI device and its space configuration.
  There's a static method that allows a quick conversion from
  EnumerableDeviceIdentifier to DeviceIdentifier while creating a
  NonnullRefPtr out of it.

The reason for doing this is for the sake of integrity and reliablity of
the system in 2 places:
- Ensure that "complicated" tasks that rely on manipulating PCI device
  registers are done in a safe manner. For example, determining a PCI
  BAR space size requires multiple read and writes to the same register,
  and if another CPU tries to do something else with our selected
  register, then the result will be a catastrophe.
- Allow the PCI API to have a united form around a shared object which
  actually holds much more data than the PCI::Address structure. This is
  fundamental if we want to do certain types of optimizations, and be
  able to support more features of the PCI bus in the foreseeable
  future.

This patch already has several implications:
- All PCI::Device(s) hold a reference to a DeviceIdentifier structure
  being given originally from the PCI::Access singleton. This means that
  all instances of DeviceIdentifier structures are located in one place,
  and all references are pointing to that location. This ensures that
  locking the operation spinlock will take effect in all the appropriate
  places.
- We no longer support adding PCI host controllers and then immediately
  allow for enumerating it with a lambda function. It was found that
  this method is extremely broken and too much complicated to work
  reliably with the new paradigm being introduced in this patch. This
  means that for Volume Management Devices (Intel VMD devices), we
  simply first enumerate the PCI bus for such devices in the storage
  code, and if we find a device, we attach it in the PCI::Access method
  which will scan for devices behind that bridge and will add new
  DeviceIdentifier(s) objects to its internal Vector. Afterwards, we
  just continue as usual with scanning for actual storage controllers,
  so we will find a corresponding NVMe controllers if there were any
  behind that VMD bridge.
2023-01-26 23:04:26 +01:00
konrad
95c469ca4c Kernel: Move Aarch64 MMU debug message into memory manager initializer
Doing so unifies startup debug messages visually.
2023-01-25 23:17:36 +01:00
konrad
e1c50b83e1 Kernel: Use RDSEED assembly snippet to seed RNG on Aarch64
There’s similar RDRAND register (encoded as ‘s3_3_c2_c4_0ʼ) to be
added if needed. RNG CPU feature on Aarch64 guarantees existence of both
RDSEED and RDRAND registers simultaneously—in contrast to x86-64, where
respective instructions are independent of each other.
2023-01-25 23:17:36 +01:00
konrad
7c8e61f4d1 Kernel: Unify x86-64 assembly snippets naming for RDSEED & RDRAND 2023-01-25 23:17:36 +01:00
konrad
d7d233ab04 Kernel: Use existing assembly snippets for x86-64 RDSEED & RDRAND calls 2023-01-25 23:17:36 +01:00
Karol Kosek
8cfd445c23 Kernel: Allow to remove files from sticky directory if user owns it
It's what the Linux chmod(1) manpage says (in the 'Restricted Deletion
Flag or Sticky Bit' section), and it just makes sense to me. :^)
2023-01-24 20:13:30 +00:00
Timon Kruiper
c4a3af12fc Kernel/aarch64: Change base address of the kernel to 0x2000000000
This is the same address that the x86_64 kernel runs at, and allows us
to run the kernel at a high virtual memory address. Since we now run
completely in high virtual memory, we can also unmap the identity
mapping. Additionally some changes in MMU.cpp are required to
successfully boot.
2023-01-24 14:54:44 +00:00
Timon Kruiper
3bc122fcef Kernel/aarch64: Ensure global variable accesses work without MMU enabled
Since we link the kernel at a high virtual memory address, the addresses
of global variables are also at virtual addresses. To be able to access
them without the MMU enabled, we have to subtract the
KERNEL_MAPPING_BASE.
2023-01-24 14:54:44 +00:00
Timon Kruiper
fdc687a911 Kernel/aarch64: Disable stack protector + sanitizers for MMU-less files
Compile source files that run early in the boot process without the MMU
enabled, without stack protector and sanitizers. Enabling them will
cause the compiler to insert accesses to global variables, such as
__stack_chk_guard, which cause the CPU to crash, because these variables
are linked at high virtual addresses, which the CPU cannot access
without the MMU enabled.
2023-01-24 14:54:44 +00:00
Timon Kruiper
ebdb899d3d Kernel/aarch64: Add pre_init function for that sets up the CPU and MMU
This is a separate file that behaves similar to the Prekernel for
x86_64, and makes sure the CPU is dropped to EL1, the MMU is enabled,
and makes sure the CPU is running in high virtual memory. This code then
jumps to the usual init function of the kernel.
2023-01-24 14:54:44 +00:00
Timon Kruiper
5e00bb0b9f Kernel/aarch64: Change MMU::kernel_virtual_range to high virtual memory
This was previously hardcoded this to be the physical memory range,
since we identity mapped the memory, however we now run the kernel at
a high virtual memory address.

Also changes PageDirectory.h to store up-to 512 pages, as the code now
needs access to more than 4 pages.
2023-01-24 14:54:44 +00:00
Timon Kruiper
5db32ecbe1 Kernel/aarch64: Access MMIO using mapping in high virtual memory
This ensures that we can unmap the identity mapping of the kernel in
physical memory.
2023-01-24 14:54:44 +00:00
Timon Kruiper
91d0451999 Kernel/aarch64: Use relative addressing in boot.S
As the kernel is now linked at high address in virtual memory, we cannot
use absolute addresses as they refer to high addresses in virtual
memory. At this point in the boot process we are still running with the
MMU off, so we have to make sure the accesses are using physical memory
addresses.
2023-01-24 14:54:44 +00:00
Timon Kruiper
a581cae4d4 Kernel/aarch64: Add function to MMU.cpp to unmap identity mapping
This function will be used once the kernel runs in high virtual memory
to unmap the identity mapping as userspace will later on use this memory
range instead.
2023-01-24 14:54:44 +00:00
Timon Kruiper
150c52e420 Kernel/aarch64: Add {panic,dbgln}_without_mmu
And use it the code that will be part of the early boot process.

The PANIC macro and dbgln functions cannot be used as it accesses global
variables, which in the early boot process do not work, since the MMU is
not yet enabled.
2023-01-24 14:54:44 +00:00
Timon Kruiper
69c49b3d00 Kernel/aarch64: Map kernel and MMIO in high virtual memory
In the upcoming commits, we'll change the kernel to run at a virtual
address in high memory. This commit prepares for that by making sure the
kernel and mmio are mapped into high virtual memory.
2023-01-24 14:54:44 +00:00
Timon Kruiper
33581d5c44 Kernel: Add KERNEL_MAPPING_BASE to Sections.h and use it in Prekernel 2023-01-24 14:54:44 +00:00
Andrew Kaster
c87557e9c1 Kernel+Libraries: Don't include limits.h from LibELF/Validation.h
The fallout of this is that Kernel/Syscalls/execve.cpp doesn't have
access to ARG_MAX anymore, so move that definition to Kernel/API as well
2023-01-21 10:43:59 -07:00
Andrew Kaster
ad30b8c447 Kernel+Libraries: Move defines and types from sys/auxv.h to Kernel/API
And don't include <sys/auxv.h> from LibELF/AuxiliaryVector.h, to reduce
the number of Kernel files that include LibC headers.
2023-01-21 10:43:59 -07:00
Andrew Kaster
7ab37ee22c Everywhere: Remove string.h include from AK/Traits.h and resolve fallout
A lot of places were relying on AK/Traits.h to give it strnlen, memcmp,
memcpy and other related declarations.

In the quest to remove inclusion of LibC headers from Kernel files, deal
with all the fallout of this included-everywhere header including less
things.
2023-01-21 10:43:59 -07:00
Andrew Kaster
100fb38c3e Kernel+Userland: Move LibC/sys/ioctl_numbers to Kernel/API/Ioctl.h
This header has always been fundamentally a Kernel API file. Move it
where it belongs. Include it directly in Kernel files, and make
Userland applications include it via sys/ioctl.h rather than directly.
2023-01-21 10:43:59 -07:00
Andrew Kaster
ddea37b521 Kernel+LibC: Move name length constants to Kernel/API from limits.h
Reduce inclusion of limits.h as much as possible at the same time.

This does mean that kmalloc.h is now including Kernel/API/POSIX/limits.h
instead of LibC/limits.h, but the scope could be limited a lot more.
Basically every file in the kernel includes kmalloc.h, and needs the
limits.h include for PAGE_SIZE.
2023-01-21 10:43:59 -07:00
Andrew Kaster
046c23f567 Kernel+LibC: Move LibC/signal_numbers.h to Kernel/API/POSIX
Make Userland and Tests users just include signal.h, and move Kernel
users to the new API file.
2023-01-21 10:43:59 -07:00
Jelle Raaijmakers
2428ba3832 Kernel: Remove dbgln when unregistering an unhandled x86_64 interrupt
A lot of interrupt numbers are initialized with the unhandled interrupt
handler. Whenever a new handler is registered on one of these
interrupts, the old handler is unregistered first. Let's not be verbose
about this since it is perfectly normal.
2023-01-20 15:22:42 +01:00
Jelle Raaijmakers
5f85f1abaa Kernel: Simplify (un)registering interrupt logic
Lose a level of indentation and remove a superfluous `handler_slot`
check.
2023-01-20 15:22:42 +01:00
konrad
78d6de2ec1 Kernel: Make a slightly better demo for Aarch64 multiprocessing 2023-01-18 22:58:42 +01:00
konrad
5791072280 Kernel: Detect Aarch64 virtual address bit width with CPU ID registers 2023-01-18 22:58:42 +01:00
konrad
401fc6afae Kernel: Detect Aarch64 physical address bit width with CPU ID registers 2023-01-18 22:58:42 +01:00
konrad
66c65f6e2c Kernel: Add and use accessors to read from Aarch64 CPU ID registers
Following registers accessors are updated and put in use:
* ID_AA64ISAR0_EL1, Instruction Set Attribute Register 0

Accessors for following registers are added and put in use:
* ID_AA64ISAR1_EL1, Instruction Set Attribute Register 1
* ID_AA64ISAR2_EL1, Instruction Set Attribute Register 2
* ID_AA64MMFR1_EL1, AArch64 Memory Model Feature Register 1
* ID_AA64MMFR2_EL1, AArch64 Memory Model Feature Register 2
* ID_AA64MMFR3_EL1, AArch64 Memory Model Feature Register 3
* ID_AA64MMFR4_EL1, AArch64 Memory Model Feature Register 4
* ID_AA64PFR0_EL1, AArch64 Processor Feature Register 0
* ID_AA64PFR1_EL1, AArch64 Processor Feature Register 1
* ID_AA64PFR2_EL1, AArch64 Processor Feature Register 2
* ID_AA64ZFR0_EL1, AArch64 SVE Feature ID register 0
* ID_AA64SMFR0_EL1, AArch64 SME Feature ID register 0
* ID_AA64DFR0_EL1, AArch64 Debug Feature Register 0
* ID_AA64DFR1_EL1, AArch64 Debug Feature Register 1

Additionally, there are few CPU features detected with
* TCR_EL1, Translation Control Register

but detection mechanism using it (for LPA/LPA2) is probably wrong as
this is control register, not a id register, and needs further work.

Finally, following registers are provided. Former one is already used,
while latter is given for future use:
* MIDR_EL1, Main ID Register
* AIDR_EL1, Auxiliary ID Register
2023-01-18 22:58:42 +01:00
konrad
6979cf230e Kernel: Print Aarch64 CPU features during CPU initialization 2023-01-18 22:58:42 +01:00
konrad
a8e9591bac Kernel: Split Aarch64 CPU setup into two stages
Former aims to bring the processor itself into desired state,
while latter allows for additional initialization with heap available.
2023-01-18 22:58:42 +01:00
konrad
97dce5d001 Kernel: Add Aarch64 CPU feature detection 2023-01-18 22:58:42 +01:00
konrad
0f81fb03f2 Kernel: Introduce stages in Aarch64 CPU initialization phase
Dropping to each exception level is now more explicit.
2023-01-18 22:58:42 +01:00
konrad
c08f059340 Kernel: Add CPUFeature enumeration for Aarch64 CPUs
Also, enumeration name & description mappings are provided along.
2023-01-18 22:58:42 +01:00
konrad
823aab8296 Kernel: Use a descriptive name for x86-64 cpu_feature_to_string_view
Settled for `cpu_feature_to_name` as that naming is more descriptive
and similarly named `cpu_feature_to_description` function will be
provided for Aarch64.
2023-01-18 22:58:42 +01:00
Brian Gianforcaro
bfa890251c Kernel: Fix uninitialized member variable in FATFS Filesystem
Reported-by: PVS Studio
2023-01-16 09:45:46 +01:00
Andrew Kaster
f5d253dcfa Everywhere: Fully qualify IsLvalueReference in TRY() macros
If USING_AK_GLOBALLY is not defined, the name IsLvalueReference might
not be available in the global namespace. Follow the pattern established
in LibTest to fully qualify AK types in macros to avoid this problem.
2023-01-15 00:56:31 +00:00
Liav A
7aebbe52b9 Meta: Fix copyright header in Kernel/Syscalls/jail.cpp file
I wrote that file in 2022, not Andreas in 2018.
2023-01-14 09:57:04 +01:00
Timothy Flynn
afc0e461e1 AK+Everywhere: Disallow returning a reference from a fallible expression
This will silently make a copy. Rather than masking this behavior, let's
explicitly disallow it.
2023-01-13 18:50:47 -05:00
MacDue
9a120d7243 AK: Add support for "debug only" formatters
These are formatters that can only be used with debug print
functions, such as dbgln(). Currently this is limited to
Formatter<ErrorOr<T>>. With this you can still debug log ErrorOr
values (good for debugging), but trying to use them in any
String::formatted() call will fail (which prevents .to_string()
errors with the new failable strings being ignored).

You make a formatter debug only by adding a constexpr method like:
static constexpr bool is_debug_only() { return true; }
2023-01-13 21:09:26 +00:00
Arda Cinar
037744e62a Kernel/Net: Get the correct interface type in SIOCGIFHWADDR ioctl
When calling ioctl on a socket with SIOCGIFHWADDR, return the correct
physical interface type. This value was previously hardcoded to
ARPHRD_ETHER (Ethernet), and now can also return ARPHRD_LOOPBACK for the
loopback adapter.
2023-01-13 15:44:04 +01:00
Liav A
6f9b84a64a Kernel: Remove outdated FIXME in the DeviceManagement code 2023-01-13 15:42:33 +01:00
Liav A
16b6e644d7 Kernel: Require "stdio" pledge promise when calling get_root_session_id 2023-01-13 13:41:30 +01:00
MacDue
969aacd627 Kernel: AK: Fix ignored .to_string() errors in IPv4Socket 2023-01-12 23:29:57 +00:00
Andreas Kling
5dcc58d54a Kernel+LibCore: Make %sid path parsing not take ages
Before this patch, Core::SessionManagement::parse_path_with_sid() would
figure out the root session ID by sifting through /sys/kernel/processes.

That file can take quite a while to generate (sometimes up to 40ms on my
machine, which is a problem on its own!) and with no caching, many of
our programs were effectively doing this multiple times on startup when
unveiling something in /tmp/session/%sid/

While we should find ways to make generating /sys/kernel/processes fast
again, this patch addresses the specific problem by introducing a new
syscall: sys$get_root_session_id(). This extracts the root session ID
by looking directly at the process table and takes <1ms instead of 40ms.

This cuts WebContent process startup time by ~100ms on my machine. :^)
2023-01-10 19:32:31 +01:00
Taj Morton
20991a6a3c Kernel/FileSystem: Fix kernel panic during FS init or mount failure
Resolves issue where a panic would occur if the file system failed to
initialize or mount, due to how the FileSystem was already added to
VFS's list. The newly-created FileSystem destructor would fail as a
result of the object still remaining in the IntrusiveList.
2023-01-09 19:26:01 -07:00
Liav A
c876412b1b Kernel: Remove the NE2000 PCI network adapter driver
Nobody tests this network card as the person who added it, Jean-Baptiste
Boric (known as boricj) is not an active contributor in the project now.
After a discussion with him on the Discord server, we agreed it's for
the best to remove the driver, as for two reasons:
- The original author (boricj) agreed to do this, stating that he will
  not be able to test the driver anymore after his Athlon XP machine is
  no longer supported after the removal of the i686 port.
- It was agreed that the NE2000 network card family is far from the
  ideal hardware we would want to support, similarly to the RTL8139 that
  got removed recently for almost the same reason.
2023-01-08 21:51:59 +01:00
Liav A
72b144e9e9 Kernel/Graphics: Introduce a new mechanism to initialize a PCI device
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-07 11:51:13 -07:00
Liav A
7625f7db73 Kernel/Graphics: Allocate 16 MiB framebuffer if failed allocating larger
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-07 11:45:08 -07:00
Liav A
25bb293629 Kernel: Make Device::after_inserting to return ErrorOr<void>
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-07 11:45:08 -07:00
Liav A
5c97c6d874 Kernel: Remove the RTL8139 PCI network adapter driver
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-07 11:37:57 -07:00
Liav A
0cede94c39 Kernel/Net: Introduce a new mechanism to initialize a PCI device
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-07 12:36:57 +01:00
Liav A
90ac9d7253 Kernel/Net: Allocate regions before invoking the RTL8139 constructor
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-07 12:36:57 +01:00
Liav A
102186b0f5 Kernel/Net: Allocate regions before invoking Intel driver constructors
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-07 12:36:57 +01:00
Liav A
04221a7533 Kernel: Mark Process::jail() method as const
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-07 03:44:59 +03:30
Liav A
d8ebcaede8 Kernel: Add helper function to check if a Process is in jail
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-06 17:29:47 +01:00
Liav A
3d87445c82 Kernel: Restore setting i8042 scan code set to scan code set 2 sequence
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-06 11:09:56 +01:00
Liav A
0f7cc468b2 Kernel: Make i8042 controller initialization sequence more robust
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-06 11:09:56 +01:00
Liav A
a9839d7ac5 Kernel/SysFS: Don't refresh/set-values inside the Jail spinlock scope
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-05 23:58:13 +01:00
Ben Wiederhake
c25bef59aa Kernel: Repair build for aarch64
This broke in 6fd478b6ce due to
insufficient testing on my part. Sorry!
2023-01-05 19:47:07 +01:00
Nico Weber
7f4680a377 Kernel/aarch64: Remove counterproductive volatile
Should not be needed, and triggers -Wvolatile in gcc.
See discussion on #16790.
2023-01-05 19:45:27 +01:00
Jelle Raaijmakers
a7806d410a Kernel: Convert 2 instances of dbgln to dmesgln_pci in AC'97 2023-01-05 01:50:35 +01:00
Evan Smal
288a73ea0e Kernel: Add dmesgln_pci logging for Kernel::PCI
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-05 01:44:19 +01:00
Nico Weber
a96f307af1 Everywhere: Make global inline functions not static
`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-04 20:04:57 +01:00
Nico Weber
0a3cc10bb6 Everywhere: Remove some redundant inline keywords
Functions defined inside class bodies (including static functions)
are implicitly inline, no need to type it out.
2023-01-04 20:04:57 +01:00
Taj Morton
31eeea08ba Kernel/FileSystem: Fix handling of FAT names that don't fill an entry
* 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-04 09:02:13 +00:00
Taj Morton
a91fc697bb Kernel/FileSystem: Remove FIXME about old/new path being the same
Added comment after confirming that Linux and OpenBSD implenment the
same behavior.
2023-01-04 09:02:13 +00:00
yyny
fb2be937ac Kernel: Allow sending SIGCONT to processes in the same group
Allow sending `SIGCONT` to processes that share the same `pgid`.
This is allowed in Linux aswell.

Also fixes a FIXME :^)
2023-01-03 18:13:11 +01:00
yyny
9ca979846c Kernel: Add sid and pgid to Credentials
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-03 18:13:11 +01:00
Ben Wiederhake
65b420f996 Everywhere: Remove unused includes of AK/Memory.h
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-02 20:27:20 -05:00
Ben Wiederhake
f07847e099 Everywhere: Remove unused includes of AK/Concepts.h
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-02 20:27:20 -05:00
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