Commit graph

4601 commits

Author SHA1 Message Date
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