Commit Graph

6043 Commits

Author SHA1 Message Date
Idan Horowitz
2882a90dec Kernel: Add the IFF_* SIOCGIFFLAGS flag macros 2021-10-28 11:24:36 +02:00
Idan Horowitz
adc9939a7b Kernel+LibC: Add support for the IPv4 TOS field via the IP_TOS sockopt 2021-10-28 11:24:36 +02:00
Idan Horowitz
20c7fcfedf Kernel: Fix accidental memory over-read in getsockopt(IP_TTL)
We were accidentally casting the pointer to m_ttl from an u8* to an int*
which resulted in copying of 3 extra unrelated bytes (which turned out
to be padding in this case).
2021-10-28 11:24:36 +02:00
Idan Horowitz
c45b1e1983 LibC: Add IPPROTO_ICMPV6 macro 2021-10-28 11:24:36 +02:00
Filiph Sandström
c6247fe414 Everywhere: Rename back-click to backward-click
This matches the current forward-click terminology.
2021-10-27 22:05:58 +03:00
Liav A
8554952690 Kernel + WindowServer: Re-define the interface to framebuffer devices
We create a base class called GenericFramebufferDevice, which defines
all the virtual functions that must be implemented by a
FramebufferDevice. Then, we make the VirtIO FramebufferDevice and other
FramebufferDevice implementations inherit from it.
The most important consequence of rearranging the classes is that we now
have one IOCTL method, so all drivers should be committed to not
override the IOCTL method or make their own IOCTLs of FramebufferDevice.
All graphical IOCTLs are known to all FramebufferDevices, and it's up to
the specific implementation whether to support them or discard them (so
we require extensive usage of KResult and KResultOr, together with
virtual characteristic functions).
As a result, the interface is much cleaner and understandable to read.
2021-10-27 07:57:44 +03:00
Liav A
78e724a899 Kernel/Graphics: Rename GraphicsDevice => GenericGraphicsAdapter
We already use the term adapter for instances of this class, so let's
better represent this class by changing its name to what it really is.
2021-10-27 07:57:44 +03:00
Liav A
c7eb761b7f Kernel/Graphics: Re-order parameters in VirtIO GraphicsAdapter methods
As suggested by @ccapitalK, it makes the interface more neat and clean.
The proper order is to get ScanoutID first, then ResourceID and after it
everything else that is needed to complete the operation successfully.
2021-10-27 07:57:44 +03:00
Liav A
f476b49fd8 Kernel/Graphics: Merge VirtIO GraphicsAdapter and VirtIO GPU code
A VirtIO graphics adapter is really the VirtIO GPU, so the virtualized
hardware has no distinction between both components so there's no
need to put such distinction in software.

We might need to split things in the future, but when we do so, we must
take proper care to ensure that the interface between the components
is correct and use the usual codebase patterns.
2021-10-27 07:57:44 +03:00
Liav A
a9538b5879 Kernel/Graphics: Convert type method => bool vga compatible method
We never used that type method except in initialization in
GraphicsManagement, and we used it there to query whether the device is
VGA compatible or not.
2021-10-27 07:57:44 +03:00
Liav A
fb0ed2ae46 Kernel/Graphics: Force VirtIO Framebuffer to inherit FramebufferDevice
The distinction is not justified because a VirtIO Framebuffer device
acts much more like a regular FramebufferDevice than a pure BlockDevice.
2021-10-27 07:57:44 +03:00
Liav A
4815282a5f Kernel/Graphics: Rename VirtIO FrameBufferDevice => FramebufferDevice 2021-10-27 07:57:44 +03:00
Andreas Kling
e0f0b6379a Kernel: Make WorkQueue::WorkItem slab allocated 2021-10-26 10:50:44 +02:00
Andreas Kling
44b273f3ac Kernel: Use SpinlockProtected<T> in WorkQueue 2021-10-26 10:44:10 +02:00
Andreas Kling
b443e9e1a9 Kernel: Use a larger kmalloc chunk size on 64-bit platforms
This reduces test-js runtime by over 40% on my machine.

(And once again we find another way to defer writing a better kernel
heap allocator..)
2021-10-26 10:38:35 +02:00
Andreas Kling
25250590d0 Kernel: Take VMObject lock once in Region::remap_vmobject_page()
We were taking and releasing the lock repeatedly instead of holding it
across the entire remap operation.
2021-10-26 09:03:41 +02:00
Andreas Kling
0592f80186 Kernel: Add TimeManagement::is_initialized()
This allows clients to check whether TimeManagement is available before
trying to ask it about time related things.
2021-10-26 01:00:54 +02:00
Ben Wiederhake
bf88adbcb6 Kernel: Avoid allocation when checking for vmmouse 2021-10-25 23:38:28 +02:00
Ben Wiederhake
8d13f6ddce Kernel+SystemServer: Change bootmode to system_mode
'bootmode' now only controls which set of services are started by
SystemServer, so it is more appropriate to rename it to system_mode, and
no longer validate it in the Kernel.
2021-10-25 23:38:28 +02:00
Ben Wiederhake
09432a8241 Kernel: Separate panic behavior from bootmode
Bootmode used to control panic behavior and SystemServer.
This patch factors panic behavior control into a separate flag.
2021-10-25 23:38:28 +02:00
Ben Wiederhake
542a88a7be Kernel: Separate framebuffers from bootmode
Bootmode used to control framebuffers, panic behavior, and SystemServer.
This patch factors framebuffer control into a separate flag.
Note that the combination 'bootmode=self-test fbdev=on' leads to
unexpected behavior, which can only be fixed in a later commit.
2021-10-25 23:38:28 +02:00
Daniel Bertalan
5f6030b13c Kernel+LibC: Default to 8-bit characters in TTY
Some ports (like `bc` with history enabled) sensibly set the termios
character size to 8 bits.

Previously, we left the character size value (given by the bitmask
CSIZE) as zero by default (meaning 5 bits per character), and returned
ENOTIMPL whenever someone modified it. This was dumb.
2021-10-25 21:42:26 +02:00
Jelle Raaijmakers
4131b35851 Kernel: Prevent VMWareMouseDevice from handling invalid mouse packets
Bit 3 is set here:
c5b2f55981/hw/input/ps2.c (L736)

Spurious mouse packets can be received without this bit set, for
example when double-clicking and keeping the mouse button depressed
instead of releasing it the second time (i.e. mousedown > mouseup >
mousedown). We should not process such packets.

This makes interaction with our buttons much smoother!

Fixes #5881.
2021-10-24 21:59:08 +02:00
Jelle Raaijmakers
8b3232121b Kernel: Do not detect mouse or keyboard when handling IRQ for I8042
Instead of detecting which flag was set in the status register, we can
use the instrument type passed to us. This works because the mouse and
keyboard use different IRQs.
2021-10-24 21:59:08 +02:00
Jelle Raaijmakers
26c84967fa Kernel: Enumify all magic constants for I8042 devices
This makes the code much easier to read.
2021-10-24 21:59:08 +02:00
Daniel Bertalan
db71c36657 Kernel: Properly align stack for signal handlers
The System V ABI requires that the stack is 16-byte aligned on function
call. Confusingly, however, they mean that the stack must be aligned
this way **before** the `CALL` instruction is executed. That instruction
pushes the return value onto the stack, so the callee will actually see
the stack pointer as a value `sizeof(FlatPtr)` smaller.

The signal trampoline was written with this in mind, but `setup_stack`
aligned the entire stack, *including the return address* to a 16-byte
boundary. Because of this, the trampoline subtracted too much from the
stack pointer, thus misaligning it.

This was not a problem on i686 because we didn't execute any
instructions from signal handlers that would require memory operands to
be aligned to more than 4 bytes. This is not the case, however, on
x86_64, where SSE instructions are enabled by default and they require
16-byte aligned operands. Running such instructions raised a GP fault,
immediately killing the offending program with a SIGSEGV signal.

This issue caused TestKernelAlarm to fail in LibC when ran locally, and
at one point, the zsh port was affected too.

Fixes #9291
2021-10-24 21:54:51 +02:00
Liav A
8e55c4bfaf Kernel/PCI: Remove InterruptDisabler usage
Instead, just ensure we pick the m_access_lock and then m_scan_lock when
doing a scan/re-scan of the PCI configuration space so we know nobody
can actually access the PCI configuration space during the scan.

The m_scan_lock is now a Spinlock, to ensure we cannot yield to other
process while we do the PCI configuration space scanning.
2021-10-23 19:17:44 +02:00
Liav A
72e831e9e9 Kernel/PCI: Ensure m_domains is not empty if scanning with memory access 2021-10-23 19:17:44 +02:00
Liav A
40b1e6376b Kernel/PCI: Split Access::rescan_hardware method
To ensure clarity, this method is essentially splitted to two methods to
be called according to the access type being determined beforehand.
2021-10-23 19:17:44 +02:00
Liav A
d395ac8f59 Kernel/PCI: Rename Access::scan_pci_domains method
We rename it to scan_pci_domains_from_acpi_mcfg_table to ensure clarity,
because this method relies on the ACPI MCFG table to work.
2021-10-23 19:17:44 +02:00
Liav A
ca32ee5714 Kernel/PCI: Simplify detect_optimal_access_type function
Instead of getting the kernel commandline argument as function parameter
we just take internally in the function.
2021-10-23 19:17:44 +02:00
Liav A
026687816d Kernel: Fix restrictions in is_allowed_to_mmap_to_userspace function
This small change simplifies the function a bit but also fixes a problem
with it.
Let's take an example to see this:
Let's say we have a reserved range between 0xe0000 to 0xfffff (EBDA),
then we want to map from the memory device (/dev/mem) the entire
EBDA to a program. If a program tries to map more than 131072 bytes,
the current logic will work - the start address is 0xe0000, and ofcourse
it's below the limit, hence it passes the first two restrictions.
Then, the third if statement will fail if we try to mmap more than
the said allowed bytes.
However, let's take another scenario, where we try to mmap from
0xf0000 - but we try to mmap less than 131072 - but more than 65536.
In such case, we again pass the first two if statements, but the third
one is passed two, because it doesn't take into account the offseted
address from the start of the reserved range (0xe0000). In such case,
a user can easily mmap 65535 bytes above 0x100000. This might
seem negligible. However, it's still a severe bug that can theoretically
be exploited into a info leak or tampering with important kernel
structures.
2021-10-22 13:13:00 +02:00
Andreas Kling
4ffee78146 Kernel: Make FrameBufferDevice::try_to_set_resolution() return KResult 2021-10-22 01:21:34 +02:00
Andreas Kling
21bfa02dd2 Kernel: Remove unused InodeIdentifier::to_string() 2021-10-22 01:19:04 +02:00
Andreas Kling
fe98cb2c4b Kernel: Make Ext2FS::free_inode() return KResult, and use TRY() more
While there's no clear propagation path for errors that happen in an
inode destructor, using TRY() still makes the code a lot nicer.
2021-10-21 23:23:23 +02:00
Andreas Kling
98b865fe10 Kernel: Make Ext2FS::write_ext2_inode() return KResult
This allows us to use TRY() in more places.
2021-10-21 23:23:23 +02:00
Andreas Kling
6f69d5204f Kernel: Make Inode::flush_metadata() return a KResult
Even if this goes nowhere yet, we have to start building an error
propagation path somewhere.
2021-10-21 23:23:23 +02:00
Daniel Bertalan
17b66eaa3c Kernel: Call try_set_coredump_property with StringView arguments
Storing assigning a string literal to a String object just to pass it to
a function expecting a StringView is wasteful. Let's just not do that.

For consistency's sake, this commit changes all of the other invocations
to use StringView literals, too.
2021-10-21 22:19:50 +02:00
Daniel Bertalan
bbb4eb0aa1 Kernel: Convert Formatter<Process> to use Formatter<FormatString>
This lets us avoid allocating memory on the heap most of the time, as
Formatter<FormatString> writes into a quite large stack buffer instead.
2021-10-21 22:19:50 +02:00
Daniel Bertalan
018c4e0e7e AK+Kernel: Format DistinctNumeric using the underlying type's formatter
Forcing the formatting to go through `Formatter<FormatString>` is
completely unnecessary, increases code size, performs a String
allocation and prevents us from using the formatting options available
on that type.

This commit also removes explicit formatters from
`BlockBasedFileSystem::BlockIndex` and `Kernel::InodeIndex`, as those
are already covered by the blanket implementation for all
`DistinctNumeric` types.
2021-10-21 22:19:50 +02:00
Liav A
64aaf263a2 Kernel/Net: Generate interface name near construction point
This change allows the Kernel to actually construct other interfaces
besides the E1000 type.
This solves a breakage that was introduced recently because of move
semantics.

A couple of points on this patch:
1. In current situation, we can waste time to create a KString and throw
it for nothing. This patch ensures we only create it near construction
point so we know we actually need it.
2. It's very likely to assume that non-x86 machines will expose network
device with a device tree (or with ACPI). The raspberry pi machine is a
good example of that. Therefore, each driver should explicitly ask the
correct interface name generation method, and this patch simplifies this
pattern greatly, especially in a case where the same network device can
appear as a PCI device or as device in another bus type on the same
platform target. For example, the (in)famous ne2000 device can be used
either as a PCI device or as an ISA device, depending on the model.
3. In my opinion, it seems much more readable to construct the name near
calling point of the object constructor than to just pass it with move
semantics.
2021-10-18 12:25:56 -07:00
Daniel Bertalan
10c3cf9a47 Kernel: Enable LTO for kernel_heap if ENABLE_KERNEL_LTO is set
By enabling LTO for the kernel_heap object too, we open the door for
optimization opportunities that come from (partially) inlining `::new`
or kmalloc. Every software spends a non-trivial amount of its run time
on allocating memory, so hopefully this change will make LTO builds even
faster.
2021-10-17 17:09:58 +01:00
Daniel Bertalan
06fc64be13 Toolchain+Meta: Update LLVM version to 13.0.0
This commit updates the Clang toolchain's version to 13.0.0, which comes
with better C++20 support and improved handling of new features by
clang-format. Due to the newly enabled `-Bsymbolic-functions` flag, our
Clang binaries will only be 2-4% slower than if we dynamically linked
them, but we save hundreds of megabytes of disk space.

The `BuildClang.sh` script has been reworked to build the entire
toolchain in just three steps: one for the compiler, one for GNU
binutils, and one for the runtime libraries. This reduces the complexity
of the build script, and will allow us to modify the CI configuration to
only rebuild the libraries when our libc headers change.

Most of the compile flags have been moved out to a separate CMake cache
file, similarly to how the Android and Fuchsia toolchains are
implemented within the LLVM repo. This provides a nicer interface than
the heaps of command-line arguments.

We no longer build separate toolchains for each architecture, as the
same Clang binary can compile code for multiple targets.

The horrible mess that `SERENITY_CLANG_ARCH` was, has been removed in
this commit. Clang happily accepts an `i686-pc-serenity` target triple,
which matches what our GCC toolchain accepts.
2021-10-17 17:09:58 +01:00
Daniel Bertalan
28c088cd91 Kernel: Support split data sections
This feature is used by Clang when performing LTO. With this change,
these split sections now go in the right place.
2021-10-17 17:09:58 +01:00
Daniel Bertalan
a8fefd89cd Everywhere: Make some symbols __attribute__((used)) for LTO
With these changes, the userland builds correctly with Clang's ThinLTO
enabled.
2021-10-17 17:09:58 +01:00
Daniel Bertalan
1faffc2192 Kernel: Introduce workaround to make LTO builds work with Clang
LLD fails to define the _GLOBAL_OFFSET_TABLE_ symbol if all inputs to it
are LLVM bitcode files (i.e. those used for LTO). To allow the kernel to
be built with ThinLTO, the workaround suggested in the original LLVM bug
report (<https://bugs.llvm.org/show_bug.cgi?id=39634>) is added in this
commit.
2021-10-17 17:09:58 +01:00
Tim Schumacher
20986b7066 Prekernel: Force enable PAE on Intel Pentium M CPUs 2021-10-17 16:15:36 +01:00
Tim Schumacher
e8808b259a Prekernel: Split early boot printing into two subroutines 2021-10-17 16:15:36 +01:00
SeekingBlues
3d174e3ad2 Kernel/ProcFS: Provide a way to write to ProcFS inodes
ProcFSGlobalInode now calls `write_bytes()`, `truncate()` and
`set_mtime()` on its associated component. This allows us to write 0 or
1 to a ProcFSSystemBoolean component to toggle a boolean value.
2021-10-17 14:46:59 +02:00
Tim Schumacher
52621093c7 Kernel: Print CPU check errors by writing to VRAM 2021-10-17 12:25:50 +01:00