From: Nicholas Nethercote Date: Fri, 10 Sep 2004 15:33:32 +0000 (+0000) Subject: Arch-abstraction: X-Git-Tag: svn/VALGRIND_3_0_0~1603 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d544b7d93d321d8ae664f2729973aa8835f28402;p=thirdparty%2Fvalgrind.git Arch-abstraction: - 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 --- diff --git a/coregrind/core.h b/coregrind/core.h index bce17e3df3..cee987d75c 100644 --- a/coregrind/core.h +++ b/coregrind/core.h @@ -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 ); diff --git a/coregrind/vg_ldt.c b/coregrind/vg_ldt.c index cce9fefcb5..d83c9f3600 100644 --- a/coregrind/vg_ldt.c +++ b/coregrind/vg_ldt.c @@ -84,6 +84,14 @@ */ #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 diff --git a/coregrind/vg_scheduler.c b/coregrind/vg_scheduler.c index bc2a0cf47c..71a979638d 100644 --- a/coregrind/vg_scheduler.c +++ b/coregrind/vg_scheduler.c @@ -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; diff --git a/coregrind/x86/state.c b/coregrind/x86/state.c index 72ca1a7c17..884fe4cc56 100644 --- a/coregrind/x86/state.c +++ b/coregrind/x86/state.c @@ -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 ---*/ /*------------------------------------------------------------*/