-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Drop non-pseudo handles to current thread in DetourUpdateThread #80
Fix: Drop non-pseudo handles to current thread in DetourUpdateThread #80
Conversation
This code doesn't builds as of now, because GetThreadId requires at least Vista. Is there a better way of determining the identity of a thread that also works pre-Vista? If not, is it acceptable to drop Windows XP support, considering it's now EoL? |
I think NtQueryInformationThread with ThreadBasicInformation should give you the thread id in THREAD_BASIC_INFORMATION.ClientId.UniqueThread on Windows XP. |
Yeah that was a solution, but |
Thanks for the bug report, and patch @sylveon! Another possible way to fix this is to duplicate the thread handle, and check the duplicated handle. That would obviously have a larger perf impact than the current proposed change, but you have greater portability. |
The problem is specifically in regards to things that aren't a pseudo handle though. Currently this is blocked on the fact that Detours needs to target Windows XP (GetThreadId was added in Vista) |
Ah, sure. Wasn't thinking straight. There is a possible compromise, GetThreadId is defined as: #if (_WIN32_WINNT >= 0x0502)
WINBASEAPI
DWORD
WINAPI
GetThreadId(
_In_ HANDLE Thread
);
#endif // _WIN32_WINNT >= 0x0502 So the SDK seems to claim it was added in Windows Server 2003 (reference). We could add the Not amazing, but as I said, a potential compromise. |
I'd be ok with that but this effectively requires people to edit the nmake file, which means in most (all?) cases it won't be used. I personally fixed the issue I was encountering another way. I was using We should at least document this behavior in the wiki, saying that passing a non-pseudo handle to the current thread is unsupported and will result in freezing. While at it, also maybe document that passing a pseudo handle is a noop? I've seen many examples do that even if it's useless. |
after official merge my PR#127, DetourUpdateAllOtherThreads will instead of the old DetourUpdateThread API, and it will exclude currrent thread automaticall. and DetourUpdateAllOtherThreads is a safer solutuon for HOOK operation. and CreateToolhelp32Snapshot mentioned above is slowly. It is not fit for extreme environment. |
|
@sylveon Good suggestion, I've added documentation for both of these. |
Not use |
I propose we go forward with this change, but just have it just fall back to the previous behavior on systems without the Thoughts? |
I can get this working this weekend |
…date-thread-non-pseudo-current-thread
Drive-by: fix a LoadLibrary leak in IsWow64ProcessHelper
I updated the code to dynamically try loading it now. |
@sonyps5201314 you got me interested, so I checked it. See my comment here: In short, I found that both methods are almost equally slow. That's unfortunate, I wish there was a quick way to get the thread list of only a single process. The kernel can get this information, see e.g. the implementation of |
Fixes #78