DBG: Use duplicated handle rather than the debug-event-provided handle
(Prevents early CloseHandle() by outside sources)
This commit is contained in:
parent
be26a685c0
commit
2b03693bf6
|
@ -801,6 +801,8 @@ static void cbCreateThread(CREATE_THREAD_DEBUG_INFO* CreateThread)
|
|||
|
||||
static void cbExitThread(EXIT_THREAD_DEBUG_INFO* ExitThread)
|
||||
{
|
||||
// Not called when the main (last) thread exits. Instead
|
||||
// EXIT_PROCESS_DEBUG_EVENT is signalled.
|
||||
hActiveThread = ThreadGetHandle(((DEBUG_EVENT*)GetDebugData())->dwThreadId);
|
||||
DWORD dwThreadId = ((DEBUG_EVENT*)GetDebugData())->dwThreadId;
|
||||
PLUG_CB_EXITTHREAD callbackInfo;
|
||||
|
|
|
@ -16,11 +16,14 @@ void ThreadCreate(CREATE_THREAD_DEBUG_INFO* CreateThread)
|
|||
memset(&curInfo, 0, sizeof(THREADINFO));
|
||||
|
||||
curInfo.ThreadNumber = ThreadGetCount();
|
||||
curInfo.Handle = CreateThread->hThread;
|
||||
curInfo.Handle = INVALID_HANDLE_VALUE;
|
||||
curInfo.ThreadId = ((DEBUG_EVENT*)GetDebugData())->dwThreadId;
|
||||
curInfo.ThreadStartAddress = (duint)CreateThread->lpStartAddress;
|
||||
curInfo.ThreadLocalBase = (duint)CreateThread->lpThreadLocalBase;
|
||||
|
||||
// Duplicate the debug thread handle -> thread handle
|
||||
DuplicateHandle(GetCurrentProcess(), CreateThread->hThread, GetCurrentProcess(), &curInfo.Handle, 0, FALSE, DUPLICATE_SAME_ACCESS);
|
||||
|
||||
// The first thread (#0) is always the main program thread
|
||||
if(curInfo.ThreadNumber <= 0)
|
||||
strcpy_s(curInfo.threadName, "Main Thread");
|
||||
|
@ -42,7 +45,10 @@ void ThreadExit(DWORD ThreadId)
|
|||
auto itr = threadList.find(ThreadId);
|
||||
|
||||
if(itr != threadList.end())
|
||||
{
|
||||
CloseHandle(itr->second.Handle);
|
||||
threadList.erase(itr);
|
||||
}
|
||||
|
||||
EXCLUSIVE_RELEASE();
|
||||
GuiUpdateThreadView();
|
||||
|
@ -50,12 +56,17 @@ void ThreadExit(DWORD ThreadId)
|
|||
|
||||
void ThreadClear()
|
||||
{
|
||||
// Clear the current array of threads
|
||||
EXCLUSIVE_ACQUIRE(LockThreads);
|
||||
|
||||
// Close all handles first
|
||||
for(auto & itr : threadList)
|
||||
CloseHandle(itr.second.Handle);
|
||||
|
||||
// Empty the array
|
||||
threadList.clear();
|
||||
EXCLUSIVE_RELEASE();
|
||||
|
||||
// Update the GUI's list
|
||||
EXCLUSIVE_RELEASE();
|
||||
GuiUpdateThreadView();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue