Commit Graph

35 Commits

Author SHA1 Message Date
Andreas Kling
a1944ec966 Kernel: Add missing AK/Format.h include in KResult.h 2021-05-28 09:37:09 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
William McPherson
2479ead718 Everywhere: Remove unnecessary clang-format offs
Mostly due to the fact that clang-format allows aligned comments via
AlignTrailingComments.

We could also use raw string literals in inline asm, which clang-format
deals with properly (and would be nicer in a lot of places).
2021-03-04 11:01:48 +01:00
Ben Wiederhake
860a3bbce3 Kernel: Use default con/de-structors
This may seem like a no-op change, however it shrinks down the Kernel by a bit:
.text -432
.unmap_after_init -60
.data -480
.debug_info -673
.debug_aranges 8
.debug_ranges -232
.debug_line -558
.debug_str -308
.debug_frame -40

With '= default', the compiler can do more inlining, hence the savings.
I intentionally omitted some opportunities for '= default', because they
would increase the Kernel size.
2021-02-28 18:09:12 +01:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Brian Gianforcaro
01a66efe9d Kernel: Mark KResult getters as [[nodiscard]]
There is no reason to call a getter without observing the result, doing
so indicates an error in the code. Mark these methods as [[nodiscard]]
to find these cases.
2021-02-15 09:34:52 +01:00
Tom
1d843c46eb Kernel: KResultOr can use the same storage as the object for the error
Since it can only hold either an object or an error code, we can share
the same storage to hold either.
2021-02-08 18:00:38 +01:00
Tom
27a395d964 Kernel: Fix KResultOr copy-move from itself case
If move-assigning from itself we shouldn't do anything.
2021-02-07 23:02:57 +01:00
Tom
f74e31c74d Kernel: Change KResultOr::take_value to use move semantics
This may be more light weight than copying the object.
2021-02-07 22:25:15 +01:00
asynts
67583bc424 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
2021-01-22 22:14:30 +01:00
Andreas Kling
19d3f8cab7 Kernel+LibC: Turn errno codes into a strongly typed enum
..and allow implicit creation of KResult and KResultOr from ErrnoCode.
This means that kernel functions that return those types can finally
do "return EINVAL;" and it will just work.

There's a handful of functions that still deal with signed integers
that should be converted to return KResults.
2021-01-20 23:20:02 +01:00
Ben Wiederhake
38c5b3f788 Kernel: Fix inverted logic in KResultOr
This silly inversion has survived so long because we don't exercise the
'unhappy paths' enough. :^)
2021-01-16 12:53:23 +01:00
Linus Groh
bbe787a0af Everywhere: Re-format with clang-format-11
Compared to version 10 this fixes a bunch of formatting issues, mostly
around structs/classes with attributes like [[gnu::packed]], and
incorrect insertion of spaces in parameter types ("T &"/"T &&").
I also removed a bunch of // clang-format off/on and FIXME comments that
are no longer relevant - on the other hand it tried to destroy a couple of
neatly formatted comments, so I had to add some as well.
2020-12-31 21:51:00 +01:00
Ben Wiederhake
64cc3f51d0 Meta+Kernel: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
Tom
03f45febe2 Kernel: Fix KResultOr move semantics
We need to track whether we actually own the storage.
2020-09-19 00:30:08 +02:00
Brian Gianforcaro
34dd8edcb3 Kernel: Decorate KResult and KResultOr<T> methods with [[nodiscard]]
This would have found my error propagation bug.
2020-08-09 00:13:39 +02:00
Brian Gianforcaro
f3cbb79f80 Kernel: Decorate KResult with [[nodiscard]] 2020-08-05 14:36:48 +02:00
Brian Gianforcaro
ea3ee4f3f3 Kernel: Decorate KResultOr with [[nodiscard]] to catch misbehaving callers
The [[nodiscard]] decorator enables us to have the compile emit a
warning anytime the decorated type or function's return value isn't
observed. It's very useful for catching error checking bugs in systems
which use C style error handling.
2020-08-05 10:26:29 +02:00
Sergey Bugaev
1e266aec27 Kernel: Always inline some KResult / KResultOr<> methods
Namely, those that contain assertions that can be easily eliminated at call site.
2020-06-02 21:49:47 +02:00
Sergey Bugaev
d2b500fbcb AK+Kernel: Help the compiler inline a bunch of trivial methods
If these methods get inlined, the compiler is able to statically eliminate most
of the assertions. Alas, it doesn't realize this, and believes inlining them to
be too expensive. So give it a strong hint that it's not the case.

This *decreases* the kernel binary size.
2020-05-20 14:11:13 +02:00
Andreas Kling
c06d5ef114 Kernel+LibC: Remove ESUCCESS
There's no official ESUCCESS==0 errno code, and it keeps breaking the
Lagom build when we use it, so let's just say 0 instead.
2020-04-10 13:09:35 +02:00
Andreas Kling
a356e48150 Kernel: Move all code into the Kernel namespace 2020-02-16 01:27:42 +01:00
Andreas Kling
2f82d4fb31 Kernel: Add KResultOr<T>::result()
This is just a handy way to get either an error or a KSuccess, even if
there is a T present.
2020-02-08 11:57:53 +01:00
Andreas Kling
94ca55cefd Meta: Add license header to source files
As suggested by Joshua, this commit adds the 2-clause BSD license as a
comment block to the top of every source file.

For the first pass, I've just added myself for simplicity. I encourage
everyone to add themselves as copyright holders of any file they've
added or modified in some significant way. If I've added myself in
error somewhere, feel free to replace it with the appropriate copyright
holder instead.

Going forward, all new source files should include a license header.
2020-01-18 09:45:54 +01:00
Andreas Kling
08cfcb888c Kernel: Add KResult::error() to make it look symmetrical with KResultOr 2020-01-06 12:08:27 +01:00
Andrew Kaster
bae8e21a8b Kernel: Add move assign operator to KResultOr 2019-12-29 23:01:27 +01:00
Andreas Kling
ae4d707684 Kernel: Align the KResult value storage appropriately.
We should figure out how to convert this code to using AK::Result.
2019-08-02 19:22:48 +02:00
Sergey Bugaev
d211307547 Kernel: Fix KResultOr move constructor not copying errors. 2019-06-14 06:24:02 +02:00
Andreas Kling
39d1a9ae66 Meta: Tweak .clang-format to not wrap braces after enums. 2019-06-07 17:13:23 +02:00
Robin Burchell
0dc9af5f7e Add clang-format file
Also run it across the whole tree to get everything using the One True Style.
We don't yet run this in an automated fashion as it's a little slow, but
there is a snippet to do so in makeall.sh.
2019-05-28 17:31:20 +02:00
Andreas Kling
60a819c14a Kernel: Yet more work on bringing up POSIX SHM. 2019-04-09 02:37:38 +02:00
Andreas Kling
028afabf6b Kernel: Port more code to KResult and KResultOr<T>. 2019-03-06 22:14:31 +01:00
Andreas Kling
5b27f11b97 Kernel: Use KResult in unlink() and rmdir(). 2019-02-27 14:11:25 +01:00
Andreas Kling
424368034b LibC: Make errno codes be #defines instead of enum values.
It turns out that a lot of 3rd party software does things like:

    #ifdef EINTR
        ...
    #endif

This won't work if EINTR is an enum. So much for that nice idea.
2019-02-26 22:40:35 +01:00
Andreas Kling
5af4e622b9 Kernel: Add KResult and KResultOr<T> classes.
The idea here is to combine a potential syscall error code with an arbitrary
type in the case of success. I feel like this will end up much less error
prone than returning some arbitrary type that kinda sorta has bool semantics
(but sometimes not really) and passing the error through an out-param.

This patch only converts a few syscalls to using it. More to come.
2019-02-25 20:50:22 +01:00