Commit graph

6247 commits

Author SHA1 Message Date
Idan Horowitz d18b3eb53d Kernel: Add the SO_OOBINLINE SOL_SOCKET-level option macro
This is not actually implemented, as we don't have any support for
out-of-band right now, but this is required for some ports to compile.
2021-12-05 12:53:29 +01:00
Idan Horowitz 613ade9dec Kernel: Implement the SO_DONTROUTE SOL_SOCKET-level option 2021-12-05 12:53:29 +01:00
Idan Horowitz 641498954f Kernel: Implement the SO_ACCEPTCONN SOL_SOCKET-level option 2021-12-05 12:53:29 +01:00
Idan Horowitz a0e2fedc20 Kernel: Stub out the SO_DEBUG SOL_SOCKET-level option 2021-12-05 12:53:29 +01:00
Idan Horowitz e521ffd156 Kernel: Add support for the MSG_WAITALL sys$recvmsg flag 2021-12-05 12:53:29 +01:00
Idan Horowitz 5514d60d8d Kernel: Add support for the MSG_DONTROUTE sys$sendmsg flag 2021-12-05 12:53:29 +01:00
Idan Horowitz 0a36d1459a Kernel: Return EINVAL on unsupported LocalSocket ioctl
ENOTTY is used to signify that no ioctl interface is provided at all,
but LocalSockets do support the FIONREAD ioctl.
2021-12-05 12:53:29 +01:00
Daniel Bertalan 294cb3cef4 Kernel: Wrap x86 assembly behind ARCH(...) in Syscall.h
Unlike GCC, Clang parses assembly eagerly, and immediately rejects
inline assembly that's not for the right architecture.
2021-12-04 11:59:59 -08:00
Daniel Bertalan 9b90f1fed5 Kernel: Do not do integer to pointer conversion in constexpr functions
Creating pointers from arbitrary values is not a valid thing to do in
constexpr functions. Furthermore, this functions is always called with
runtime values anyways, so there's no use in having it be constexpr.
Instead, make it ALWAYS_INLINE.
2021-12-04 11:59:59 -08:00
Daniel Bertalan 8e2d0c8d5c Kernel: Do not return a null ref in Processor::current on aarch64
Clang rejects binding a reference to a null pointer at compile-time.
Let's just crash explicitly, instead of waiting for a null dereference
to mess things up.
2021-12-04 11:59:59 -08:00
Idan Horowitz 711a7104f3 Kernel: Handle invalid stack pointer during signal dispatch
Instead of crashing the kernel, we simply terminate the process.
2021-12-01 21:44:11 +02:00
Idan Horowitz 40f64d7379 Kernel: Dispatch handle-able signals instead of crashing if possible
This matches the behaviour of the other *nixs and allows processes to
try and recover from such signals in userland.
2021-12-01 21:44:11 +02:00
Idan Horowitz f415218afe Kernel+LibC: Implement sigaltstack()
This is required for compiling wine for serenity
2021-12-01 21:44:11 +02:00
Idan Horowitz d5d0eb45bf Kernel: Clear up some comments in the sys$mprotect implementation 2021-12-01 21:44:11 +02:00
Idan Horowitz f27bbec7b2 Kernel: Move incorrect early return in sys$mprotect
Since we're iterating over multiple regions that interesect with the
requested range, just one of them having the requested access flags
is not enough to finish the syscall early.
2021-12-01 21:44:11 +02:00
Idan Horowitz a9e436c4a3 Kernel: Replace usages of SIGSTKFLT with SIGSEGV
SIGSTKFLT is a signal that signifies a stack fault in a x87 coprocessor,
this signal is not POSIX and also unused by Linux and the BSDs, so let's
use SIGSEGV so programs that setup signal handlers for the common
signals could still handle them in serenity.
2021-12-01 21:44:11 +02:00
Idan Horowitz 4ca39c7110 Kernel: Move the expand_range_to_page_boundaries helper to MemoryManager
This helper can (and will) be used in more parts of the kernel besides
the mmap-family of syscalls.
2021-12-01 21:44:11 +02:00
Idan Horowitz ff6b43734c Kernel: Add Region::clear_to_zero
This helper method can be used to quickly and efficiently zero out a
region.
2021-12-01 21:44:11 +02:00
Idan Horowitz 5f95a1a7b7 LibC: Define the MADV_DONTNEED madvise advice macro
This isn't actually implemented at the moment, but it is required for
wine to compile
2021-12-01 21:44:11 +02:00
Idan Horowitz fc13d0782f LibC: Make the madvise advice field a value instead of a bitfield
The advices are almost always exclusive of one another, and while POSIX
does not define madvise, most other unix-like and *BSD systems also only
accept a singular value per call.
2021-12-01 21:44:11 +02:00
Idan Horowitz 48f92f6482 LibC: Add the SIGFPE si_code macros 2021-12-01 21:44:11 +02:00
James Mintram 224b865fda Kernel: Add an x86 include check+error in x86/TSS.h 2021-12-01 11:22:04 -08:00
James Mintram b08eb37b11 Kernel: Add an x86 include check+error in x86/TrapFrame.h 2021-12-01 11:22:04 -08:00
James Mintram 80cdfee10a Kernel: Add an x86 include check+error in x86/Spinlock.h 2021-12-01 11:22:04 -08:00
James Mintram 34b341e35d Kernel: Add an x86 include check+error in x86/RegisterState.h 2021-12-01 11:22:04 -08:00
James Mintram 1dc1412dee Kernel: Add an x86 include check+error in x86/ProcessorInfo.h 2021-12-01 11:22:04 -08:00
James Mintram e20884dc0c Kernel: Add an x86 include check+error in x86/Processor.h 2021-12-01 11:22:04 -08:00
James Mintram eb33df0c30 Kernel: Add an x86 include check+error in x86/PageFault.h 2021-12-01 11:22:04 -08:00
James Mintram 17fb2adf61 Kernel: Add an x86 include check+error in x86/PageDirectory.h 2021-12-01 11:22:04 -08:00
James Mintram 70a18a2271 Kernel: Add an x86 include check+error in x86/MSR.h 2021-12-01 11:22:04 -08:00
James Mintram bffc3da9d7 Kernel: Add an x86 include check+error in x86/ISRStubs.h 2021-12-01 11:22:04 -08:00
James Mintram 1e5b82f0c6 Kernel: Add an x86 include check+error in x86/IO.h 2021-12-01 11:22:04 -08:00
James Mintram b9ae6daa02 Kernel: Add an x86 include check+error in x86/Inerrupts.h 2021-12-01 11:22:04 -08:00
James Mintram ed2aa96511 Kernel: Add an x86 include check+error in x86/InerruptDisabler.h 2021-12-01 11:22:04 -08:00
James Mintram 62d86afee9 Kernel: Add an x86 include check+error in x86/DescriptorTable.h 2021-12-01 11:22:04 -08:00
James Mintram db1fbdabf9 Kernel: Add an x86 include check+error in x86/CPUID.h 2021-12-01 11:22:04 -08:00
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