Changeset 184229 in webkit
- Timestamp:
- May 12, 2015 6:47:15 PM (9 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r184220 r184229 1 2015-05-12 Mark Lam <mark.lam@apple.com> 2 3 Windows: Cannot use HANDLE from GetCurrentThread() to get the CONTEXT of another thread. 4 https://bugs.webkit.org/show_bug.cgi?id=144924 5 6 Reviewed by Alex Christensen. 7 8 The present stack scanning code in the Windows port is expecting that the 9 GetCurrentThread() API will provide a unique HANDLE for each thread. The code 10 then saves and later uses that HANDLE with GetThreadContext() to get the 11 runtime state of the target thread from the GC thread. According to 12 https://msdn.microsoft.com/en-us/library/windows/desktop/ms683182(v=vs.85).aspx, 13 GetCurrentThread() does not provide this unique HANDLE that we expect: 14 15 "The function cannot be used by one thread to create a handle that can 16 be used by other threads to refer to the first thread. The handle is 17 always interpreted as referring to the thread that is using it. A 18 thread can create a "real" handle to itself that can be used by other 19 threads, or inherited by other processes, by specifying the pseudo 20 handle as the source handle in a call to the DuplicateHandle function." 21 22 As a result of this, GetCurrentThread() always returns the same HANDLE value, and 23 we end up never scanning the stacks of other threads because we wrongly think that 24 they are all equal (in identity) to the scanning thread. This, in turn, results 25 in crashes due to objects that are incorrectly collected. 26 27 The fix is to call DuplicateHandle() to create a HANDLE that we can use. The 28 MachineThreads::Thread class already accurately tracks the period of time when 29 we need that HANDLE for the VM. Hence, the life-cycle of the HANDLE can be tied 30 to the life-cycle of the MachineThreads::Thread object for the corresponding thread. 31 32 * heap/MachineStackMarker.cpp: 33 (JSC::getCurrentPlatformThread): 34 (JSC::MachineThreads::Thread::Thread): 35 (JSC::MachineThreads::Thread::~Thread): 36 (JSC::MachineThreads::Thread::suspend): 37 (JSC::MachineThreads::Thread::resume): 38 (JSC::MachineThreads::Thread::getRegisters): 39 1 40 2015-05-12 Benjamin Poulain <bpoulain@apple.com> 2 41 -
trunk/Source/JavaScriptCore/heap/MachineStackMarker.cpp
r184218 r184229 73 73 typedef mach_port_t PlatformThread; 74 74 #elif OS(WINDOWS) 75 typedef HANDLEPlatformThread;75 typedef DWORD PlatformThread; 76 76 #elif USE(PTHREADS) 77 77 typedef pthread_t PlatformThread; … … 152 152 return pthread_mach_thread_np(pthread_self()); 153 153 #elif OS(WINDOWS) 154 return GetCurrentThread ();154 return GetCurrentThreadId(); 155 155 #elif USE(PTHREADS) 156 156 return pthread_self(); … … 177 177 sigaddset(&mask, SigThreadSuspendResume); 178 178 pthread_sigmask(SIG_UNBLOCK, &mask, 0); 179 #elif OS(WINDOWS) 180 ASSERT(platformThread == GetCurrentThreadId()); 181 bool isSuccessful = 182 DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), 183 &platformThreadHandle, 0, FALSE, DUPLICATE_SAME_ACCESS); 184 RELEASE_ASSERT(isSuccessful); 179 185 #endif 180 186 } 181 187 182 188 public: 189 ~Thread() 190 { 191 #if OS(WINDOWS) 192 CloseHandle(platformThreadHandle); 193 #endif 194 } 195 183 196 static Thread* createForCurrentThread() 184 197 { … … 229 242 PlatformThread platformThread; 230 243 void* stackBase; 244 #if OS(WINDOWS) 245 HANDLE platformThreadHandle; 246 #endif 231 247 }; 232 248 … … 336 352 return result == KERN_SUCCESS; 337 353 #elif OS(WINDOWS) 338 bool threadIsSuspended = (SuspendThread(platformThread ) != (DWORD)-1);354 bool threadIsSuspended = (SuspendThread(platformThreadHandle) != (DWORD)-1); 339 355 ASSERT(threadIsSuspended); 340 356 return threadIsSuspended; … … 352 368 thread_resume(platformThread); 353 369 #elif OS(WINDOWS) 354 ResumeThread(platformThread );370 ResumeThread(platformThreadHandle); 355 371 #elif USE(PTHREADS) 356 372 pthread_kill(platformThread, SigThreadSuspendResume); … … 397 413 #elif OS(WINDOWS) 398 414 regs.ContextFlags = CONTEXT_INTEGER | CONTEXT_CONTROL; 399 GetThreadContext(platformThread , ®s);415 GetThreadContext(platformThreadHandle, ®s); 400 416 return sizeof(CONTEXT); 401 417 #elif USE(PTHREADS)
Note: See TracChangeset
for help on using the changeset viewer.