From 44f22c99ef71453bbba9814368c8d13c342d49e8 Mon Sep 17 00:00:00 2001 From: Drew Stratford Date: Sat, 2 Nov 2019 22:11:41 +1300 Subject: [PATCH] Thread.cpp: add method get_RegisterDump_from_stack(). This refactors some the RegisterDump code from dispatch_signal into a stand-alone function, allowing for better reuse. --- Kernel/Thread.cpp | 13 +++++++++---- Kernel/Thread.h | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index ef12fb74c4..452f8f712f 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -417,10 +417,7 @@ ShouldUnblockThread Thread::dispatch_signal(u8 signal) } ProcessPagingScope paging_scope(m_process); - // The userspace registers should be stored at the top of the stack - // We have to subtract 2 because the processor decrements the kernel - // stack before pushing the args. - auto& regs = *(RegisterDump*)(kernel_stack_top() - sizeof(RegisterDump) - 2); + auto& regs = get_RegisterDump_from_stack(); u32 old_signal_mask = m_signal_mask; u32 new_signal_mask = action.mask; @@ -509,6 +506,14 @@ void Thread::push_value_on_stack(u32 value) *stack_ptr = value; } +RegisterDump& Thread::get_RegisterDump_from_stack() +{ + // The userspace registers should be stored at the top of the stack + // We have to subtract 2 because the processor decrements the kernel + // stack before pushing the args. + return *(RegisterDump*)(kernel_stack_top() - sizeof(RegisterDump) - 2); +} + 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)", PROT_READ | PROT_WRITE, false); diff --git a/Kernel/Thread.h b/Kernel/Thread.h index f8f54f6724..d2c89e2bdd 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -210,6 +210,8 @@ public: u32 frame_ptr() const { return m_tss.ebp; } u32 stack_ptr() const { return m_tss.esp; } + RegisterDump& get_RegisterDump_from_stack(); + u16 selector() const { return m_far_ptr.selector; } TSS32& tss() { return m_tss; } const TSS32& tss() const { return m_tss; }