- 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
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 );
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 );
*/
#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
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;
/* 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
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;
/* 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;
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 ---*/
/*------------------------------------------------------------*/