Bug 1452204 part 1 - Correctly set walkCallingThread. r?glandium draft
authorXidorn Quan <me@upsuper.org>
Mon, 04 Jun 2018 19:17:32 +1000
changeset 804501 658805be640e59249a6421c1e0a8e6ef18f3e199
parent 804500 14b4ca1f71f33093a18378c2517e68b4b9dcae30
child 804502 1587c646b8d029956e0e09740132aa242dfc8073
child 805210 26a01187a3350f7df02b22fc0712cbb7765d8bb9
push id112392
push userxquan@mozilla.com
push dateWed, 06 Jun 2018 04:27:11 +0000
reviewersglandium
bugs1452204
milestone62.0a1
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
mozglue/misc/StackWalk.cpp
--- 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)) {