unpatch GetExitCodeThread

This commit is contained in:
RadWolfie 2022-01-15 16:44:44 -06:00 committed by ergo720
parent b39801df11
commit 7e5f9a7cb7
7 changed files with 20 additions and 5 deletions

View File

@ -354,7 +354,7 @@ std::map<const std::string, const xbox_patch_t> g_PatchTable = {
PATCH_ENTRY("ConvertThreadToFiber", xbox::EMUPATCH(ConvertThreadToFiber), PATCH_IS_FIBER),
PATCH_ENTRY("CreateFiber", xbox::EMUPATCH(CreateFiber), PATCH_IS_FIBER),
PATCH_ENTRY("DeleteFiber", xbox::EMUPATCH(DeleteFiber), PATCH_IS_FIBER),
PATCH_ENTRY("GetExitCodeThread", xbox::EMUPATCH(GetExitCodeThread), PATCH_ALWAYS),
//PATCH_ENTRY("GetExitCodeThread", xbox::EMUPATCH(GetExitCodeThread), PATCH_ALWAYS),
//PATCH_ENTRY("GetThreadPriority", xbox::EMUPATCH(GetThreadPriority), PATCH_ALWAYS),
PATCH_ENTRY("OutputDebugStringA", xbox::EMUPATCH(OutputDebugStringA), PATCH_ALWAYS),
//PATCH_ENTRY("RaiseException", xbox::EMUPATCH(RaiseException), PATCH_ALWAYS),

View File

@ -983,6 +983,7 @@ int WINAPI xbox::EMUPATCH(GetThreadPriority)
}
#endif
#if 0
// ******************************************************************
// * patch: GetExitCodeThread
// ******************************************************************
@ -1006,6 +1007,7 @@ xbox::bool_xt WINAPI xbox::EMUPATCH(GetExitCodeThread)
RETURN(0);
}
}
#endif
// ******************************************************************
// * patch: XapiThreadStartup

View File

@ -541,6 +541,7 @@ xbox::bool_xt WINAPI EMUPATCH(SetThreadPriorityBoost)
);
#endif
#if 0
// ******************************************************************
// * patch: GetExitCodeThread
// ******************************************************************
@ -549,6 +550,7 @@ xbox::bool_xt WINAPI EMUPATCH(GetExitCodeThread)
HANDLE hThread,
LPDWORD lpExitCode
);
#endif
// ******************************************************************
// * patch: XapiThreadStartup

View File

@ -1916,10 +1916,13 @@ KTHREAD, *PKTHREAD, *RESTRICTED_POINTER PRKTHREAD;
typedef struct _ETHREAD
{
struct _KTHREAD Tcb;
uchar_xt UnknownA[0x1C]; // 0x110
uchar_xt UnknownA[0x10]; // 0x110
ntstatus_xt ExitStatus; // 0x120
uchar_xt UnknownB[0x8]; // 0x124
HANDLE UniqueThread; // 0x12C
}
ETHREAD, *PETHREAD;
static_assert(sizeof(ETHREAD) == 0x130);
// ******************************************************************
// * PCREATE_THREAD_NOTIFY_ROUTINE

View File

@ -408,7 +408,7 @@ XBSYSAPI EXPORTNUM(258) xbox::void_xt NTAPI xbox::PsTerminateSystemThread
}
}*/
EmuKeFreeThread();
EmuKeFreeThread(ExitStatus);
KiUniqueProcess.StackCount--;
_endthreadex(ExitStatus);

View File

@ -215,7 +215,7 @@ void EmuKeFreePcr(xbox::HANDLE UniqueThread)
__writefsdword(TIB_ArbitraryDataSlot, NULL);
}
void EmuKeFreeThread()
void EmuKeFreeThread(xbox::ntstatus_xt ExitStatus)
{
// This functions is to be used for cxbxr threads that execute xbox code. We can't just call PsTerminateSystemThread because some additional
// xbox state is not created for this kind of threads
@ -223,6 +223,14 @@ void EmuKeFreeThread()
xbox::KeEmptyQueueApc();
xbox::PETHREAD eThread = xbox::PspGetCurrentThread();
eThread->Tcb.HasTerminated = 1;
// Emulate our exit strategy for GetExitCodeThread
eThread->ExitStatus = ExitStatus;
eThread->Tcb.Header.SignalState = 1;
xbox::HANDLE UniqueThread = eThread->UniqueThread;
if (GetNativeHandle(eThread->UniqueThread)) {
xbox::NtClose(eThread->UniqueThread);

View File

@ -35,7 +35,7 @@ extern void EmuInitFS();
// generate fs segment selector
extern void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData, xbox::PVOID Ethread);
// free resources allocated for the thread
void EmuKeFreeThread();
void EmuKeFreeThread(xbox::ntstatus_xt ExitStatus = X_STATUS_ABANDONED);
// free kpcr allocated for the thread
void EmuKeFreePcr(xbox::HANDLE UniqueThread);