diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index eb4dbab2c43..fc7e27a1c04 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -399,17 +399,12 @@ int Process::do_exec(String path, Vector arguments, Vector envir m_tss.gs = 0x23; m_tss.ss = 0x23; m_tss.cr3 = page_directory().cr3(); - m_stack_region = allocate_region(LinearAddress(), default_userspace_stack_size, "stack"); - ASSERT(m_stack_region); - m_stack_top3 = m_stack_region->laddr().offset(default_userspace_stack_size).get(); - m_tss.esp = m_stack_top3; + make_userspace_stack(move(arguments), move(environment)); m_tss.ss0 = 0x10; m_tss.esp0 = old_esp0; m_tss.ss2 = m_pid; m_executable = descriptor->inode(); - m_initial_arguments = move(arguments); - m_initial_environment = move(environment); if (descriptor->metadata().is_setuid()) m_euid = descriptor->metadata().uid; @@ -424,6 +419,17 @@ int Process::do_exec(String path, Vector arguments, Vector envir return 0; } +void Process::make_userspace_stack(Vector arguments, Vector environment) +{ + auto* region = allocate_region(LinearAddress(), default_userspace_stack_size, "stack"); + ASSERT(region); + m_stack_top3 = region->laddr().offset(default_userspace_stack_size).get(); + m_tss.esp = m_stack_top3; + + m_initial_arguments = move(arguments); + m_initial_environment = move(environment); +} + int Process::exec(String path, Vector arguments, Vector environment) { // The bulk of exec() is done by do_exec(), which ensures that all locals @@ -679,17 +685,6 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring m_stack_top0 = (stack_bottom + default_kernel_stack_size) & 0xffffff8; m_tss.esp = m_stack_top0; } else { - if (fork_parent) { - m_stack_top3 = fork_parent->m_stack_top3; - } else { - auto* region = allocate_region(LinearAddress(), default_userspace_stack_size, "stack"); - ASSERT(region); - m_stack_top3 = region->laddr().offset(default_userspace_stack_size).get(); - m_tss.esp = m_stack_top3; - } - } - - if (is_ring3()) { // Ring3 processes need a separate stack for Ring0. m_kernel_stack = kmalloc(default_kernel_stack_size); m_stack_top0 = ((dword)m_kernel_stack + default_kernel_stack_size) & 0xffffff8; diff --git a/Kernel/Process.h b/Kernel/Process.h index 71b69253f35..b95c6335066 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -306,6 +306,7 @@ private: int do_exec(String path, Vector arguments, Vector environment); void push_value_on_stack(dword); + void make_userspace_stack(Vector arguments, Vector environment); int alloc_fd(); void set_default_signal_dispositions(); @@ -389,7 +390,6 @@ private: Vector m_initial_environment; HashTable m_gids; - Region* m_stack_region { nullptr }; Region* m_signal_stack_user_region { nullptr }; Region* m_signal_stack_kernel_region { nullptr };