aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coregrind/amd64/state.c29
-rw-r--r--coregrind/core.h3
-rw-r--r--coregrind/m_machine.c49
-rw-r--r--coregrind/m_scheduler/scheduler.c11
-rw-r--r--coregrind/x86/state.c21
-rw-r--r--include/pub_tool_aspacemgr.h4
-rw-r--r--include/pub_tool_machine.h6
-rw-r--r--include/tool.h3
-rw-r--r--memcheck/mac_leakcheck.c3
9 files changed, 60 insertions, 69 deletions
diff --git a/coregrind/amd64/state.c b/coregrind/amd64/state.c
index 4159c9b20..9fbf6fc32 100644
--- a/coregrind/amd64/state.c
+++ b/coregrind/amd64/state.c
@@ -86,35 +86,6 @@ void VGA_(init_thread1state) ( Addr client_rip,
/*------------------------------------------------------------*/
-/*--- 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 cf8b15aab..ba956aa7f 100644
--- a/coregrind/core.h
+++ b/coregrind/core.h
@@ -101,9 +101,6 @@ extern void
// 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 50bd26fc8..09cebc349 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 @@ void VG_(set_shadow_regs_area) ( ThreadId tid, OffT offset, SizeT size,
}
+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 1554040ab..49b07e015 100644
--- a/coregrind/m_scheduler/scheduler.c
+++ b/coregrind/m_scheduler/scheduler.c
@@ -164,17 +164,6 @@ ThreadId VG_(first_matching_thread_stack)
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 7bbb5d17e..462dbdf1b 100644
--- a/coregrind/x86/state.c
+++ b/coregrind/x86/state.c
@@ -132,27 +132,6 @@ void VGA_(init_thread1state) ( Addr client_eip,
}
/*------------------------------------------------------------*/
-/*--- 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 ea709f680..4d2668f84 100644
--- a/include/pub_tool_aspacemgr.h
+++ b/include/pub_tool_aspacemgr.h
@@ -49,7 +49,9 @@ extern void VG_(init_shadow_range)(Addr p, UInt sz, Bool call_init);
/* 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 b80573373..fab2f582d 100644
--- a/include/pub_tool_machine.h
+++ b/include/pub_tool_machine.h
@@ -64,6 +64,12 @@ extern void VG_(get_shadow_regs_area) ( ThreadId tid, OffT guest_state_offset,
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 60cb335e2..38b385760 100644
--- a/include/tool.h
+++ b/include/tool.h
@@ -78,9 +78,6 @@ extern ThreadId VG_(first_matching_thread_stack)
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 b7ef0216d..09cad7023 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 @@ void MAC_(do_detect_memory_leaks) (
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);