]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Make sure that the return value of highest_used_stack_address() is a valid stack...
authorBart Van Assche <bvanassche@acm.org>
Sun, 4 May 2008 11:59:01 +0000 (11:59 +0000)
committerBart Van Assche <bvanassche@acm.org>
Sun, 4 May 2008 11:59:01 +0000 (11:59 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8005

exp-drd/drd_clientreq.c

index 8b86cde987f4c334f9fa56f4c9e8029c1a822618..d69657a9ffe578eed844d987093fcac1e95cdfdd 100644 (file)
@@ -91,20 +91,35 @@ static Addr highest_used_stack_address(const ThreadId vg_tid)
 {
     UInt nframes;
     const UInt n_ips = 10;
+    UInt i;
     Addr ips[n_ips], sps[n_ips];
     Addr husa;
 
     nframes = VG_(get_StackTrace)(vg_tid, ips, n_ips, sps, 0, 0);
+    tl_assert(1 <= nframes && nframes <= n_ips);
+
+    /* A hack to work around VG_(get_StackTrace)()'s behavior that sometimes */
+    /* the topmost stackframes it returns are bogus (this occurs sometimes   */
+    /* at least on amd64, ppc32 and ppc64).                                  */
+
+    husa = sps[0];
 
-    /* Paranoia ... */
     tl_assert(VG_(thread_get_stack_max)(vg_tid)
-              - VG_(thread_get_stack_size)(vg_tid) <= VG_(get_SP)(vg_tid)
-              && VG_(get_SP)(vg_tid) < VG_(thread_get_stack_max)(vg_tid));
+              - VG_(thread_get_stack_size)(vg_tid) <= husa
+              && husa < VG_(thread_get_stack_max)(vg_tid));
+
+    for (i = 1; i < nframes; i++)
+    {
+      if (sps[i] == 0)
+        break;
+      if (husa < sps[i] && sps[i] < VG_(thread_get_stack_max)(vg_tid))
+        husa = sps[i];
+    }
 
-    husa = (nframes >= 1 ? sps[nframes - 1] : VG_(get_SP)(vg_tid));
     tl_assert(VG_(thread_get_stack_max)(vg_tid)
               - VG_(thread_get_stack_size)(vg_tid) <= husa
               && husa < VG_(thread_get_stack_max)(vg_tid));
+
     return husa;
 }