Commit graph

7480 commits

Author SHA1 Message Date
Brian Gianforcaro 2d06f6399f Kernel: Fix SMP deadlock in MM::allocate_contiguous_physical_pages
This deadlock was introduced with the creation of this API. The lock
order is such that we always need to take the page directory lock
before we ever take the MM lock.

This function violated that, as both Region creation and region
destruction require the pd and mm locks, but with the mm lock
already acquired we deadlocked with SMP mode enabled while other
threads were allocating regions.

With this change SMP boots to the desktop successfully for me,
(and then subsequently has other issues). :^)
2022-08-09 12:09:59 +02:00
Liav A cf33d0b5f7 Kernel/FileSystem: Use a new debug flag for SysFS debug messages 2022-08-08 02:33:25 +00:00
Timon Kruiper c92e68da38 Kernel: Rounding size of bss to be a multiple of 8 for aarch64 linker.ld
This fixes a bug where the bss was not completely zeroed out. This bug
showed up when running the aarch64 Kernel baremetal on a Raspberry Pi.
2022-08-06 14:00:54 +01:00
Timon Kruiper 22aea9f659 Kernel: Add logic to RPi UART driver to emit CR when encountering LF
This makes sure that the debug message are properly aligned when running
the kernel bare-metal on a Raspberry Pi. While we are here, also move
the function out of line.
2022-08-06 14:00:54 +01:00
Tim Schumacher 9fad80c34c Kernel: Silently discard SO_REUSEADDR
We were previously rejecting `SO_REUSEADDR` with an `ENOPROTOOPT`, but
that made QEMU unhappy. Instead, just silently discard it and print a
FIXME message in case anybody wonders what went wrong if the system
won't reuse an address.
2022-08-01 04:23:41 +00:00
Liav A fcc0e4d538 Kernel/FileSystem: Funnel calls to Inode::prepare_to_write_data method
Instead of requiring each FileSystem implementation to call this method
when trying to write data, do the calls at 2 points to avoid further
calls (or lack of them due to not remembering to use it) at other files
and locations in the codebase.
2022-07-30 23:31:08 +02:00
Liav A 38bf7863d0 Kernel: Remove PCI information node from ProcFS
The SystemMonitor program was the last client to utilize this node, and
now it is not using this node anymore, we can simply remove this for
good.
2022-07-30 23:29:07 +02:00
gggggg-gggggg 6f40b19746 Kernel: Detect the Insert key 2022-07-30 23:25:20 +02:00
Undefine 97cc33ca47 Everywhere: Make the codebase more architecture aware 2022-07-27 21:46:42 +00:00
b14ckcat b8cfec7b1f Kernel: Move SysFS USB create function 2022-07-27 05:52:35 +00:00
b14ckcat 4b1537387f Kernel: Fix USB hotplug crash
Currently the SysFS node for USB devices is only initialized for USB
hubs, which means it will cause a kernel crash upon being dereferenced
in a non-hub device. This fixes the problem by making initialization
happen for all USB devices.
2022-07-27 05:52:35 +00:00
Filiph Sandström bac4bdc5d2 Kernel: Fix incorrect return type on aarch64
InterruptController's model incorrectly returned a char[] instead
of a StringView.
2022-07-25 16:01:46 +01:00
zzLinus ca74443012 Kernel/LibC: Implement posix syscall clock_getres() 2022-07-25 15:33:50 +02:00
Linus Groh f52e468cd6 Kernel: Fix L1/L2/L3 cache conditionals in ProcFSCPUInformation 2022-07-24 23:01:59 +01:00
Liav A 60f7d61ad2 Kernel/SysFS: Fix parent directory hierarchy with symbolic links
We should actually start counting from the parent directory and not from
the symbolic link as it will represent a wrong count of hops from the
actual mountpoint.

The symlinks in /sys/dev/block and /sys/dev/char worked only by luck,
because I have set it to the wrong parent directory which is the
/sys/dev directory, so with the symlink it was 3 hops to /sys, together
with the root directory, therefore, everything seemed to work.

Now that the device symlinks in /sys/dev/block and /sys/dev/char are set
to the right parent directory and we start measure hops from root
directory with the parent directory of a symlink, everything seem to
work correctly now.
2022-07-24 13:38:24 +01:00
Liav A 977aa81310 Kernel+Userland: Add ioctl to set process ownership of DisplayConnector
Now that the infrastructure of the Graphics subsystem is quite stable,
it is time to try to fix a long-standing problem, which is the lack of
locking on display connector devices. Reading and writing from multiple
processes to a framebuffer controlled by the display connector is not a
huge problem - it could be solved with POSIX locking.

The real problem is some program that will try to do ioctl operations on
a display connector without the WindowServer being aware of that which
can lead to very bad situations, for example - assuming a framebuffer is
encoded at a known resolution and certain display timings, but another
process changed the ModeSetting of the display connector, leading to
inconsistency on the properties of the current ModeSetting.

To solve this, there's a new "master" ioctl to take "ownership" and
another one to release that ownership of a display connector device. To
ensure we will not hold a Process object forever just because it has an
ownership over a display connector, we hold it with a weak reference,
and if the process is gone, someone else can take an ownership.
2022-07-23 10:42:08 +01:00
Liav A 1968aba69b Kernel+Userland: Rename FB.h => Graphics.h
This header file represents the entire interface between the kernel and
userland, and as such, no longer should be called FB.h but something
that represents the whole graphics subsystem.
2022-07-23 10:42:08 +01:00
Liav A b7d0b5d745 Kernel/Graphics: Remove out-of-context comment note 2022-07-23 10:42:08 +01:00
Linus Groh 8150d71821 Everywhere: Prefix 'TYPEDEF_DISTINCT_ORDERED_ID' with 'AK_' 2022-07-22 23:09:43 +01:00
Tim Schumacher 899fd74f8e LibC: Implement pthread_cancel 2022-07-22 10:07:15 -07:00
Tim Schumacher e79f0e2ee9 Kernel+LibC: Don't hardcode the maximum signal number everywhere 2022-07-22 10:07:15 -07:00
Samuel Bowman f6ab636d31 Kernel: Move DiskPartition up into Kernel/Storage
Everything in Kernel/Storage/Partition but DiskPartition has been moved
into LibPartiton. This makes the Partition directory unnecessary so
DiskPartition is moved up into Kernel/Storage.
2022-07-21 20:13:44 +01:00
Samuel Bowman 25de9de7dc Kernel+LibPartition: Move GUIDPartitionTable into LibPartition 2022-07-21 20:13:44 +01:00
Samuel Bowman 9053d86b82 Kernel+LibPartition: Move EBRPartitionTable into LibPartition 2022-07-21 20:13:44 +01:00
Samuel Bowman 1a6ef03e4a Kernel+LibPartition: Move MBRPartitionTable into LibPartition 2022-07-21 20:13:44 +01:00
Samuel Bowman 940dde9947 Kernel+LibPartition: Move PartitionTable into LibPartition 2022-07-21 20:13:44 +01:00
Samuel Bowman be1c5c6b9f Kernel+LibPartition: Move DiskPartitionMetadata into LibPartition
This commit creates a new library LibPartition which will contain
partition related code sharable between Kernel and Userland and
includes DiskPartitionMetadata as the first shared class.
2022-07-21 20:13:44 +01:00
Idan Horowitz 3a80b25ed6 Kernel: Support F_SETLKW in fcntl 2022-07-21 16:39:22 +02:00
Idan Horowitz 9db10887a1 Kernel: Clean up sys$futex and add support for cross-process futexes 2022-07-21 16:39:22 +02:00
Idan Horowitz 55c7496200 Kernel: Propagate OOM conditions out of sys$futex 2022-07-21 16:39:22 +02:00
Idan Horowitz 364f6a9bf0 Kernel: Remove the Socket::{protocol,}connect ShouldBlock argument
This argument is always set to description.is_blocking(), but
description is also given as a separate argument, so there's no point
to piping it through separately.
2022-07-21 16:39:22 +02:00
kleines Filmröllchen d0e614c045 Kernel: Don't check that interrupts are enabled during early boot
The interrupts enabled check in the Kernel mutex is there so that we
don't lock mutexes within a spinlock, because mutexes reenable
interrupts and that will mess up the spinlock in more ways than one if
the thread moves processors. This check is guarded behind a debug flag
because it's too hard to fix all the problems at once, but we regressed
and weren't even getting to init stage 2 with it enabled. With this
commit, we get to stage 2 again. In early boot, there are no interrupts
enabled and spinlocks used, so we can sort of kind of safely ignore the
interrupt state. There might be a better solution with another boot
state flag that checks whether APs are up (because they have interrupts
enabled from the start) but that seems overkill.
2022-07-19 12:12:13 +01:00
b14ckcat 6aea13e229 Kernel/USB: Make UHCI descriptor pool thread-safe
Right now the TD and QH descriptor pools look to be susceptible
to a race condition in the event they are accessed simultaneously
by separate threads making USB transfers. This fix does not seem to
add any noticeable overhead.
2022-07-19 11:29:58 +01:00
Liav A f96e8e97e6 Kernel/Storage: Remove redundant reference to a controller in IDEChannel
IDEChannel which is an ATAPort derived class holded a NonnullRefPtr to a
parent IDEController, although we can easily defer the usage of it to
not be in the IDEChannel code at all, so it allows to keep NonnullRefPtr
to the parent ATAController in the ATAPort base class and only there.
2022-07-19 11:07:34 +01:00
Liav A 0810c1b972 Kernel/Storage: Introduce basic abstraction layer for ATA components
This abstraction layer is mainly for ATA ports (AHCI ports, IDE ports).
The goal is to create a convenient and flexible framework so it's
possible to expand to support other types of controller (e.g. Intel PIIX
and ICH IDE controllers) and to abstract operations that are possible on
each component.

Currently only the ATA IDE code is affected by this, making it much
cleaner and readable - the ATA bus mastering code is moved to the
ATAPort code so more implementations in the near future can take
advantage of such functionality easily.

In addition to that, the hierarchy of the ATA IDE code resembles more of
the SATA AHCI code now, which means the IDEChannel class is solely
responsible for getting interrupts, passing them for further processing
in the ATAPort code to take care of the rest of the handling logic.
2022-07-19 11:07:34 +01:00
Liav A 7719ef3a61 Kernel/Storage: Move ATA device signature definitions to a general file 2022-07-19 11:07:34 +01:00
Liav A 2c987367e6 Kernel/Storage: Merge IDE functionality from BusMasterChannel to Channel
This simplifies the flow of how things work currently and is a step for
more improvements in the next commits.
2022-07-19 11:07:34 +01:00
Liav A ade672c576 Kernel/Storage: Rename ATA.h => Definitions.h 2022-07-19 11:07:34 +01:00
Liav A c001e3f567 Kernel/Storage: Move AHCI and IDE code into new subdirectories
We do that to increase clarity of the major and secondary components in
the subsystem. To ensure it's even more understandable, we rename the
files to better represent the class within them and to remove redundancy
in the name.

Also, some includes are removed from the general components of the ATA
components' classes.
2022-07-19 11:07:34 +01:00
Liav A 412a5999d0 Kernel+Userland: Remove GRAPHICS_IOCTL_GET_HEAD_EDID ioctl
We are able to read the EDID from SysFS, therefore there's no need to
provide this ioctl on a DisplayConnector anymore.
Also, now we can simply require the video pledge to be set before doing
any ioctl on a DisplayConnector.
2022-07-19 11:02:37 +01:00
Liav A ecf015e6ee Userland: Make graphics_connector_get_head_edid to read EDID from SysFS
The EDID blob is now exposed in the SysFS for each DisplayConnector, so
we don't need to use the ioctl interface anymore to read the EDID.
2022-07-19 11:02:37 +01:00
Liav A 3af70cb0fc Kernel/Devices: Abstract SysFS Device add/remove methods more properly
It is starting to get a little messy with how each device can try to add
or remove itself to either /sys/dev/block or /sys/dev/char directories.

To better do this, we introduce 4 virtual methods to take care of that,
so until we ensure all nodes in /sys/dev/block and /sys/dev/char are
actual symlinks, we allow the Device base class to call virtual methods
upon insertion or before being destroying, so it add itself elegantly to
either of these directories or remove itself when needed.

For special cases where we need to create symlinks, we have two virtual
methods to be called otherwise to do almost the same thing mentioned
before, but to use symlinks instead.
2022-07-19 11:02:37 +01:00
Liav A da8d18b263 Kernel/SysFS: Add exposing interface for DisplayConnectors
Under normal conditions (when mounting SysFS in /sys), there will be a
new directory in the /sys/devices directory called "graphics".
For now, under that directory there will be only a sub-directory called
"connectors" which will contain all DisplayConnectors' details, each in
its own sub-directory too, distinguished in naming with its minor
number.

Therefore, /sys/devices/graphics/connectors/MINOR_NUMBER/ will contain:
- General device attributes such as mutable_mode_setting_capable,
  double_buffering_capable, flush_support, partial_flush_support and
  refresh_rate_support. These values are exposed in the ioctl interface
  of the DisplayConnector class too, but these can be useful later on
  for command line utilities that want/need to expose these basic
  settings.
- The EDID blob, simply named "edid". This will help userspace to fetch
  the edid without the need of using the ioctl interface later on.
2022-07-19 11:02:37 +01:00
Hendiadyoin1 66fc06001d Kernel: Add some inline capacity to find_regions_intersecting
This should avoid some allocations during simple cases of munmap,
mprotect and msync, where you usually don't have a lot of regions anyway
2022-07-15 12:42:43 +02:00
Hendiadyoin1 c3e57bfccb Kernel: Try to set [cm]time in Inode::did_modify_contents
This indirectly resolves a fixme in sys$msync
2022-07-15 12:42:43 +02:00
Hendiadyoin1 10d9bb93be Kernel: Handle multiple regions in sys$msync 2022-07-15 12:42:43 +02:00
Hendiadyoin1 d783389877 Kernel+LibC: Add posix_fallocate syscall 2022-07-15 12:42:43 +02:00
Hendiadyoin1 ad904cdcab Kernel: Use find_last_split_view to get the executable name in do_exec 2022-07-15 12:42:43 +02:00
Liav A 1dbd32488f Kernel/SysFS: Add /sys/devices/storage directory
This change in fact does the following:
1. Use support for symlinks between /sys/dev/block/ storage device
identifier nodes and devices in /sys/devices/storage/{LUN}.
2. Add basic nodes in a /sys/devices/storage/{LUN} directory, to let
userspace to know about the device and its details.
2022-07-15 12:29:23 +02:00
Liav A 22335e53e0 Kernel/Devices: Add two protected methods for DeviceManagement functions
These methods are essentially splitted from the after_inserting method
and the will_be_destroyed method so later on we can allow Storage
devices to override the after_inserting method and the will_be_destroyed
method while still being able to use shared functionality as before,
such as adding the device to and removing it from the device list.
2022-07-15 12:29:23 +02:00
Liav A 9b49d9ee60 Kernel: Declare BlockDevice::is_block_device method protected 2022-07-15 12:29:23 +02:00
Liav A cdab213750 Kernel/SysFS: Adapt USB plug code to work with SysFS patterns 2022-07-15 12:29:23 +02:00
Liav A 70afa0b171 Kernel/SysFS: Mark SysFSDirectory traverse and lookup methods as final
This enforces us to remove duplicated code across the SysFS code. This
results in great simplification of how the SysFS works now, because we
enforce one way to treat SysFSDirectory objects.
2022-07-15 12:29:23 +02:00
Liav A 6733f19b3c Kernel/SysFS: Reduce the responsibilities of the Registry object
Instead, let the /sys/dev/block and /sys/dev/char directories to handle
the registering part of SysFSDeviceComponents by themselves.
2022-07-15 12:29:23 +02:00
Liav A ecc29bb52e Kernel/SysFS: Add Symbolic link functionality to the filesystem
This will be used later on to help connecting a node at /sys/dev/block/
that represents a Storage device to a directory in /sys/devices/storage/
with details on that device in that directory.
2022-07-15 12:29:23 +02:00
Liav A 7e88bbe550 Kernel/SysFS: Add two methods related to relative paths for components
These methods will be used later on to introduce symbolic links support
in the SysFS, so the kernel will be able to resolve relative paths of
components in filesystem based on using the m_parent_directory pointer
in each SysFSComponent object.
2022-07-15 12:29:23 +02:00
Liav A 4744ccbff0 Kernel/Storage: Add LUN address to each StorageDevice
LUN address is essentially how people used to address SCSI devices back
in the day we had these devices more in use. However, SCSI was taken as
an abstraction layer for many Unix and Unix-like systems, so it still
common to see LUN addresses in use. In Serenity, we don't really provide
such abstraction layer, and therefore until now, we didn't use LUNs too.
However (again), this changes, as we want to let users to address their
devices under SysFS easily. LUNs make sense in that regard, because they
can be easily adapted to different interfaces besides SCSI.
For example, for legacy ATA hard drive being connected to the first IDE
controller which was enumerated on the PCI bus, and then to the primary
channel as slave device, the LUN address would be 0:0:1.

To make this happen, we add unique ID number to each StorageController,
which increments by 1 for each new instance of StorageController. Then,
we adapt the ATA and NVMe devices to use these numbers and generate LUN
in the construction time.
2022-07-15 12:29:23 +02:00
Liav A b49af59b4a Kernel/Storage: Declare NVMeNameSpace constructor as private
Also, don't mark it as explicit.
2022-07-15 12:29:23 +02:00
Liav A 7db6b77e75 Kernel: Export both interface type and command set of a StorageDevice 2022-07-15 12:29:23 +02:00
Liav A 6ff1aeb64d Kernel/SysFS: Rename Devices code folder => DeviceIdentifiers
This folder in the SysFS code represents everything related to /sys/dev,
which is a directory meant to be a convenient interface to track all IDs
of all block and character devices (ID = major:minor numbers).
2022-07-15 12:29:23 +02:00
b14ckcat 4ad437f3a7 Kernel/USB: Support UHCI full speed bandwidth reclamation 2022-07-15 12:28:09 +02:00
Liav A 95238bdb16 Kernel/Storage: Check IDE error condition under the correct lock
This bug was probably around for a very long time, but it is noticeable
only under VirtualBox as it generated an non fatal error which caused a
kernel panic because we VERIFYed the wrong lock to be locked.
2022-07-15 12:27:32 +02:00
Liav A ebbc38cd2a Kernel/Graphics: Remove GenericGraphicsAdapter::vga_compatible method
There's no point in keeping this method as we don't really care if a
graphics adapter is VGA compatible or not because we don't use this
method anymore.
2022-07-15 12:23:22 +02:00
Liav A e4e5fa74d0 Kernel+Userland: Rename prefix of user_physical => physical
There's no such supervisor pages concept, so there's no need to call
physical pages with the "user_physical" prefix anymore.
2022-07-14 23:27:46 +02:00
Liav A 1c499e75bd Kernel+Userland: Remove supervisor pages concept
There's no real value in separating physical pages to supervisor and
user types, so let's remove the concept and just let everyone to use
"user" physical pages which can be allocated from any PhysicalRegion
we want to use. Later on, we will remove the "user" prefix as this
prefix is not needed anymore.
2022-07-14 23:27:46 +02:00
Liav A 37b4133c51 Kernel: Allocate user physical pages instead of supervisor ones for DMA
We are limited on the amount of supervisor pages we can allocate, so
don't allocate from that pool. Supervisor pages are always below 16 MiB
barrier so using those was crucial when we used devices like the ISA
SoundBlaster 16 card, because that device required very low physical
addresses to be used.
2022-07-14 13:15:24 +02:00
Daniel Bertalan e93d19bbb1 Kernel: Don't lock the scheduler in ProcFSOverallProcesses::try_generate
This used to be needed to protect accesses to Process::all_instances.
That list now has a more granular lock, so we don't need to take the
scheduler lock.

This fixes a crash when we try to access a locked Thread::m_fds in the
loop, which calls Thread::block, which then asserts that the scheduler
lock must not be locked by the current process.

Fixes #13617
2022-07-14 13:13:40 +02:00
Liav A cd8bcd06c6 Kernel/Graphics: Allocate VGA window region according to the usual rules
We should not allocate a kernel region inside the constructor of the
VGATextModeConsole class. We do use MUST() because allocation cannot
fail at this point, but that happens in the static factory method
instead.
2022-07-13 19:15:17 +01:00
Liav A f052b9574c Kernel/Graphics: Rename m_vga_region => m_vga_window_region 2022-07-13 19:15:17 +01:00
Liav A 00dbd667d5 Kernel/Graphics: Rename TextModeConsole => VGATextModeConsole
This change represents well the fact that the text mode console is based
on VGA text mode.
2022-07-13 19:15:17 +01:00
Liav A 97a769d2a9 Kernel/Graphics: Remove unnecessary VGAConsole class abstraction
The original intention was to support other types of consoles based on
standard VGA modes, but it never came to an implementation, nor we need
such feature at all.
Therefore, this class is not needed and can be removed.
2022-07-13 19:15:17 +01:00
sin-ack fbc771efe9 Everywhere: Use default StringView constructor over nullptr
While null StringViews are just as bad, these prevent the removal of
StringView(char const*) as that constructor accepts a nullptr.

No functional changes.
2022-07-12 23:11:35 +02:00
sin-ack c8585b77d2 Everywhere: Replace single-char StringView op. arguments with chars
This prevents us from needing a sv suffix, and potentially reduces the
need to run generic code for a single character (as contains,
starts_with, ends_with etc. for a char will be just a length and
equality check).

No functional changes.
2022-07-12 23:11:35 +02:00
sin-ack 3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
sin-ack c70f45ff44 Everywhere: Explicitly specify the size in StringView constructors
This commit moves the length calculations out to be directly on the
StringView users. This is an important step towards the goal of removing
StringView(char const*), as it moves the responsibility of calculating
the size of the string to the user of the StringView (which will prevent
naive uses causing OOB access).
2022-07-12 23:11:35 +02:00
Liav A 4771917184 Kernel/Graphics: Simplify initialization flow explanation comment
Most of it was not relevant anymore to what we do in the initialization
method anyway, and now it represents it quite well and "to the point".
2022-07-12 19:54:48 +01:00
Liav A 5824f30752 Kernel/Graphics: Fix comparison of framebuffer type in initialization 2022-07-12 19:54:48 +01:00
Liav A 3bd0106755 Kernel/Graphics: Remove VGA folder and its content
We never supported VGA framebuffers and that folder was a big misleading
part of the graphics subsystem.

We do support bare-bones VGA text console (80x25), but that only happens
to be supported because we can't be 100% sure we can always initialize
framebuffer so in the worst scenario we default to plain old VGA console
so the user can still use its own machine.

Therefore, the only remaining parts of VGA is in the GraphicsManagement
code to help driving the VGA text console if needed.
2022-07-12 19:54:48 +01:00
Tim Schumacher 3b3af58cf6 Kernel: Annotate all KBuffer and DoubleBuffer with a custom name 2022-07-12 00:55:31 +01:00
Idan Horowitz 8717e78918 Kernel: Stop committing pages for COW of uncommitted pages on sys$fork
Uncommitted pages (shared zero pages) can not contain any existing data
and can not be modified, so there's no point to committing a bunch of
extra pages to cover for them in the forked child.
2022-07-11 16:29:10 +02:00
Idan Horowitz 1d96c30488 Kernel: Stop leaking leftover committed cow pages from forked processes
Since both the parent process and child process hold a reference to the
COW committed set, once the child process exits, the committed COW
pages are effectively leaked, only being slowly re-claimed each time
the parent process writes to one of them, realizing it's no longer
shared, and uncommitting it.
In order to mitigate this we now hold a weak reference the parent
VMObject from which the pages are cloned, and we use it on destruction
when available to drop the reference to the committed set from it as
well.
2022-07-10 22:17:21 +03:00
Idan Horowitz c1fe844da4 Kernel: Stop leaking first thread on errors in sys$fork
Until the thread is first set as Runnable at the end of sys$fork, its
state is Invalid, and as a result, the Finalizer which is searching for
Dying threads will never find it if the syscall short-circuits due to
an error condition like OOM. This also meant the parent Process of the
thread would be leaked as well.
2022-07-10 22:17:21 +03:00
gggggg-gggggg d728017578 Kernel+LibC+LibCore: Pass fcntl extra argument as pointer-sized variable
The extra argument to fcntl is a pointer in the case of F_GETLK/F_SETLK
and we were pulling out a u32, leading to pointer truncation on x86_64.
Among other things, this fixes Assistant on x86_64 :^)
2022-07-10 20:09:11 +02:00
Liav A 9dbec601b0 Kernel+SystemServer: Make KCOVDevice a character device
This device should not be a block device, as in Serenity, block devices
represent an interface to either disk partitions or storage devices.
2022-07-10 14:57:55 +02:00
Idan Horowitz b700d1a474 Kernel: Support sys$connect to LocalSockets with short sockaddr_uns
This is not explicitly specified by POSIX, but is supported by other
*nixes, already supported by our sys$bind, and expected by various
programs. While were here, also clean up the user memory copies a bit.
2022-07-10 14:24:34 +02:00
Idan Horowitz 68980bf711 Kernel: Stop reporting POLLHUP exclusively when available in sys$poll
As per Dr. Posix, unlike POLLERR and POLLNVAL, POLLHUP is only mutually
exclusive with POLLOUT, all other events may be reported together with
it.
2022-07-10 14:24:34 +02:00
Idan Horowitz 08e88bfcad Kernel: Remove unused WriteNotOpen File BlockFlag 2022-07-10 14:24:34 +02:00
Idan Horowitz 275e5cdb64 Kernel: Report POLLNVAL events in sys$poll instead of returning EBADF
As required by Dr. Posix.
2022-07-10 14:24:34 +02:00
Idan Horowitz e32f6903f6 Kernel: Stop providing POLLRDHUP events in sys$poll by default
Dr. Posix specifies that only POLLERR, POLLHUP & POLLNVAL are provided
by default.
2022-07-10 14:24:34 +02:00
Idan Horowitz 5ca46abb51 Kernel: Set POLLHUP on WriteHangUp in sys$poll instead of POLLNVAL
POLLNVAL signifies an invalid fd, not a write hang up.
2022-07-10 14:24:34 +02:00
Idan Horowitz 020c898290 Kernel: Handle SHUT_RDWR in Socket::shutdown
We were previously assuming that the how value was a bitfield, but that
is not the case, so we must explicitly check for SHUT_RDWR when
deciding on the read and write shutdowns.
2022-07-10 14:24:34 +02:00
Idan Horowitz a6f237a247 Kernel: Accept SHUT_RD and SHUT_WR as shutdown() how values
The previous check for valid how values assumed this field was a bitmap
and that SHUT_RDWR was simply a bitwise or of SHUT_RD and SHUT_WR,
which is not the case.
2022-07-10 14:24:34 +02:00
Maciej 303be38f65 Kernel/Routing: Hide some leftover debugging under a debug flag 2022-07-09 16:53:26 +03:00
Maciej bea1668159 Kernel/Net: Support removing route entries with unknown gateway
If you specify gateway as 0.0.0.0, the SIOCDELRT ioctl will remove all
route entries that match all the other arguments.
2022-07-09 09:22:25 +01:00
Tim Schumacher cf0ad3715e Kernel: Implement sigsuspend using a SignalBlocker
`sigsuspend` was previously implemented using a poll on an empty set of
file descriptors. However, this broke quite a few assumptions in
`SelectBlocker`, as it verifies at least one file descriptor to be
ready after waking up and as it relies on being notified by the file
descriptor.

A bare-bones `sigsuspend` may also be implemented by relying on any of
the `sigwait` functions, but as `sigsuspend` features several (currently
unimplemented) restrictions on how returns work, it is a syscall on its
own.
2022-07-08 22:27:38 +00:00
Tim Schumacher edbffb3c7a Kernel: Unblock SignalBlocker if a signal was just unmarked as pending
When updating the signal mask, there is a small frame where we might set
up the receiving process for handing the signal and therefore remove
that signal from the list of pending signals before SignalBlocker has a
chance to block. In turn, this might cause SignalBlocker to never notice
that the signal arrives and it will never unblock once blocked.

Track the currently handled signal separately and include it when
determining if SignalBlocker should be unblocking.
2022-07-08 22:27:38 +00:00
Tim Schumacher cd189999d1 Kernel: Don't let locks of the same owner conflict with each other
Documentation on POSIX locks seems sparse, but this is how the Linux
kernel implementation handles it.
2022-07-08 22:27:38 +00:00
Tim Schumacher dc6016cd18 Kernel: Don't fail on unlocking nonexistent file locks
I haven't found any POSIX specification on this, but the Linux kernel
appears to handle it like that.

This is required by QEMU, as it just bulk-unlocks all its file locking
bytes without checking first if they are held.
2022-07-08 22:27:38 +00:00
Tim Schumacher 7d3f71a648 Kernel: Do not disable userland access to the RDTSC instruction
Access to RDTSC is occasionally restricted to give malware one less
option to accurately time attacks (side-channels, etc.).

However, QEMU requires access to the timestamp counter for the exact
same reason (which is accurately timing its CPU ticks), so lets just
enable it for now.
2022-07-08 22:27:38 +00:00
Tim Schumacher 5efa8e507b Kernel: Implement an axallowed mount option
Similar to `W^X` and `wxallowed`, this allows for anonymous executable
mappings.
2022-07-08 22:27:38 +00:00
Liav A 8de395694d Kernel/Storage: Do proper locking & reset in the AHCIController code
The initialize_hba method now calls the reset method to reset the HBA
and initialize each AHCIPort. Also, after full HBA reset we need to turn
on the AHCI functionality of the HBA and global interrupts since they
are cleared to 0 according to the specification in the GHC register.
2022-07-08 01:06:47 +03:00
Liav A 4d36989954 Kernel/Storage: Move Identify page allocation to the AHCIPort class
Instead of doing this in a parent class like the AHCIController, let's
do that directly in the AHCIPort class as that class is the only user of
these sort of physical pages. While it seems like we waste an entire 4KB
of physical RAM for each allocation, this could serve us later on if we
want to fetch other types of logs from the ATA device.
2022-07-08 01:06:47 +03:00
Liav A bf82c4b81b Kernel/Storage: Rename AHCIPortHandler => AHCIInterruptHandler
This reflects better what this object is all about - handling interrupts
of AHCI ports, and nothing more than that.
2022-07-08 01:06:47 +03:00
Liav A cc734c106e Kernel/Storage: Simplify AHCIPortHandler class
The way AHCIPortHandler held AHCIPorts and even provided them with
physical pages for the ATA identify buffer just felt wrong.
To fix this, AHCIPortHandler is not a ref-counted object anymore. This
solves the big part of the problem, because AHCIPorts can't hold a
reference to this object anymore, only the AHCIController can do that.
Then, most of the responsibilities are shifted to the AHCIController,
making the AHCIPortHandler a handler of port interrupts only.
2022-07-08 01:06:47 +03:00
Liav A 4169ac4a7b Kernel/Storage: Remove 3 stale methods in AHCIPortHandler class 2022-07-08 01:06:47 +03:00
Liav A 9416dede54 Kernel/AHCI: Don't use UNMAP_AFTER_INIT in header files
Instead, declare such methods and functions in the code itself.
2022-07-08 01:06:47 +03:00
Liav A d771ca3278 Kernel: Clean up the AHCI code a bit
The AHCI code is not very good at OOM conditions, so this is a first
step towards OOM correctness. We should not allocate things inside C++
constructors because we can't catch OOM failures, so most allocation
code inside constructors is exported to a different function.

Also, don't use a HashMap for holding RefPtr of AHCIPort objects in
AHCIPortHandler because this structure is not very OOM-friendly. Instead
use a fixed Array of 32 RefPtrs, as at most we can have 32 AHCI ports
per AHCI controller.
2022-07-08 01:06:47 +03:00
Tim Schumacher 67f352b824 Kernel: Copy signal handlers when forking 2022-07-05 20:58:38 +03:00
Tim Schumacher add4dd3589 Kernel: Do a POSIX-correct signal handler reset on exec 2022-07-05 20:58:38 +03:00
Idan Horowitz af71aa4e0b Kernel: Negate condition in ARPTableBlockerSet::should_add_blocker
To prevent a race condition in case we received the ARP response in the
window between creating and initializing the Thread Blocker and the
actual blocking, we were checking if the IP address was updated in the
ARP table just before starting to block.
Unfortunately, the condition was partially flipped, which meant that if
the table was updated with the IP address we would still end up
blocking, at which point we would never end unblocking again, which
would result in LookupServer locking up as well.
2022-07-04 01:56:43 +03:00
b14ckcat 143339767b Kernel/USB: Move buffer allocation from USB transfer to USB pipe
Currently when allocating buffers for USB transfers, it is done
once for every transfer rather than once upon creation of the
USB device. This commit changes that by moving allocation of buffers
to the USB Pipe class where they can be reused.
2022-07-03 01:15:07 +02:00
b14ckcat 13445f5a43 Kernel/USB: Use proper error codes for UHCI transfers 2022-06-29 13:38:13 +01:00
Liav A cd115270fc Kernel/Graphics: Move GenericDisplayConnector code to a new sub-folder
In the same fashion like in the Linux kernel, we support pre-initialized
framebuffers that were set up by either the BIOS or the bootloader.
These framebuffers can be backed by any kind of video hardware, and are
not tied to VGA hardware at all. Therefore, this code should be in a
separate sub-folder in the Graphics subsystem to indicate this.
2022-06-25 11:32:09 +01:00
Brian Gianforcaro 458244c0c1 Kernel: Enable -ftrivial-auto-var-init as a security mitigation
The flag will automatically initialize all variables to a pattern based
on it's type. The goal being here is to eradicate an entire bug class
of issues that can originate from uninitialized stack memory.

Some examples include:

 - Kernel information disclosure, where uninitialized struct members
   or struct padding is copied back to usermode, leaking kernel
   information such as stack or heap addresses, or secret data like
   stack cookies.

 - Control flow based on uninitialized memory can cause a variety of
   issues at runtime, including stack corruptions like buffer
   overflows, heap corruptions due to deleting stray pointers.
   Even basic logic bugs can result from control flow operating on
   uninitialized data.

As of GCC 12 this flag is now supported.
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=a25e0b5e6ac8a77a71c229e0a7b744603365b0e9

Clang has already supported it for a few releases.
https://reviews.llvm.org/D54604
2022-06-24 12:35:36 +01:00
kleines Filmröllchen f6af357763 Kernel/Audio: Fix buffer size underflow for non-page-aligned sizes
When the size of the audio data was not a multiple of a page size,
subtracting the page size from this unsigned variable would underflow it
close to 2^32 and be clamped to the page size again. This would lead to
writes into garbage addresses because of an incorrect write size,
interestingly only causing the write() call to error out.

Using saturating math neatly fixes this problem and allows buffer
lengths that are not a multiple of a page size.
2022-06-23 23:26:33 +01:00
Michał Lach e2b0f6795f LibVT+Kernel: Separate the caret shapes and its steadiness
Currently CursorStyle enum handles both the styles and the steadiness or
blinking of the terminal caret, which doubles the amount of its entries.
This commit changes CursorStyle to CursorShape and moves the blinking
option to a seperate boolean value.
2022-06-22 12:12:00 +01:00
Idan Horowitz 1950e79d48 Kernel: Eliminate possible KASLR leak by disabling CR4.FSGSBASE
The RDGSBASE userspace instruction allows programs to read the contents
of the gs segment register which contains a kernel pointer to the base
of the current Processor struct.

Since we don't use this instruction in Serenity at the moment, we can
simply disable it for now to ensure we don't break KASLR. Support can
later be restored once proper swapping of the contents of gs is done on
userspace/kernel boundaries.
2022-06-22 07:52:35 +03:00
Tim Schumacher cedec9751a Kernel: Decrease the amount of address space offset randomization
This is basically unchanged since the beginning of 2020, which is a year
before we had proper ASLR.

Now that we have a proper ASLR implementation, we can turn this down a
bit, as it is no longer our only protection against predictable dynamic
loader addresses, and it actually obstructs the default loading address
of x86_64 quite frequently.
2022-06-21 22:38:15 +01:00
Andrew Kaster 455038d6fc Kernel: Add sysconf for IOV_MAX 2022-06-19 09:05:35 +02:00
Andrew Kaster 1d3b5d330d Kernel: Tolerate cloning MAP_STACK regions that are PROT_NONE
There's nothing stopping a userspace program from keeping a bunch of
threads around with a custom signal stack in a suspended state with
their normal thread stack mprotected to PROT_NONE.

OpenJDK seems to do this, for example.
2022-06-19 09:05:35 +02:00
Andrew Kaster 940be19259 Kernel: Create /proc/pid/cmdline to expose process arguments in procfs
In typical serenity style, they are just a JSON array
2022-06-19 09:05:35 +02:00
Andreas Kling 0132e494d6 Kernel: Add missing #include in SysFS.cpp 2022-06-17 12:22:07 +02:00
Liav A 30b58cd06c Kernel/SysFS: Remove derived BIOSSysFSComponent classes
These are not needed, because both do exactly the same thing, so we can
move the code to the BIOSSysFSComponent class.
2022-06-17 11:01:27 +02:00
Liav A 23c1c40e86 Kernel/SysFS: Migrate components code from SysFS.cpp to the SysFS folder 2022-06-17 11:01:27 +02:00
Liav A 4d05a41b30 Kernel/SysFS: Split the bulky BIOS.h file into multiple files 2022-06-17 11:01:27 +02:00
Liav A 9c6834698f Kerenl/Firmware: Add map_ebda and map_bios methods in the original place
In a previous commit I moved everything into the new subdirectories in
FileSystem/SysFS directory without trying to actually make changes in
the code itself too much. Now it's time to split the code to make it
more readable and understandable, hence this change occurs now.
2022-06-17 11:01:27 +02:00
Liav A 7310a9a641 Kernel/Interrupts: Add missing include for IRQController header file
This is necessary for the next commit in the patch, otherwise this can't
be compiled. It seems like this was a hidden issue that is discovered
now only by changing includes in a mass-scale.
2022-06-17 11:01:27 +02:00
Liav A 99bac4f34f Kernel/SysFS: Split bulky SysFSPCI file into separate files 2022-06-17 11:01:27 +02:00
Liav A e488245234 Kernel/SysFS: Split bulky SysFSUSB file into two separate class files 2022-06-17 11:01:27 +02:00
Liav A 290eb53cb5 Kernel/SysFS: Stop cluttering the codebase with pieces of SysFS parts
Instead, start to put everything in one place to resemble the directory
structure of the SysFS when actually using it.
2022-06-17 11:01:27 +02:00
SeekingBlues 8730e56e88 LibC: Add WIFCONTINUED macro
Like other systems, we can encode the continued state with 0xffff in the
status value. This is needed for some ports.
2022-06-17 10:59:26 +02:00
kleines Filmröllchen 1b25513ed7 Kernel: Don't VERIFY that the DMA channel is running on AC'97 interrupt
Fixes #13771; as discussed it's not really a problem to receive an
interrupt while the DMA channel is not running, but we do want to log
it.
2022-06-15 20:53:10 +03:00
Andreas Kling 4e4a930b13 Kernel: Use the system boot time as default timestamp in /sys and /dev 2022-06-15 17:15:04 +02:00
Andreas Kling adaaea4c9a Kernel: Make TimeManagement::boot_time() static 2022-06-15 17:15:04 +02:00
Andreas Kling 9e994da2ac Kernel+AK: Split Weakable.h into userspace and kernel variants
Only the kernel expects AK::Weakable to lock its refcount manipulation,
so let's not force userspace to pay for that as well.
2022-06-15 17:15:04 +02:00
Timur Sultanov 0a63461341 Kernel: Add s6_addr32 field in in6_addr struct 2022-06-12 00:28:26 +01:00
MacDue 1dcdcc7efb Kernel/Console: Fix gaps between background glyph color 2022-06-11 12:19:29 +01:00
Liav A 20c9e4c05c Kernel/Graphics: Ensure VMWare and VirtualBox EDIDs have manufacturer ID 2022-06-10 22:32:54 +01:00
Liav A 3d36b194d1 Kernel/Graphics: Ensure generic EDID always has correct checksum 2022-06-10 22:32:54 +01:00
Liav A 938d579d16 Kernel/Graphics: Re-organize the DisplayConnector class a bit
Move methods that are overriding the virtual methods in the File class,
to a private access scope in the DisplayConnector class because nobody
tries to access them in any derived class of this class.
2022-06-10 22:32:54 +01:00
MacDue 348750a9f4 Kernel/Console: Tidy up code a little
- Remove some magic numbers
- Remove some duplicate branches
- Reduce the amount of casting between u8* and u32*
- Some renaming of confusing variables
2022-06-09 22:06:46 +02:00
MacDue 805a3d5b29 Kernel/Console: Factor out framebuffer offset and support glyph_spacing
This allows the 9px width of Cathode to be preserved without increasing
the bitmap size.
2022-06-09 22:06:46 +02:00
MacDue adef79b793 Kernel/Console: Replace QEMU bitmap font with Cathode
This has very similar look, but was invented here :^)
2022-06-09 22:06:46 +02:00
Liav A b4e409f721 Kernel/Graphics: Drop support for the DisplayConnector write interface
The WindowServer doesn't use this interface anymore and therefore it's
not used by any userspace application, so let's remove this stale method
to ensure we don't have to bother with it anymore.
2022-06-06 20:11:05 +01:00
Liav A e2ed6ef741 Kernel/Graphics: Bring back the mmap interface for DisplayConnectors
The mmap interface was removed when we introduced the DisplayConnector
class, as it was quite unsafe to use and didn't handle switching between
graphical and text modes safely. By using the SharedFramebufferVMObject,
we are able to elegantly coordinate the switch by remapping the attached
mmap'ed-Memory::Region(s) with different mappings, therefore, keeping
WindowServer to think that the mappings it has are still valid, while
they are going to a different physical range until we are back to the
graphical mode (after a switch from text mode).

Most drivers take advantage of the fact that we know where is the actual
framebuffer in physical memory space, the SharedFramebufferVMObject is
created with that information. However, the VirtIO driver is different
in that aspect, because it relies on DMA transactions to show graphics
on the framebuffer, so the SharedFramebufferVMObject is created with
that mindset to support the arbitrary framebuffer location in physical
memory space.
2022-06-06 20:11:05 +01:00
Liav A 3d22917548 Kernel/Memory: Introduce the SharedFramebufferVMObject class
This new type of VMObject will be used to coordinate switching safely
from graphical mode to text mode and vice-versa, by supplying a way to
remap all Regions that were created with this object, so mappings can be
changed according to the given state of system mode. This makes it quite
easy to give applications like WindowServer the feeling of having full
access to the framebuffer device from a DisplayConnector, but still keep
the Kernel in control to be able to safely switch to text console.
2022-06-06 20:11:05 +01:00
Liav A ec925cbb89 Kernel: Set console active before try to enable graphical mode
We should first enable the VirtualConsole and then enable graphical
mode, to ensure proper display output on the switched-to virtual console
that has been chosen. When de-activating graphical mode, we do the
de-activating first then enable the VirtualConsole to ensure proper text
output on screen.
2022-06-06 20:11:05 +01:00
Liav A d84d81fc4e Kernel/Graphics: Flush the entire buffer if using VirtIO console
Keeping the exact details of a dirty rectangle doesn't make any sense
when we just flush the entire screen, so just keep a simple boolean
value to know if the screen needs to be flushed or not.
2022-06-06 20:11:05 +01:00
Idan Horowitz ea1e5b630d Kernel: Verify system memory info consistency 2022-06-06 01:36:18 +03:00
Idan Horowitz b4e45a6636 Kernel: Tighten assertion in MM::find_free_user_physical_page
If our book-keeping of user physical pages is correct, we should always
find a physical page, regardless if it was committed or uncommitted.
2022-06-06 01:36:18 +03:00
Idan Horowitz 427f1f7e31 Kernel: Only use uncommitted pages when allocating contiguous user pages 2022-06-06 01:36:18 +03:00
Brian Gianforcaro 6b85b358f8 Kernel: Unify Kernel task names for consistency
This change unifies the naming convention for kernel tasks.

The goal of this change is to:

- Make the task names more descriptive, so users can more
  easily understand their purpose in System Monitor.

- Unify the naming convention so they are consistent.
2022-06-05 14:09:44 +01:00
Timon Kruiper 1072d523e2 Kernel: Initialize and use interrupts in the aarch64 Kernel
Now that everything is in place, we can actually use interrupts in the
aarch64 Kernel build. :^)
2022-06-02 13:14:12 +01:00
Timon Kruiper dab6dbe893 Kernel: Add interrupt support to aarch64 RPi Timer driver
Since we can now build and use the IRQHandler class, we can implement
interrupt support for the Timer in the aarch64 build.
2022-06-02 13:14:12 +01:00
Timon Kruiper 8b77c61e7d Kernel: Use AK::NeverDestroyed<Timer> to store the timer class
For an upcoming change to support interrupts in this driver, this class
has to inherit from IRQHandler. That in turn will make this class
virtual, which will then actually call the destructor of the class. We
don't want this to happen, thus we have to wrap the class in a
AK::NeverDestroyed.
2022-06-02 13:14:12 +01:00
Timon Kruiper a0b0c4e723 Kernel: Make RPi Timer::set_clock_rate static
This allows it to be called in UART without calling the Timer
constructor. This in turn allows the UART to be used before interrupts
are enabled.
2022-06-02 13:14:12 +01:00
Timon Kruiper 3cf8d3361e Kernel: Add support for handling interrupts on aarch64
There is currently some code duplication between the aarch64
implementation and the x86 one, but this initial implementation works
for now. :^)
2022-06-02 13:14:12 +01:00
Timon Kruiper c959344c00 Kernel: Add simple implementation for InterruptManagement on aarch64
This class currently hardcodes the use of the Raspberry Pi interrupt
controller.
2022-06-02 13:14:12 +01:00
Timon Kruiper 5eac2b9f33 Kernel: Add driver for interrupt controller on the Raspberry Pi
This implements the simpler IRQController class and adds a
pending_interrupts() function to the class.
2022-06-02 13:14:12 +01:00
Timon Kruiper f085903f62 Kernel: Move IRQController and InterruptManagement to Arch directory
These 2 classes currently contain much code that is x86(_64) specific.
Move them to the architecture specific directory. This also allows for a
simpler implementation for aarch64.
2022-06-02 13:14:12 +01:00
Timon Kruiper 63ee2781fb Kernel: Put Raspberry Pi devices into RPi namespace
This makes it clear in the code that these drivers are specific for the
Raspberry Pi devices.
2022-06-02 13:14:12 +01:00
Timon Kruiper 77f24056e0 Kernel: Disable interrupts when halting the aarch64 processor
This will actually halt the processor.
2022-06-02 13:14:12 +01:00
Timon Kruiper 846d9ae858 Kernel: Do not specify new alignment for aarch64
Using the alignment of 4 causes a panic in the aarch64 Kernel. Instead
just don't pass the flag, which will use the default alignment.
2022-06-02 13:14:12 +01:00
Timon Kruiper cbe1717181 Kernel: Rename idt_init() to initialize_interrupts()
Also move the function out of the x86/Interrupts.h file into the generic
Interrupts.h file and add a stub for aarch64.
2022-06-02 13:14:12 +01:00
Timon Kruiper 02b94c6f0e Kernel: Add UnhandledInterruptHandler and SharedIRQHandler to aarch64 2022-06-02 13:14:12 +01:00
Timon Kruiper d631a3daf6 Kernel: Add Interrupts/IRQHandler.cpp to the aarch64 build
This requires a few stubs such that the compiler won't complain.
2022-06-02 13:14:12 +01:00
Timon Kruiper a4534678f9 Kernel: Implement InterruptDisabler using generic Processor functions
Now that the code does not use architectural specific code, it is moved
to the generic Arch directory and the paths are modified accordingly.
2022-06-02 13:14:12 +01:00
Timon Kruiper ea9cf8b6ab Kernel: Separate NonMaskableInterruptDisabler into its own file
This is for the upcoming change to make InterruptDisabler class work for
the aarch64 build.
2022-06-02 13:14:12 +01:00
Timon Kruiper 9413fe9fe5 Kernel: Add interrupt related functions to Processor class
This adds {enable, disable}_interrupts() and are_interrupts_enabled()
to the Processor class, and also implements them for x86(_64) and
aarch64.
2022-06-02 13:14:12 +01:00
Timon Kruiper 80be5f8044 Kernel: Add DAIF system register to aarch64 registers
This register can be used to check whether the 4 different types of
interrupts are masked. A different variant can be used to set/clear
specific interrupt bits.
2022-06-02 13:14:12 +01:00
Timon Kruiper 2fd5e9f729 Kernel: Add GenericInterruptHandler.cpp to aarch64 build
This requires us to add an Interrupts.h file in the Kernel/Arch
directory, which includes the architecture specific files.

The commit also stubs out the functions to be able to compile the
aarch64 Kernel.
2022-06-02 13:14:12 +01:00
Jesse Buhagiar a1ed9d3c60 Kernel/USB: Rename get_interfaces to something more sensible
This name was misleading, as it wasn't really "getting" anything. It has
hence been renamed to `enumerate_interfaces` to reflect what it's
actually doing.
2022-06-02 13:14:29 +02:00
Jesse Buhagiar 29f891bb54 Kernel/USB: Flesh out USB SysFS objects
Each USB object now contains the entire descriptor chain for the device
instead of just info from the device descriptor.
2022-06-02 13:14:29 +02:00
Jesse Buhagiar ed657e3d2b Kernel/USB: Add interface descriptor accessor 2022-06-02 13:14:29 +02:00
Jesse Buhagiar 9002e837d3 Kernel/USB: Add configuration descriptor accessor 2022-06-02 13:14:29 +02:00
Jesse Buhagiar cd8939f4a0 Kernel/USB: Make USBInterface endpoints accessible
These weren't accessible by an accessor, so let's fix that :^)
2022-06-02 13:14:29 +02:00
Jesse Buhagiar 361737650f Kernel/USB: Make USBConfiguration interfaces accessible
These weren't accessible by an accessor, so let's fix that :^)
2022-06-02 13:14:29 +02:00
brapru 1dd22582da Kernel: Ignore interfaces without an IP address when updating ARP
For the same reason we ignore interfaces without an IP address when
choosing where to send a route, we should also ignore interfaces without
IP addresses when updating the ARP table on incoming packets from
local addresses.

On an interface with a null address, the mask checking would always
result in zero, which resulted in the system updating the ARP table on
almost every incoming packet from any address (private or public).

This patch fixes this behavior by only applying this check to interfaces
with valid addresses and now the ARP table won't get constantly
hammered.

Closes #13713
2022-05-31 10:22:46 +01:00
SeekingBlues df8df947f6 Kernel: Do not include AK/Platform.h in mcontext headers
Including signal.h would cause several ports to fail on build,
because it would end up including AK/Platform.h through these
mcontext headers. This is problematic because AK/Platform.h defines
several macros with very common names, such as `NAKED` (breaks radare2),
and `NO_SANITIZE_ADDRESS` and `ALWAYS_INLINE` (breaks ruby).
2022-05-30 21:39:41 +02:00
Lucas CHOLLET a506ec08d8 Kernel: Expose cache size for Intel CPUs
The patch also prevents any try if the CPU's vendor isn't known and
improves the const-correctness of the AMD version.
2022-05-30 13:41:23 +01:00
Liav A 58acdce41f Kernel/FileSystem: Simplify even more the mount syscall
As with the previous commit, we put a distinction between filesystems
that require a file description and those which don't, but now in a much
more readable mechanism - all initialization properties as well as the
create static method are grouped to create the FileSystemInitializer
structure. Then when we need to initialize an instance, we iterate over
a table of these structures, checking for matching structure and then
validating the given arguments from userspace against the requirements
to ensure we can create a valid instance of the requested filesystem.
2022-05-29 19:31:02 +01:00
Liav A 4c588441e3 Kernel: Simplify mount syscall flow for regular calls
We do this by putting a distinction between two types of filesystems -
the first type is backed in RAM, and includes TmpFS, ProcFS, SysFS,
DevPtsFS and DevTmpFS. Because these filesystems are backed in RAM,
trying to mount them doesn't require source open file description.
The second type is filesystems that are backed by a file, therefore the
userspace program has to open them (hence it has a open file description
on them) and provide the appropriate source open file description.
By putting this distinction, we can early check if the user tried to
mount the second type of filesystems without a valid file description,
and fail with EBADF then.
Otherwise, we can proceed to either mount either type of filesystem,
provided that the fs_type is valid.
2022-05-29 19:31:02 +01:00
Linus Groh 20e2e39fcc Kernel: Expose size of L1 data/instruction, L2, and L3 CPU caches :^)
These are added as properties of the "caches" object to each processor,
if available.
2022-05-29 15:23:57 +02:00
brapru 7a4e41f8f8 Kernel: Add support for route flags
Previously the routing table did not store the route flags. This
adds basic support and exposes them in the /proc directory so that a
userspace caller can query the route and identify the type of each
route.
2022-05-26 16:33:10 +02:00
Peter Elliott f6943c85b0 Kernel: Fix EINVAL when mmaping with address and no MAP_FIXED
The current behavior accidently trys to allocate 0 bytes when a non-null
address is provided and MAP_FIXED is specified. This is clearly a bug.
2022-05-23 00:13:26 +02:00
Peter Elliott 1c86678a64 Kernel: Change values of SHUT_{RD,WR,RDWR}
For some reason, guile requires these to be specific values.
2022-05-23 00:13:26 +02:00
b14ckcat 8a7876d65c Kernel/USB: Add support for bulk transfers 2022-05-21 22:12:05 +02:00
Timon Kruiper 5fc66c6072 Kernel: Fix capitalization of MiniStdLib.cpp in CMakeLists.txt
Commit fd3e3d5e28 added this, however
misspelled MiniStdLib.cpp. CMake wasn't complaining about this, but the
flags were also not applied to the file.
2022-05-21 20:23:32 +01:00
Timon Kruiper 9f3303c869 Kernel: Add -mgeneral-regs-only flag to aarch64 Kernel build
With the update to GCC 12.1.0, the compiler now vectorizes code with
-O2. This causes vector ops to be emitted, which are not supported in
the Kernel. Add the -mgeneral-regs-only flag to force the compiler to
not emit floating-point and SIMD ops.
2022-05-21 20:23:32 +01:00
Timon Kruiper cc7723b6c4 Meta: Add option to disable Kernel Address Sanitizer
By default we enable the Kernel Undefined Behavior Sanitizer, which
checks for undefined behavior at runtime. However, sometimes a developer
might want to turn that off, so now there is a easy way to do that.
2022-05-21 20:23:32 +01:00
Timon Kruiper 1461a7601d Kernel: Report value of ESR_EL1 when exception happens on aarch64 2022-05-21 20:23:32 +01:00
Timon Kruiper 2c05afaa7b Kernel: Add Exception Syndrome Register to aarch64 Registers.h
This allows us to print more information about what kind of exception
happend.
2022-05-21 20:23:32 +01:00
Timon Kruiper e43fdcc77e Kernel: Add more exception handlers for aarch64 Kernel
The aarch64 Kernel runs with SP_EL0, thus exceptions that happen can now
be handled.
2022-05-21 20:23:32 +01:00
Timon Kruiper 06432719fd Kernel: Set up initial exception stack when going into EL1 on aarch64
When an exception is triggered on aarch64, the processor always switches
to the exception stack which is defined by the SP_EL1 register.
2022-05-21 20:23:32 +01:00
Timon Kruiper 9f730fab8d Kernel: Add alignment specifier to aarch64 register definitions
When disabling UBSAN, the compiler would complain that the constraints
of the inline assembly could not be met. By adding the alignas specifier
the compiler can now determine that the struct can be passed into a
register, and thus the constraints are met.
2022-05-21 20:23:32 +01:00
Ariel Don 8a854ba309 Kernel+LibC: Implement futimens(3)
Implement futimes() in terms of utimensat(). Now, utimensat() strays
from POSIX compliance because it also accepts a combination of a file
descriptor of a regular file and an empty path. utimensat() then uses
this file descriptor instead of the path to update the last access
and/or modification time of a file. That being said, its prior behavior
remains intact.

With the new behavior of utimensat(), `path` must point to a valid
string; given a null pointer instead of an empty string, utimensat()
sets `errno` to `EFAULT` and returns a failure.
2022-05-21 18:15:00 +02:00
Ariel Don 9a6bd85924 Kernel+LibC+VFS: Implement utimensat(3)
Create POSIX utimensat() library call and corresponding system call to
update file access and modification times.
2022-05-21 18:15:00 +02:00
Jesse Buhagiar 964f8fbf3a Kernel: Implement AVX XSAVE support
This adds some new buffers to the `FPUState` struct, which contains
enough space for the `xsave` instruction to run. This instruction writes
the upper part of the x86 SIMD registers (YMM0-15) to a seperate
256-byte area, as well as an "xsave header" describing the region.

If the underlying processor supports AVX, the `fxsave` instruction is no
longer used, as `xsave` itself implictly saves all of the SSE and x87
registers.

Co-authored-by: Leon Albrecht <leon.a@serenityos.org>
2022-05-15 12:25:23 +02:00
Timon Kruiper 18cad73b01 Kernel: Put code in the aarch64 init.cpp file into the Kernel namespace 2022-05-12 23:14:05 +02:00
Timon Kruiper 9282e0db16 Kernel: Move __assertion_failed to aarch64/Panic.cpp
This is for an upcoming change to add the Kernel namespace to the
init.cpp file.
2022-05-12 23:14:05 +02:00
Timon Kruiper d451bdec6f Kernel: Remove PREKERNEL_SOURCES from aarch64 CMakeLists.txt 2022-05-12 23:14:05 +02:00
Timon Kruiper 4db44c09a4 Kernel: Use the Kernel UBSanitizer implementation in the aarch64 Kernel
Now we actually print useful information when an UBSAN fault is
detected. :^)
2022-05-12 23:14:05 +02:00
Timon Kruiper 1f3977b303 Kernel: Remove Prekernel namespace in the aarch64 Kernel
Now that we merged all the Prekernel files into the Kernel files, we can
get rid of the Prekernel namespace as well.
2022-05-12 23:14:05 +02:00
Timon Kruiper c96a3f0c48 Kernel: Move the aarch64 boot.S out of the Prekernel directory 2022-05-12 23:14:05 +02:00
Timon Kruiper e88cd338f1 Kernel: Move Prekernel{CPU, Exceptions}.cpp out of Prekernel directory
This lets us delete the Prekernel.h file, and gets us closer to deleting
the Prekernel from the aarch64 Kernel.
2022-05-12 23:14:05 +02:00
Timon Kruiper e7c5fd978b Kernel: Move Prekernel assembly utils to aarch64/ASM_wrapper.h
By moving these functions to the ASM_wrapper.h file, we can get rid of
another Prekernel file.
2022-05-12 23:14:05 +02:00
Timon Kruiper e80d8d697c Kernel: Replace Prekernel::halt with Processor::halt in aarch64 build
This allows us to get rid of one more Prekernel file.
2022-05-12 23:14:05 +02:00
Daniel Bertalan fd3e3d5e28 LibC+Kernel: Prevent string functions from calling themselves
Most of the string.h and wchar.h functions are implemented quite naively
at the moment, and GCC's pattern recognition pass might realize what we
are trying to do, and transform them into libcalls. This is usually a
useful optimization, but not when we're implementing the functions
themselves :^)

Relevant discussion from the GCC Bugzilla:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102725

This prevents the infamous recursive `strlen`.

A more proper fix would be writing these functions in assembly. That
would likely give a small performance boost as well ;)
2022-05-12 13:12:37 +02:00
Daniel Bertalan f157ad8a35 Kernel: Do not implement VERIFY_NOT_REACHED() as VERIFY(false)
If a switch case ends in VERIFY_NOT_REACHED(), gcc 12 thinks it might
fall through.
2022-05-12 13:12:37 +02:00
Timon Kruiper b8854549f2 Kernel: Sort aarch64 CMake sources alphabetically 2022-05-09 21:12:56 +02:00
Timon Kruiper c515e1341a Kernel: Add initial implementation of Processor in aarch64
Instead of storing the current Processor into a core local register, we
currently just store it into a global, since we don't support SMP for
aarch64 anyway. This simplifies the initial implementation.
2022-05-09 21:12:56 +02:00
Timon Kruiper ed4bfaed12 Kernel: Call the constructors in the aarch64 init function
Now that we have separated the kmalloc.cpp constructors into a separate
library, we can actually call the constructors in the init function.
2022-05-09 21:12:56 +02:00
Timon Kruiper 2e49d6b001 Kernel: Separate kmalloc.cpp into a separate library similar to x86_64
This will allow the call the constructors of the kmalloc.cpp file
before calling the other constructors in the Kernel.
2022-05-09 21:12:56 +02:00
Timon Kruiper d449fef606 Kernel: Reorder sections in aarch64 linker script to save space
By putting the NOLOAD sections (.bss and .super_pages) at the end of the
ELF file, objcopy does not have to insert a lot of zeros to make sure
that the .ksyms section is at the right place in memory. Now the .ksyms
section comes before the two NOLOAD sections. This shrinks the
kernel8.img with 6MB, from 8.3M to 2.3M. :^)
2022-05-09 21:12:56 +02:00
Timon Kruiper a1b352fdc0 Kernel: Add some mission sections to the aarch64 linker script
The sections did end up in the ELF file, however they weren't
explicitely mentioned in the linker.ld script. In the future, we can add
the --orphan-handling=error flag to the linker options, which will
enforce that the sections used in the sources files also are mentioned
in the linker script.
2022-05-09 21:12:56 +02:00
Liav A 9bec9c2b78 Kernel: Force y offset 0 when switching between console & graphics modes
This fixes a weird bug that when sometimes a user tried to switch to
console mode, the screen was frozen on graphics mode. After a hour of
debugging this, it became apparent that the problem was that we left the
y offset of the bochs graphics device in an invalid state, so it was not
zero because the WindowServer changed it, and the framebuffer console
code is not aware of horizontal and vertical offsets of the framebuffer
screen, leading to the problem that the framebuffer console updates the
first framebuffer (y offset = 0), but hardware was indicated to show the
second framebuffer (y offset = first framebuffer height).

Therefore, when doing a switch between these modes, always set the y
offset to be zero.
2022-05-06 18:05:14 +02:00
Liav A cd08c4a5aa Kernel/HID: Take a spinlock when calling KeyboardClient::on_key_pressed
The KeyboardClient class member could be updated due to TTY switch, so
we must ensure we always use a valid pointer.
2022-05-06 18:05:14 +02:00
Liav A b8493bf70f Kernel/Graphics: Protect the list of display connectors with a Spinlock
This list could be updated in runtime if an hotplug event occurs, so we
must protect it with a spin lock to avoid corruption of the list.
2022-05-06 18:05:14 +02:00
Liav A 340773ddb7 Kernel/Graphics: Implement basic support for VMWare SVGA adapter 2022-05-06 18:04:57 +02:00
Liav A a0a1ac0656 Kernel/Graphics: Use boot console if the subsystem is disabled
This lets us actually to initialize VirtualConsoles later on.
2022-05-06 12:28:19 +02:00
Liav A 0d784de3a6 Kernel/Graphics: Implement basic cursor for FramebufferConsole 2022-05-06 12:28:02 +02:00
MacDue d951e2ca97 Kernel: Add /proc/{pid}/children to ProcFS
This exposes the child processes for a process as a directory
of symlinks to the respective /proc entries for each child.

This makes for an easier and possibly more efficient way
to find and count a process's children. Previously the only
method was to parse the entire /proc/all JSON file.
2022-05-06 02:12:51 +04:30
MacDue 222079cd80 Kernel: Expose .length() of KBufferBuilder 2022-05-06 02:12:51 +04:30
Liav A 969e5fa163 Kernel/Console: Use 8x16 character font bitmap instead of old 8x8 bitmap
This in turn makes the built-in kernel console much more nicer to look
into, so let's remove the support for 8x8 bitmap and instead add 8x16
font bitmap.
2022-05-05 21:51:57 +02:00
Liav A b96b2fb9be Kernel/Graphics: Simplify the GenericGraphicsAdapter class
The old methods are already can be considered deprecated, and now after
we removed framebuffer devices entirely, we can safely remove these
methods too, which simplfies the GenericGraphicsAdapter class a lot.
2022-05-05 20:55:57 +02:00
Liav A d49a35df31 Kernel/Graphics: Simplify the feature level of the Graphics subsystem
Instead of letting the user to determine whether framebuffer devices
will be created (which is useless because they are gone by now), let's
simplify the flow by allowing the user to choose between full, limited
or disabled functionality. The determination happens only once, so, if
the user decided to disable graphics support, the initialize method
exits immediately. If limited functionality is chosen, then a generic
DisplayConnector is initialized with the preset framebuffer resolution,
if present, and then the initialize method exits. As a default, the code
proceeds to initialize all drivers as usual.
2022-05-05 20:55:57 +02:00
Liav A e301af8352 Everywhere: Purge all support and usage of framebuffer devices
Long live the DisplayConnector object!
2022-05-05 20:55:57 +02:00
Liav A aad968cc5e Everywhere: Rename fb prefix function names => graphics_connector 2022-05-05 20:55:57 +02:00
Liav A 10adc27eda Everywhere: Rename FB prefix structure names => Graphics 2022-05-05 20:55:57 +02:00
Liav A d2e93ec50a Everywhere: Rename FB prefix name ioctls => GRAPHICS 2022-05-05 20:55:57 +02:00
Liav A f15b93c9a1 Kernel/Graphics: Use DisplayConnector design with generic framebuffers 2022-05-05 20:55:57 +02:00
Liav A c27c414ed1 Kernel/Graphics: Apply DisplayConnector design on the VirtIO driver 2022-05-05 20:55:57 +02:00
Liav A 4ff6150f1b WindowServer: Use FB_IOCTL_FLUSH_HEAD to flush a framebuffer if possible
This ioctl is more appropriate when the hardware supports flushing of
the entire framebuffer, so we use that instead of the previous default
FB_IOCTL_FLUSH_HEAD_BUFFERS ioctl.
2022-05-05 20:55:57 +02:00
Liav A 41283a2de6 Kernel/Graphics: Use VirtIO GPU3DDevice constructor indirectly
We shouldn't expose the VirtIO GPU3DDevice constructor as public method,
so instead, let's use the usual pattern of a static construction method
that uses the constructor within the method.
2022-05-05 20:55:57 +02:00
Liav A 728358c599 Kernel/Graphics: Migrate Intel driver to use the DisplayConnector design 2022-05-05 20:55:57 +02:00
Liav A e9a74cbefb Kernel/Graphics: Use DisplayConnector design for the Bochs driver 2022-05-05 20:55:57 +02:00
Liav A 6d7e2596e0 WindowServer: Implement mechanism to restore safe mode setting
Such mechanism will be used by the Intel Graphics driver, because we
lack support of changing the resolution on this driver currently, so,
when WindowServer will try to mode-set the display then it will fail,
and will use the safe mode-setting call instead to be able to show
something on screen.
2022-05-05 20:55:57 +02:00
Liav A d9a2706079 DisplaySettings+WindowServer: Add support for display connector devices 2022-05-05 20:55:57 +02:00
Liav A e6ebf9e5c1 Kernel/Memory: Add TypedMapping base_address method
This method will be used to ease usage with the structure when we need
to do virtual pointer arithmetics.
2022-05-05 20:55:57 +02:00
Liav A 9f0b5b04ff Kernel/Graphics: Export Bochs definitions to a header file
These definitions will be used later when applying the DisplayConnector
design on the Bochs driver.
2022-05-05 20:55:57 +02:00
Liav A 912b8ab965 Kernel/Graphics: Introduce the DisplayConnector class
The DisplayConnector class is meant to replace the FramebufferDevice
class. The advantage of this class over the FramebufferDevice class is:
1. It removes the mmap interface entirely. This interface is unsafe, as
multiple processes could try to use it, and when switching to and from
text console mode, there's no "good" way to revoke a memory mapping from
this interface, let alone when there are multiple processes that call
this interface. Therefore, in the DisplayConnector class there's no
implementation for this method at all.
2. The class uses a new real-world structure called ModeSetting, which
takes into account the fact that real hardware requires more than width,
height and pitch settings to mode-set the display resolution.
3. The class assumes all instances should supply some sort of EDID,
so it facilitates such mechanism to do so. Even if a given driver does
not know what is the actual EDID, it will ask to create default-generic
EDID blob.
3. This class shifts the responsibilies of switching between console
mode and graphical mode from a GraphicsAdapter to the DisplayConnector
class, so when doing the switch, the GraphicsManagement code actually
asks each DisplayConnector object to do the switch and doesn't rely on
the GraphicsAdapter objects at all.
2022-05-05 20:55:57 +02:00
Liav A ebf7225728 Kernel/Graphics: Declare BochsGraphicsAdapter::get_edid private method 2022-05-05 20:55:57 +02:00
Tim Schumacher 0ce43fae9c Kernel: Add IPv4 network class masks 2022-05-05 20:47:38 +02:00
Tim Schumacher 7dd4648565 Kernel: Add IPsec ESP and AH protocol numbers 2022-05-05 20:47:38 +02:00
Tim Schumacher 098af0f846 Kernel: Properly define IOV_MAX 2022-05-05 20:47:38 +02:00
Tim Schumacher 6d59d4d3d9 Kernel: Add the remaining POSIX MADV_* constants 2022-05-05 20:47:38 +02:00
Tim Schumacher 94ab75d3df Kernel: Add O_SYNC into fcntl.h 2022-05-05 20:47:38 +02:00
Timon Kruiper 2cf36a1ca2 Kernel: Panic when an assertion is failed in aarch64 Kernel
This in turn makes sure that we get a nice backtrace when an assertion
failed, or when a VERIFY_NOT_REACHED() is hit.
2022-05-03 21:53:36 +02:00
Timon Kruiper 771d0719ea Kernel: Remove unused aarch64 Prekernel::panic() function 2022-05-03 21:53:36 +02:00
Timon Kruiper f8e4eecbfb Kernel: Replace calls to Prekernel::panic() with PANIC macro on aarch64 2022-05-03 21:53:36 +02:00