1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-03 05:22:08 +00:00

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
parent 0cf65cf7ec
commit 83fed5b2de
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)