From 904c871727cca9fc53f6447228df9d8f8bcb2de8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 31 Oct 2019 13:57:07 +0100 Subject: [PATCH] Kernel: Allow userspace stacks to grow up to 4 MB by default Make userspace stacks lazily allocated and allow them to grow up to 4 megabytes. This avoids a lot of silly crashes we were running into with software expecting much larger stacks. :^) --- Kernel/Thread.cpp | 4 ++-- Kernel/Thread.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 467c4903ca8..ca6a3271aef 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -502,7 +502,7 @@ void Thread::push_value_on_stack(u32 value) void Thread::make_userspace_stack_for_main_thread(Vector arguments, Vector environment) { - auto* region = m_process.allocate_region(VirtualAddress(), default_userspace_stack_size, "Stack (Main thread)"); + auto* region = m_process.allocate_region(VirtualAddress(), default_userspace_stack_size, "Stack (Main thread)", PROT_READ | PROT_WRITE, false); ASSERT(region); m_tss.esp = region->vaddr().offset(default_userspace_stack_size).get(); @@ -537,7 +537,7 @@ void Thread::make_userspace_stack_for_main_thread(Vector arguments, Vect void Thread::make_userspace_stack_for_secondary_thread(void* argument) { - m_userspace_stack_region = m_process.allocate_region(VirtualAddress(), default_userspace_stack_size, String::format("Stack (Thread %d)", tid())); + m_userspace_stack_region = m_process.allocate_region(VirtualAddress(), default_userspace_stack_size, String::format("Stack (Thread %d)", tid()), PROT_READ | PROT_WRITE, false); ASSERT(m_userspace_stack_region); m_tss.esp = m_userspace_stack_region->vaddr().offset(default_userspace_stack_size).get(); diff --git a/Kernel/Thread.h b/Kernel/Thread.h index baeb85146de..e0e34ad853f 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -313,7 +313,7 @@ public: } static constexpr u32 default_kernel_stack_size = 65536; - static constexpr u32 default_userspace_stack_size = 65536; + static constexpr u32 default_userspace_stack_size = 4 * MB; private: IntrusiveListNode m_runnable_list_node;