]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Arch-abstraction:
authorNicholas Nethercote <n.nethercote@gmail.com>
Fri, 10 Sep 2004 15:33:32 +0000 (15:33 +0000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Fri, 10 Sep 2004 15:33:32 +0000 (15:33 +0000)
- move some LDT constants into the x86-specific code.
- abstract out uses of LDT and TLS in vg_scheduler into the x86-specific code.

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

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

index bce17e3df34f16f745e88936c4941984527cd80a..cee987d75c0ee8bb9233f3c8b82d6947a658a22b 100644 (file)
@@ -605,11 +605,9 @@ struct vg_mallocfunc_info {
 
 extern Bool VG_(sk_malloc_called_by_scheduler);
 
-
-/* Maximum number of LDT entries supported (by the x86). */
-#define VG_M_LDT_ENTRIES     8192
-/* The size of each LDT entry == sizeof(VgLdtEntry) */
-#define VG_LDT_ENTRY_SIZE  8
+/* ---------------------------------------------------------------------
+   Exports of vg_ldt.c
+   ------------------------------------------------------------------ */
 
 /* Alloc & copy, and dealloc. */
 extern VgLdtEntry* VG_(allocate_LDT_for_thread)   ( VgLdtEntry* parent_ldt );
@@ -1499,6 +1497,11 @@ extern void VGA_(init_high_baseBlock) ( Addr client_eip, Addr esp_at_startup );
 extern void VGA_(load_state) ( arch_thread_t*, ThreadId tid );
 extern void VGA_(save_state) ( arch_thread_t*, ThreadId tid );
 
+extern void VGA_(clear_thread)   ( arch_thread_t * );
+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 Bool VGA_(setup_pointercheck) ( void );
 
 extern Int  VGA_(ptrace_setregs_from_BB)  ( Int pid );
index cce9fefcb5c8b9bcfb0a4b8192f576ecaa4d24c9..d83c9f36004fec5ffbc3bf3fec0e6dd551a2b0b8 100644 (file)
 */
 
 #include "core.h"
+
+
+/* Maximum number of LDT entries supported (by the x86). */
+#define VG_M_LDT_ENTRIES   8192
+/* The size of each LDT entry == sizeof(VgLdtEntry) */
+#define VG_LDT_ENTRY_SIZE     8
+
+
 /* Allocate and deallocate LDTs for threads. */
 
 /* Create an LDT.  If the parent_ldt is NULL, zero out the
index bc2a0cf47c7e5dce1d5941a82fc26ed5cec010ea..71a979638deb8c01332ab9e22ea429d9933648ca 100644 (file)
@@ -356,8 +356,7 @@ static
 void mostly_clear_thread_record ( ThreadId tid )
 {
    vg_assert(tid >= 0 && tid < VG_N_THREADS);
-   VG_(threads)[tid].arch.ldt                  = NULL;
-   VG_(clear_TLS_for_thread)(VG_(threads)[tid].arch.tls);
+   VGA_(clear_thread)(&VG_(threads)[tid].arch);
    VG_(threads)[tid].tid                  = tid;
    VG_(threads)[tid].status               = VgTs_Empty;
    VG_(threads)[tid].associated_mx        = NULL;
@@ -422,7 +421,8 @@ void VG_(scheduler_init) ( void )
    /* Copy VG_(baseBlock) state to tid_main's slot. */
    vg_tid_currently_in_baseBlock = tid_main;
    vg_tid_last_in_baseBlock = tid_main;
-   VG_(baseBlock)[VGOFF_(tls_ptr)] = (UInt)VG_(threads)[tid_main].arch.tls;
+
+   VGA_(init_thread)(&VG_(threads)[tid_main].arch);
    save_thread_state ( tid_main );
 
    VG_(threads)[tid_main].stack_highest_word 
@@ -1252,12 +1252,7 @@ void cleanup_after_thread_exited ( ThreadId tid, Bool forcekill )
    VG_TRACK( die_mem_stack, VG_(threads)[tid].stack_base,
                             VG_(threads)[tid].stack_size );
 
-   /* Deallocate its LDT, if it ever had one. */
-   VG_(deallocate_LDT_for_thread)( VG_(threads)[tid].arch.ldt );
-   VG_(threads)[tid].arch.ldt = NULL;
-
-   /* Clear its TLS array. */
-   VG_(clear_TLS_for_thread)( VG_(threads)[tid].arch.tls );
+   VGA_(cleanup_thread)( &VG_(threads)[tid].arch );
 
    /* Not interested in the timeout anymore */
    VG_(threads)[tid].awaken_at = 0xFFFFFFFF;
@@ -1757,22 +1752,8 @@ void do__apply_in_new_thread ( ThreadId parent_tid,
    /* Copy the parent's CPU state into the child's, in a roundabout
       way (via baseBlock). */
    load_thread_state(parent_tid);
-
-   /* We inherit our parent's LDT. */
-   if (VG_(threads)[parent_tid].arch.ldt == NULL) {
-      /* We hope this is the common case. */
-      VG_(baseBlock)[VGOFF_(ldt)] = 0;
-   } else {
-      /* No luck .. we have to take a copy of the parent's. */
-      VG_(threads)[tid].arch.ldt
-        = VG_(allocate_LDT_for_thread)( VG_(threads)[parent_tid].arch.ldt );
-      VG_(baseBlock)[VGOFF_(ldt)] = (UInt)VG_(threads)[tid].arch.ldt;
-   }
-
-   /* Initialise the thread's TLS array */
-   VG_(clear_TLS_for_thread)( VG_(threads)[tid].arch.tls );
-   VG_(baseBlock)[VGOFF_(tls_ptr)] = (UInt)VG_(threads)[tid].arch.tls;
-
+   VGA_(setup_child)( &VG_(threads)[tid].arch,
+                      &VG_(threads)[parent_tid].arch );
    save_thread_state(tid);
    vg_tid_last_in_baseBlock = tid;
 
index 72ca1a7c17764a4c9e6f8bb8100a25c78f99923c..884fe4cc5698209819b127bc4eb2a7e6a0e1ec76 100644 (file)
@@ -447,6 +447,48 @@ n",
       VG_(baseBlock)[VGOFF_(m_ssestate) + i] = junk;
 }
 
+/*------------------------------------------------------------*/
+/*--- Thread stuff                                         ---*/
+/*------------------------------------------------------------*/
+
+void VGA_(clear_thread)( arch_thread_t *arch )
+{
+   arch->ldt = NULL;
+   VG_(clear_TLS_for_thread)(arch->tls);
+}  
+
+void VGA_(init_thread)( arch_thread_t *arch )
+{
+   VG_(baseBlock)[VGOFF_(tls_ptr)] = (UInt)arch->tls;
+}  
+
+void VGA_(cleanup_thread) ( arch_thread_t *arch )
+{  
+   /* Deallocate its LDT, if it ever had one. */
+   VG_(deallocate_LDT_for_thread)( arch->ldt ); 
+   arch->ldt = NULL;
+   
+   /* Clear its TLS array. */
+   VG_(clear_TLS_for_thread)( arch->tls );
+}  
+
+void VGA_(setup_child) ( arch_thread_t *regs, arch_thread_t *parent_regs )
+{  
+   /* We inherit our parent's LDT. */
+   if (parent_regs->ldt == NULL) {
+      /* We hope this is the common case. */
+      VG_(baseBlock)[VGOFF_(ldt)] = 0;
+   } else {
+      /* No luck .. we have to take a copy of the parent's. */
+      regs->ldt = VG_(allocate_LDT_for_thread)( parent_regs->ldt );
+      VG_(baseBlock)[VGOFF_(ldt)] = (UInt) regs->ldt;
+   }
+
+   /* Initialise the thread's TLS array */
+   VG_(clear_TLS_for_thread)( regs->tls );
+   VG_(baseBlock)[VGOFF_(tls_ptr)] = (UInt) regs->tls;
+}  
+
 /*------------------------------------------------------------*/
 /*--- pointercheck                                         ---*/
 /*------------------------------------------------------------*/