Bug 1088343 (part 0) - Clean up the windows implementation of NS_StackWalk a little. r=ehsan.
--- a/xpcom/base/nsStackWalk.cpp
+++ b/xpcom/base/nsStackWalk.cpp
@@ -197,30 +197,16 @@ StackWalkInitCriticalAddress()
#include <imagehlp.h>
// We need a way to know if we are building for WXP (or later), as if we are, we
// need to use the newer 64-bit APIs. API_VERSION_NUMBER seems to fit the bill.
// A value of 9 indicates we want to use the new APIs.
#if API_VERSION_NUMBER < 9
#error Too old imagehlp.h
#endif
-// Define these as static pointers so that we can load the DLL on the
-// fly (and not introduce a link-time dependency on it). Tip o' the
-// hat to Matt Pietrick for this idea. See:
-//
-// http://msdn.microsoft.com/library/periodic/period97/F1/D3/S245C6.htm
-//
-extern "C" {
-
-extern HANDLE hStackWalkMutex;
-
-bool EnsureSymInitialized();
-
-bool EnsureWalkThreadReady();
-
struct WalkStackData
{
uint32_t skipFrames;
HANDLE thread;
bool walkCallingThread;
HANDLE process;
HANDLE eventStart;
HANDLE eventEnd;
@@ -229,28 +215,21 @@ struct WalkStackData
uint32_t pc_count;
uint32_t pc_max;
void** sps;
uint32_t sp_size;
uint32_t sp_count;
void* platformData;
};
-void PrintError(char* aPrefix, WalkStackData* aData);
-unsigned int WINAPI WalkStackThread(void* aData);
-void WalkStackMain64(struct WalkStackData* aData);
-
-
DWORD gStackWalkThread;
CRITICAL_SECTION gDbgHelpCS;
-}
-
// Routine to print an error message to standard error.
-void
+static void
PrintError(const char* aPrefix)
{
LPVOID lpMsgBuf;
DWORD lastErr = GetLastError();
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr,
lastErr,
@@ -260,17 +239,19 @@ PrintError(const char* aPrefix)
nullptr
);
fprintf(stderr, "### ERROR: %s: %s",
aPrefix, lpMsgBuf ? lpMsgBuf : "(null)\n");
fflush(stderr);
LocalFree(lpMsgBuf);
}
-bool
+static unsigned int WINAPI WalkStackThread(void* aData);
+
+static bool
EnsureWalkThreadReady()
{
static bool walkThreadReady = false;
static HANDLE stackWalkThread = nullptr;
static HANDLE readyEvent = nullptr;
if (walkThreadReady) {
return walkThreadReady;
@@ -316,17 +297,17 @@ EnsureWalkThreadReady()
readyEvent = nullptr;
::InitializeCriticalSection(&gDbgHelpCS);
return walkThreadReady = true;
}
-void
+static void
WalkStackMain64(struct WalkStackData* aData)
{
// Get the context information for the thread. That way we will
// know where our sp, fp, pc, etc. are and can fill in the
// STACKFRAME64 with the initial values.
CONTEXT context;
HANDLE myProcess = aData->process;
HANDLE myThread = aData->thread;
@@ -434,18 +415,17 @@ WalkStackMain64(struct WalkStackData* aD
if (frame64.AddrReturn.Offset == 0) {
break;
}
}
return;
}
-
-unsigned int WINAPI
+static unsigned int WINAPI
WalkStackThread(void* aData)
{
BOOL msgRet;
MSG msg;
// Call PeekMessage to force creation of a message queue so that
// other threads can safely post events to us.
::PeekMessage(&msg, nullptr, WM_USER, WM_USER, PM_NOREMOVE);
@@ -737,17 +717,17 @@ BOOL SymGetModuleInfoEspecial64(HANDLE a
// Clear out aLineInfo to indicate that it's not valid
memset(aLineInfo, 0, sizeof(*aLineInfo));
}
}
return retval;
}
-bool
+static bool
EnsureSymInitialized()
{
static bool gInitialized = false;
bool retStat;
if (gInitialized) {
return gInitialized;
}