Bläddra i källkod

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.
Drew Stratford 5 år sedan
förälder
incheckning
44f22c99ef
2 ändrade filer med 11 tillägg och 4 borttagningar
  1. 9 4
      Kernel/Thread.cpp
  2. 2 0
      Kernel/Thread.h

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

+ 2 - 0
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; }