Commit Graph

26778 Commits

Author SHA1 Message Date
Andreas Kling
3b995c6d01 Kernel: Tidy up Process::try_create_user_process()
This function is currently only ever used to create the init process
(SystemServer). It had a few idiosyncratic things about it that this
patch cleans up:

- Errors were returned in an int& out-param.
- It had a path for non-0 process PIDs which was never taken.
2021-09-04 23:11:04 +02:00
Andreas Kling
ba1a6ca971 Kernel: Move pledge verification into Process member functions
REQUIRE_PROMISE and REQUIRE_NO_PROMISES were macros for some reason,
and used all over the place.

This patch adds require_promise(Pledge) and require_no_promises()
to Process and makes the macros call these on the current process
instead of inlining code everywhere.
2021-09-04 23:11:04 +02:00
Andreas Kling
5d5a3708c4 Kernel: Rename Thread::clone() => try_clone() and propagate errors 2021-09-04 23:11:04 +02:00
Andreas Kling
cfc1a628d5 Kernel: Add missing error check after Process::try_create()
As the name now suggests, this API can fail. :^)
2021-09-04 23:11:04 +02:00
Andreas Kling
5e2e17c38c Kernel: Rename Process::create() => try_create() 2021-09-04 23:11:03 +02:00
Karol Kosek
1814f66c63 SoundPlayer: Convert to double before calculating
freq_bin was converted to double after it was calculated, so there was
a much higher probability it could be 0 instead of some comma number,
which meant that the bars always stayed on top.
2021-09-04 22:52:02 +02:00
Karol Kosek
43c37ae701 SoundPlayer: Simplify Bars Visualization drawing logic a bit
The freq_bin in bins_per_group was multiplied only to be divided later,
which could even result in a crash if you set higher buffer size
(like 1000ms) in PlaybackManager, due to rounding errors I presume.
2021-09-04 22:52:02 +02:00
Tom
918f7cb4a8 Meta: Force legacy xAPIC when using 8 cores or less
This is merely so that we exercise the legacy xAPIC code when we don't
really need x2APIC.
2021-09-04 22:22:58 +02:00
Tom
8a258edfd6 Kernel: Add x2APIC support
This allows addressing all cores on more modern processors. For now,
we still have a hardcoded limit of 64 due to s_processors being a
static array.
2021-09-04 22:22:58 +02:00
Tom
123087e235 Kernel: Allow specifying ecx with CPUID
Some CPUID functions (e.g. 0xb) require input values in ecx.
2021-09-04 22:22:58 +02:00
Tom
d14d68c462 SystemMonitor: Fix CPU usage calculation
Casting u64 to float is probably not a safe thing to do. Also, keep
time deltas in u64 values as they can easily wrap between calculations.
This fixes CPU usage calculation when a process is spinning in a loop.
2021-09-04 21:48:46 +02:00
Karol Kosek
dcc9db48c5 HackStudio: Drop files to the selected editor
Previously, the files were opened in the current editor, instead of one
that received a drop event.
2021-09-04 21:48:27 +02:00
luiz
964249a5b0 LibGUI: Fixes modified indicator behavior after saving
Pior to this change when the user added text after having saved the file
the Text Editor wouldn't enable the modified flag, unless this new text
was a new line.

This happened because the UndoStack was merging the Command added by
the new text with the old text one, and when is_current_modified()
was called, the m_stack_index would not have been incremented, and
it would return false.

In this change was added a condition to verify if the modified tag is
active, and the merge is only done if the document is already modified.
2021-09-04 21:04:33 +02:00
Karol Kosek
83c412ee9e SoundPlayer: Create only one playlist widget
Prior this change, opening a playlist always spawned a new widget.
This could end up with having a few the same widgets, which you couldn't
even close (besides the last one).
2021-09-04 21:03:01 +02:00
Karol Kosek
09685d0239 AudioApplet: Fix initial mute state
During conversion from Core::ConfigFile to LibConfig
in c646efaf49, the requested key name
has been changed from 'Mute' to 'Muted', resulting in using always
the default value.
2021-09-04 21:01:28 +02:00
Idan Horowitz
e8f6840471 AK+LibRegex: Disable construction of views from temporary Strings 2021-09-04 21:01:15 +02:00
Liav A
e606ff3751 Kernel/VirtIO: Determine VirtIO device class also with the PCI device ID
According to the VirtIO 1.0 specification:
"Non-transitional devices SHOULD have a PCI Device ID in the range
0x1040 to 0x107f. Non-transitional devices SHOULD have a PCI Revision ID
of 1 or higher. Non-transitional devices SHOULD have a PCI Subsystem
Device ID of 0x40 or higher."

It also says that:
"Transitional devices MUST have a PCI Revision ID of 0. Transitional
devices MUST have the PCI Subsystem Device ID matching the Virtio
Device ID, as indicated in section 5. Transitional devices MUST have the
Transitional PCI Device ID in the range 0x1000 to 0x103f."

So, for legacy devices, we know that revision ID in the PCI header won't
be 1, so we probe for PCI_SUBSYSTEM_ID value.
Instead of using the subsystem device ID, we can probe the DEVICE_ID
value directly in case it's not a legacy device.
This should cover all possibilities for identifying VirtIO devices, both
per the specification of 0.9.5, and future revisions from 1.0 onwards.
2021-09-04 20:53:26 +02:00
Andreas Kling
24ef8b118a LibSymbolication: Unbreak symbolication with -z separate-code linking
We were incorrectly assuming that the mapped .text segment for an ELF
image was always at the base of the image mapping. Now that we have
.rodata mappings as well, it's possible for one of them to come before
the .text.
2021-09-04 20:30:56 +02:00
Andreas Kling
b7ee0191ea LibELF: Name non-executable map regions ".rodata" instead of ".text" 2021-09-04 20:30:56 +02:00
Andreas Kling
769f777098 Assistant: Use HashMap::ensure() in Database::did_receive_results() 2021-09-04 20:30:56 +02:00
Andreas Kling
6f6473d6a4 SystemMonitor: Use HashMap::ensure() in ProcessModel::update() 2021-09-04 20:30:56 +02:00
Andreas Kling
e40e91b9df LibDebug: Use HashMap::ensure() in DebugInfo::prepare_lines() 2021-09-04 20:30:56 +02:00
Andreas Kling
500067d3a6 LibGfx: Make FontDatabase cache store fonts in NonnullRefPtr
We don't cache failed font lookups, so there's no need for nullity here.
2021-09-04 20:30:56 +02:00
Andreas Kling
363c78e5d2 LookupServer: Use HashMap::ensure() in load_etc_hosts() 2021-09-04 20:30:56 +02:00
Andreas Kling
1a71e20f93 AK: Add HashMap::ensure(key, callback)
This function ensures that a key is present in the HashMap.
If it's not present, it is inserted, and the corresponding value
is initialized with whatever the callback returns.

It allows us to express this:

    auto it = map.find(key);
    if (it == map.end()) {
        map.set(it, make_a_value());
        it = map.find(key);
    }
    auto& value = it->value;

Like this:

    auto& value = map.ensure(key, [] { return make_a_value(); });

Note that the callback is only invoked if we have to insert a missing
key into the HashMap. This is important in case constructing the default
value is expensive or otherwise undesirable.
2021-09-04 20:30:56 +02:00
Linus Groh
0094259d72 LibJS: Implement Intl.DisplayNames.supportedLocalesOf() 2021-09-04 19:08:18 +01:00
Linus Groh
8f3a5ba5d8 LibJS: Add Array::create_from() for generic Vector<T>
It relies on a mapper function to convert each T& to a JS::Value. This
allows us to avoid awkward Vector<T> to MarkedValueList conversion at
the call site.
2021-09-04 19:08:18 +01:00
Ben Wiederhake
e7e2ccc04c Documentation: Prevent QtCreator from formatting IPC as C++ 2021-09-04 17:57:59 +02:00
sin-ack
1999b66f38 LibGfx: Intersect the bounding box with the main rect in draw_text
Without this, the bounding rect for the text as generated by TextLayout
can go beyond the bounds of the user-supplied drawing rect and cause the
text to overlap because of the line_rect.intersect(rect) a few lines
below.
2021-09-04 16:48:27 +02:00
Liav A
ed6c1f53af Kernel/VirtIO: Defer initialization of device out of the constructor
This ensures we safely handle interrupts (which can call virtual
functions), so they don't happen in the constructor - this pattern can
lead to a crash, if we are still in the constructor context because
not all methods are available for usage (some are pure virtual,
so it's possible to call __cxa_pure_virtual).

Also, under some conditions like adding a PCI device via PCI-passthrough
mechanism in QEMU, it became exposed to the eye that the code asserts on
RNG::handle_device_config_change(). That device has no configuration but
if the hypervisor still misbehaves and tries to configure it, we should
simply return false to indicate nothing happened.
2021-09-04 16:36:02 +02:00
Liav A
e490c17bde Kernel/SysFS: Ensure data stability when reading from Inodes
Like with the ProcFS, description data can change at anytime, so it's
wise to ensure that when the userland reads from an Inode, data is
consistent unless the userland indicated it wants to refresh the data
(by seeking to offset 0, or re-attaching the Inode).
Otherwise, if the data changes in the middle of the reading, it can
cause silent corruption in output which can lead to random crashes.
2021-09-04 16:33:56 +02:00
Stephan Unverwerth
a595345e7c AK: Make declaration of std::move and std::forward optional
This introduces a new define AK_DONT_REPLACE_STD that disables our own
implementation of std::move and std::forward. Some ports include both
STL and AK headers which causes conflicts when trying to resolve those
functions. The port can define AK_DONT_REPLACE_STD before including
Serenity headers in that case.
2021-09-04 16:32:54 +02:00
Liav A
f2ba44cbdf Kernel/DevFS: Remove unnecessary include 2021-09-04 16:19:12 +02:00
Liav A
d189cb6a24 Kernel/Devices: Remove unnecessary virtual method
The is_disk_device method is not being overrided by any class or called
by anyone, so let's just remove it.
2021-09-04 16:19:12 +02:00
Idan Horowitz
1a19d2c2df LibGfx: Stop using a Utf8View that points to a temporary String 2021-09-04 16:13:30 +02:00
Idan Horowitz
72b21343ad LibGfx: Convert line text into a Utf8View before finding its direction
We were accidentally calling TextDirection::get_text_direction with a
String instead of a UtfView, which meant each byte was treated as a
codepoint, resulting in incorrect identification of text direction.
2021-09-04 16:13:30 +02:00
Tobias Christiansen
5d732711a2 PixelPaint: Fix broken opening of files from Shell
The fd would get closed when the File went out of scope, so we couldn't
open any file specified by 'pp <path to file>'. We need the fd to be
alive and we solemnly swear to take good care of it and close it
ourselves later.
2021-09-04 16:07:10 +02:00
David Isaksson
9699648b2a SystemMonitor: Make memory statistics dynamically formatted by size
Previously all memory values on the performance was formatted as KiB,
but with such formatting it can be quite hard to read large numbers
(as mentioned by Andreas on todays office hours livestream :^)).
This patch makes use of the human readable formatting utilies and
displays them in an easier to read format.
2021-09-04 16:05:32 +02:00
Ben Wiederhake
7224308358 LibGfx: Reject GIFs with ridiculously large symbols
This also prevents exploitation by malicious GIFs.
Found by OSS Fuzz, long-standing issue
(since 259f8541fc)
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29034
2021-09-04 16:00:25 +02:00
Ben Wiederhake
39c09cec88 LibGfx: Elide predictable reallocations in GIF loader 2021-09-04 16:00:25 +02:00
Timothy Flynn
90971673c7 LibJS: Implement Intl.Locale.prototype.minimize 2021-09-04 13:51:40 +01:00
Timothy Flynn
a77f323dfb LibUnicode: Implement the Remove Likely Subtags method
Unlike Add Likely Subtags, this method doesn't require generated data.
Instead, it is defined in terms of Add Likely Subtags.
2021-09-04 13:51:40 +01:00
Timothy Flynn
0b1f5118d5 LibJS: Implement Intl.Locale.prototype.maximize 2021-09-04 13:51:40 +01:00
Timothy Flynn
03d7f01e0c LibJS: Add a constructor to create an Intl.Locale object from a LocaleID 2021-09-04 13:51:40 +01:00
Timothy Flynn
3abfe7f7db LibJS: Add missing Intl.Locale initializer for plain boolean type 2021-09-04 13:51:40 +01:00
Timothy Flynn
e6a2ab1202 LibUnicode: Generate an implementation of the Add Likely Subtags method 2021-09-04 13:51:40 +01:00
Timothy Flynn
28ae63177e LibUnicode: Generate the entire locale likely-subtags dataset
The amount of aliases in the likely-subtags dataset is quite large, so
this also needed to change the way the data is generated. Otherwise, the
compiler would complain about the size of the generated code.

Previously, a static method was generated that would effectively parse
the dataset into a HashMap of Unicode::LanguageID at runtime. We now
perform that parsing at generation-time, and instead generate an Array
of a structure similar to Unicode::LanguageID (we cannot use the same
structure because it contains String and Optional, which cannot be used
at compile-time).
2021-09-04 13:51:40 +01:00
Timothy Flynn
ca90231794 LibUnicode: Define is_unicode_*_subtag helpers inline in their header
The UnicodeLocale generator will need to parse canonicalized locale
strings, and will require using these methods. However, the generator
cannot depend on LibUnicode because Locale.cpp within LibUnicode already
depends on the generated file. Instead, defining the methods that the
generator needs inline allows the generator to use them without linking
against LibUnicode.
2021-09-04 13:51:40 +01:00
Andreas Kling
74ce098d58 Kernel: Delete the rvalue-ref qualified version of KResultOr::value()
This makes calling value() on a temporary KResultOr be a compile-time
error. This exposed a number of missing error checks (fixed in the
preceding commits.)
2021-09-04 13:08:37 +02:00
Andreas Kling
d065de1fcf Kernel: Add missing error check when opening TTY for a new process 2021-09-04 13:08:37 +02:00