|
From: Steve V.
|
do_clone() uses the passed stack pointer to guess at the scope of the
new stack and registers it. Somtimes this guess is bad enough to cause
problems. This patch will first check to see if the passed stack pointer
is already part of a registered stack. If it is, use that stack and don't
register a new stack. (Bug 168538)
Index: valgrind/coregrind/m_stacks.c
===================================================================
--- valgrind.orig/coregrind/m_stacks.c 2008-08-21 15:42:21.000000000 -0700
+++ valgrind/coregrind/m_stacks.c 2008-08-21 15:44:17.000000000 -0700
@@ -171,6 +171,17 @@
}
/*
+ * Lookup the passed stack pointer and try to determine if it points to
+ * an already registered stack.
+ */
+Bool VG_(is_stack_registered)(Addr sp)
+{
+ if (find_stack_by_addr(sp) == NULL)
+ return False;
+ return True;
+}
+
+/*
* Register a new stack from start - end. This is invoked from the
* VALGRIND_STACK_REGISTER client request, and is also called just before
* we start the client running, to register the main process stack.
Index: valgrind/coregrind/m_syswrap/syswrap-x86-linux.c
===================================================================
--- valgrind.orig/coregrind/m_syswrap/syswrap-x86-linux.c 2008-08-21 15:42:44.000000000 -0700
+++ valgrind/coregrind/m_syswrap/syswrap-x86-linux.c 2008-08-21 15:44:17.000000000 -0700
@@ -260,11 +260,12 @@
ctst->sig_mask = ptst->sig_mask;
ctst->tmp_sig_mask = ptst->sig_mask;
- /* We don't really know where the client stack is, because its
- allocated by the client. The best we can do is look at the
- memory mappings and try to derive some useful information. We
- assume that esp starts near its highest possible value, and can
- only go down to the start of the mmaped segment. */
+ /* Unless the client stack is already registered, we don't really know
+ where it is, because it's allocated by the client. The best we can
+ do is look at the memory mappings and try to derive some useful
+ information. We assume that esp starts near its highest possible
+ value, and can only go down to the start of the mmaped segment. */
+ if (!VG_(is_stack_registered)((Addr)esp)) {
seg = VG_(am_find_nsegment)((Addr)esp);
if (seg && seg->kind != SkResvn) {
ctst->client_stack_highest_word = (Addr)VG_PGROUNDUP(esp);
@@ -280,6 +281,11 @@
ctid, esp);
ctst->client_stack_szB = 0;
}
+ } else {
+ if (debug)
+ VG_(printf)("tid %d: client stack already registered (%#lx)\n",
+ ctid, esp);
+ }
/* Assume the clone will succeed, and tell any tool that wants to
know that this thread has come into existence. We cannot defer
Index: valgrind/coregrind/pub_core_stacks.h
===================================================================
--- valgrind.orig/coregrind/pub_core_stacks.h 2008-08-21 15:42:21.000000000 -0700
+++ valgrind/coregrind/pub_core_stacks.h 2008-08-21 15:44:17.000000000 -0700
@@ -40,6 +40,7 @@
extern void VG_(deregister_stack) ( UWord id );
extern void VG_(change_stack) ( UWord id, Addr start, Addr end );
extern void VG_(stack_limits) ( Addr SP, Addr *start, Addr *end );
+extern Bool VG_(is_stack_registered) ( Addr SP );
extern VG_REGPARM(3)
void VG_(unknown_SP_update) ( Addr old_SP, Addr new_SP, UInt otag );
|