Commit Graph

26749 Commits

Author SHA1 Message Date
Andreas Kling
e1da3b1841 Kernel: Make KResult pull in the TRY macro 2021-09-05 14:08:12 +02:00
Andreas Kling
b4d8e166d8 AK: Add a TRY(expression) macro to simplify the unwrap-or-return pattern
The way we use classes like Kernel::KResultOr<T> and AK::Result<T, E>
makes checking for errors (and short-circuiting returns) quite verbose.

This patch adds a new TRY(expression) macro that either evaluates to
the released result of the expression if successful, or returns the
error if not.

Before:

    auto foo_or_error = get_foo();
    if (foo_or_error.is_error())
        return foo_or_error.release_error();
    auto foo = foo_or_error.release_value();

After:

    auto foo = TRY(get_foo());

The macro uses a GNU C++ extension which is supported by GCC, Clang,
Intel C++, and possibly others. It's not *ideal*, but since it makes our
codebase considerably nicer, let's try(!) it out. :^)

Co-authored-by: Ali Mohammad Pur <mpfard@serenityos.org>
2021-09-05 14:08:12 +02:00
Andreas Kling
fd44336ef8 Kernel: Add KResultOr::release_error()
This is just for symmetry with AK::Result, so that we can use them
interchangeably in generic code.
2021-09-05 13:29:06 +02:00
Ali Mohammad Pur
09dd397160 LibWeb+LibWasm: Implement the WebAssembly.Table object 2021-09-05 15:42:50 +04:30
Ali Mohammad Pur
d52a26de3f LibWasm: Move the vector size limit to Constants.h and increase it a bit 2021-09-05 15:42:50 +04:30
sin-ack
566c5d1e99 AK+Kernel: Move KResult.h to Kernel/API for userspace access
This commit moves the KResult and KResultOr objects to Kernel/API to
signify that they may now be freely used by userspace code at points
where a syscall-related error result is to be expected. It also exposes
KResult and KResultOr to the global namespace to make it nicer to use
for userspace code.
2021-09-05 12:54:48 +02:00
Brian Gianforcaro
d8de352ead LibJS: Declare type aliases with "using" instead of "typedef" 2021-09-05 09:48:43 +01:00
Brian Gianforcaro
3d12d0f408 Kernel: Declare syscall handlers with "using" instead of "typedef"
Also use bit_cast to avoid -Wcast-function-type warning.
2021-09-05 09:48:43 +01:00
Brian Gianforcaro
9d1b27263f Kernel: Declare type aliases with "using" instead of "typedef"
This is the idiomatic way to declare type aliases in modern C++.
Flagged by Sonar Cloud as a "Code Smell", but I happen to agree
with this particular one. :^)
2021-09-05 09:48:43 +01:00
Andreas Kling
7463eb52e8 Kernel: Improve names in the ARP table thread blocker
More instances of functions named "unblock()" that don't actually
unblock in all cases being renamed to something more precise.
2021-09-05 01:10:56 +02:00
Andreas Kling
e851a77346 Kernel: Rename FileBlocker::unblock() => unblock_if_conditions_are_met()
Since this may not actually unblock, the old name was very confusing.
2021-09-05 01:10:56 +02:00
Andreas Kling
68a6d4c30a Kernel: Tidy up InodeWatcher construction
- Rename create() => try_create()
- Use adopt_nonnull_ref_or_enomem()
2021-09-05 01:10:56 +02:00
Andreas Kling
393229e2aa Kernel: Remove UserOrKernelBuffer::copy_into_string()
All former users of this API have been converted to use KString. :^)
2021-09-05 01:10:56 +02:00
Andreas Kling
211c1c087d Kernel/Plan9FS: Use KString instead of String in one place 2021-09-05 01:10:56 +02:00
Andreas Kling
9d736772bd Kernel/Ext2FS: Remove a String allocation in debug logging
We were creating a temporary String just to log the target when writing
a symlink directly into inline storage.
2021-09-05 01:10:55 +02:00
Ralf Donau
4f0e2f2584 Utilities: Modernize output and comparison in the sort utility
Use the comparison operator of AK/String instead of strcmp(3) and
replace fput* by outln.
2021-09-05 00:15:26 +02:00
Andreas Kling
7d8e036e26 Kernel: Tidy up UDPSocket creation a bit
- Rename create() => try_create()
- Use adopt_nonnull_ref_or_enomem()
2021-09-04 23:11:04 +02:00
Andreas Kling
648c768d81 Kernel: Tidy up TCPSocket creation a bit
- Rename create() => try_create()
- Use adopt_nonnull_ref_or_enomem()
2021-09-04 23:11:04 +02:00
Andreas Kling
ac85fdeb1c Kernel: Handle ProcessGroup allocation failures better
- Rename create* => try_create*
- Don't null out existing process group on allocation failure
2021-09-04 23:11:04 +02:00
Andreas Kling
28d6c3a136 Meta: Add Karol Kosek to the contributors list :^) 2021-09-04 23:11:04 +02:00
Andreas Kling
12f820eb08 Kernel: Make Process::try_create() propagate errors better 2021-09-04 23:11:04 +02:00
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