Renamed VG_(mark_from_registers) to the more general
VG_(apply_to_GP_regs).  Moved it into m_machine.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3919 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/amd64/state.c b/coregrind/amd64/state.c
index 4159c9b..9fbf6fc 100644
--- a/coregrind/amd64/state.c
+++ b/coregrind/amd64/state.c
@@ -86,35 +86,6 @@
 
 
 /*------------------------------------------------------------*/
-/*--- Thread stuff                                         ---*/
-/*------------------------------------------------------------*/
-
-void VGA_(mark_from_registers)(ThreadId tid, void (*marker)(Addr))
-{
-   ThreadState *tst = VG_(get_ThreadState)(tid);
-   ThreadArchState *arch = &tst->arch;
-
-   /* XXX ask tool about validity? */
-   (*marker)(arch->vex.guest_RAX);
-   (*marker)(arch->vex.guest_RCX);
-   (*marker)(arch->vex.guest_RDX);
-   (*marker)(arch->vex.guest_RBX);
-   (*marker)(arch->vex.guest_RSI);
-   (*marker)(arch->vex.guest_RDI);
-   (*marker)(arch->vex.guest_RSP);
-   (*marker)(arch->vex.guest_RBP);
-   (*marker)(arch->vex.guest_R8);
-   (*marker)(arch->vex.guest_R9);
-   (*marker)(arch->vex.guest_R10);
-   (*marker)(arch->vex.guest_R11);
-   (*marker)(arch->vex.guest_R12);
-   (*marker)(arch->vex.guest_R13);
-   (*marker)(arch->vex.guest_R14);
-   (*marker)(arch->vex.guest_R15);
-}
-
-
-/*------------------------------------------------------------*/
 /*--- Debugger-related operations                          ---*/
 /*------------------------------------------------------------*/
 
diff --git a/coregrind/core.h b/coregrind/core.h
index cf8b15a..ba956aa 100644
--- a/coregrind/core.h
+++ b/coregrind/core.h
@@ -101,9 +101,6 @@
 // For attaching the debugger
 extern Int  VGA_(ptrace_setregs_from_tst) ( Int pid, ThreadArchState* arch );
 
-// Used by leakcheck
-extern void VGA_(mark_from_registers)(ThreadId tid, void (*marker)(Addr));
-
 /* ---------------------------------------------------------------------
    Finally - autoconf-generated settings
    ------------------------------------------------------------------ */
diff --git a/coregrind/m_machine.c b/coregrind/m_machine.c
index 50bd26f..09cebc3 100644
--- a/coregrind/m_machine.c
+++ b/coregrind/m_machine.c
@@ -32,6 +32,7 @@
 #include "pub_core_libcassert.h"
 #include "pub_core_libcbase.h"
 #include "pub_core_machine.h"
+#include "pub_core_scheduler.h"
 
 #define INSTR_PTR(regs)    ((regs).vex.VGA_INSTR_PTR)
 #define STACK_PTR(regs)    ((regs).vex.VGA_STACK_PTR)
@@ -94,6 +95,54 @@
 }
 
 
+static void apply_to_GPs_of_tid(VexGuestArchState* vex, void (*f)(Addr))
+{
+#if defined(VGA_x86)
+   (*f)(vex->guest_EAX);
+   (*f)(vex->guest_ECX);
+   (*f)(vex->guest_EDX);
+   (*f)(vex->guest_EBX);
+   (*f)(vex->guest_ESI);
+   (*f)(vex->guest_EDI);
+   (*f)(vex->guest_ESP);
+   (*f)(vex->guest_EBP);
+#elif defined(VGA_amd64)
+   (*f)(vex->guest_RAX);
+   (*f)(vex->guest_RCX);
+   (*f)(vex->guest_RDX);
+   (*f)(vex->guest_RBX);
+   (*f)(vex->guest_RSI);
+   (*f)(vex->guest_RDI);
+   (*f)(vex->guest_RSP);
+   (*f)(vex->guest_RBP);
+   (*f)(vex->guest_R8);
+   (*f)(vex->guest_R9);
+   (*f)(vex->guest_R10);
+   (*f)(vex->guest_R11);
+   (*f)(vex->guest_R12);
+   (*f)(vex->guest_R13);
+   (*f)(vex->guest_R14);
+   (*f)(vex->guest_R15);
+#else
+#  error Unknown arch
+#endif
+}
+
+
+void VG_(apply_to_GP_regs)(void (*f)(UWord))
+{
+   ThreadId tid;
+
+   for (tid = 1; tid < VG_N_THREADS; tid++) {
+      if (VG_(is_valid_tid)(tid)) {
+         ThreadState* tst = VG_(get_ThreadState)(tid);
+         apply_to_GPs_of_tid(&(tst->arch.vex), f);
+      }
+   }
+}
+
+
+
 /*--------------------------------------------------------------------*/
 /*--- end                                                          ---*/
 /*--------------------------------------------------------------------*/
diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c
index 1554040..49b07e0 100644
--- a/coregrind/m_scheduler/scheduler.c
+++ b/coregrind/m_scheduler/scheduler.c
@@ -164,17 +164,6 @@
    return VG_INVALID_THREADID;
 }
  
-void VG_(mark_from_registers)(void (*mark_addr)(Addr))
-{
-   ThreadId tid;
-
-   for(tid = 1; tid < VG_N_THREADS; tid++) {
-      if (!VG_(is_valid_tid)(tid))
-	 continue;
-      VGA_(mark_from_registers)(tid, mark_addr);
-   }
-}
-
 /* Print the scheduler status. */
 void VG_(pp_sched_status) ( void )
 {
diff --git a/coregrind/x86/state.c b/coregrind/x86/state.c
index 7bbb5d1..462dbdf 100644
--- a/coregrind/x86/state.c
+++ b/coregrind/x86/state.c
@@ -132,27 +132,6 @@
 }
 
 /*------------------------------------------------------------*/
-/*--- Thread stuff                                         ---*/
-/*------------------------------------------------------------*/
-
-void VGA_(mark_from_registers)(ThreadId tid, void (*marker)(Addr))
-{
-   ThreadState *tst = VG_(get_ThreadState)(tid);
-   ThreadArchState *arch = &tst->arch;
-
-   /* XXX ask tool about validity? */
-   (*marker)(arch->vex.guest_EAX);
-   (*marker)(arch->vex.guest_ECX);
-   (*marker)(arch->vex.guest_EDX);
-   (*marker)(arch->vex.guest_EBX);
-   (*marker)(arch->vex.guest_ESI);
-   (*marker)(arch->vex.guest_EDI);
-   (*marker)(arch->vex.guest_ESP);
-   (*marker)(arch->vex.guest_EBP);
-}
-
-
-/*------------------------------------------------------------*/
 /*--- Debugger-related operations                          ---*/
 /*------------------------------------------------------------*/
 
diff --git a/include/pub_tool_aspacemgr.h b/include/pub_tool_aspacemgr.h
index ea709f6..4d2668f 100644
--- a/include/pub_tool_aspacemgr.h
+++ b/include/pub_tool_aspacemgr.h
@@ -49,7 +49,9 @@
 /* Calls into the core used by leak-checking */
 
 /* Calls "add_rootrange" with each range of memory which looks like a
-   plausible source of root pointers. */
+   plausible source of root pointers.  This is very Memcheck-specific --
+   it's used in leak detection.
+*/
 extern void VG_(find_root_memory)(void (*add_rootrange)(Addr addr, SizeT sz));
 
 #endif   // __PUB_TOOL_ASPACEMGR
diff --git a/include/pub_tool_machine.h b/include/pub_tool_machine.h
index b805733..fab2f58 100644
--- a/include/pub_tool_machine.h
+++ b/include/pub_tool_machine.h
@@ -64,6 +64,12 @@
 extern void VG_(set_shadow_regs_area) ( ThreadId tid, OffT guest_state_offset,
                                         SizeT size, const UChar* area );
 
+// Apply a function 'f' to all the general purpose registers in all the
+// current threads.
+// This is very Memcheck-specific -- it's used to find the roots when
+// doing leak checking.
+extern void VG_(apply_to_GP_regs)(void (*f)(UWord val));
+
 #endif   // __PUB_TOOL_MACHINE
 
 /*--------------------------------------------------------------------*/
diff --git a/include/tool.h b/include/tool.h
index 60cb335..38b3857 100644
--- a/include/tool.h
+++ b/include/tool.h
@@ -78,9 +78,6 @@
    not expected to return. */
 extern void VG_(set_fault_catcher)(void (*catcher)(Int sig, Addr addr));
 
-/* Calls "mark_addr" with register values (which may or may not be pointers) */
-extern void VG_(mark_from_registers)(void (*mark_addr)(Addr addr));
-
 /* ------------------------------------------------------------------ */
 /* other, randomly useful functions */
 extern Bool VG_(has_cpuid) ( void );
diff --git a/memcheck/mac_leakcheck.c b/memcheck/mac_leakcheck.c
index b7ef021..09cad70 100644
--- a/memcheck/mac_leakcheck.c
+++ b/memcheck/mac_leakcheck.c
@@ -37,6 +37,7 @@
 #include "pub_tool_libcassert.h"
 #include "pub_tool_libcprint.h"
 #include "pub_tool_libcsignal.h"
+#include "pub_tool_machine.h"
 
 /* Define to debug the memory-leak-detector. */
 #define VG_DEBUG_LEAKCHECK 0
@@ -684,7 +685,7 @@
    VG_(find_root_memory)(lc_scan_memory);
 
    /* Push registers onto mark stack */
-   VG_(mark_from_registers)(lc_markstack_push);
+   VG_(apply_to_GP_regs)(lc_markstack_push);
 
    /* Keep walking the heap until everything is found */
    lc_do_leakcheck(-1);