From 617bcfa1a1f232cde5ce5d98162100f79db62493 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 22 Jun 2012 16:31:59 -0400 Subject: [PATCH] Bug 767479 - Handle the case of more than 1024 frames when walking the stack of another thread on Windows, and also use the infallible allocator when walking the stack of your own thread; r=dbaron --- xpcom/base/nsStackWalk.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/xpcom/base/nsStackWalk.cpp b/xpcom/base/nsStackWalk.cpp index 89d4ef05ddba..2409b370527f 100644 --- a/xpcom/base/nsStackWalk.cpp +++ b/xpcom/base/nsStackWalk.cpp @@ -173,6 +173,7 @@ StackWalkInitCriticalAddress() #include #include #include +#include #include "plstr.h" #include "mozilla/FunctionTimer.h" @@ -488,6 +489,13 @@ NS_StackWalk(NS_WalkStackCallback aCallback, PRUint32 aSkipFrames, // If we're walking the stack of another thread, we don't need to // use a separate walker thread. WalkStackMain64(&data); + + if (data.pc_count > data.pc_size) { + data.pcs = (void**) _alloca(data.pc_count * sizeof(void*)); + data.pc_size = data.pc_count; + data.pc_count = 0; + WalkStackMain64(&data); + } } else { data.eventStart = ::CreateEvent(NULL, FALSE /* auto-reset*/, FALSE /* initially non-signaled */, NULL); @@ -501,7 +509,7 @@ NS_StackWalk(NS_WalkStackCallback aCallback, PRUint32 aSkipFrames, if (walkerReturn != WAIT_OBJECT_0) PrintError("SignalObjectAndWait (1)"); if (data.pc_count > data.pc_size) { - data.pcs = (void**) malloc(data.pc_count * sizeof(void*)); + data.pcs = (void**) _alloca(data.pc_count * sizeof(void*)); data.pc_size = data.pc_count; data.pc_count = 0; ::PostThreadMessage(gStackWalkThread, WM_USER, 0, (LPARAM)&data); @@ -520,9 +528,6 @@ NS_StackWalk(NS_WalkStackCallback aCallback, PRUint32 aSkipFrames, for (PRUint32 i = 0; i < data.pc_count; ++i) (*aCallback)(data.pcs[i], aClosure); - if (data.pc_size > ArrayLength(local_pcs)) - free(data.pcs); - return NS_OK; }