Use a separate array for the native handles in NtWaitForMultipleObjectsEx

This commit is contained in:
ergo720 2022-02-20 16:07:42 +01:00
parent f174872702
commit d3b2554b20
2 changed files with 13 additions and 3 deletions

View File

@ -19,6 +19,8 @@ namespace xbox
#define NtCurrentThread() ((HANDLE)-2)
#define X_MAXIMUM_WAIT_OBJECTS 64
// ******************************************************************
// * NtAllocateVirtualMemory
// ******************************************************************

View File

@ -2190,12 +2190,20 @@ XBSYSAPI EXPORTNUM(235) xbox::ntstatus_xt NTAPI xbox::NtWaitForMultipleObjectsEx
LOG_FUNC_ARG(Timeout)
LOG_FUNC_END;
if (!Count || (Count > X_MAXIMUM_WAIT_OBJECTS)) {
RETURN(X_STATUS_INVALID_PARAMETER);
}
// This function can wait on thread handles, which are currently created by ob,
// so we need to check their presence in the handle array
::HANDLE nativeHandles[X_MAXIMUM_WAIT_OBJECTS];
for (ulong_xt i = 0; i < Count; ++i) {
if (const auto &nativeHandle = GetNativeHandle(Handles[i])) {
// This is a ob handle, so replace it with its native counterpart
Handles[i] = *nativeHandle;
nativeHandles[i] = *nativeHandle;
}
else {
nativeHandles[i] = Handles[i];
}
}
@ -2212,12 +2220,12 @@ XBSYSAPI EXPORTNUM(235) xbox::ntstatus_xt NTAPI xbox::NtWaitForMultipleObjectsEx
pNewTime = &NewTime;
}
xbox::ntstatus_xt ret = WaitApc([Count, Handles, WaitType, Alertable]() -> std::optional<ntstatus_xt> {
xbox::ntstatus_xt ret = WaitApc([Count, &nativeHandles, WaitType, Alertable]() -> std::optional<ntstatus_xt> {
NtDll::LARGE_INTEGER ExpireTime;
ExpireTime.QuadPart = 0;
NTSTATUS Status = NtDll::NtWaitForMultipleObjects(
Count,
Handles,
nativeHandles,
(NtDll::OBJECT_WAIT_TYPE)WaitType,
Alertable,
&ExpireTime);