1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:47:35 +00:00

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.
This commit is contained in:
Andreas Kling 2021-09-06 19:24:54 +02:00
parent 69b9b2888c
commit 56a2594de7
21 changed files with 100 additions and 122 deletions

View file

@ -475,9 +475,7 @@ KResult Process::do_exec(NonnullRefPtr<FileDescription> main_program_description
return ENOENT;
auto new_process_name = parts.take_last();
auto new_main_thread_name = KString::try_create(new_process_name);
if (!new_main_thread_name)
return ENOMEM;
auto new_main_thread_name = TRY(KString::try_create(new_process_name));
auto main_program_metadata = main_program_description->metadata();
@ -598,7 +596,7 @@ KResult Process::do_exec(NonnullRefPtr<FileDescription> main_program_description
// NOTE: Be careful to not trigger any page faults below!
m_name = move(new_process_name);
new_main_thread->set_name(new_main_thread_name.release_nonnull());
new_main_thread->set_name(move(new_main_thread_name));
{
ProtectedDataMutationScope scope { *this };

View file

@ -44,15 +44,13 @@ KResultOr<FlatPtr> Process::sys$create_thread(void* (*entry)(void*), Userspace<c
auto thread = TRY(Thread::try_create(*this));
// FIXME: Don't make a temporary String here
auto new_thread_name = KString::try_create(String::formatted("{} [{}]", m_name, thread->tid().value()));
if (!new_thread_name)
return ENOMEM;
auto new_thread_name = TRY(KString::try_create(String::formatted("{} [{}]", m_name, thread->tid().value())));
// We know this thread is not the main_thread,
// So give it a unique name until the user calls $set_thread_name on it
// length + 4 to give space for our extra junk at the end
StringBuilder builder(m_name.length() + 4);
thread->set_name(new_thread_name.release_nonnull());
thread->set_name(move(new_thread_name));
if (!is_thread_joinable)
thread->detach();

View file

@ -86,9 +86,7 @@ KResultOr<FlatPtr> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params
new_unveiled_path = TRY(custody_or_error.value()->try_serialize_absolute_path());
} else if (custody_or_error.error() == ENOENT && parent_custody && (new_permissions & UnveilAccess::CreateOrRemove)) {
auto parent_custody_path = TRY(parent_custody->try_serialize_absolute_path());
new_unveiled_path = KLexicalPath::try_join(parent_custody_path->view(), KLexicalPath::basename(path->view()));
if (!new_unveiled_path)
return ENOMEM;
new_unveiled_path = TRY(KLexicalPath::try_join(parent_custody_path->view(), KLexicalPath::basename(path->view())));
} else {
// FIXME Should this be EINVAL?
return custody_or_error.error();