Commit Graph

6782 Commits

Author SHA1 Message Date
Andreas Kling
f630d0f095 Kernel: Mark sys$realpath() as not needing the big lock
This syscall doesn't access any data that was implicitly protected by
the big lock.
2022-03-08 00:19:49 +01:00
Andreas Kling
580d89f093 Kernel: Put Process unveil state in a SpinlockProtected container
This makes path resolution safe to perform without holding the big lock.
2022-03-08 00:19:49 +01:00
Andreas Kling
24f02bd421 Kernel: Put Process's current directory in a SpinlockProtected
Also let's call it "current_directory" instead of "cwd" everywhere.
2022-03-08 00:19:49 +01:00
Andreas Kling
71792e4b3f Kernel: Make SpinlockProtected constructor forward all arguments
This allows you to instantiate SpinlockProtected<T> where T requires
constructor arguments.
2022-03-08 00:19:49 +01:00
Andreas Kling
7543c34d07 Kernel: Mark sys$anon_create() as not needing the big lock
This syscall is already safe for no-big-lock since it doesn't access any
unprotected data.
2022-03-08 00:19:49 +01:00
Idan Horowitz
29eee390ec Kernel: Implement kmalloc_good_size for the new kmalloc
This lets kmalloc-aware data structures like Vector and HashTable use
up the extra wasted space we allocate in the slab heaps & heap chunks.
2022-03-08 00:46:25 +02:00
Andreas Kling
baa6ff5649 Kernel: Wrap HIDManagement keymap data in SpinlockProtected
This serializes access to the current keymap data everywhere in the
kernel, allowing to mark sys$setkeymap() as not needing the big lock.
2022-03-07 16:35:23 +01:00
Ali Mohammad Pur
6608812e4b Kernel: Over-align the FPUState on the stack in sigreturn
The stack is misaligned at this point for some reason, this is a hack
that makes the resulting object "correctly" aligned, thus avoiding a
KUBSAN error.
2022-03-04 20:07:05 +01:00
Ali Mohammad Pur
23f6a00162 Kernel: Fix silly unintentional use of operator,
Everyone's favourite activity, copy pasta, has produced yet another
confusing use of operator,; fix this and make it less confusing.
2022-03-04 20:07:05 +01:00
Ali Mohammad Pur
88d7bf7362 Kernel: Save and restore FPU state on signal dispatch on i386/x86_64 2022-03-04 20:07:05 +01:00
Ali Mohammad Pur
e14e919b78 Kernel: Fill some siginfo and ucontext fields on SA_SIGINFO
There's no reason to fill in any of these fields if SA_SIGINFO is not
given, as the signal handler won't be reading from them at all.
2022-03-04 20:07:05 +01:00
Ali Mohammad Pur
4bd01b7fe9 Kernel: Add support for SA_SIGINFO
We currently don't really populate most of the fields, but that can
wait :^)
2022-03-04 20:07:05 +01:00
Ali Mohammad Pur
585054d68b Kernel: Comment the living daylights out of signal trampoline/sigreturn
Mere mortals like myself cannot understand more than two lines of
assembly without a million comments explaining what's happening, so do
that and make sure no one has to go on a wild stack state chase when
hacking on these.
2022-03-04 20:07:05 +01:00
Ali Mohammad Pur
7238c946f0 Kernel: Make the signal trampoline stack alignment a bit more readable
The comments were confusing, and had a mathematical error, stop trying
to be clever and just let the computer do the math.
Also assert that we're pushing exactly as many stack elements as we're
using for the alignment calculations.
2022-03-04 20:07:05 +01:00
Ali Mohammad Pur
848eaf2220 Kernel: Reject sigaction() with SA_SIGINFO
We can't handle this, so let sigaction() fail instead of PANIC()'ing
later when we try to dispatch a signal with SA_SIGINFO set.
2022-03-04 20:07:05 +01:00
Ali Mohammad Pur
cf63447044 Kernel: Move signal handlers from being thread state to process state
POSIX requires that sigaction() and friends set a _process-wide_ signal
handler, so move signal handlers and flags inside Process.
This also fixes a "pid/tid confusion" FIXME, as we can now send the
signal to the process and let that decide which thread should get the
signal (which is the thread with tid==pid, but that's now the Process's
problem).
Note that each thread still retains its signal mask, as that is local to
each thread.
2022-03-04 20:07:05 +01:00
Jelle Raaijmakers
4f91616759 Kernel: Report AC'97 vendor and device ID 2022-03-04 11:07:25 +01:00
Jakub Berkop
d01d754b83 Kernel: Fixed behavior of repeated calls to register_string
Previously register_string would return incorrect values when
called multiple times with the same input. This patch makes this
function return the same index, identical strings. This change was
required, as this functionality is now being used with read syscall
profiling, (#12465), which uses 'register_string' to registers file
path on every read syscall.
2022-03-03 14:53:35 -08:00
Liav A
30eeba1981 Kernel/Storage: Don't try to enumerate PCI adapters if PCI is disabled
If there's no PCI bus, then it's safe to assume that we run on a x86
machine that has an ISA IDE controller in the system. In such case, we
just instantiate a ISAIDEController object that assumes fixed locations
of IDE IO ports.
2022-03-02 18:41:54 +01:00
Liav A
fafa339264 Kernel/Graphics: Don't try to enumerate PCI adapters if PCI is disabled
If there's no PCI bus, then it's safe to assume that the x86 machine we
run on supports VGA text mode console output with an ISA VGA adapter.
If this is the case, we just instantiate a ISAVGAAdapter object that
assumes this situation and allows us to boot into VGA text mode console.
2022-03-02 18:41:54 +01:00
Liav A
15315be55c Kernel/Audio: Don't try to enumerate PCI adapters if PCI is disabled 2022-03-02 18:41:54 +01:00
Liav A
71de4f7114 Kernel/Net: Don't try to enumerate PCI adapters if PCI is disabled 2022-03-02 18:41:54 +01:00
Liav A
b849e4f907 Kernel/PCI: Don't create /proc/pci if PCI is disabled
Reading from /proc/pci assumes we have PCI enabled and also enumerated.
However, if PCI is disabled for some reason, we can't allow the user to
read from it as there's no valuable data we can supply.
2022-03-02 18:41:54 +01:00
Liav A
2272d93215 Kernel/PCI: Unify disable checks under PCI::Access::is_disabled method
To declare that we don't have a PCI bus in the system we do two things:
1. Probe IO ports before enabling access -
In case we are using the QEMU ISA-PC machine type, IO probing results in
floating bus condition (returning 0xFF values), thus, we know we don't
have PCI bus on the system.
2. Allow the user to specify to not use the PCI bus at all in the kernel
commandline.
2022-03-02 18:41:54 +01:00
Liav A
f6e635938f Kernel: Change PCI access commandline option to also represent no access
This change allow the user to request the kernel to not use any PCI
resources/devices at all.

Also, don't try to initialize devices that rely on PCI if disabled.
2022-03-02 18:41:54 +01:00
Andreas Kling
884ebc42b1 Kernel: Respect actual framebuffer pitch
Instead of winging it with "width * 4", use the actual pitch since it
may be different.

This makes the kernel text console show up in native 1368x768 on my
ThinkPad X250. :^)
2022-03-01 19:01:19 +01:00
Lucas CHOLLET
839d3d9f74 Kernel: Add getrusage() syscall
Only the two timeval fields are maintained, as required by the POSIX
standard.
2022-02-28 20:09:37 +01:00
Jelle Raaijmakers
c3c683c9e1 Kernel: Whitespace and Error cleanup in AC97
No functional changes.
2022-02-27 20:38:34 +01:00
Jelle Raaijmakers
0e78e6b1e8 Kernel: Do not reset AC'97 PCM out on buffer completion
We now only reset the PCM out channel during initialization, and handle
the case where the channel's current index has passed the last valid
index properly.

This fixes issues with stuttering audio between multiple subsequent
`aplay` invocations, for example.
2022-02-27 20:38:34 +01:00
Jelle Raaijmakers
694ff12272 Kernel: Read and report AC'97 codec revision
This might help with debugging on bare metal. Since the minimum version
that can be specified is revision 2.1, and we do not use any feature
from revision 2.2 or newer, this is merely future-proofing ourselves
for new features yet to be built. Additionally, removing the `VERIFY()`
ensures we will not crash on cards that only support earlier revisions.
2022-02-27 20:38:34 +01:00
Jelle Raaijmakers
9a46573ffc Kernel: Make AC'97 initialization fallible
Let's not crash in `AudioManagement` if we run into trouble.
2022-02-27 20:38:34 +01:00
Idan Horowitz
feb00b7105 Everywhere: Make JSON serialization fallible
This allows us to eliminate a major source of infallible allocation in
the Kernel, as well as lay down the groundwork for OOM fallibility in
userland.
2022-02-27 20:37:57 +01:00
Idan Horowitz
6682afb5d4 Kernel: Add UDPSocket::try_for_each() for fallible iteration
This API will allow users to short circuit iteration and properly
propagate errors.
2022-02-27 20:37:57 +01:00
Idan Horowitz
aabc8d348b Kernel: Add TCPSocket::try_for_each() for fallible iteration
This API will allow users to short circuit iteration and properly
propagate errors.
2022-02-27 20:37:57 +01:00
Idan Horowitz
24be52b3f5 Kernel: Add LocalSocket::try_for_each() for fallible iteration
This API will allow users to short circuit iteration and properly
propagate errors.
2022-02-27 20:37:57 +01:00
Idan Horowitz
74ab8ccde0 Kernel: Add NetworkingManagement::try_for_each() for fallible iteration
This API will allow users to short circuit iteration and properly
propagate errors.
2022-02-27 20:37:57 +01:00
Idan Horowitz
da5d678f2a Kernel: Add DeviceManagement::try_for_each() for fallible iteration
This API will allow users to short circuit iteration and properly
propagate errors.
2022-02-27 20:37:57 +01:00
Idan Horowitz
064b93c2ad Kernel: Add OpenFileDescriptions::try_enumerate for fallible iteration
This API will allow users to short circuit iteration and properly
propagate errors.
2022-02-27 20:37:57 +01:00
Idan Horowitz
aca6c0c031 Kernel: Add Process::try_for_each_thread() for fallible iteration
This API will allow users to short circuit iteration and properly
propagate errors.
2022-02-27 20:37:57 +01:00
Idan Horowitz
f4875b9967 Kernel: Add Processor::try_for_each() for fallible iteration
This API will allow users to short circuit iteration and properly
propagate errors.
2022-02-27 20:37:57 +01:00
Idan Horowitz
853f7092f8 Kernel: Defer signal handling without a register capture earlier
We were deferring the signal handling after already marking the signal
as handling, which led to some failures in the Shell tests.
2022-02-27 00:38:00 +02:00
Idan Horowitz
011bd06053 Kernel: Set CS selector when initializing thread context on x86_64
These are not technically required, since the Thread constructor
already sets these, but they are set on i686, so let's try and keep
consistent behaviour between the different archs.
2022-02-27 00:38:00 +02:00
Jelle Raaijmakers
8bf0e04c16 Kernel: Allow setting AC'97 sample rate during playback
The Qemu AC'97 device stops its PCM channel's DMA engine when it is
running and the sample rate is changed. We now make sure the DMA engine
is restarted after changing the sample rate, allowing you to e.g. run
`asctl set r 22050` during `aplay` playback.
2022-02-26 20:23:15 +01:00
Jelle Raaijmakers
e2891e9aa4 Kernel: Clean up AC'97 driver code style
* Remove braces from single-line conditionals
* Use aggregate initialization style for member variables
2022-02-26 20:23:15 +01:00
Peter Ross
9d94c85b6a Kernel: Use IO init method for Bochs emulated VGA adapter
In short: QEMU supports both Memory-Mapped-IO and classic IO methods
for controlling the emulated VGA device. Bochs and VirtualBox only
support the classic IO method. An excellent write up on the history of
these interfaces can be found here:
https://www.kraxel.org/blog/2018/10/qemu-vga-emulation-and-bochs-display

The IO method was how things were done originally in SerenityOS. Commit
6a728e2d76 introduced the MMIO method for
all devices, breaking Bochs and VirtualBox compatibility. Later in
commit 6a9dc5562d the classic IO method
was restored for VirtualBox graphics adapters.

QEMU and Bochs use the same PCI VID/DID (0x1234/0x1111) for the emulated
VGA adapter. To distinguish betwen QEMU and Bochs we use the PCI
revision ID field (0=Bochs, 2=QEMU).
2022-02-24 09:08:04 +02:00
Liav A
a38a637f5c Kernel/Audio: Remove the SB16 driver
This driver is not tested and probably not used on any modern hardware
machine, because it is plugged into the ISA bus and not the PCI bus.
Also, the run script doesn't utilize this device anymore, making it more
hard to test this driver and to ensure it doesn't rot.
2022-02-24 07:26:45 +01:00
Brian Gianforcaro
d05fa14e52 Kernel: Use TRY() when validating clock_id in TimeManagement
Gets rid of a bit of code duplication, and makes the API more consistent
with the style we are moving towards.
2022-02-21 15:47:51 -08:00
Tom
a5ce5564a9 Kernel: Fix allocating identity-mapped APIC memory on x86_64
We were not allocating enough memory due to using u32 instead of
FlatPtr for each AP's stack pointer.
2022-02-21 20:44:09 +02:00
Idan Horowitz
5fa75dbcda Kernel: Try to dispatch pending signals on context switch
This ensures that processes that don't perform any syscalls will also
eventually receive signals.
2022-02-21 19:42:16 +01:00
Idan Horowitz
0911112286 Kernel: VERIFY that signals are not sent to Kernel processes
Kernel processes can't handle signals, nor should they ever receive any
2022-02-21 19:42:16 +01:00