1
0
Fork 0

DBG: Use duplicated handle rather than the debug-event-provided handle

(Prevents early CloseHandle() by outside sources)
This commit is contained in:
Nukem 2016-02-15 01:10:11 -05:00
parent be26a685c0
commit 2b03693bf6
2 changed files with 16 additions and 3 deletions

View File

@ -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;

View File

@ -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();
}