Commit graph

4180 commits

Author SHA1 Message Date
Nicholas-Baron 4454735bf8 Kernel: Add -Wnull-dereference flag
`-Wnull-dereference` has found a lot of "possible null dereferences" in userland.
However, in the kernel, no warnings occurred. To keep it that way,
preemptivly add the flag here and remove it once it is enabled system
wide.

This flag makes the compiler check statically for a null deref. It does
not take into account any human-imposed invariants and as such, may need a
`VERIFY(ptr);`, `if(ptr)`, or `if(!ptr)` before using a pointer.
However, as long as a pointer is not reassigned,
the verify will be valid, meaning that adding `VERIFY` can be done sparingly.
2021-04-17 01:07:36 +02:00
AnotherTest e4412f1f59 AK+Kernel: Make IntrusiveList capable of holding non-raw pointers
This should allow creating intrusive lists that have smart pointers,
while remaining free (compared to the impl before this commit) when
holding raw pointers :^)
As a sidenote, this also adds a `RawPtr<T>` type, which is just
equivalent to `T*`.
Note that this does not actually use such functionality, but is only
expected to pave the way for #6369, to replace NonnullRefPtrVector<T>
with intrusive lists.

As it is with zero-cost things, this makes the interface a bit less nice
by requiring the type name of what an `IntrusiveListNode` holds (and
optionally its container, if not RawPtr), and also requiring the type of
the container (normally `RawPtr`) on the `IntrusiveList` instance.
2021-04-16 22:26:52 +02:00
sin-ack 091d352526 Kernel: Add some missing socket ioctls
This patch adds a few missing ioctls which were required by Wine.
SIOCGIFNETMASK, SIOCGIFBRDADDR and SIOCGIFMTU are fully implemented,
while SIOCGIFFLAGS and SIOCGIFCONF are stubs.
2021-04-16 18:57:35 +02:00
Nicholas-Baron c4ede38542 Everything: Add -Wnon-virtual-dtor flag
This flag warns on classes which have `virtual` functions but do not
have a `virtual` destructor.

This patch adds both the flag and missing destructors. The access level
of the destructors was determined by a two rules of thumb:
1. A destructor should have a similar or lower access level to that of a
   constructor.
2. Having a `private` destructor implicitly deletes the default
   constructor, which is probably undesirable for "interface" types
   (classes with only virtual functions and no data).

In short, most of the added destructors are `protected`, unless the
compiler complained about access.
2021-04-15 20:57:13 +02:00
Brian Gianforcaro a973b22359 Kernel: Suppress maybe-uninitialized' warning s_syscall_table in gcc-10.3.0 2021-04-14 21:49:54 +02:00
Brian Gianforcaro 8d70bead20 Build: Update toolchain include path to gcc 10.3.0 2021-04-14 21:49:54 +02:00
Gunnar Beutner c3ee70591a Kernel: Read the ELF header from the inode rather than the mapped pages
Reading from the mapping doesn't work when the text segment has a non-zero
offset because in that case the first mapped page doesn't contain the ELF
header.
2021-04-14 13:12:52 +02:00
Gunnar Beutner 2d91761cf6 Kernel: Make sure the offset stays the same when using mremap()
When using mmap() on a file with a non-zero offset subsequent
calls to mremap() would incorrectly reset the offset to zero.
2021-04-14 13:12:52 +02:00
Jean-Baptiste Boric dcff87215b Kernel: Fix RAM OK test condition for NE2000NetworkAdapter 2021-04-13 21:52:34 +02:00
Jean-Baptiste Boric a73bd0fff8 Kernel: Remove type from StorageDevice class 2021-04-13 21:52:34 +02:00
Brian Gianforcaro 1d7a0ab5ea Kernel: Mark s_syscall_table const so it ends up in ro_data. 2021-04-12 23:56:57 +02:00
Idan Horowitz 2c93123daf Kernel: Replace process' regions vector with a Red Black tree
This should provide some speed up, as currently searches for regions
containing a given address were performed in O(n) complexity, while
this container allows us to do those in O(logn).
2021-04-12 18:03:44 +02:00
Idan Horowitz 497c759ab7 Kernel: Remove old region from process' regions vector before splitting
This does not affect functionality right now, but it means that the
regions vector will now never have any overlapping regions, which will
allow the use of balance binary search trees instead of a vector in the
future. (since they require keys to be exclusive)
2021-04-12 18:03:44 +02:00
Andreas Kling f27352dfdc Kernel: Use more if-with-initializer in VFS 2021-04-11 00:40:38 +02:00
Andreas Kling acebc9beaf Ext2FS: Use if-with-initializer a lot more
This pattern felt really cluttery:

auto result = something();
if (result.is_error())
    return result;

Since it leaves "result" lying around in the no-error case.
Let's use some C++17 if initializer expressions to improve this:

if (auto result = something(); result.is_error())
    return result;

Now the "result" goes out of scope if we don't need it anymore.
This is doubly nice since we're also free to reuse the "result"
name later in the same function.
2021-04-11 00:33:16 +02:00
AnotherTest a6e4482080 AK+Everywhere: Make StdLibExtras templates less wrapper-y
This commit makes the user-facing StdLibExtras templates and utilities
arguably more nice-looking by removing the need to reach into the
wrapper structs generated by them to get the value/type needed.
The C++ standard library had to invent `_v` and `_t` variants (likely
because of backwards compat), but we don't need to cater to any codebase
except our own, so might as well have good things for free. :^)
2021-04-10 21:01:31 +02:00
Andreas Kling 642b428793 Ext2FS: Support reading from file holes
It's perfectly valid for ext2 inodes to have blocks with index 0.
It means that no physical block was allocated for that area of an inode
and we should treat it as if it's filled with zeroes.

Fixes #6139.
2021-04-10 11:09:43 +02:00
Andreas Kling b5b38d372c Ext2FS: Clarify error handling in Ext2FSInode::read_bytes() somewhat 2021-04-10 10:58:19 +02:00
Andreas Kling 86a6366749 Kernel: Do some basic metadata integrity verification in kmalloc/kfree
Use BitmapView::set_range_and_verify_that_all_bits_flip() to validate
the heap chunk metadata bits as we go through them in kmalloc/kfree.
2021-04-09 17:08:49 +02:00
Andreas Kling 79ebcacce2 Kernel: Add some basic double-kfree() detection
Double kfree() is exceedingly rare in our kernel since we use automatic
memory management and smart pointers for almost all code. However, it
doesn't hurt to do some basic checking that might one day catch bugs.

This patch makes us VERIFY that we don't already consider the first
chunk of a kmalloc() allocation free when kfree()'ing it.
2021-04-09 17:08:49 +02:00
Hendiadyoin1 e8ef10e2a6 Kernel/LibC: Make memset implementations the same
I dont know why we do a fast path in the Kernel, but not in Userspace

Also simplified the byte explosion in memset to "explode_byte"
it even seemed so, that we missed the highest byte when memseting something
2021-04-08 23:57:16 +02:00
Liav A a0be30f655 Kernel: Introduce two new boot arguments to assist with bare metal debug
The first one is for disabling the PS2 controller, the other one is for
disabling physical storage enumeration.
We can't be sure any machine will work with our implementation,
therefore this will help us to test more machines.
2021-04-08 22:17:13 +02:00
Andreas Kling a6ec6b831b Kernel: Remove unused UHCI_ENABLED flag 2021-04-07 22:47:22 +02:00
Liav A fc92a4b228 Kernel/PCI: Disable ECAM method by default
Until I figure out what's going wrong with it on bare-metal, disable it
unless explicitly enabled by the user.
2021-04-06 22:25:28 +02:00
Liav A da109eeab8 Kernel/Storage: Wait a few microseconds after selecting the IDE drive
We need to do it to let real hardware to put the correct voltages
on the wire.
Apparently my ICH7 machine refused to boot, and was reading lots of
garbage from an unconnected IDE channel. It was fixed after I added a
delay of 20 microseconds. It probably can be reduced, I just took a safe
value and it seems to work correctly without any problems :)
2021-04-06 22:25:28 +02:00
Liav A 210754a93a Kernel/PCI + CPU: Allow to access unaligned data 2021-04-06 22:25:28 +02:00
Liav A 543c29377b Kernel/PCI: Don't expose virtual addresses on the kernel log 2021-04-06 22:25:28 +02:00
Jean-Baptiste Boric 346e0f4dac Kernel: Don't crash if unable to map ramdisk inside kernel address space 2021-04-06 18:17:16 +02:00
Jean-Baptiste Boric 436ca2491d Kernel: Fix KUBSAN crash with RamdiskDevice 2021-04-06 18:17:16 +02:00
Andreas Kling ee2a1f5af7 Kernel+LibCore: Note whether a process is kernel mode in /proc/all 2021-04-06 17:55:47 +02:00
Andreas Kling 0b8226811f Kernel+CrashReporter: Add metadata about page faults to crash reports
Crash reports for page faults now tell you what kind of memory access
failed and where. :^)
2021-04-04 20:13:55 +02:00
Andreas Kling 5001b71c42 Kernel: Reading past the end of an Ext2FSInode should return 0
Fixes #5763.
2021-04-04 17:21:07 +02:00
Liav A 8abbb7e090 Kernel/PCI: Introduce a new ECAM access mechanism
Now the kernel supports 2 ECAM access methods.
MMIOAccess was renamed to WindowedMMIOAccess and is what we had until
now - each device that is detected on boot is assigned to a
memory-mapped window, so IO operations on multiple devices can occur
simultaneously due to creating multiple virtual mappings, hence the name
is a memory-mapped window.

This commit adds a new class called MMIOAccess (not to be confused with
the old MMIOAccess class). This class creates one memory-mapped window.
On each IO operation on a configuration space of a device, it maps the
requested PCI bus region to that window. Therefore it holds a SpinLock
during the operation to ensure that no other PCI bus region was mapped
during the call.

A user can choose to either use PCI ECAM with memory-mapped window
for each device, or for an entire bus. By default, the kernel prefers to
map the entire PCI bus region.
2021-04-03 19:34:52 +02:00
Liav A 441e374396 Kernel: Enable PCI ECAM method again if available
Apparently we don't enable PCI ECAM (MMIO access to the PCI
configuration space) even if we can. This is a regression, as it was
enabled in the past and in unknown time it was regressed.

The CommandLine::is_mmio_enabled method was renamed to
CommandLine::is_pci_ecam_enabled to better represent the meaning
of this method and what it determines.

Also, an UNMAP_AFTER_INIT macro was removed from a method
in the MMIOAccess class as it halted the system when the kernel
tried to access devices after the boot process.
2021-04-03 19:34:52 +02:00
Liav A 8e3e3a71cb Kernel: Introduce a new HID subsystem
The end goal of this commit is to allow to boot on bare metal with no
PS/2 device connected to the system. It turned out that the original
code relied on the existence of the PS/2 keyboard, so VirtualConsole
called it even though ACPI indicated the there's no i8042 controller on
my real machine because I didn't plug any PS/2 device.
The code is much more flexible, so adding HID support for other type of
hardware (e.g. USB HID) could be much simpler.

Briefly describing the change, we have a new singleton called
HIDManagement, which is responsible to initialize the i8042 controller
if exists, and to enumerate its devices. I also abstracted a bit
things, so now every Human interface device is represented with the
HIDDevice class. Then, there are 2 types of it - the MouseDevice and
KeyboardDevice classes; both are responsible to handle the interface in
the DevFS.

PS2KeyboardDevice, PS2MouseDevice and VMWareMouseDevice classes are
responsible for handling the hardware-specific interface they are
assigned to. Therefore, they are inheriting from the IRQHandler class.
2021-04-03 11:57:23 +02:00
Liav A 27bf91ab87 Revert "Kernel/PCI: Allow to set the PCI IRQ line of a device"
This reverts commit 36a82188a8.

This register is write-only for the firmware (BIOS), and read-only for
us so we shouldn't set the PCI IRQ line never.
The firmware figured out the IRQ routing to the PIC for us, so changing
it won't affect anything. I was mistaken when I thought that changing
the value of this register will allow us to change its interrupt line,
like when changing a PCI BAR to relocate device resources as desired
with the requirements of the OS.
2021-04-03 11:57:23 +02:00
Liav A 2718d7c74c Kernel/Storage: Add support for IDE controllers in PCI native mode
Also handle native and compatibility channel modes together, so if only
one IDE channel was set to work on PCI native mode, we need to handle it
separately, so the other channel continue to operate with the legacy IO
ports and interrupt line.
2021-04-03 11:57:23 +02:00
Brendan Coles 627cfe017c Kernel: NetworkTask: Remove 10.0.2.x as default IP for NIC interfaces 2021-04-03 11:25:18 +02:00
AnotherTest e3fd914187 Kernel: Send SIGCHLD to the parent process when changing stopped state
This is done also by linux (signal.c:936 in v5.11) at least.
It's a pretty handy notification that allows the parent process to skip
going through a `waitpid` and guesswork to figure out the current state
of a child process.
2021-03-31 23:49:26 +02:00
Baitinq 19c578024b
Kernel: Added TIOCSTI ioctl placeholder (#6037)
Added a dummy TIOCSTI ioctl placeholder. This is a dangerous ioctl that
can be used to inject input into a tty. Added for compatibility. Always
fails with EIO.
2021-03-31 22:58:41 +02:00
Andreas Kling 54f6b52f71 Kernel: Don't dump regions twice when crashing due to bad access
For whatever reason we were dumping regions when first handling the
page fault, and then again when tearing down the process.
2021-03-30 11:50:49 +02:00
Andreas Kling 664571c88f Kernel: Clarify Thread::block() a little bit with a better local name 2021-03-30 11:50:48 +02:00
Itamar ba0df27653 Kernel: Support write() after setting O_APPEND on a non-seekable file
Previously, Process::do_write would error if the O_APPEND flag was set
on a non-seekable file.

Other systems (such as Linux) seem to be OK with doing this, so we now
do not attempt to seek to the end the file if it's not seekable.
2021-03-29 19:56:54 +02:00
Andreas Kling 497c4c3858 Kernel: Let's also not reverse the blocking flag for FIONBIO.. 2021-03-29 08:59:22 +02:00
Andreas Kling 0f270afda8 Kernel: Let's allow unsetting non-blocking mode with FIONBIO as well
Thanks to almightyhydra for pointing this out! :^)
2021-03-29 08:58:13 +02:00
Idan Horowitz 9f656b6fa9 LibCoreDump+CrashDaemon: Compress coredumps
Most coredumps contain large amounts of consecutive null bytes and as
such are a prime candidate for compression.

This commit makes CrashDaemon compress files once the kernel finishes
emitting them, as well as adds the functionality needed in LibCoreDump
to then parse them.
2021-03-28 20:42:33 +02:00
Andreas Kling 5f71bf0cc7 Kernel+LibC: Implement sys$ioctl() FIONBIO
This is another (older) way of making a file descriptor non-blocking.
2021-03-28 17:50:08 +02:00
Liav A 3547d90a0f Kernel/Storage: Select the drive before working with busmaster register
This is a "quirk" I've observed on a Intel ICH7 test machine. Apparently
we need to select the device (master or slave) before starting to work
with the bus master register.
It's very possible that other machines are requiring this step to happen
before the DMA transfer can occur correctly.

Also, when reading with DMA, we should set the transfer direction before
clearing the interrupt status.

For the sake of completeness, I added a few lines in places that I
deemed it to be reasonable to clear the interrupt status there.
2021-03-27 16:40:16 +01:00
Liav A 1d0c183388 Kernel/Storage: Add some debug printing about IDE controllers 2021-03-27 16:40:16 +01:00
Liav A 186e03b99d Kernel/Storage: Remove redundant public declaration in IDEController.h 2021-03-27 16:40:16 +01:00