diff options
author | Liav A <liavalb@gmail.com> | 2021-08-07 22:40:54 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-12 20:57:32 +0200 |
commit | 04c2addaa89ac63d6830baae70afdcbca0c4cd21 (patch) | |
tree | 451234716415a718e98900ccb84ebcc7de60edc6 | |
parent | 01b79910b3b881c26a972487fddb4251682438f5 (diff) | |
download | serenity-04c2addaa89ac63d6830baae70afdcbca0c4cd21.zip |
Kernel: Fail process creating earlier if can't create AddressSpace
It makes more sense to fail the Process creation earlier if we can't
create an AddressSpace for the new Process.
-rw-r--r-- | Kernel/Process.cpp | 12 | ||||
-rw-r--r-- | Kernel/Process.h | 2 |
2 files changed, 7 insertions, 7 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 94ca8f0c8a..359b277a35 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -229,10 +229,13 @@ void Process::unprotect_data() RefPtr<Process> Process::create(RefPtr<Thread>& first_thread, const String& name, uid_t uid, gid_t 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 {}; auto process = adopt_ref_if_nonnull(new (nothrow) Process(name, uid, gid, ppid, is_kernel_process, move(cwd), move(executable), tty)); if (!process) return {}; - auto result = process->attach_resources(first_thread, fork_parent); + auto result = process->attach_resources(space.release_nonnull(), first_thread, fork_parent); if (result.is_error()) return {}; return process; @@ -261,12 +264,9 @@ Process::Process(const String& name, uid_t uid, gid_t gid, ProcessID ppid, bool dbgln_if(PROCESS_DEBUG, "Created new process {}({})", m_name, this->pid().value()); } -KResult Process::attach_resources(RefPtr<Thread>& first_thread, Process* fork_parent) +KResult Process::attach_resources(NonnullOwnPtr<Memory::AddressSpace>&& preallocated_space, RefPtr<Thread>& first_thread, Process* fork_parent) { - m_space = Memory::AddressSpace::try_create(fork_parent ? &fork_parent->address_space() : nullptr); - if (!m_space) - return ENOMEM; - + m_space = move(preallocated_space); if (fork_parent) { // NOTE: fork() doesn't clone all threads; the thread that called fork() becomes the only thread in the new process. first_thread = Thread::current()->clone(*this); diff --git a/Kernel/Process.h b/Kernel/Process.h index bea511b106..c8152fd7b0 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -514,7 +514,7 @@ private: Process(const String& name, uid_t uid, gid_t gid, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> cwd, RefPtr<Custody> executable, TTY* tty); static RefPtr<Process> create(RefPtr<Thread>& first_thread, const String& name, uid_t, gid_t, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> cwd = nullptr, RefPtr<Custody> executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr); - KResult attach_resources(RefPtr<Thread>& first_thread, Process* fork_parent); + KResult attach_resources(NonnullOwnPtr<Memory::AddressSpace>&&, RefPtr<Thread>& first_thread, Process* fork_parent); static ProcessID allocate_pid(); void kill_threads_except_self(); |