From badef5c649848f3e4a7e3c027e6722a257e92821 Mon Sep 17 00:00:00 2001 From: sonyps5201314 Date: Wed, 9 Aug 2023 17:10:09 +0800 Subject: [PATCH] =?UTF-8?q?Fea=20#62,=20=E6=96=B0=E5=A2=9EGetThreadGroupAf?= =?UTF-8?q?finity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ThunksList.md | 1 + src/Thunks/api-ms-win-core-systemtopology.hpp | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/ThunksList.md b/ThunksList.md index b42541c..01bb32b 100644 --- a/ThunksList.md +++ b/ThunksList.md @@ -190,6 +190,7 @@ | *GetCurrentProcessorNumberEx | 不存在时,调用GetCurrentProcessorNumber。 | *GetNumaNodeProcessorMask | 不存在时,假定所有CPU都在当前Numa。 | *GetNumaNodeProcessorMaskEx | 不存在时,调用GetNumaNodeProcessorMask。 +| *GetThreadGroupAffinity | 不存在时,调用NtQueryInformationThread。 | *SetThreadGroupAffinity | 不存在时,调用SetThreadAffinityMask。 | *CancelIoEx | 不存在时,调用CancelIo(会把此句柄的所有IO操作取消掉!)。 | *CancelSynchronousIo | 不存在时,仅返回失败。 diff --git a/src/Thunks/api-ms-win-core-systemtopology.hpp b/src/Thunks/api-ms-win-core-systemtopology.hpp index caad1ac..70732b0 100644 --- a/src/Thunks/api-ms-win-core-systemtopology.hpp +++ b/src/Thunks/api-ms-win-core-systemtopology.hpp @@ -82,6 +82,57 @@ namespace YY } #endif +#if (YY_Thunks_Support_Version < NTDDI_WIN7) + + // Windows 7 [desktop apps only] + // Windows Server 2008 R2 [desktop apps only] + __DEFINE_THUNK( + kernel32, + 8, + BOOL, + WINAPI, + GetThreadGroupAffinity, + _In_ HANDLE _hThread, + _Out_ PGROUP_AFFINITY _pAffinity + ) + { + if (const auto _pfnGetThreadGroupAffinity = try_get_GetThreadGroupAffinity()) + { + return _pfnGetThreadGroupAffinity(_hThread, _pAffinity); + } + else + { + if (!_pAffinity) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + const auto _pfnNtQueryInformationThread = try_get_NtQueryInformationThread(); + if (!_pfnNtQueryInformationThread) + { + SetLastError(ERROR_INVALID_FUNCTION); + return FALSE; + } + + THREAD_BASIC_INFORMATION _ThreadBasicInfo; + long _Status = _pfnNtQueryInformationThread(_hThread, ThreadBasicInformation, &_ThreadBasicInfo, sizeof(_ThreadBasicInfo), nullptr); + + if (_Status < 0) + { + internal::BaseSetLastNTError(_Status); + return FALSE; + } + + _pAffinity->Group = 0; + _pAffinity->Mask = _ThreadBasicInfo.AffinityMask; + _pAffinity->Reserved[0] = 0; + _pAffinity->Reserved[1] = 0; + _pAffinity->Reserved[2] = 0; + return TRUE; + } + } +#endif #if (YY_Thunks_Support_Version < NTDDI_WIN7)