diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-22 00:27:06 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-22 00:27:06 +0100 |
commit | e96941920209434ebaf76d6c6b1dc24f18026352 (patch) | |
tree | f885a502c4d41a238ee5cbc16f627d707f4836ec /Kernel | |
parent | b30773638e6fb6ac1741ce3d7eed228f5f70bf51 (diff) | |
download | serenity-e96941920209434ebaf76d6c6b1dc24f18026352.zip |
Kernel: Don't allocate and discard an extra stack for every process.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Process.cpp | 29 | ||||
-rw-r--r-- | Kernel/Process.h | 2 |
2 files changed, 13 insertions, 18 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index eb4dbab2c4..fc7e27a1c0 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -399,17 +399,12 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> 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<String> arguments, Vector<String> envir return 0; } +void Process::make_userspace_stack(Vector<String> arguments, Vector<String> 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<String> arguments, Vector<String> 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 71b69253f3..b95c633506 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -306,6 +306,7 @@ private: int do_exec(String path, Vector<String> arguments, Vector<String> environment); void push_value_on_stack(dword); + void make_userspace_stack(Vector<String> arguments, Vector<String> environment); int alloc_fd(); void set_default_signal_dispositions(); @@ -389,7 +390,6 @@ private: Vector<String> m_initial_environment; HashTable<gid_t> m_gids; - Region* m_stack_region { nullptr }; Region* m_signal_stack_user_region { nullptr }; Region* m_signal_stack_kernel_region { nullptr }; |