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:
parent
2723bef3d9
commit
8f22515b7d
|
@ -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++)
|
||||
|
|
|
@ -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 :
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue