Commit Graph

9 Commits

Author SHA1 Message Date
Brian Gianforcaro
4cc41ea186 Kernel: Add an error propagating KString::format(..) API :^)
In the continuous effort of better handling OOM in the kernel,
we want to move away from all AK::String usage. One of the final
pieces left to accomplish this goal is replacing all of the usages
of `String::formatted` with something that can actually propagate
failure.

The StringBuilder API was enhanced in the recent past to propagate
failure and thus a slightly modified version of what exists in
`AK::format` will work well for implementing failable format with
`KString`.
2021-11-30 11:16:35 +01:00
Andreas Kling
79fa9765ca Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace!
This was a slightly tedious refactoring that took a long time, so it's
not unlikely that some bugs crept in.

Nevertheless, it does pass basic functionality testing, and it's just
real nice to finally see the same pattern in all contexts. :^)
2021-11-08 01:10:53 +01:00
Andreas Kling
56a2594de7 Kernel: Make KString factories return KResultOr + use TRY() everywhere
There are a number of places that don't have an error propagation path
right now, so I've added FIXME's about that.
2021-09-06 19:25:36 +02:00
Daniel Bertalan
b847541ee8 Kernel: Allow passing null pointer to delete
The C++ standard says that it's legal to call the `delete` operator with
a null pointer argument, in which case it should be a no-op. I
encountered this issue when running a kernel that's compiled with Clang.
I assume this fact was used for some kind of optimization.
2021-07-14 13:12:25 +02:00
Andreas Kling
43d7a7f274 Kernel: Use kfree_sized() in KString 2021-07-11 14:14:51 +02: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
Brian Gianforcaro
d838a02e74 Kernel: Add KString::must_{..} factory methods
There are a bunch of places like drivers which for all intense and
purposes can't really fail allocation during boot, and if they do
fail we should crash immediately.

This change adds `KString::must_create_uninitialized(..)` as well as
`KString::must_create(..)` for use during early boot initialization of
the Kernel. They enforce that they are only used during early boot.
2021-05-31 14:50:49 +04:30
Brian Gianforcaro
af2c3ab524 Kernel: Remove usage of adopt_own in KString 2021-05-29 09:04:05 +02:00
Andreas Kling
279383a8f3 Kernel: Add KString, a single-owner string with OOM failure exposion
This is a simple string class for use in the kernel. It encapsulates
a length + character array in a single-allocation object.

Main differences from AK::String:

- Single-owner (no reference counting.)
- Allocation failures are exposed, not hidden.

The basic idea is to allow better and more precise string management
in the kernel.
2021-05-28 09:37:09 +02:00