Bug 1452204 part 1 - Correctly set walkCallingThread. r?glandium
GetCurrentThread() returns a pseudo handle, so comparing it against
the passed in argument doesn't make sense in most cases. This patch
changes it to using the thread id for comparison, which is guaranteed
to be unique in the whole lifetime of a thread.
MozReview-Commit-ID: 5TNAgLkcS6m
--- a/mozglue/misc/StackWalk.cpp
+++ b/mozglue/misc/StackWalk.cpp
@@ -502,19 +502,25 @@ MozStackWalkThread(MozWalkStackCallback
InitializeDbgHelpCriticalSection();
// EnsureWalkThreadReady's _beginthreadex takes a heap lock and must be
// avoided if we're walking another (i.e. suspended) thread.
if (!aThread && !EnsureWalkThreadReady()) {
return;
}
- HANDLE currentThread = ::GetCurrentThread();
- HANDLE targetThread = aThread ? aThread : currentThread;
- data.walkCallingThread = (targetThread == currentThread);
+ HANDLE targetThread = aThread;
+ if (!aThread) {
+ targetThread = ::GetCurrentThread();
+ data.walkCallingThread = true;
+ } else {
+ DWORD threadId = ::GetThreadId(aThread);
+ DWORD currentThreadId = ::GetCurrentThreadId();
+ data.walkCallingThread = (threadId == currentThreadId);
+ }
// Have to duplicate handle to get a real handle.
if (!myProcess) {
if (!::DuplicateHandle(::GetCurrentProcess(),
::GetCurrentProcess(),
::GetCurrentProcess(),
&myProcess,
PROCESS_ALL_ACCESS, FALSE, 0)) {