1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:18:11 +00:00

Kernel: Use TRY() when creating first thread in a new process

This commit is contained in:
Andreas Kling 2021-09-05 14:04:51 +02:00
parent 2ab8fd89fc
commit ae885b188f

View file

@ -263,19 +263,16 @@ KResult Process::attach_resources(NonnullOwnPtr<Memory::AddressSpace>&& prealloc
{
m_space = move(preallocated_space);
auto thread_or_error = [&] {
auto create_first_thread = [&] {
if (fork_parent) {
// NOTE: fork() doesn't clone all threads; the thread that called fork() becomes the only thread in the new process.
return Thread::current()->try_clone(*this);
}
// NOTE: This non-forked code path is only taken when the kernel creates a process "manually" (at boot.)
return Thread::try_create(*this);
}();
};
if (thread_or_error.is_error())
return thread_or_error.error();
first_thread = thread_or_error.release_value();
first_thread = TRY(create_first_thread());
if (!fork_parent) {
// FIXME: Figure out if this is really necessary.