Commit graph

4799 commits

Author SHA1 Message Date
Gunnar Beutner 9077c64d37 Kernel: Correct spelling mistake 2021-06-26 11:08:52 +02:00
Gunnar Beutner 078eeb7bb0 Kernel: Make addresses returned by kmalloc() properly aligned for x86_64 2021-06-26 11:08:52 +02:00
Gunnar Beutner 1e20dd2a45 Kernel: Add PML4T support for the PageDirectory class 2021-06-26 11:08:52 +02:00
Gunnar Beutner f5cd366006 Kernel: Fix memcpy and memset for x86_64
Those size_ts sure are growing up fast.
2021-06-26 11:08:52 +02:00
Gunnar Beutner c4acfdc0fb Kernel: Add slab allocator for 256 bytes
Our types are getting a tiny bit larger for x86_64 so we need another
slab allocator to deal with that.
2021-06-26 11:08:52 +02:00
Gunnar Beutner e52051903b Kernel: Fix off-by-one error in Processor::write_raw_gdt_entry 2021-06-26 11:08:52 +02:00
Gunnar Beutner f630299d49 Kernel: Add support for setting up a x86_64 GDT once in C++ land 2021-06-26 11:08:52 +02:00
Gunnar Beutner 29d9666e02 Kernel: Fix GDT limits
The GDT limits are inclusive, so for correctness we should subtract
one from the structs' size.
2021-06-26 11:08:52 +02:00
Sahan Fernando b9ad6058aa Kernel: Add VirtIOGPU graphics device 2021-06-25 19:26:30 +02:00
Sahan Fernando b569b2df35 Kernel: Don't clear VirtualConsoles when initializing
Instead of calling clear() for each virtual console we initialize, we
only call clear() when activating it from ConsoleManagement.
2021-06-25 19:26:30 +02:00
Sahan Fernando ae5d961d97 Kernel: Pass TTY-switch keyboard combo to userspace 2021-06-25 19:26:30 +02:00
Sahan Fernando 4f53e52ca3 Kernel: Fix use after AK::move in Kernel::TimerQueue 2021-06-25 19:26:30 +02:00
Sahan Fernando 974e996d33 Userland: Add FB_FLUSH ioctl for fbdev 2021-06-25 19:26:30 +02:00
Sahan Fernando 34e9fa4d3b Kernel: Abstract FramebufferConsole away from contiguous physical range
Currently, Kernel::Graphics::FramebufferConsole is written assuming that
the underlying framebuffer memory exists in physically contiguous
memory. There are a bunch of framebuffer devices that would need to use
the components of FramebufferConsole (in particular access to the kernel
bitmap font rendering logic). To reduce code duplication, framebuffer
console has been split into two parts, the abstract
GenericFramebufferConsole class which does the rendering, and the
ContiguousFramebufferConsole class which contains all logic related to
managing the underling vm object.

Also, a new flush method has been added to the class, to support devices
that require an extra flush step to render.
2021-06-25 19:26:30 +02:00
Sahan Fernando cf1c8eb778 Kernel: Add Scheduler::is_initialized 2021-06-25 19:26:30 +02:00
Alexander 2b4cab284c Kernel/AHCI: Dont assume ports start at 0
This fixes a bug that occurs when the controller's ports are not
(internally) numbered sequentially.
This is done by checking the bits set in PI.
This bug was found on bare-metal, on a laptop with 1 Port that
was reported as port 4.
2021-06-25 16:27:01 +02:00
Alexander e9b7d58d10 Kernel/AHCI: Fix shift of 1
This makes the 1 in the shift unsigned.
This also changes the is_set_at parameter to be a u8.
2021-06-25 16:27:01 +02:00
Gunnar Beutner c9747a3236 Kernel: Build the x86_64 kernel as an ELF32 executable
Multiboot only supports ELF32 executables. This changes the build
process to build an ELF32 executable which has a 32-bit entry point,
but consists of mostly 64-bit code.
2021-06-25 15:19:09 +02:00
Gunnar Beutner 04ba5cfcad Kernel: Ensure that the Multiboot header is placed into the first 8kB
The Multiboot header must be within the first 8kB of the executable
for it to be picked up by QEMU, GRUB and other multiboot-capable
boot loaders.
2021-06-25 15:19:09 +02:00
Gunnar Beutner 4c555684b7 Kernel: Set an appropriate GDT for 64-bit mode 2021-06-25 15:19:09 +02:00
Gunnar Beutner d84abe51f5 Kernel: Use PML4T for 64-bit mode 2021-06-25 15:19:09 +02:00
Gunnar Beutner 13e4093da4 Kernel: Move Multiboot header into a separate file 2021-06-25 15:19:09 +02:00
Gunnar Beutner 19c0498ccc Kernel: Update the x86_64 boot code to match i386's code 2021-06-25 15:19:09 +02:00
Daniel Bertalan ffb118265b Kernel: Remove superfluous alignas(T) from KResultOr<T>
Since `m_storage` is already guaranteed to be correctly aligned for the
type, we can forgo specifying it for the entire class.

This fixes an error: previously, this would *force* the value type's
alignment on the entire class, which would try to make 1-byte aligned
ints with `KResultOr<bool>`. GCC somehow compiled this (probably just
ignored it), but this caused a build error with Clang.

Closes #8072
2021-06-24 17:35:49 +04:30
Daniel Bertalan 221bd464a0 Kernel: Fix attribute ordering
Clang requires that attributes declared using the bracketed
`[[attr_name]]` syntax come before those with
`__attribute__((attr-name))`.

This fixes a Clang build error.
2021-06-24 17:35:49 +04:30
Daniel Bertalan 74535628a8 Kernel: Use proper Atomic<T> types in CPU
This is needed because Clang's intrinsic atomic functions behave weirdly
if only one of their pointer arguments is volatile.
2021-06-24 17:35:49 +04:30
Daniel Bertalan f820917a76 Everywhere: Use nothrow new with adopt_{ref,own}_if_nonnull
This commit converts naked `new`s to `AK::try_make` and `AK::try_create`
wherever possible. If the called constructor is private, this can not be
done, so we instead now use the standard-defined and compiler-agnostic
`new (nothrow)`.
2021-06-24 17:35:49 +04:30
Daniel Bertalan 5491e0cdcc AK+Kernel: Make fallible allocations compiler-agnostic
In standard C++, operators `new` and `new[]` are guaranteed to return a
valid (non-null) pointer and throw an exception if the allocation
couldn't be performed. Based on this, compilers did not check the
returned pointer before attempting to use them for object construction.

To avoid this, the allocator operators were changed to be `noexcept` in
PR #7026, which made GCC emit the desired null checks. Unfortunately,
this is a non-standard feature which meant that Clang would not accept
these function definitions, as it did not match its expected
declaration.

To make compiling using Clang possible, the special "nothrow" versions
of `new` are implemented in this commit. These take a tag type of
`std::nothrow_t` (used for disambiguating from placement new/etc.), and
are allowed by the standard to return null. There is a global variable,
`std::nothrow`, declared with this type, which is also exported into the
global namespace.

To perform fallible allocations, the following syntax should be used:

```cpp
auto ptr = new (nothrow) T;
```

As we don't support exceptions in the kernel, the only way of uphold the
"throwing" new's guarantee is to abort if the allocation couldn't be
performed. Once we have proper OOM handling in the kernel, this should
only be used for critical allocations, where we wouldn't be able to
recover from allocation failures anyway.
2021-06-24 17:35:49 +04:30
Max Wipfli 84c0f98fb2 Kernel: Reimplement the dbgputch and dbgputstr syscalls
This rewrites the dbgputch and dbgputstr system calls as wrappers of
kstdio.h.

This fixes a bug where only the Kernel's debug output was also sent to
a serial debugger, while the userspace's debug output was only sent to
the Bochs debugger.

This also fixes a bug where debug output from one process would
sometimes "interrupt" the debug output from another process in the
middle of a line.
2021-06-24 10:29:09 +02:00
Max Wipfli 67067904f5 Kernel: Add dbgputch() to kstdio.h
This adds a dbgputch() alongside dbgputstr() in kstdio.h. The function
already existed as the static function debugger_out(). It has now been
exposed to users of kstdio.h.
2021-06-24 10:29:09 +02:00
Gunnar Beutner 441d6dcdf9 Kernel: Fix compiling TmpFSInode::write_bytes on x86_64 2021-06-24 09:27:13 +02:00
Gunnar Beutner 38fca26f54 Kernel: Add stubs for missing x86_64 functionality
This adds just enough stubs to make the kernel compile on x86_64. Obviously
it won't do anything useful - in fact it won't even attempt to boot because
Multiboot doesn't support ELF64 binaries - but it gets those compiler errors
out of the way so more progress can be made getting all the missing
functionality in place.
2021-06-24 09:27:13 +02:00
Gunnar Beutner dc3cc7368b Kernel: Don't use function-level static variables
When building the kernel for x86_64 the compiler injects calls to
__cxa_guard_acquire which depends on a bunch of pthread functions
we don't have in the kernel.
2021-06-24 09:27:13 +02:00
Hendiadyoin1 62f9377656 Kernel: Move special sections into Sections.h
This also removes a lot of CPU.h includes infavor for Sections.h
2021-06-24 00:38:23 +02:00
Hendiadyoin1 925be2758e Kernel: Remove unused CPU.h includes
In most cases we did not need it at all, in other, we only needed one
header from it
2021-06-24 00:38:23 +02:00
Hendiadyoin1 553ea3036d Kernel: Remove PAGE_SIZE from CPU.h
We have that information in LibC, lets use that instead
2021-06-24 00:38:23 +02:00
Hendiadyoin1 7ca3d413f7 Kernel: Pull apart CPU.h
This does not add any functional changes
2021-06-24 00:38:23 +02:00
Sam Atkins ab7023dbe5 Kernel: Ensure Ext2FSInode's lookup is populated before using it
This fixes #8133.

Ext2FSInode::remove_child() searches the lookup cache, so if it's not
initialized, removing the child fails. If the child was a directory,
this led to it being corrupted and having 0 children.

I also added populate_lookup_cache to add_child. I hadn't seen any
bugs there, but if the cache wasn't populated before, adding that
one entry would make it think it was populated, so that would cause
bugs later.
2021-06-22 11:01:59 +02:00
Sahan Fernando bd5b1d1413 Kernel: Use fewer supervisor pages in VirtIOQueues 2021-06-22 10:58:36 +02:00
stelar7 c0034d6364 Kernel: Add more entries to the list of valid E1000E device ids 2021-06-21 20:15:15 +02:00
Daniel Bertalan ae6367999f Kernel: Fix assertion failure on large TTY writes
The `File::can_write` mechanism lets us check that writes won't block,
meaning some bytes can be immediately written to the underlying device.
This means calling `File::write` in a situation where no data could be
written is a logic error, which we `VERIFY()` in `Process::do_write()`.

TTY, in particular, processes the write in 256-byte buffered chunks.
Previously, we would assert that none of these sub-writes returned zero.
This was a logic error, as this rejected some successful writes. For
example, if there was exactly enough free space in `SlavePty`'s internal
buffer for the previous sub-write to complete fully. This made it
impossible to perform writes larger than `SlavePty`'s internal buffer.

Note that it's not an issue if `on_tty_write` returns zero, as partial
writes are handled correctly by the `buffer.read_buffered` helper. We
won't spin in a loop trying to write to a full buffer.

Fixes #8090
2021-06-21 16:57:07 +02:00
Tom fb488e2b27 Kernel: Allow VGA-capable graphics adapters to exist with legacy VGA
If we have a VGA-capable graphics adapter that we support, we should
prefer it over any legacy VGA because we wouldn't use it in legacy VGA
mode in this case.

This solves the problem where we would only use the legacy VGA card
when both a legacy VGA card as well as a VGA-mode capable adapter is
present.
2021-06-20 12:07:06 +02:00
Gunnar Beutner 3c3a1726df Kernel: Make sure threads which don't do any syscalls are terminated
Steps to reproduce:

$ cat loop.c
int main() { for (;;); }
$ gcc -o loop loop.c
$ ./loop

Terminating this process wasn't previously possible because we only
checked whether the thread should be terminated on syscall exit.
2021-06-19 12:55:00 +02:00
Gunnar Beutner c980a51776 Kernel: Make sure the kernel's ELF PHDRs don't use rwx
This doesn't really matter in terms of writability for the kernel text
because we set up proper page mappings anyway which prohibit writing
to the text segment. However, this makes the profiler happy which
previously died when validating the kernel's ELF program headers.
2021-06-19 12:54:33 +02:00
Liav A 29f9a38f76 Kernel: Don't use naked new statements in init process
Instead, try to create the device objects in separate static methods,
and if we fail for some odd reason to allocate memory for such devices,
just panic with that reason.
2021-06-19 09:30:43 +02:00
Andreas Kling 3bf5e482cf Kernel: Make the "in early boot" flag read-only-after-init 2021-06-18 17:40:05 +02:00
Jesse Buhagiar f2ff55dd09 Kernel: Add /proc/bus/usb to store information about connected devices 2021-06-18 17:04:57 +04:30
Jesse Buhagiar 71c9572e74 USB: Store device descriptor on enumeration
We now store the device descriptor obtained from the device
during enumeration in the device's object in memory instead
of exposing all of the different members contained within it.
2021-06-18 17:04:57 +04:30
Jesse Buhagiar 7b42146f33 USB: Store devices in globally accessible array
USB Devices are now stored so that they may be later retrieved and
operated on (i.e, fetching their assigned device address via
ProcFS)
2021-06-18 17:04:57 +04:30
Gunnar Beutner 22b0cbe1fe Kernel: Fix crash when changing screen resolution
Steps to reproduce:

1. Change resolution to 640x480.
2. Change resolution to 1280x1024.
3. Observe the following kernel panic:

Kernel::__panic(char const*, unsigned int, char const*) +0x55
Kernel::handle_crash(Kernel::RegisterState&, char const*, ...) +0x112
page_fault_handler +0x1130
page_fault_asm_entry +0x26
Kernel::VirtualConsole::refresh_after_resolution_change() +0x35e4
Kernel::ConsoleManagement::resolution_was_changed() +0x38b
Kernel::Graphics::FramebufferConsole::set_resolution(...) +0x3e1
Kernel::BochsGraphicsAdapter::try_to_set_resolution(...) +0x319
.L4213 +0x40a
Kernel::Process::sys$ioctl(int, unsigned int, unsigned int) +0x2fa
Kernel::Syscall::handle(Kernel::RegisterState&, ...) +0xfdc
syscall_handler +0x19c0
Kernel::syscall_asm_entry_dummy() +0x31
2021-06-18 13:45:21 +02:00
Tim Schumacher 9559ac9dd6 Kernel: Correctly decode proc_file_type from identifier
inode identifiers in ProcFS are encoded in a way that the parent ID is
shifted 12 bits to the left and the PID is shifted by 16 bits. This
means that the rightmost 12 bits are reserved for the file type or the
fd.

Since the to_fd and to_proc_file_type decoders only decoded the
rightmost 8 bits, decoded values would wrap around beyond values of 255,
resulting in a different value compared to what was originally encoded.
2021-06-18 10:15:14 +02:00
Jean-Baptiste Boric 8cd96f031d Kernel: Fix CPUID usage inside cpu_detect()
Since no features inside the 0x80000001 leaf are required for
SerenityOS to work, don't assert if it's unavailable.
2021-06-18 01:02:25 +02:00
Jean-Baptiste Boric fb3447f7ec Kernel: Use FXSR feature only if supported by CPU
If FXSR is not present, fall back to fnsave and frstor instructions.
These instructions aren't available on the canonical i686 CPU which is
the Pentium Pro processor.
2021-06-18 01:02:25 +02:00
Jean-Baptiste Boric fea23d0ec1 Kernel: Detect support for CPUID FXSR
The fxsave and fxrstor instructions are available only if the FXSR
feature is present.
2021-06-18 01:02:25 +02:00
Gunnar Beutner 58c182b19e Kernel: Update check in Inode::read_entire
The nread variable can't be less than zero anymore.
2021-06-17 19:52:54 +02:00
Gunnar Beutner bf779e182e Kernel: Remove obsolete size_t casts 2021-06-17 19:52:54 +02:00
Gunnar Beutner 9b14a8605a Kernel: Add a VERIFY() to make sure our DMA address is valid
This checks whether the address we're trying to use for DMA is low
enough so as not to overflow the I/O register.
2021-06-17 19:52:13 +02:00
Gunnar Beutner 017c5fc7d9 Kernel: Move super_pages section into the bottom 16MB
This ensures that pages returned by
MM.allocate_supervisor_physical_page() have a physical address that
is in the bottom 16MB and can thus be used by the SB16 driver for DMA.

Fixes #8092.
2021-06-17 19:52:13 +02:00
Gunnar Beutner b007898c35 Kernel: Make sure the kernel is re-linked when the linker script changes 2021-06-17 19:52:13 +02:00
Gunnar Beutner 67c2d39422 Kernel: Fix incorrect argument name 2021-06-17 19:52:13 +02:00
Liav A b91df26d4a Kernel/Interrupts: Return boolean on whether we handled the interrupt
If we are in a shared interrupt handler, the called handlers might
indicate it was not their interrupt, so we should not increment the
call counter of these handlers.
2021-06-17 16:53:25 +02:00
Liav A 7a6d5a7b8b Kernel/VirtIO: Indicate we handling unknown interrupt early when called 2021-06-17 16:53:25 +02:00
Liav A c802b1a363 Kernel/Interrupts: Add sensible purposes to VirtIO and USB devices
When we enumerate the interrupt handlers, it's a good idea to show a
meaningful name to the user instead of "IRQ Handler".
2021-06-17 16:53:25 +02:00
Liav A 030999d269 Kernel/Interrupts: Enumerate nested handlers in a shared handler
When asked to enumerate all interrupt handlers, display all shared
handlers within it instead of just returning the responsible handler of
them.
2021-06-17 16:53:25 +02:00
Gunnar Beutner bc3076f894 Kernel: Remove various other uses of ssize_t 2021-06-16 21:29:36 +02:00
Gunnar Beutner ca3cae81eb Kernel: Use KResultOr<size_t> for the DoubleBuffer class 2021-06-16 21:29:36 +02:00
Gunnar Beutner 1c3346e3ce Kernel: Use KResultOr<size_t> throughout the TTY subsystem
Previously the VirtualConsole::on_tty_write() method would return an
incorrect value when an error had occurred. This prompted me to
update the TTY subsystem to use KResultOr<size_t> everywhere.
2021-06-16 21:29:36 +02:00
Brian Gianforcaro 2b819ff181 Kernel: Replace TimerQueue InlinedLinkedList usage with IntrusiveList
Note that there are a few minor differences between the InlineLinekdList
and IntrusiveList API, so this isn't just a pure data structure change.

 - first()/last() instead of head()/tail()

 - There is no need for a for_each(..) implementation, as it already
   exposes the ability to do range based for loops.
2021-06-16 10:40:01 +02:00
Brian Gianforcaro b4aaa99968 Kernel: Remove unused header includes from TimerQueue.cpp
CLion found these, remove them.
2021-06-16 10:40:01 +02:00
Luke 155f1026ce Kernel/AHCI: Don't set the C command header attribute
This has a quirk with the AMD Hudson-2 SATA controller. [1022:7801]
Having this flag set makes the controller become stuck in a busy loop.

I decided to remove the flag instead of making it a quirk as it still
works with Qemu, VirtualBox, VMware Player and the Intel Wildcat
Point-LP SATA Controller [8086:9c83] without it, thus making it simpler
to just remove it.

Partial fix for #7738 (as it still does not work in IDE mode)
2021-06-15 14:43:22 +02:00
Jelle Raaijmakers ab840423a8 Kernel: Verify Process coredump threads are empty 2021-06-14 16:27:37 +02:00
Jelle Raaijmakers 5b03b62518 Kernel: Only call Process::die() once on terminating signal
Previously, when e.g. the `SIGABRT` signal was sent to a process,
`Thread::dispatch_signal()` would invoke
`Process::terminate_due_to_signal()` which would then `::die()`. The
result `DispatchSignalResult::Terminate` is then returned to
`Thread::check_dispatch_pending_signal()` which proceeds to invoke
`Process::die()` a second time.

Change the behavior of `::check_dispatch_pending_signal()` to no longer
call `Process::die()` if it receives `::Terminate` as a signal handling
result, since that indicates that the process was already terminated.

This fixes #7289.
2021-06-14 16:27:37 +02:00
Jelle Raaijmakers 30abfc2b21 Kernel: Pass absolute path to shebang interpreter
When you invoke a binary with a shebang line, the `execve` syscall
makes sure to pass along command line arguments to the shebang
interpreter including the path to the binary to execute.

This does not work well when the binary lives in $PATH. For example,
given this script living in `/usr/local/bin/my-script`:

  #!/bin/my-interpreter
  echo "well hello friends"

When executing it as `my-script` from outside `/usr/local/bin/`, it is
executed as `/bin/my-interpreter my-script`. To make sure that the
interpreter can find the binary to execute, we need to replace the
first argument with an absolute path to the binary, so that the
resulting command is:

  /bin/my-interpreter /usr/local/bin/my-script
2021-06-13 21:19:51 +02:00
Jelle Raaijmakers 26250779d1 Kernel: Also move() the shebang path in execve 2021-06-13 21:19:51 +02:00
Jesse Buhagiar 06f1edb516 USB: Further Implement USB Structures
These are the actual structures that allow USB to work (i.e the ones
actually defined in the specification). This should provide us enough
of a baseline implementation that we can build on to support
different types of USB device.
2021-06-12 18:17:25 +04:30
Andreas Kling dc65f54c06 AK: Rename Vector::append(Vector) => Vector::extend(Vector)
Let's make it a bit more clear when we're appending the elements from
one vector to the end of another vector.
2021-06-12 13:24:45 +02:00
Max Wipfli 90e229c9b5 Kernel: Use m_inode to stat in FileDescription::stat() if available
This is necessary since the Device class does not hold a reference to
its inode (because there could be multiple), and thus doesn't override
File::stat(). For simplicity, we should just always stat via the inode
if there is one, since that shouldn't ever be the wrong thing.

This partially reverts #7867.
2021-06-11 12:09:26 +02:00
Daniel Bertalan 54a33c45bb Kernel: Add missing BrightWhite color to VirtualConsole
Because of the 'default' label, the compiler did not warn about the
missing field. The `VERIFY_NOT_REACHED` was moved out of the switch to
fix this.
2021-06-11 11:38:15 +02:00
Gunnar Beutner c3d702431a Kernel: Block writes while we're establishing the TCP connection
Previously we would not block the caller until the connection was
established and would instead return EPIPE for the first send() call
which then likely caused the caller to abandon the socket.

This was broken by 0625342.
2021-06-11 11:32:40 +02:00
Gunnar Beutner da24228348 Kernel: Print stack traces for crashes in release builds
Previously we'd just reset the CPU and reboot.
2021-06-11 11:32:01 +02:00
Gunnar Beutner bcf6da8cde Kernel: Enable VERIFY() checks even if the DEBUG macro is not defined
Fixes #7910.
2021-06-11 11:32:01 +02:00
Idan Horowitz 70fc0a528c Kernel: Increase m_bytes_out only once during transmission
We were accidentally increasing m_bytes_out by the packet size and then
immediately calling send_packet(), which did the same thing as well.
2021-06-11 00:56:32 +02:00
Luke d2f1476428 Kernel: Add support for the RTL8168E-VL variant to the RTL8168 driver
Specifically chip version 17.
2021-06-10 21:54:51 +02:00
Idan Horowitz a898e01d4d Kernel: Add driver for RTL8168 & RTL8111 NICs
These are pretty common on older LGA1366 & LGA1150 motherboards.

NOTE: Since the registers datasheets for all versions of the chip
besides versions 1 - 3  are still under NDAs i had to collect
several "magical vendor constants" from the *BSD driver and the
linux driver that i was not able to name verbosely, and as such
these are labeled with the comment "vendor magic values".
2021-06-10 21:54:51 +02:00
Daniel Bertalan a3c4397432 Kernel: Re-render console after echoing characters
If we do not flush the dirty lines, characters typed in canonical mode
only appear after the virtual console has been switched away from, or
the application has been killed. Instead, we now immediately perform the
flush.
2021-06-10 17:18:02 +02:00
Daniel Bertalan ce9460de59 Kernel+LibVT: Fix selection with scrollback wrap-around
If lines are removed from the tail of the scrollback buffer, the
previous line indices will refer to different lines; therefore we need
to offset them.
2021-06-10 17:18:02 +02:00
Daniel Bertalan 89843cd692 Kernel+LibVT: Implement left-right scrolling
This commit implements the left/right scrolling used in the `ICH`/`DCH`
escape sequences for `VirtualConsole`. This brings us one step closer to
VT420/xterm compatibility.

We can now finally remove the last escape sequence related `ifdef`s.
2021-06-10 17:18:02 +02:00
Daniel Bertalan 7419569a2b Kernel+LibVT: Add function for deleting a range of characters
Previously, this was done by telling the client to put a space at each
character in the range. This was inefficient, because a large number of
function calls took place and incorrect, as the ANSI standard dictates
that character attributes should be cleared as well.

The newly added `clear_in_line` function solves this issue. It performs
just one bounds check when it's called and can be implemented as a
pretty tight loop.
2021-06-10 17:18:02 +02:00
Daniel Bertalan 8f8fd9c5a8 LibVT+Kernel: Support clearing the scrollback buffer
As per the `xterm ctlseqs` documentation, `\e3J` should clear the
scrollback buffer, and leave the visible lines unchanged.

This commit fixes a FIXME.
2021-06-10 17:18:02 +02:00
Daniel Bertalan ae6bdc4e29 LibVT+Kernel: Clean up scroll API
This commit cleans up some of the `#ifdef`-ed code smell in
`Terminal`, by extending the scroll APIs to take a range of lines as a
parameter. This makes it possible to use the same code for `IL`/`DL` as
for scrolling.

Note that the current scrolling implementation is very naive, and does
many insertions/deletions in the middle of arrays, whereas swaps should
be enough. This optimization will come in a later commit.

The `linefeed` override was removed from `VirtualConsole`. Previously,
it exhibited incorrect behavior by moving to column 0. Now that we use
the method defined in `Terminal`, code which relied on this behavior
stopped working. We go instead go through the TTY layer which handles
the various output flags. Passing the input character-by-character
seems a bit excessive, so a fix for it will come in another PR.
2021-06-10 17:18:02 +02:00
Liav A b54bfdd696 Kernel/PCI: Remove UNMAP_AFTER_INIT from a few methods
This fixes #7942.

We can't unmap these methods because they can be called after the boot
process from lspci(8) utility, or by using the SystemMonitor program
(and looking into the "PCI devices" tab).
2021-06-09 20:15:14 +01:00
Ali Mohammad Pur 50349de38c Meta: Disable -Wmaybe-uninitialized
It's prone to finding "technically uninitialized but can never happen"
cases, particularly in Optional<T> and Variant<Ts...>.
The general case seems to be that it cannot infer the dependency
between Variant's index (or Optional's boolean state) and a particular
alternative (or Optional's buffer) being untouched.
So it can flag cases like this:
```c++
if (index == StaticIndexForF)
    new (new_buffer) F(move(*bit_cast<F*>(old_buffer)));
```
The code in that branch can _technically_ make a partially initialized
`F`, but that path can never be taken since the buffer holding an
object of type `F` and the condition being true are correlated, and so
will never be taken _unless_ the buffer holds an object of type `F`.

This commit also removed the various 'diagnostic ignored' pragmas used
to work around this warning, as they no longer do anything.
2021-06-09 23:05:32 +04:30
Liav A c6480a0426 Kernel/Net: Support Intel 82574 adapter
We call it E1000E, because the layout for these cards is somewhat not
the same like E1000 supported cards.

Also, this card supports advanced features that are not supported on
8254x cards.
2021-06-09 22:44:09 +04:30
Liav A 2e2201e8e1 Kernel/CommandLine: Add option to disable physical networking hardware
This is useful for debugging sessions mostly.
2021-06-09 22:44:09 +04:30
Liav A 1c94b5e8eb Kernel: Introduce the NetworkingManagement singleton
Instead of initializing network adapters in init.cpp, let's move that
logic into a separate class to handle this.
Also, it seems like a good idea to shift responsiblity on enumeration
of network adapters after the boot process, so this singleton will take
care of finding the appropriate network adapter when asked to with an
IPv4 address or interface name.

With this change being merged, we simplify the creation logic of
NetworkAdapter derived classes, so we enumerate the PCI bus only once,
searching for driver candidates when doing so, and we let each driver
to test if it is resposible for the specified PCI device.
2021-06-09 22:44:09 +04:30
Brian Gianforcaro aa63fe20a5 Kernel: Mark VirtIOConsole constructor as UNMAP_AFTER_INIT 2021-06-09 10:57:51 +02:00
Brian Gianforcaro 7e88ac63b9 Kernel: Mark VirtIORNG constructor as UNMAP_AFTER_INIT 2021-06-09 10:57:51 +02:00
Brian Gianforcaro d27cecd729 Kernel: Mark VirtIO detection/creation functions as UNMAP_AFTER_INIT 2021-06-09 10:57:51 +02:00
Brian Gianforcaro 80a3cc47e5 Kernel: Mark MMIOAccess detection function as UNMAP_AFTER_INIT 2021-06-09 10:57:51 +02:00
Brian Gianforcaro 40ea464fb0 Kernel: Mark PCI Access enumeration functions as UNMAP_AFTER_INIT 2021-06-09 10:57:51 +02:00
Brian Gianforcaro 9e6f0fd925 Kernel: Mark SyncTask::spawn() as UNMAP_AFTER_INIT 2021-06-09 10:57:51 +02:00
Brian Gianforcaro 83841e47e5 Kernel: Mark FinalizerTask::spawn() as UNMAP_AFTER_INIT 2021-06-09 10:57:51 +02:00
Brian Gianforcaro c8b6bd4b97 Kernel: Mark WorkQueue initailzation functions as UNMAP_AFTER_INIT 2021-06-09 10:57:51 +02:00
Brian Gianforcaro b5d388a9b3 Kernel: Mark NE2000NetworkAdapter::ram_test() UNMAP_AFTER_INIT 2021-06-09 10:57:51 +02:00
Brian Gianforcaro e9add0bb80 Kernel: Mark E1000NetworkAdapter is_valid_device_id(..) UNMAP_AFTER_INIT 2021-06-09 10:57:51 +02:00
Brian Gianforcaro f124affc8e Kernel: Mark PCISerialDevice::detect() as UNMAP_AFTER_INIT 2021-06-09 10:57:51 +02:00
Max Wipfli 573664758a Kernel: Properly reset m_unveiled_paths on execve()
When a process executes another program, its unveil state is reset. For
this, we not only need to clear all nodes from m_unveiled_paths, but
also reset the metadata of m_unveiled_paths (the root node) itself.

This fixes the following bug:
1) A process unveils "/", then executes another program.
2) That other program also unveils some path.
3) "/" is now unveiled for the new program.
2021-06-08 12:15:04 +02:00
Max Wipfli c1de46aaaf Kernel: Don't assume there are no nodes if m_unveiled_paths.is_empty()
If m_unveiled_paths.is_empty(), the root node (which is m_unveiled_paths
itself) is the matching veil. This means we should not return nullptr in
this case, but just use the code path for the general case.

This fixes a bug where calling e.g. unveil("/", "r") would refuse you
access to anything, because find_matching_unveiled_path would wrongly
return nullptr.

Since find_matching_unveiled_path can no longer return nullptr, we can
now just return a reference instead.
2021-06-08 12:15:04 +02:00
Max Wipfli 8930db0900 Kernel: Change unveil state to dropped even when node already exists
This also changes the UnveilState to Dropped when the path unveil() is
called for already has a node.

This fixes a bug where unveiling "/" would previously keep the
UnveilState as None, which meant that everything was still accessible
until unveil() was called with any non-root path (or nullptr).
2021-06-08 12:15:04 +02:00
Max Wipfli 2fcebfd6a8 Kernel: Update intermediate nodes when changing unveil permissions
When changing the unveil permissions of a preexisting node, we need to
make sure that any intermediate nodes that were created before and
should inherit permissions from the updated node are updated properly.

This fixes the following bug:
unveil("/home/anon/Documents", "r");
unveil("/home", "r");
Now there was a intermediate node for "/home/anon" which still had no
permission, even though it should have inherited the permissions from
"/home".
2021-06-08 12:15:04 +02:00
Max Wipfli e8a317023d Kernel: Allow unveiling subfolders regardless of parent's permissions
This fixes a bug where unveiling a subdirectory of an already unveiled
path would sometimes be allowed and sometimes not (depending on what
other unveil calls have been made).

Now, it is always allowed to unveil a subdirectory of an already
unveiled directory, even if it has higher permissions.

This removes the need for the permissions_inherited_from_root flag in
UnveilMetadata, so it has been removed.
2021-06-08 12:15:04 +02:00
Max Wipfli 9d41dd2ed0 Kernel: Use LexicalPath to avoid two consecutive slashes in unveil path
This patch fixes a bug in the unveil syscall where an UnveilNode's path
would start with two slashes if it's parent node was "/".
2021-06-08 12:15:04 +02:00
Jelle Raaijmakers d6a3f1fcd7 Kernel: Simplify execve shebang argument handling 2021-06-08 11:30:58 +02:00
Max Wipfli cac94b1c16 Kernel: Implement InodeFile::stat() and simplify FileDescription::stat() 2021-06-08 11:12:31 +02:00
Gunnar Beutner 3bac14e19e Kernel: Remove incorrect VERIFY() in Thread::relock_process
Turns are there are legitimate cases where the thread state isn't
Thread::Running.
2021-06-07 14:45:38 +04:30
Brian Gianforcaro 77f4f6e0de Kernel: Fix error propagation if Thread::WaitBlocker constructor fails
There is logic at the end of the constructor that sets m_should_block
to false if we encountered errors. We were missing this step due to the
erroneous early return, the code then ended up waiting and then
asserting on unblock since the WaitBlocker is in a invalid state.

This fix is to not return early, and let normal control flow handle it.

Fixes: #7857

Verified with `stress-ng --yield=10` locally.
2021-06-07 09:43:30 +02:00
Brian Gianforcaro 9fccbde371 Kernel: Switch Process to InstrusiveList from InlineLinkedList 2021-06-07 09:42:55 +02:00
Brian Gianforcaro 252e98761a Kernel: Remove unnecessary cast to int during ensure capacity 2021-06-07 09:42:55 +02:00
Gunnar Beutner 3c2a6a25da Kernel: Don't finalize a thread while it still has code running
After marking a thread for death we might end up finalizing the thread
while it still has code to run, e.g. via:

Thread::block -> Thread::dispatch_one_pending_signal
-> Thread::dispatch_signal -> Process::terminate_due_to_signal
-> Process::die -> Process::kill_all_threads -> Thread::set_should_die

This marks the thread for death. It isn't destroyed at this point
though.

The scheduler then gets invoked via:

Thread::block -> Thread::relock_process

At that point we still have a registered blocker on the stack frame
which belongs to Thread::block. Thread::relock_process drops the
critical section which allows the scheduler to run.

When the thread is then scheduled out the scheduler sets the thread
state to Thread::Dying which allows the finalizer to destroy the Thread
object and its associated resources including the kernel stack.

This probably also affects objects other than blockers which rely
on their destructor to be run, however the problem was most noticible
because blockers are allocated on the stack of the dying thread and
cause an access violation when another thread touches the blocker
which belonged to the now-dead thread.

Fixes #7823.
2021-06-06 15:58:48 +02:00
Gunnar Beutner 0625342382 Kernel: Return EPIPE when trying to write to an unconnected socket
When attempting to write to a socket that is not connected or - for
connection-less protocols - doesn't have a peer address set we should
return EPIPE instead of blocking the thread.
2021-06-05 22:11:49 +02:00
Daniel Bertalan 169e93f0a7 Kernel: Perform output processing on echo
Previously, we would echo characters back just as they were passed to
us, even in canonical mode. This caused newlines to not work correctly
in some programs.

Fixes #7802
2021-06-05 13:01:39 +02:00
Jelle Raaijmakers 3dab9d0b5c Kernel: Implement offset for lseek with SEEK_END 2021-06-04 23:49:48 +02:00
Jelle Raaijmakers f6d372b2ab Kernel: Process::exec(): Check if path is a regular file
https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html

  [EACCES] The new process image file is not a regular file and the
           implementation does not support execution of files of its
           type.

Let's check whether the passed `path` is indeed a regular file.
2021-06-04 23:45:17 +02:00
Gunnar Beutner a42383523a Kernel: Update the TX byte counter when sending network packets
This previously worked but was broken by b436dd1.
2021-06-05 00:36:55 +04:30
Gunnar Beutner 60298121d8 Kernel: Make sure we increment the TX counter
This was broken by b436dd1.
2021-06-04 19:06:47 +02:00
Liav A 6a9dc5562d Kernel: Use IO ports instad of MMIO with Bochs graphics in VirtualBox
This is needed for VirtualBox, because it doesn't support controlling
the device with MMIO.

Fixes #7558.
2021-06-04 13:02:32 +02:00
Liav A d18d91dedc Kernel/Graphics: Add a proper method to check if Intel GPU is supported 2021-06-04 13:02:32 +02:00
Jelle Raaijmakers e483de93ce LibC: Define MSG_OOB 2021-06-04 10:39:41 +02:00
Jelle Raaijmakers 496988de47 LibC: Add POSIX timer constants 2021-06-04 10:39:41 +02:00
Daniel Bertalan 99033876ec LibVT+Kernel: Create Color class
Previously, we converted colors to their RGB values immediately when
they were set. This meant that their semantic meaning was lost, we could
not tell a precise RGB value apart from a named/indexed color.

The new way of storing colors will allow us to retain this information,
so we can change a color scheme on the fly, and previously emitted text
will also be affected.
2021-06-04 09:02:43 +01:00
Gunnar Beutner 7f7897c900 Kernel: Make sure outgoing ICMP packets have the correct checksum
The internet_checksum() function relies on the buffer - or at least the
checksum field - to be all zeroes.
2021-06-03 20:59:30 +02:00
Liav A 47c1a31f89 Kernel: Support new lines when doing critical printing
If we are printing strings in the critical path, handling new lines
require us to break abstraction a bit to print new lines.

Fixes #7562.
2021-06-03 16:16:22 +01:00
Liav A e8d85b0694 Kernel/Graphics: Remove unused overloaded write methods of Console
If we happen to print a string, we could use a StringView instead. For
now, let's remove them entirely.
2021-06-03 16:16:22 +01:00
Luke 01d7c1b722 Kernel: Fix "sv" being inside of "no-fbdev" instead of outside
It was previously "no-fbdevsv" when it should be "no-fbdev"sv.
2021-06-03 17:08:06 +02:00
Brian Gianforcaro 7e691f96e1 Kernel: Switch ProcessGroup to IntrusiveList from InlineLinkedList 2021-06-03 13:27:40 +02:00
Gunnar Beutner ed0068d04d AK: Allow inlining ref-count functionality
Previously we'd incur the costs for a function call via the PLT even
for the most trivial ref-count actions like increasing/decreasing the
reference count.

By moving the code to the header file we allow the compiler to inline
this code into the caller's function.
2021-06-03 08:06:51 +02:00
Gunnar Beutner 6f38ce8f47 Kernel: Avoid allocations in the VMObject constructor
This avoids allocations in the VMObject constructor. The number of
inline elements was determined empirically and covers most common cases
including LibC malloc.
2021-06-02 23:00:14 +01:00
Gunnar Beutner 596361791c Kernel: Add operator delete for KString
This doesn't change anything because our global operator delete also
calls kfree() - however instead of relying on this implementation
detail this makes this dependency more explicit.
2021-06-02 22:59:39 +01:00
Gunnar Beutner 87ff76bd57 Kernel: Make KString non-copyable and non-movable
The user is supposed to hold these in an OwnPtr but bad things would
happen if the user takes these out of the OwnPtr so let's make the
class non-copyable and non-movable.
2021-06-02 18:00:13 +02:00
Gunnar Beutner fe0ae3161a Kernel: Fix use-after-free in sys$mremap
Now that Region::name() has been changed to return a StringView we
can't rely on keeping a copy of the region's name past the region's
destruction just by holding a copy of the StringView.
2021-06-02 18:00:13 +02:00
Brian Gianforcaro 7c0b2eb0f5 Kernel: Handle OOM of file system in sys$mount 2021-06-01 23:14:40 +01:00
Brian Gianforcaro cbe1e05771 Kernel: Move ProcFS API towards OOM safety 2021-06-01 23:14:40 +01:00
Brian Gianforcaro 23c021912e Kernel: Move TmpFS towards OOM safety 2021-06-01 23:14:40 +01:00
Brian Gianforcaro 8f9872581b Kernel: Move DevFS APIs towards OOM safety 2021-06-01 23:14:40 +01:00
Brian Gianforcaro d2d6ab40f9 Kernel: Make AnonymousFile::create API OOM safe 2021-06-01 23:14:40 +01:00
stelar7 01e5af487f Kernel: Dont try to register ephemeral TCP ports twice 2021-06-01 23:32:27 +04:30
Luke 4ee58d36c0 Kernel/ACPI: Sprinkle links to the specification all over
The latest version of the ACPI specification (6.4) now has a web
version, making it possible to link directly to the relevant sections
of the specification.

I added links to the stuff that was easy to find.

The spec can be found here: https://uefi.org/specs/ACPI/6.4/index.html
2021-05-31 19:06:46 +01:00
Nick Miller 10ba6f254c Kernel: Rename instances of IO port 0xe9 to BOCHS_DEBUG_PORT 2021-05-31 19:06:13 +01:00
Liav A 10c747f2be Documentation: Add explanation about AHCI locking 2021-05-31 18:28:25 +01:00
Sebastian Zaha 77044dd383
Kernel: Fix crash when switching to console 5 & 6
The changes in commit 20743e8 removed the s_max_virtual_consoles
constant and hardcoded the number of consoles to 4. But in
PS2KeyboardDevice the keyboard shortcuts for switching to consoles were
hardcoded to 6.

I reintroduced the constant and added it in both places.
2021-05-31 17:42:21 +01:00