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.
This commit is contained in:
Drew Stratford 2019-11-02 22:11:41 +13:00 committed by Andreas Kling
parent a6e9119537
commit 44f22c99ef
Notes: sideshowbarker 2024-07-19 11:26:10 +09:00
2 changed files with 11 additions and 4 deletions

View file

@ -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<String> arguments, Vector<String> environment)
{
auto* region = m_process.allocate_region(VirtualAddress(), default_userspace_stack_size, "Stack (Main thread)", PROT_READ | PROT_WRITE, false);