Commit Graph

16264 Commits

Author SHA1 Message Date
Tom
e9e76b8074 Kernel: Fix Thread::relock_process leaving critical section
We don't want to explicitly enable interrupts when leaving the
critical section to trigger a context switch.
2021-01-27 22:48:41 +01:00
Tom
ccaeb47401 Kernel: Don't hold scheduler lock while setting up blocker in Thread::block
This fixes a deadlock when one processor is trying to block while another is
trying to unblock the same.
2021-01-27 22:48:41 +01:00
Tom
250a310454 Kernel: Release MM lock while yielding from inode page fault handler
We need to make sure other processors can grab the MM lock while we
wait, so release it when we might block. Reading the page from
disk may also block, so release it during that time as well.
2021-01-27 22:48:41 +01:00
Tom
ac3927086f Kernel: Keep a list of threads per Process
This allow us to iterate only the threads of the process.
2021-01-27 22:48:41 +01:00
Tom
03a9ee79fa Kernel: Implement thread priority queues
Rather than walking all Thread instances and putting them into
a vector to be sorted by priority, queue them into priority sorted
linked lists as soon as they become ready to be executed.
2021-01-27 22:48:41 +01:00
Tom
c531084873 Kernel: Track processor idle state and wake processors when waking threads
Attempt to wake idle processors to get threads to be scheduled more quickly.
We don't want to wait until the next timer tick if we have processors that
aren't doing anything.
2021-01-27 22:48:41 +01:00
Tom
39f408daa0 Kernel: Use the CPU# as logical apic id 2021-01-27 22:48:41 +01:00
Tom
95bfc12ff4 AK: Include the processor id in log messages 2021-01-27 22:48:41 +01:00
Andreas Kling
e67402c702 Kernel: Remove Range "valid" state and use Optional<Range> instead
It's easier to understand VM ranges if they are always valid. We can
simply use an empty Optional<Range> to encode absence when needed.
2021-01-27 21:14:42 +01:00
Andreas Kling
67bc5e0bbd DynamicLoader: Pass MAP_FIXED to mmap() where applicable
Otherwise the kernel is free to allocate a different address.
2021-01-27 21:14:42 +01:00
Andreas Kling
5ab27e4bdc Kernel: sys$mmap() without MAP_FIXED should consider address a hint
If we can't use that specific address, it's still okay to put it
anywhere else in VM.
2021-01-27 21:14:42 +01:00
Tom
e2f9e557d3 Kernel: Make Processor::id a static function
This eliminates the window between calling Processor::current and
the member function where a thread could be moved to another
processor. This is generally not as big of a concern as with
Processor::current_thread, but also slightly more light weight.
2021-01-27 21:12:24 +01:00
Tom
21d288a10e Kernel: Make Thread::current smp-safe
Change Thread::current to be a static function and read using the fs
register, which eliminates a window between Processor::current()
returning and calling a function on it, which can trigger preemption
and a move to a different processor, which then causes operating
on the wrong object.
2021-01-27 21:12:24 +01:00
Tom
f88a8b16d7 Kernel: Make entering and leaving critical sections atomic
We also need to store m_in_critical in the Thread upon switching,
and we need to restore it. This solves a problem where threads
moving between different processors could end up with an unexpected
value.
2021-01-27 21:12:24 +01:00
Tom
33cdc1d2f1 Kernel: Use new Thread::previous_mode to track ticks 2021-01-27 21:12:24 +01:00
Tom
0bd558081e Kernel: Track previous mode when entering/exiting traps
This allows us to determine what the previous mode (user or kernel)
was, e.g. in the timer interrupt. This is used e.g. to determine
whether a signal handler should be set up.

Fixes #5096
2021-01-27 21:12:24 +01:00
Itamar
fa18010477 HackStudio: Integate with C++ parser-based autocomplete
By default, C++ auto completion will still be performed by the
lexer-based logic.
However, the parser-based logic can be switched on via the menubar.
2021-01-27 21:10:57 +01:00
Itamar
8ed96eb27c HackStudio: Attach previous Language Client when detaching
Previously, if a new LanguageClient was created & destroyed, the
ServerConnection to the language server would be left without an
attached LanguageClient.
As a result, auto-completion results would not be updated in the UI.

Starting with this commit, the LanguageClient holds a WeakPtr to the
previous LanguageClient that was attached to the ServerConnection,
and re-attaches it after detaching itself.
2021-01-27 21:10:57 +01:00
Itamar
c85dad2383 HackStudio: Add parser-based c++ autocomplete engine 2021-01-27 21:10:57 +01:00
Itamar
c96b6987c4 LibCpp: Add the beginning of a C++ parser
This parser will be used by the C++ langauge server to provide better
auto-complete (& maybe also other things in the future).

It is designed to be error tolerant, and keeps track of the position
spans of the AST nodes, which should be useful later for incremental
parsing.
2021-01-27 21:10:57 +01:00
Zac
aec9658b4f EditingEngine: Fix move_to_previous_word not working on last char of doc
Code meant for the move_to_next_word functions which set the cursor to
the last character in the file if it was reached was copied into the
move_to_previous_word functions which lead them not moving when
the function was called from the end of the file.
2021-01-27 21:09:18 +01:00
Andreas Kling
76a69be217 Kernel: Assert in RangeAllocator that sizes are multiple of PAGE_SIZE 2021-01-27 19:45:53 +01:00
Andreas Kling
f6c6047e49 LibJS: Add overflow checks when creating TypedArray from ArrayBuffer
Thanks to Iliad for finding this! :^)
2021-01-27 07:57:07 +01:00
AnotherTest
c899ace3ad LibGfx: Correct the allocated buffer size in serialize_to_byte_buffer()
Fixes #5131.
2021-01-27 06:40:15 +01:00
asynts
7cf0c7cc0d Meta: Split debug defines into multiple headers.
The following script was used to make these changes:

    #!/bin/bash
    set -e

    tmp=$(mktemp -d)

    echo "tmp=$tmp"

    find Kernel \( -name '*.cpp' -o -name '*.h' \) | sort > $tmp/Kernel.files
    find . \( -path ./Toolchain -prune -o -path ./Build -prune -o -path ./Kernel -prune \) -o \( -name '*.cpp' -o -name '*.h' \) -print | sort > $tmp/EverythingExceptKernel.files

    cat $tmp/Kernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/Kernel.macros
    cat $tmp/EverythingExceptKernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/EverythingExceptKernel.macros

    comm -23 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/Kernel.unique
    comm -1 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/EverythingExceptKernel.unique

    cat $tmp/Kernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/Kernel.header
    cat $tmp/EverythingExceptKernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/EverythingExceptKernel.header

    for macro in $(cat $tmp/Kernel.unique)
    do
        cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.new-includes ||:
    done
    cat $tmp/Kernel.new-includes | sort > $tmp/Kernel.new-includes.sorted

    for macro in $(cat $tmp/EverythingExceptKernel.unique)
    do
        cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.old-includes ||:
    done
    cat $tmp/Kernel.old-includes | sort > $tmp/Kernel.old-includes.sorted

    comm -23 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.new
    comm -13 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.old
    comm -12 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.mixed

    for file in $(cat $tmp/Kernel.includes.new)
    do
        sed -i -E 's/#include <AK\/Debug\.h>/#include <Kernel\/Debug\.h>/' $file
    done

    for file in $(cat $tmp/Kernel.includes.mixed)
    do
        echo "mixed include in $file, requires manual editing."
    done
2021-01-26 21:20:00 +01:00
AnotherTest
37bfaf4e7c Shell: Do not bail on signaled if condition
Fixes #5119
2021-01-26 21:19:22 +01:00
Maciej Zygmanowski
645657865d Kernel: Add RTC as fallback entropy source if HPET is not found 2021-01-26 21:14:44 +01:00
Maciej Zygmanowski
0a61924727 Kernel: Use HPET as entropy source if CPU doesn't support RDRAND
We don't have anything better for these CPUs for now.
2021-01-26 21:14:44 +01:00
Maciej Zygmanowski
ceb5682b54 Kernel: Add HPET::read_main_counter() 2021-01-26 21:14:44 +01:00
Maciej Zygmanowski
67e93745cb Kernel: Ensure that HPET is initialized before using random the first time 2021-01-26 21:14:44 +01:00
Nico Weber
97234a5b9d LibGUI: Switch cancel/confirm button order on file picker dialog
Most (all?) other dialogs in the system have the cancel button on the
right, so make the file picker consistent with the rest.
2021-01-26 21:02:46 +01:00
Nico Weber
09b881797f LibGUI: Tweak "Overwrite file?" dialog text to use one sentence per sentence 2021-01-26 21:02:46 +01:00
Jean-Baptiste Boric
ccfb3bef75 lspci: Add numerical display 2021-01-26 21:00:16 +01:00
Andreas Kling
3ff88a1d77 Kernel: Assert on attempt to map private region backed by shared inode
If we find ourselves with a user-accessible, non-shared Region backed by
a SharedInodeVMObject, that's pretty bad news, so let's just panic the
kernel instead of getting abused.

There might be a better place for this kind of check, so I've added a
FIXME about putting more thought into that.
2021-01-26 18:35:10 +01:00
Andreas Kling
a131927c75 Kernel: sys$munmap() region splitting did not preserve "shared" flag
This was exploitable since the shared flag determines whether inode
permission checks are applied in sys$mprotect().

The bug was pretty hard to spot due to default arguments being used
instead. This patch removes the default arguments to make explicit
at each call site what's being done.
2021-01-26 18:35:04 +01:00
Linus Groh
e7183cc762 Kernel: Don't drop pledge()'d promises/execpromises when passing nullptr
When passing nullptr for either promises or execpromises to pledge(),
the expected behaviour is to not change their current value at all - we
were accidentally resetting them to 0, effectively dropping previously
pledge()'d promises.
2021-01-26 18:18:01 +01:00
Andreas Kling
c7858622ec Kernel: Update process promise states on execve() and fork()
We now move the execpromises state into the regular promises, and clear
the execpromises state.

Also make sure to duplicate the promise state on fork.

This fixes an issue where "su" would launch a shell which immediately
crashed due to not having pledged "stdio".
2021-01-26 15:26:37 +01:00
Andreas Kling
1e25d2b734 Kernel: Remove allocate_region() functions that don't take a Range
Let's force callers to provide a VM range when allocating a region.
This makes ENOMEM error handling more visible and removes implicit
VM allocation which felt a bit magical.
2021-01-26 14:13:57 +01:00
Dexter
d697d33fa6
Documentation: Fix typo in CodingStyle.md (#5121) 2021-01-26 12:26:27 +01:00
Linus Groh
22df4727b1 Base: Update crash(1) man page
Update the outdated list of options, mention UserspaceEmulator, update
example shell output.
2021-01-26 11:40:08 +01:00
Andreas Kling
f3f2d77624 LibJS: Remove an unused TypedArray constructor 2021-01-25 23:23:33 +01:00
Linus Groh
5978424cf9 crash: Add option for failing assertion 2021-01-25 23:22:21 +01:00
Linus Groh
6568cba731 crash: Add option for pledge() violation 2021-01-25 23:22:21 +01:00
Linus Groh
629180b7d8 Kernel: Support pledge() with empty promises
This tells the kernel that the process wants to use pledge, but without
pledging anything - effectively restricting it to syscalls that don't
require a certain promise. This is part of OpenBSD's pledge() as well,
which served as basis for Serenity's.
2021-01-25 23:22:21 +01:00
Tom
b580c005f1 Kernel: Fix possible context switch within first context switch of a thread
We were enabling interrupts too early, before the first context switch to
a thread was complete. This could then trigger another context switch
within the context switch, which lead to a crash.
2021-01-25 23:22:12 +01:00
Tom
bd73102513 Kernel: Fix some race conditions with Lock and waiting/waking threads
There is a window between acquiring/releasing the lock with the atomic
variables and subsequently waiting or waking threads. With a single
processor this window was closed by using a critical section, but
this doesn't prevent other processors from running these code paths.
To solve this, set a flag in the WaitQueue while holding m_lock which
determines if threads should be blocked at all.
2021-01-25 22:54:55 +01:00
Tom
4cf0859612 Kernel: Fix race condition in Lock::lock that may leave corrupted state 2021-01-25 22:54:55 +01:00
TheMorc
d4668507d4 Ports: Improve configure script
Just a small modification so that ports that are configured e.g.
using cmake don't need a dummy configure file anymore.
2021-01-25 22:34:43 +01:00
TheMorc
ffc51853bf Ports: Add ProTracker 2 clone 2021-01-25 22:34:43 +01:00
Zac
b56ef9042b Vim: Add a simple yank and put implementation 2021-01-25 22:31:43 +01:00