]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Arch-abstraction:
authorNicholas Nethercote <n.nethercote@gmail.com>
Mon, 13 Sep 2004 13:16:40 +0000 (13:16 +0000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Mon, 13 Sep 2004 13:16:40 +0000 (13:16 +0000)
- in vg_scheduler.c, abstract out some stack manipulations.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2711

coregrind/core.h
coregrind/vg_scheduler.c
coregrind/x86/state.c

index 074899c6fe1a2887d5b3a96de3fe3506bb2afd46..ac9b0add941edbe14283b3d0d4ef888b3a3e34c3 100644 (file)
@@ -1502,6 +1502,9 @@ extern void VGA_(init_thread)    ( arch_thread_t* );
 extern void VGA_(cleanup_thread) ( arch_thread_t* );
 extern void VGA_(setup_child)    ( arch_thread_t*, arch_thread_t* );
 
+extern void VGA_(set_arg_and_bogus_ret) ( ThreadId tid, UWord arg, Addr ret );
+extern void VGA_(thread_initial_stack)  ( ThreadId tid, UWord arg, Addr ret );
+
 // Symtab stuff
 extern UInt* VGA_(reg_addr_from_BB)  ( Int reg );
 extern UInt* VGA_(reg_addr_from_tst) ( Int reg, arch_thread_t* );
index 1cac4f95d9fc008ebfeb15c2b739922130498b14..7c8acdcaca07122f2b161f549d053b8e41276a32 100644 (file)
@@ -1159,17 +1159,10 @@ void make_thread_jump_to_cancelhdlr ( ThreadId tid )
       vg_libpthread.c. */
    vg_assert(VG_(threads)[tid].cancel_pend != NULL);
 
-   /* Push a suitable arg, and mark it as readable. */
-   SET_PTHREQ_ESP(tid, VG_(threads)[tid].arch.m_esp - 4);
-   * (UInt*)(VG_(threads)[tid].arch.m_esp) = (UInt)PTHREAD_CANCELED;
-   VG_TRACK( post_mem_write, VG_(threads)[tid].arch.m_esp, sizeof(void*) );
-
-   /* Push a bogus return address.  It will not return, but we still
-      need to have it so that the arg is at the correct stack offset.
-      Don't mark as readable; any attempt to read this is and internal
-      valgrind bug since thread_exit_wrapper should not return. */
-   SET_PTHREQ_ESP(tid, VG_(threads)[tid].arch.m_esp - 4);
-   * (UInt*)(VG_(threads)[tid].arch.m_esp) = 0xBEADDEEF;
+   /* Set an argument and bogus return address.  The return address will not
+      be used, but we still need to have it so that the arg is at the
+      correct stack offset. */
+   VGA_(set_arg_and_bogus_ret)(tid, (UInt)PTHREAD_CANCELED, 0xBEADDEEF);
 
    /* .cancel_pend will hold &thread_exit_wrapper */
    ARCH_INSTR_PTR(VG_(threads)[tid].arch) = (UInt)VG_(threads)[tid].cancel_pend;
@@ -1710,8 +1703,7 @@ void do__quit ( ThreadId tid )
 }
 
 
-/* Should never be entered.  If it is, will be on the simulated
-   CPU. */
+/* Should never be entered.  If it is, will be on the simulated CPU. */
 static 
 void do__apply_in_new_thread_bogusRA ( void )
 {
@@ -1804,22 +1796,11 @@ void do__apply_in_new_thread ( ThreadId parent_tid,
    VG_TRACK ( die_mem_stack, VG_(threads)[tid].stack_base, 
                              VG_(threads)[tid].stack_size
                              - VG_AR_CLIENT_STACKBASE_REDZONE_SZB);
-   VG_TRACK ( ban_mem_stack, VG_(threads)[tid].arch.m_esp
+   VG_TRACK ( ban_mem_stack, ARCH_STACK_PTR(VG_(threads)[tid].arch)
                              VG_AR_CLIENT_STACKBASE_REDZONE_SZB );
    
-   /* push two args */
-   SET_PTHREQ_ESP(tid, VG_(threads)[tid].arch.m_esp - 8);
-
-   VG_TRACK ( new_mem_stack, (Addr)VG_(threads)[tid].arch.m_esp, 2 * 4 );
-   VG_TRACK ( pre_mem_write, Vg_CorePThread, tid, "new thread: stack",
-                             (Addr)VG_(threads)[tid].arch.m_esp, 2 * 4 );
-   /* push arg and (bogus) return address */
-   * (UInt*)(VG_(threads)[tid].arch.m_esp+4) = (UInt)arg;
-   * (UInt*)(VG_(threads)[tid].arch.m_esp) 
-      = (UInt)&do__apply_in_new_thread_bogusRA;
-
-   VG_TRACK ( post_mem_write, VG_(threads)[tid].arch.m_esp, 2 * 4 );
+   VGA_(thread_initial_stack)(tid, (UWord)arg,
+                              (Addr)&do__apply_in_new_thread_bogusRA);
 
    /* this is where we start */
    ARCH_INSTR_PTR(VG_(threads)[tid].arch) = (UInt)fn;
index 05bb401665b361df26bb2a424c5c38282e9c18cb..3ed1a1bfdac1f12b5f753d024ad5b22e2d6bd6b2 100644 (file)
@@ -490,6 +490,40 @@ void VGA_(setup_child) ( arch_thread_t *regs, arch_thread_t *parent_regs )
    VG_(baseBlock)[VGOFF_(tls_ptr)] = (UInt) regs->tls;
 }  
 
+void VGA_(set_arg_and_bogus_ret)( ThreadId tid, UWord arg, Addr ret )
+{
+   /* Push the arg, and mark it as readable. */
+   SET_PTHREQ_ESP(tid, VG_(threads)[tid].arch.m_esp - sizeof(UWord));
+   * (UInt*)(VG_(threads)[tid].arch.m_esp) = arg;
+   VG_TRACK( post_mem_write, VG_(threads)[tid].arch.m_esp, sizeof(void*) );
+
+   /* Don't mark the pushed return address as readable; any attempt to read
+      this is an internal valgrind bug since thread_exit_wrapper() should not
+      return. */
+   SET_PTHREQ_ESP(tid, VG_(threads)[tid].arch.m_esp - sizeof(UWord));
+   * (UInt*)(VG_(threads)[tid].arch.m_esp) = ret;
+}
+
+void VGA_(thread_initial_stack)(ThreadId tid, UWord arg, Addr ret)
+{
+   Addr esp = (Addr)ARCH_STACK_PTR(VG_(threads)[tid].arch);
+
+   /* push two args */
+   esp -= 8;
+   SET_PTHREQ_ESP(tid, esp);
+   
+   VG_TRACK ( new_mem_stack, esp, 2 * 4 );
+   VG_TRACK ( pre_mem_write, Vg_CorePThread, tid, "new thread: stack",
+                             esp, 2 * 4 );
+
+   /* push arg and (bogus) return address */
+   *(UWord*)(esp+4) = arg;
+   *(UWord*)(esp)   = ret;
+
+   VG_TRACK ( post_mem_write, esp, 2 * 4 );
+}
+
+
 /*------------------------------------------------------------*/
 /*--- Symtab stuff                                         ---*/
 /*------------------------------------------------------------*/