-
Notifications
You must be signed in to change notification settings - Fork 3.3k
AK+Kernel+Userland: Don't allow AK::{Byte,}String and Vector::append() in the kernel
#26406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AK+Kernel+Userland: Don't allow AK::{Byte,}String and Vector::append() in the kernel
#26406
Conversation
Kernel code should use KString instead. Compared to AK::String, KString is a very simple string class that just wraps a char array and doesn't have any fancy features such as reference counting.
| Vector<StringView> parts; | ||
| for_each_split_view(separator, split_behavior, [&](StringView view) { | ||
| parts.append(view); | ||
| parts.try_append(view).release_value_but_fixme_should_propagate_errors(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure if this is the right solution. Maybe we should instead not allow split_view() in the kernel at all. Directly using for_each_split_view() should be enough for most use cases in the kernel, otherwise we could maybe add try_split_view().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can always think about that in a follow-up 🙂
|
(a bit surprising match() isn't allowed; I'm guessing it internally allocates) |
|
Would be nice if we could make this a decorator or the like, #ifdef KERNEL
#define NOKERNEL [[error("Implicit allocation is disallowed in the Kernel")]]
#else
#define NOKERNEL
#endifdecorator
|
Yeah the current #ifdef zoo isn't nice and I thought of maybe reorganizing some of these functions to only have one big
For some things I may want to include an additional message with what to use instead like: #ifndef KERNEL
Vector(const&) = delete("use .clone() instead");
#endifWith that |
ea70035 to
31269f4
Compare
|
I think I'm going to keep using |
Kernel code should use KString instead. Compared to AK::ByteString, KString is a very simple string class that just wraps a char array and doesn't have any fancy features such as reference counting. Additionally, AK::ByteString isn't OOM-safe at all currently.
31269f4 to
14f5b8e
Compare
We currently don't support loadable modules, so all callers of this function use `MUST()` on the result for now.
Vector::append() will be disallowed in the kernel by the next commit.
This makes it not as easy to forgot to handle OOMs in the kernel. This commit replaces most usages of this function with `try_append(...).release_value_but_fixme_should_propagate_errors()`. But in some cases, using the `TRY` macro or `unchecked_append()` is already possible. In places where allocations should not fail or an OOM would be fatal anyways, `MUST(try_append(...))` should be used explicitly.
14f5b8e to
5bd4d9b
Compare
Kernel code should use
KStringinstead ofAK::{Byte,}String. Enforce this by making it a compile-time error to include<AK/String.h>or<AK/ByteString.h>.Additional, make it not as easy to forget to handle OOMs by only allowing
Vector::try_append()in the kernel.(Not all
Vector::append()overloads were guarded behind a#ifndef KERNELbefore)