|
From: Nicholas N. <nj...@ca...> - 2004-09-10 15:37:04
|
CVS commit by nethercote:
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.
M +8 -5 core.h 1.20
M +8 -0 vg_ldt.c 1.19
M +6 -25 vg_scheduler.c 1.177
M +42 -0 x86/state.c 1.6
--- valgrind/coregrind/core.h #1.19:1.20
@@ -606,9 +606,7 @@ 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. */
@@ -1500,4 +1498,9 @@ extern void VGA_(load_state) ( arch_thre
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 );
--- valgrind/coregrind/vg_ldt.c #1.18:1.19
@@ -85,4 +85,12 @@
#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. */
--- valgrind/coregrind/vg_scheduler.c #1.176:1.177
@@ -357,6 +357,5 @@ void mostly_clear_thread_record ( Thread
{
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;
@@ -423,5 +422,6 @@ void VG_(scheduler_init) ( void )
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 );
@@ -1253,10 +1253,5 @@ void cleanup_after_thread_exited ( Threa
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 */
@@ -1758,20 +1753,6 @@ void do__apply_in_new_thread ( ThreadId
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;
--- valgrind/coregrind/x86/state.c #1.5:1.6
@@ -449,4 +449,46 @@ n",
/*------------------------------------------------------------*/
+/*--- 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 ---*/
/*------------------------------------------------------------*/
|