Commit graph

6211 commits

Author SHA1 Message Date
James Mintram 8350b44ebd Kernel: Add an x86 include check+error in x86/CPU.h 2021-12-01 11:22:04 -08:00
James Mintram 3e3c632969 Kernel: Add an x86 include check+error in x86/ASM_Wrapper.h 2021-12-01 11:22:04 -08:00
James Mintram 1c86b7043b Kernel: Remove ASM_Wrapper include from platform independent processor.h 2021-12-01 11:22:04 -08:00
Hendiadyoin1 c7b90fa7d3 Kernel: Don't rewrite the whole file on sys$msync 2021-12-01 09:47:46 +01:00
Hendiadyoin1 259f78545a Kernel: Allow flushing of partial regions in sys$msync 2021-12-01 09:47:46 +01:00
Hendiadyoin1 49d6ad6633 Kernel: Handle more error cases in sys$msync 2021-12-01 09:47:46 +01:00
Brian Gianforcaro d7568b28b4 Kernel: Surface errors when generating a process core dump :^) 2021-11-30 11:16:35 +01:00
Brian Gianforcaro fa517b213a Kernel: Handle string format errors in FileSystem APIs :^) 2021-11-30 11:16:35 +01:00
Brian Gianforcaro e626d7098d Kernel: Handle string format errors in Device::pseudo_path(..) :^) 2021-11-30 11:16:35 +01:00
Brian Gianforcaro 1f65728d8b Kernel: Handle string format errors in PCIDeviceAttributeSysFSComponent 2021-11-30 11:16:35 +01:00
Brian Gianforcaro 74ee491b84 Kernel: Handle string format errors in SlabAllocator stats :^)
Switch to KString::formatted and fix API so we can propagate errors.
2021-11-30 11:16:35 +01:00
Brian Gianforcaro a0e59099fc Kernel: Handle string format errors in KCOVInstance :^) 2021-11-30 11:16:35 +01:00
Brian Gianforcaro a5cec06135 Kernel: Handle string format error in page_fault_handler(..) :^)
Utilize the new KString::formatted to provide a fallback
if formatting fails because of OOM or whatever reason.
2021-11-30 11:16:35 +01:00
Brian Gianforcaro 4cc41ea186 Kernel: Add an error propagating KString::format(..) API :^)
In the continuous effort of better handling OOM in the kernel,
we want to move away from all AK::String usage. One of the final
pieces left to accomplish this goal is replacing all of the usages
of `String::formatted` with something that can actually propagate
failure.

The StringBuilder API was enhanced in the recent past to propagate
failure and thus a slightly modified version of what exists in
`AK::format` will work well for implementing failable format with
`KString`.
2021-11-30 11:16:35 +01:00
Jelle Raaijmakers e187207610 Kernel: Register Virtio console ports with device management
Previously, Virtio console ports would not show up in `/sys/dev/char/`.
Also adds support to `SystemServer` to create more than one console
port device in `/dev/` in the multiport case.
2021-11-30 10:53:41 +01:00
James Mintram f7c0cdcc19 Kernel: Use peripheral addresses returned from MMIO to map prekernel mem 2021-11-28 22:01:21 -08:00
James Mintram 4e9777243e Kernel: Refactor prekernel MMU to use a bump allocator 2021-11-28 22:01:21 -08:00
James Mintram 4a4a3193f8 Kernel: Rename Aarch64Asm -> ASM_wrapper and add Aarch64::Asm namespace 2021-11-28 22:01:21 -08:00
James Mintram 34709c8d39 Kernel: Rename Aarch64Registers -> Registers and add Aarch64 namespace 2021-11-28 22:01:21 -08:00
James Mintram 271b9b8da3 Kernel: Set up and activate the MMU in the aarch64 perkernel 2021-11-28 22:01:21 -08:00
James Mintram c2d7e200eb Kernel: Move common aarch64 asm functions into kernel folder and NS 2021-11-28 22:01:21 -08:00
James Mintram 68b5d00f42 Kernel: Split prekernel exception level code into its own file 2021-11-28 22:01:21 -08:00
James Mintram 18f1530c84 Kernel: Change prekernel to use shared SP across Exception Levels 2021-11-28 22:01:21 -08:00
James Mintram 5a75bd31b0 Kernel: Replace inline asm with typesafe static member functions 2021-11-28 22:01:21 -08:00
James Mintram 4bc5936a57 Kernel: Remove unused header from Aarch64_asm_utils 2021-11-28 22:01:21 -08:00
Jelle Raaijmakers 497180a650 Kernel: Ignore AC97 non-completion interrupts
Fixes #11094
2021-11-28 19:26:22 +02:00
Jelle Raaijmakers 689ad0752c Kernel: Add AC97_DEBUG macro 2021-11-28 19:26:22 +02:00
Sam Atkins 6dd2ebfe8e Kernel: Log when a process exits with an unlocked veil
This catches applications that make use of `unveil()`, but then do not
lock the veil with `unveil(nullptr, nullptr)`.
2021-11-28 09:16:37 -08:00
Liav A 8abc4fa8c2 Kernel/Audio: Implement 2 correctness fixes in AC97
The fixes are:
1. Don't copy PCI::DeviceIdentifier during construction. This is a heavy
structure to copy so we definitely don't want to do that. Instead, use
a const reference to it like what happens in other parts in the Kernel.
2. Declare the constructor as explicit to avoid construction errors.
2021-11-27 23:43:56 -08:00
Liav A ed5a4f2938 Kernel/Storage: Restore booting from MBR partitions functionality
We had such functionality in the past, but it was regressed and now is
restored.
2021-11-28 08:05:58 +01:00
Jelle Raaijmakers 58bcb93777 Kernel: Implement variable rate audio support for AC97 devices
Previously we `VERIFY()`ed that the device supports variable-rate audio
(VRA). Now, we query the VRA bit and if VRA is not supported, we do not
enable double-rate audio and disallow setting any sample rate except
the fixed 48kHz rate as defined by the AC'97 specification. This should
allow the driver to function on a wider array of hardware.

Note that in the AC'97 specification, DRA without VRA is allowed when
supported: this effectively doubles the sample rate to 96kHZ. For now,
we ignore that possibility and let it default to 48kHZ.
2021-11-26 22:15:29 +01:00
macarc bffdc056a2 Kernel: Ensure KeyEvent::key sent to Userspace respects keyboard layout
Before, only KeyEvent::code_point took the user's keyboard layout
into consideration, while KeyEvent::key was hardcoded QWERTY. This
affected, among other things, Vim Emulation.

Now, KeyEvent::key respects the user's keyboard layout, so will be the
same as KeyEvent::code_point for visible (alphanumeric + symbol) keys.

Co-Authored-By: Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
2021-11-26 11:19:36 -08:00
Ben Wiederhake 33079c8ab9 Kernel+UE+LibC: Remove unused dbgputch syscall
Everything uses the dbgputstr syscall anyway, so there is no need to
keep supporting it.
2021-11-24 22:56:39 +01:00
Jelle Raaijmakers 46ad5f2a17 Kernel: Fix futex syscall return values
We were returning `int`s from two functions that caused `ErrorOr` to
not recognize the error codes as a special case. For example,
`ETIMEDOUT` was returned as the positive number 66 resulting in all
kinds of defective behavior.

As a result, SDL2's timer subsystem was not working at all, since the
`SDL_MUTEX_TIMEDOUT` value was never returned.
2021-11-24 19:44:57 +01:00
Jelle Raaijmakers f97c9a5968 Kernel: Allow higher audio sample rates than 65kHZ (u16)
Executing `asctl set r 96000` no longer results in weird sample rates
being set on the audio devices. SB16 checks for a sample rate between 1
and 44100 Hz, while AC97 implements double-rate support which allows
sample rates between 8kHz and 96kHZ.
2021-11-24 19:08:13 +01:00
Jelle Raaijmakers eb2b0d847e Kernel: Allow writes larger than PAGE_SIZE to AC97 device
Previously, `cat /dev/random > /dev/audio` would crash Serenity. Fix
this by splitting up the written data into `PAGE_SIZE` chunks.
2021-11-23 14:08:14 +01:00
Jelle Raaijmakers 70ca8b24dc Kernel: Add generic channel support to AC97
This factors out some hardcoded PCMOut registers into a new private
class called AC97Channel, which wraps around a channel's registers and
provides some shared functionality.

No functional changes.
2021-11-23 14:08:14 +01:00
Andreas Kling dd6e73176d Kernel: Make sys$mmap() interpret 0-alignment as page-sized alignment
This allows userspace to get a sane default behavior without having to
specify the page size.
2021-11-23 11:44:42 +01:00
Jelle Raaijmakers 7a2a0c1052 Kernel: Implement AC97 audio device driver 2021-11-23 10:06:24 +01:00
Jelle Raaijmakers 1aafb6cd23 Kernel: Teach DeviceManagement to handle multiple audio devices 2021-11-23 10:06:24 +01:00
Jelle Raaijmakers 61d77274db Kernel: Move SB16 to Audio subdirectory 2021-11-23 10:06:24 +01:00
Andreas Kling f99af1bef0 Kernel: Make sure OpenFileDescription is kept alive while read() blocks
It's not safe to store OpenFileDescription in a raw pointer when
blocking, since another thread may decide to close the corresponding
file descriptor.
2021-11-21 20:22:48 +01:00
Andreas Kling c0deafe457 Kernel: Avoid repeated memory zeroing while generating coredumps
Reuse the same buffer-full-of-zeroes for every un-paged-in page that we
dump out.
2021-11-21 20:22:48 +01:00
Andreas Kling e1779b064a Kernel: Remove bogus TODO in coredump generation
When dumping the memory contents of a process, we should not page in
things from inodes that were not already paged in.
2021-11-21 20:22:48 +01:00
Andreas Kling f2c3a41a8f Kernel: Make UserOrKernelBuffer::for_user_buffer() return ErrorOr<T>
This simplifies EFAULT propagation with TRY(). :^)
2021-11-21 20:22:48 +01:00
Andreas Kling b820ae2828 Kernel: Share code between DoubleBuffer's read() and peek()
The only difference between these is whether the buffer index is
advanced after the read.
2021-11-21 20:22:48 +01:00
Andreas Kling 9387271049 Everywhere: Fix spelling of "offsetted"
This word is actually pretty awkward in context, but this patch merely
fixes the spelling instead of finding a better word.
2021-11-21 20:22:48 +01:00
Andreas Kling daef7e2c71 Kernel+LibC: Fix misspelled "VERTICAL" in framebuffer ioctls 2021-11-21 20:22:48 +01:00
Itamar 38ddf301f6 Kernel+LibC: Fix ptrace for 64-bit
This makes the types used in the PT_PEEK and PT_POKE actions
suitable for 64-bit platforms as well.
2021-11-20 21:22:24 +00:00
Andreas Kling e08d213830 Kernel: Use DistinctNumeric for filesystem ID's
This patch adds the FileSystemID type, which is a distinct u32.
This prevents accidental conversion from arbitrary integers.
2021-11-18 21:11:30 +01:00
Andreas Kling 578a576a98 Kernel: Make VirtualRangeAllocator setup functions propagate errors
If an internal allocation failure occurs while setting up a new VRA,
we'll now propagate the error to our caller instead of panicking.
2021-11-18 21:11:30 +01:00
Andreas Kling 0f22ba5bf2 AK: Make RedBlackTree::try_insert() return ErrorOr<void> instead of bool 2021-11-18 21:11:30 +01:00
Andreas Kling b285323d91 Kernel: Propagate Vector append failures from Inode::apply_flock() 2021-11-18 21:11:30 +01:00
Andreas Kling 1f894cee59 Kernel: Automatically sync shared file mappings when unmapped
To make sure we don't lose changes, shared file mappings will now be
fully synced when they are unmapped, whether explicitly or implicitly
(by the program exiting/crashing/etc.)

This can incur a lot of work, since we don't keep track of dirty pages,
but that's something we can optimize down the road. :^)
2021-11-17 19:35:53 +01:00
Andreas Kling af6358e1e1 Kernel: Allow mmap() with PROT_WRITE+MAP_SHARED
Now that we have a way to flush changes back to disk, let's allow this
type of mapping.
2021-11-17 19:35:13 +01:00
Andreas Kling 32aa37d5dc Kernel+LibC: Add msync() system call
This allows userspace to trigger a full (FIXME) flush of a shared file
mapping to disk. We iterate over all the mapped pages in the VMObject
and write them out to the underlying inode, one by one. This is rather
naive, and there's lots of room for improvement.

Note that shared file mappings are currently not possible since mmap()
returns ENOTSUP for PROT_WRITE+MAP_SHARED. That restriction will be
removed in a subsequent commit. :^)
2021-11-17 19:34:15 +01:00
Andreas Kling f2d5548d7a Kernel: Add MemoryManager::copy_physical_page()
This is a handy helper that copies out the full contents of a physical
page into a caller-provided buffer. It uses quickmapping internally
(and takes the MM lock for the duration.)
2021-11-17 19:32:07 +01:00
Andreas Kling 216e21a1fa AK: Convert AK::Format formatting helpers to returning ErrorOr<void>
This isn't a complete conversion to ErrorOr<void>, but a good chunk.
The end goal here is to propagate buffer allocation failures to the
caller, and allow the use of TRY() with formatting functions.
2021-11-17 00:21:13 +01:00
Daniel Bertalan 304c03f457 Kernel: Reject writable shared file mappings
We have no way of writing changes to memory-mapped files back to disk,
and software relying on this functionality for output would fail
miserably. Let's just return ENOTSUP instead to allow callers to fall
back to standard file IO instead of silently discarding writes.

This makes the LLD port work, which uses memory-mapped files to write
its output by default.
2021-11-17 00:15:30 +01:00
Andrew Kaster f1d8978804 AK+Kernel: Remove implicit conversion from Userspace<T*> to FlatPtr
This feels like it was a refactor transition kind of conversion. The
places that were relying on it can easily be changed to explicitly ask
for the ptr() or a new vaddr() method on Userspace<T*>.

FlatPtr can still implicitly convert to Userspace<T> because the
constructor is not explicit, but there's quite a few more places that
are relying on that conversion.
2021-11-16 00:13:22 +01:00
Andrew Kaster 7243bcb7da Kernel: Use static_ptr_cast to convert between Userspace<T*> types
Some calls of copy_to_user were converting Userspace<T*> to
Userspace<U*> via the implicit conversion to FlatPtr. Change them to use
the static_ptr_cast overload that is designed to express this conversion
2021-11-16 00:13:22 +01:00
Andrew Kaster 194456efdc Kernel: Remove unnecessary StringBuilder from sys$create_thread()
A series of refactors changed Threads to always have a name, and to
store their name as a KString. Before the refactors a StringBuilder was
used to format the default thread name for a non-main thread, but it is
since unused. Remove it and the AK/String related header includes from
the thread syscall implementation file.
2021-11-16 00:13:22 +01:00
Andrew Kaster b1d5d3cc34 Kernel: Avoid redundant bool comparisons in Kernel::Thread
Two instances of comparing a bool with == true or == false, and one
instance where we can just return an expression instead of checking it
to return true on succeess and false on failure.
2021-11-14 22:52:35 +01:00
Andrew Kaster c9d1c12efa Kernel: Remove unused forward declaration of Syscall::StringArgument
The real struct is in Kernel::Syscall::StringArgument, so the namespace
was wrong anyway. But regardless, this forward declaration was unused.
2021-11-14 22:52:35 +01:00
Andrew Kaster 39993a8fab Kernel: Avoid else after return in Process and ThreadSafeRefCounted 2021-11-14 22:52:35 +01:00
Andrew Kaster eb1181b898 Kernel: Convert Process-related const member functions to static
Process::get_syscall_path_argument() and
ProcFSExposedComponent::modified_time() both are independent of this.
2021-11-14 22:52:35 +01:00
Andrew Kaster bc29c7f04f Kernel: Make OpenFileDescriptions::max_open() static and constexpr
This method was just returning a static constexpr member variable
verbatim, so there's no point requiring a member function to observe
its value.
2021-11-14 22:52:35 +01:00
Andrew Kaster fff265a9a9 Kernel: Suppress clang-tidy warning on declaration of s_mm_lock
Seems we are declaring this guy as extern RecursiveSpinLock s_mm_lock;
in both Thread.h and MemoryManager.h. Smells funny for sure.
2021-11-14 22:52:35 +01:00
Andrew Kaster 542640e766 Kernel: Mark private members of SharedCommittedCowPages as private
They were marked public, which seems like an obvious typo.
2021-11-14 22:52:35 +01:00
Andrew Kaster 16d8556472 Kernel: Remove redundant return statement from Spinlock::lock()
Also from RecursiveSpinlock::lock()
2021-11-14 22:52:35 +01:00
Andrew Kaster 5920b84696 Kernel: Stop truncating PageTableEntry::raw(), and make set_bit private
set_bit() in both PageDirectory and PageTableEntry are now private, and
remove a useless cast from PageTableEntry::raw().
2021-11-14 22:52:35 +01:00
Andrew Kaster e824bead54 Kernel: Resolve clang-tidy readability-qualified-auto warning
... In files included by Kernel/Process.cpp or Kernel/Thread.cpp
2021-11-14 22:52:35 +01:00
Andrew Kaster 65edc62c02 Kernel: Resolve clang-tidy readability-make-member-function-const
... In files included from Kernel/Thread.cpp or Kernel/Process.cpp

Some places the warning is suppressed, because we do not want a const
object do have non-const access to the returned sub-object.
2021-11-14 22:52:35 +01:00
Andrew Kaster a92132e44a Kernel: Resolve clang-tidy readability-implicit-bool-conversion warnings
... In files included from Kernel/Process.cpp and Kernel/Thread.cpp
2021-11-14 22:52:35 +01:00
Andrew Kaster 7014d37dd6 AK+Kernel: Suppress clang-tidy warnings from the cert-* category
cert-dcl50-cpp: No variadic functions, suppressed in RefCounted and
ThreadSafeRefCounted for implementing the magic one_ref_left and
will_be_destroyed functions.

cert-dcl58-cpp: No opening ::std, suppressed in the places we put names
in ::std to aid tools (move, forward, nullptr_t, align_val_t, etc).
2021-11-14 22:52:35 +01:00
Liav A 0e5983e603 Kernel/AHCI: Simplify wait and timeout pattern significantly
Instead of repeating ourselves with the pattern of waiting for some
condition to be met, we can have a general method for this task,
and then we can provide the retry count, the required delay and a lambda
function for the checked condition.
2021-11-13 23:35:27 +01:00
Liav A 557351724a Kernel/AHCI: Remove unnecessary AHCIPort class member 2021-11-13 23:35:27 +01:00
Liav A 3ea49259df Kernel/Storage: Don't use interrupts when resetting SATA AHCI devices
Don't use interrupts when trying to reset a device that is connected to
a port on the AHCI controller, and instead poll for changes in status to
break out from the loop. At the worst case scenario we can wait 0.01
seconds for each SATA reset.
2021-11-13 12:53:57 +01:00
Liav A 1ae76676a5 Kernel/Storage: Don't use interrupts when identifying AHCI devices
Don't use interrupts when trying to identify a device that is connected
to a port on the AHCI controller, and instead poll for changes in status
to end the transaction.

Not only this simplifies the initialization sequence, it ensures that
for whatever reason the controller doesn't send an IRQ, we are never
getting stuck at this point.
2021-11-13 10:05:22 +01:00
Liav A 4dc3617f3c Kernel/Storage: Move all ATA related code to a new subdirectory
Like what happened with the PCI and USB code, this feels like the right
thing to do because we can improve on the ATA capabilities and keep it
distinguished from the rest of the subsystem.
2021-11-13 10:05:22 +01:00
Daniel Bertalan 648a139af3 Kernel+LibC: Pass off_t to pread() via a pointer
`off_t` is a 64-bit signed integer, so passing it in a register on i686
is not the best idea.

This fix gets us one step closer to making the LLVM port work.
2021-11-13 10:04:46 +01:00
Jelle Raaijmakers 86a1ff5204 Kernel: Drain I8042 PS/2 keyboard output after enabling
As soon as we enable the first PS/2 port on the I8042 controller, the
output buffer may become full. We need to drain it before attempting
any new commands with the controller (such as enabling the second PS/2
port).

Fixes #10872.
2021-11-12 07:35:18 +01:00
Andreas Kling 80d4e830a0 Everywhere: Pass AK::ReadonlyBytes by value 2021-11-11 01:27:46 +01:00
Andreas Kling 8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Andreas Kling ad5d217e76 Kernel/Ext2FS: Propagate HashMap errors instead of panicking 2021-11-11 01:27:46 +01:00
Andreas Kling 9d1f238450 AK: Make HashTable and HashMap try_* functions return ErrorOr<T>
This allows us to use TRY() and MUST() with them.
2021-11-11 01:27:46 +01:00
Andreas Kling f86ee71f65 Kernel/Ext2FS: Propagate errors from block list computation functions 2021-11-10 21:58:58 +01:00
Andreas Kling 4661ca5f15 Kernel: Propagate Vector append errors in two places in Ext2FS
There are a bunch more of these, just taking care of some simple ones.
2021-11-10 21:58:58 +01:00
Andreas Kling 5ce753b74d Kernel: Make Inode::traverse_as_directory() callback return ErrorOr
This allows us to propagate errors from inside the callback with TRY().
2021-11-10 21:58:58 +01:00
Andreas Kling 88b6428c25 AK: Make Vector::try_* functions return ErrorOr<void>
Instead of signalling allocation failure with a bool return value
(false), we now use ErrorOr<void> and return ENOMEM as appropriate.
This allows us to use TRY() and MUST() with Vector. :^)
2021-11-10 21:58:58 +01:00
Andreas Kling 5f7d008791 AK+Everywhere: Stop including Vector.h from StringView.h
Preparation for using Error.h from Vector.h. This required moving some
things out of line.
2021-11-10 21:58:58 +01:00
Ben Wiederhake ad5061bb7a Kernel: Make (f)statvfs report filesystem ID correctly 2021-11-10 16:13:10 +01:00
Ben Wiederhake 631447da57 Kernel: Fix TOCTOU in fstatvfs
In particular, fstatvfs used to assume that a file that was earlier
opened using some path will forever be at that path. This is wrong, and
in the meantime new mounts and new filesystems could take up the
filename or directories, leading to a completely inaccurate result.
This commit improves the situation:
- All filesystem information is now always accurate.
- The mount flags *might* be erroneously zero, if the custody for the
  open file is not available. I don't know when that might happen, but
  it is definitely not the typical case.
2021-11-10 16:13:10 +01:00
Ben Wiederhake bf7a2ff941 AK+Kernel: Make BitmapView read-only 2021-11-10 14:39:42 +01:00
Ben Wiederhake 850db15d66 Everywhere: Remove unused AK/Bitmap includes 2021-11-10 14:39:42 +01:00
Andreas Kling 79fa9765ca Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace!
This was a slightly tedious refactoring that took a long time, so it's
not unlikely that some bugs crept in.

Nevertheless, it does pass basic functionality testing, and it's just
real nice to finally see the same pattern in all contexts. :^)
2021-11-08 01:10:53 +01:00
Ben Wiederhake 3582184d8c Kernel: Expose inode information in /proc/pid/fds 2021-11-08 00:34:58 +01:00
AMACB 60362ef401 Kernel: Initialize regs.fs in Processor::init_context
Commit f285241c replaced the line that sets regs.fs with a line that
sets regs.gs, but not vice versa.
2021-11-06 11:54:28 +01:00
Liav A 066b1183cd Kernel: Return ENOTIMPL when trying to read from SysFS inodes
Instead of asserting, just return reasonable error back to userland.
2021-11-05 16:26:45 +02:00
Jelle Raaijmakers a4b1c0fd0c Kernel: Process available VMWare mouse events immediately
The Qemu I8042 controller does not send one IRQ per event, it sends
over four since it will not stop trying to emulate the PS/2 mouse.

If the VMWare backdoor is active, a fake I8042 mouse event will be sent
that we can then use to check if there are VMWare mouse events present.
However, we were only processing one mouse event at a time, even though
multiple events could have been queued up. Luckily this does not often
lead to issues, since after the first IRQ we would still get three
additional interrupts that would then empty the queue.

This change makes sure we always empty the event queue immediately,
instead of waiting on the next interrupt to happen. Functionally this
changes nothing - it could merely improve latency by not waiting for
new interrupts to come in.

Coincidently, this brings our implementation closer to how Linux deals
with the VMMouse.
2021-11-04 18:53:37 +01:00