Kernel: Don't allocate and discard an extra stack for every process.

This commit is contained in:
Andreas Kling 2019-02-22 00:27:06 +01:00
parent b30773638e
commit e969419202
Notes: sideshowbarker 2024-07-19 15:38:46 +09:00
2 changed files with 13 additions and 18 deletions

View file

@ -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;

View file

@ -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 };