Kernel: Tidy up Memory::AddressSpace construction

- Return KResultOr<T> in places
- Propagate errors
- Use TRY()
This commit is contained in:
Andreas Kling 2021-09-05 15:13:20 +02:00
commit 83fed5b2de
Notes: sideshowbarker 2024-07-18 04:43:02 +09:00
6 changed files with 16 additions and 30 deletions

View file

@ -219,16 +219,10 @@ void Process::unprotect_data()
KResultOr<NonnullRefPtr<Process>> Process::try_create(RefPtr<Thread>& first_thread, String const& name, UserID uid, GroupID gid, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> cwd, RefPtr<Custody> executable, TTY* tty, Process* fork_parent)
{
auto space = Memory::AddressSpace::try_create(fork_parent ? &fork_parent->address_space() : nullptr);
if (!space)
return ENOMEM;
auto process = adopt_ref_if_nonnull(new (nothrow) Process(name, uid, gid, ppid, is_kernel_process, move(cwd), move(executable), tty));
if (!process)
return ENOMEM;
auto result = process->attach_resources(space.release_nonnull(), first_thread, fork_parent);
if (result.is_error())
return result;
return process.release_nonnull();
auto space = TRY(Memory::AddressSpace::try_create(fork_parent ? &fork_parent->address_space() : nullptr));
auto process = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Process(name, uid, gid, ppid, is_kernel_process, move(cwd), move(executable), tty)));
TRY(process->attach_resources(move(space), first_thread, fork_parent));
return process;
}
Process::Process(const String& name, UserID uid, GroupID gid, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> cwd, RefPtr<Custody> executable, TTY* tty)