forked from Bananymous/banan-os
Kernel: Threads now use only 4 KiB stack :)
This commit is contained in:
parent
f5e676b2b7
commit
12779cdef8
|
@ -40,6 +40,9 @@ namespace Kernel
|
|||
State state() const { return m_state; }
|
||||
void terminate() { m_state = State::Terminating; }
|
||||
|
||||
uintptr_t stack_base() const { return (uintptr_t)m_stack_base; }
|
||||
size_t stack_size() const { return m_stack_size; }
|
||||
|
||||
static Thread& current() ;
|
||||
BAN::RefPtr<Process> process();
|
||||
|
||||
|
@ -50,6 +53,7 @@ namespace Kernel
|
|||
void on_exit();
|
||||
|
||||
private:
|
||||
static constexpr size_t m_stack_size = 4096 * 1;
|
||||
void* m_stack_base = nullptr;
|
||||
uintptr_t m_rip = 0;
|
||||
uintptr_t m_rsp = 0;
|
||||
|
|
|
@ -9,10 +9,11 @@
|
|||
namespace Kernel
|
||||
{
|
||||
|
||||
static pid_t s_next_pid = 1;
|
||||
|
||||
BAN::ErrorOr<BAN::RefPtr<Process>> Process::create_kernel(entry_t entry, void* data)
|
||||
{
|
||||
static pid_t next_pid = 1;
|
||||
auto process = TRY(BAN::RefPtr<Process>::create(next_pid++));
|
||||
auto process = TRY(BAN::RefPtr<Process>::create(s_next_pid++));
|
||||
TRY(process->m_working_directory.push_back('/'));
|
||||
TRY(process->add_thread(entry, data));
|
||||
return process;
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
namespace Kernel
|
||||
{
|
||||
|
||||
static constexpr size_t thread_stack_size = 16384;
|
||||
|
||||
template<size_t size, typename T>
|
||||
static void write_to_stack(uintptr_t& rsp, const T& value)
|
||||
|
@ -45,10 +44,10 @@ namespace Kernel
|
|||
|
||||
BAN::ErrorOr<void> Thread::initialize(entry_t entry, void* data)
|
||||
{
|
||||
m_stack_base = kmalloc(thread_stack_size, PAGE_SIZE);
|
||||
m_stack_base = kmalloc(m_stack_size, PAGE_SIZE);
|
||||
if (m_stack_base == nullptr)
|
||||
return BAN::Error::from_errno(ENOMEM);
|
||||
m_rsp = (uintptr_t)m_stack_base + thread_stack_size;
|
||||
m_rsp = (uintptr_t)m_stack_base + m_stack_size;
|
||||
m_rip = (uintptr_t)entry;
|
||||
|
||||
write_to_stack<sizeof(void*)>(m_rsp, this);
|
||||
|
|
Loading…
Reference in New Issue