Commit graph

6247 commits

Author SHA1 Message Date
Liav A ac7953f945 Kernel: Allow switching to IOAPIC mode even without enabling SMP
This small change allows to use the IOAPIC by default without to enable
SMP mode, which emulates Uni-Processor setup with IOAPIC instead of
using the PIC.

This opens the opportunity to utilize other types of interrupts like MSI
and MSI-X interrupts.
2021-12-14 09:02:06 +01:00
Liav A f57900a41b Kernel/Interrupts: Add ByteReaders to read possible unaligned MADT data
The MADT data could be on unaligned boundary - for example, a GSI number
(u32) on unaligned address which leads to a KUBSAN error and halting the
system.
2021-12-14 09:02:06 +01:00
Liav A bbdb55126c Kernel/SysFS: Don't allocate ACPISysFS components in constructors
Instead defer it to a method to be called after the construction of
ACPISysFSDirectory.
2021-12-14 09:01:33 +01:00
Liav A 381fdaa163 Kernel/SysFS: Make it clear that some components must be created in boot
Using the phrase "create" doesn't give information on whether the object
must be allocated or a failure to do so can be handled gracefully.
Therefore, we must use better phrase for such purpose, so "must_create"
for the allocate-and-construct static methods is definitely good choice.
2021-12-14 09:01:33 +01:00
Liav A 478f543899 Kernel/SysFS: Prevent allocation for component name during construction
Instead, allocate before constructing the object and pass NonnullOwnPtr
of KString to the object if needed. Some classes can determine their
names as they have a known attribute to look for or have a static name.
2021-12-14 09:01:33 +01:00
Luke Wilde 62af3acf56 Kernel: Fix backtrace dumping on x86_64
- dump_backtrace was using ebp instead of rbp on x86_64, only using the
  lower 32-bits of rbp.
- The symbol loader was only fetching half of the pointer from the
  symbol table. (8 chars instead of 16 chars)
2021-12-13 09:17:32 +01:00
Clay Freeman e3e40cca65 Kernel: Replace final loop in PhysicalRegion::return_page() with math
Since it's possible to determine where the small zones will start to
occur for each PhysicalRegion, we can use arithmetic so that the call
time for both large and small zones is identical.
2021-12-13 00:13:43 +01:00
Daniel Bertalan 8dd11ae717 Kernel+SystemServer: Add /dev/tty
This file refers to the controlling terminal associated with the current
process. It's specified by POSIX, and is used by ports like openssh to
interface with the terminal even if the standard input/output is
redirected to somewhere else.

Our implementation leverages ProcFS's existing facilities to create
process-specific symbolic links. In our setup, `/dev/tty` is a symbolic
link to `/proc/self/tty`, which itself is a symlink to the appropriate
`/dev/pts` entry. If no TTY is attached, `/dev/tty` is left dangling.
2021-12-12 22:32:35 +01:00
Jean-Baptiste Boric 23257cac52 Kernel: Remove sys$select() syscall
Now that the userland has a compatiblity wrapper for select(), the
kernel doesn't need to implement this syscall natively. The poll()
interface been around since 1987, any code still using select()
should be slapped silly.

Note: the SerenityOS source tree mostly uses select() and not poll()
despite SerenityOS having support for poll() since early 2019...
2021-12-12 21:48:50 +01:00
Jean-Baptiste Boric 2177c2a30b Kernel: Split off sys$poll() into Syscalls/poll.cpp 2021-12-12 21:48:50 +01:00
Idan Horowitz 762e047ec9 Kernel+LibC: Implement sigtimedwait()
This includes a new Thread::Blocker called SignalBlocker which blocks
until a signal of a matching type is pending. The current Blocker
implementation in the Kernel is very complicated, but cleaning it up is
a different yak for a different day.
2021-12-12 08:34:19 +02:00
Idan Horowitz 13d98999b7 Kernel: Flip incorrect bitwise set/clear of signal mask 2021-12-12 08:34:19 +02:00
Idan Horowitz 1397a5ab02 Kernel: Unblock threads only on unmasked signals
Signals that were explicitly masked should not unblock threads.
2021-12-12 08:34:19 +02:00
Idan Horowitz 81a76a30a1 Kernel: Preserve pending signals across execve(2)s
As required by posix. Also rename Thread::clear_signals to
Thread::reset_signals_for_exec since it doesn't actually clear any
pending signals, but rather does execve related signal book-keeping.
2021-12-12 08:34:19 +02:00
Idan Horowitz 31fa3f8b1b Kernel: Remove alternative signal stack settings on execve(2)
A successful call to execve(2) removes any existing alternate signal
stack.
2021-12-12 08:34:19 +02:00
Idan Horowitz 0ca1231d8f Kernel: Inherit alternative signal stack on fork(2)
A child process created via fork(2) inherits a copy of its parent's
alternate signal stack settings.
2021-12-12 08:34:19 +02:00
Idan Horowitz 92a6c91f4e Kernel: Preserve signal mask across fork(2) and execve(2)
A child created via fork(2) inherits a copy of its parent's signal
mask; the signal mask is preserved across execve(2).
2021-12-12 08:34:19 +02:00
Hendiadyoin1 7a206868f8 Kernel: Move architecture dependent includes to the top in Processor.h
With the declaration order dependency resolved in the last two commits
we can now do this, which looks a lot nicer.
2021-12-11 13:23:27 -08:00
Hendiadyoin1 3f434506f5 Kernel: Extract ProcessorSpecificDataID from from Arch/Processor.h 2021-12-11 13:23:27 -08:00
Hendiadyoin1 556b516182 Kernel: Extract DeferredCallEntry from Arch/Processor.h 2021-12-11 13:23:27 -08:00
Hendiadyoin1 e34eb3e36d Kernel: Remove unused String.h includes
This makes searching for not yet OOM safe interfaces a bit easier.
2021-12-11 13:15:26 -08:00
Daniel Bertalan 4a81b33c07 Everywhere: Fix -Winconsistent-missing-override warnings from Clang
This option is already enabled when building Lagom, so let's enable it
for the main build too. We will no longer be surprised by Lagom Clang
CI builds failing while everything compiles locally.

Furthermore, the stronger `-Wsuggest-override` warning is enabled in
this commit, which enforces the use of the `override` keyword in all
classes, not just those which already have some methods marked as
`override`. This works with both GCC and Clang.
2021-12-11 13:14:15 -08:00
Andreas Kling 813593a485 Kernel: Fix overly loose MemoryManager::kernel_region_from_vaddr()
It's not enough to just find the largest-address-not-above the argument,
we must also check that the found region actually contains the argument.

Regressed in a23edd42b8, thanks to Idan
for pointing this out.
2021-12-11 21:18:42 +01:00
Andreas Kling 259cca456f Kernel: Make PhysicalRegion::return_page() do arithmetic instead of loop
Most of the time, we will be freeing physical pages within the
full-sized zones. We can do some simple math to find the right zone
immediately instead of looping through the zones, checking each one.

We still do loop through the slack/remainder zones at the end.
There's probably an even nicer way to solve this, but this is already a
nice improvement. :^)
2021-12-11 20:13:32 +01:00
Andreas Kling 63117f826b Kernel: Simplify 64-bit HPET reads on x86_64
We don't have to worry about racy 32-bit reads when we're reading the
64-bit HPET value using a 64-bit CPU. :^)
2021-12-11 20:13:25 +01:00
Andreas Kling a23edd42b8 Kernel: Store kernel memory regions in a RedBlackTree
We were already doing this for userspace memory regions (in the
Memory::AddressSpace class), so let's do it for kernel regions as well.

This gives a nice speed-up on test-js and probably basically everything
else as well. :^)
2021-12-11 20:13:20 +01:00
Hendiadyoin1 9be409585c Kernel: Some clang-tidy fixes in Bus/VirtIO 2021-12-09 22:53:42 -08:00
Hendiadyoin1 471b38db68 Kernel: Some clang-tidy fixes in Bus/USB 2021-12-09 22:53:42 -08:00
Hendiadyoin1 b03b7f806a Kernel: Mark USBTransfer's constructor as private
We have a try_create method for that.
2021-12-09 22:53:42 -08:00
Hendiadyoin1 21c5c4026b Kernel: Mark ACPI::Parser's empty destructor as default 2021-12-09 22:53:42 -08:00
Hendiadyoin1 73aa5c75d5 Kernel: Fix some clang-tidy warnings in PCI::Access 2021-12-09 22:53:42 -08:00
Hendiadyoin1 19ba32651d Kernel: Use AK:any_of in PCI::Device capability checks
This is equivalent to std::any_of as clang-tidy suggests.
2021-12-09 22:53:42 -08:00
Hendiadyoin1 5adf5f4dee Kernel: Construct PCIDeviceAttributeSysFSComponent with StringViews
There is no use to create a temporary String of a char const* to just
cast it to a StringView on SysFSComponent construction again.
Also this could have lead to a UAF bug.
2021-12-09 22:53:42 -08:00
Hendiadyoin1 de26dd253b Kernel: Pass capabilities as const reference in PCI::Address 2021-12-09 22:53:42 -08:00
Hendiadyoin1 3070252090 Kernel: Mark PCI::Address as trivially copyable 2021-12-09 22:53:42 -08:00
Hendiadyoin1 f9e8fe557c Kernel: Add missing include to SlabAllocator 2021-12-09 22:53:42 -08:00
Idan Horowitz 39ecb832e4 Kernel: Don't try to dispatch urgent signals for kernel crashes
If we crashed in the kernel there's no point to sending a signal to the
active process, we're going to panic soon anyway.
2021-12-06 19:36:42 +01:00
Idan Horowitz 548488f050 Kernel: Terminate current thread immediately on unhandled urgent signal
If we're sending an urgent signal (i.e. due to unexpected conditions)
and the Process did not setup any signal handler, we should immediately
terminate the Thread, to ensure the current trap frame is preserved for
the impending core dump.
2021-12-06 19:36:42 +01:00
Andreas Kling 0f9ca51c76 Kernel: Remove unused Inode::preopen_fd() 2021-12-06 19:22:16 +01:00
Ben Wiederhake 0e6e1092f0 Kernel: Make ptrace return an error on error
Returning 'result.error().code()' erroneously creates an
ErrorOr<FlatPtr> of the positive errno code, which breaks our
error-returning convention.

This seems to be due to a forgotten minus-sign during the refactoring in
9e51e295cf. This latent bug was never
discovered, because currently the error-handling paths are rarely
exercised.
2021-12-05 22:59:09 +01:00
Ben Wiederhake 0f8483f09c Kernel: Implement new ptrace function PT_PEEKBUF
This enables the tracer to copy large amounts of data in a much saner
way.
2021-12-05 22:59:09 +01:00
Ben Wiederhake 3e223185b3 Kernel+strace: Remove unnecessary indirection for PEEK
Also, remove incomplete, superfluous check.
Incomplete, because only the byte at the provided address was checked;
this misses the last bytes of the "jerk page".
Superfluous, because it is already correctly checked by peek_user_data
(which calls copy_from_user).

The caller/tracer should not typically attempt to read non-userspace
addresses, we don't need to "hot-path" it either.
2021-12-05 22:59:09 +01:00
Sam Atkins c6a97ea843 Kernel: Mark kernel smart-pointer classes as [[nodiscard]]
And cast the unused return values to void.
2021-12-05 15:31:03 +01:00
Sam Atkins 907feb84a0 Kernel: Cast unused smart-pointer return value to void 2021-12-05 15:31:03 +01:00
Idan Horowitz b2464cf4c0 Kernel: Define PT_WRITE_I and PT_WRITE_D
These are aliases for PT_POKE that are used in some *BSDs.
2021-12-05 12:53:29 +01:00
Idan Horowitz 265764ff2f Kernel: Add support for the POLLWRBAND poll event 2021-12-05 12:53:29 +01:00
Idan Horowitz f2fef049e1 Kernel: Define the POLLRDNORM alias for POLLIN
This flag is equivalent to POLLIN.
2021-12-05 12:53:29 +01:00
Idan Horowitz 05aa764402 Kernel: Define the POLLWRNORM alias for POLLOUT
This is defined by posix to be equivalent to POLLOUT
2021-12-05 12:53:29 +01:00
Idan Horowitz 8074157c10 Kernel: Add the IPPROTO_{IGMP, IPIP, RAW} protocol macros
These are not implemented currently, but are required for some ports to
compile.
2021-12-05 12:53:29 +01:00
Idan Horowitz 2860637ff3 Kernel: Add the IP_{BLOCK_SOURCE, UNBLOCK_SOURCE, OPTIONS} macros
These are not implemented currently, but are required for some ports to
compile.
2021-12-05 12:53:29 +01:00