CxbxKrnlRegisterThread refactoring; All callers first called DuplicateHandle. Now this is part of CxbxKrnlRegisterThread itself. Also, a possible failure of DuplicateHandle is logged.

This commit is contained in:
patrickvl 2018-01-14 18:00:25 +01:00 committed by Luke Usher
parent 2723bef3d9
commit 8f22515b7d
3 changed files with 16 additions and 23 deletions

View File

@ -983,13 +983,7 @@ __declspec(noreturn) void CxbxKrnlInit
}
}
// duplicate handle in order to retain Suspend/Resume thread rights from a remote thread
{
HANDLE hDupHandle = NULL;
DuplicateHandle(g_CurrentProcessHandle, GetCurrentThread(), g_CurrentProcessHandle, &hDupHandle, 0, FALSE, DUPLICATE_SAME_ACCESS);
CxbxKrnlRegisterThread(hDupHandle);
}
CxbxKrnlRegisterThread(GetCurrentThread());
// Clear critical section list
//extern void InitializeSectionStructures(void);
@ -1168,6 +1162,19 @@ __declspec(noreturn) void CxbxKrnlCleanup(const char *szErrorMessage, ...)
void CxbxKrnlRegisterThread(HANDLE hThread)
{
// we must duplicate this handle in order to retain Suspend/Resume thread rights from a remote thread
{
HANDLE hDupHandle = NULL;
if (DuplicateHandle(g_CurrentProcessHandle, hThread, g_CurrentProcessHandle, &hDupHandle, 0, FALSE, DUPLICATE_SAME_ACCESS)) {
hThread = hDupHandle; // Thread handle was duplicated, continue registration with the duplicate
}
else {
auto message = CxbxGetLastErrorString("DuplicateHandle");
EmuWarning(message.c_str());
}
}
int v=0;
for(v=0;v<MAXIMUM_XBOX_THREADS;v++)

View File

@ -471,14 +471,7 @@ VOID XTL::CxbxInitWindow(Xbe::Header *XbeHeader, uint32 XbeHeaderSize)
// We set the priority of this thread a bit higher, to assure reliable timing :
SetThreadPriority(hThread, THREAD_PRIORITY_ABOVE_NORMAL);
// we must duplicate this handle in order to retain Suspend/Resume thread rights from a remote thread
{
HANDLE hDupHandle = NULL;
DuplicateHandle(g_CurrentProcessHandle, hThread, g_CurrentProcessHandle, &hDupHandle, 0, FALSE, DUPLICATE_SAME_ACCESS);
CxbxKrnlRegisterThread(hDupHandle);
}
CxbxKrnlRegisterThread(hThread);
}
/* TODO : Port this Dxbx code :

View File

@ -353,14 +353,7 @@ XBSYSAPI EXPORTNUM(255) xboxkrnl::NTSTATUS NTAPI xboxkrnl::PsCreateSystemThreadE
// Log ThreadID identical to how GetCurrentThreadID() is rendered :
EmuWarning("KRNL: Created Xbox proxy thread. Handle : 0x%X, ThreadId : [0x%.4X]\n", *ThreadHandle, dwThreadId);
// we must duplicate this handle in order to retain Suspend/Resume thread rights from a remote thread
{
HANDLE hDupHandle = NULL;
DuplicateHandle(g_CurrentProcessHandle, *ThreadHandle, g_CurrentProcessHandle, &hDupHandle, 0, FALSE, DUPLICATE_SAME_ACCESS);
CxbxKrnlRegisterThread(hDupHandle);
}
CxbxKrnlRegisterThread(*ThreadHandle);
if (ThreadId != NULL)
*ThreadId = (xboxkrnl::HANDLE)dwThreadId;