/
githubmirror
/
x64dbg
Обзор
Документация
Войти
/
githubmirror
/
x64dbg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
development
src/dbg/threading.cpp
139 строк
3 KB
Duncan Ogilvie
Remove XP compatibility code behind _WIN32_WINNT
17 авг 2025, 19:01
17 авг 2025, 19:01
49ef645
Код
Авторство
О чём код?
#include <ntstatus.h> #include "threading.h" static HANDLE waitArray[WAITID_LAST]; void waitclear() { for(int i = 0; i < WAITID_LAST; i++) unlock((WAIT_ID)i); } void wait(WAIT_ID id) { WaitForSingleObject(waitArray[id], INFINITE); } bool waitfor(WAIT_ID id, unsigned int Milliseconds) { return WaitForSingleObject(waitArray[id], Milliseconds) == 0; } void lock(WAIT_ID id) { ResetEvent(waitArray[id]); } void unlock(WAIT_ID id) { SetEvent(waitArray[id]); } bool waitislocked(WAIT_ID id) { return !(WaitForSingleObject(waitArray[id], 0) == WAIT_OBJECT_0); } void waitinitialize() { for(int i = 0; i < WAITID_LAST; i++) waitArray[i] = CreateEventW(NULL, TRUE, TRUE, NULL); } void waitdeinitialize() { for(int i = 0; i < WAITID_LAST; i++) { wait((WAIT_ID)i); CloseHandle(waitArray[i]); } } bool SectionLockerGlobal::m_Initialized = false; CacheAligned<CRITICAL_SECTION> SectionLockerGlobal::m_crLocks[SectionLock::LockLast]; CacheAligned<SRWLOCK> SectionLockerGlobal::m_srwLocks[SectionLock::LockLast]; SectionLockerGlobal::owner_info SectionLockerGlobal::m_exclusiveOwner[SectionLock::LockLast]; DWORD SectionLockerGlobal::m_guiMainThreadId; void SectionLockerGlobal::Initialize() { // This is supposed to only be called once, but // create a flag anyway if(m_Initialized) return; // This gets called on the same thread as the GUI m_guiMainThreadId = GetCurrentThreadId(); // Destroy previous data if any existed memset(m_srwLocks, 0, sizeof(m_srwLocks)); for(int i = 0; i < ARRAYSIZE(m_srwLocks); i++) InitializeSRWLock(&m_srwLocks[i]); m_Initialized = true; } void SectionLockerGlobal::Deinitialize() { if(!m_Initialized) return; for(int i = 0; i < ARRAYSIZE(m_srwLocks); i++) { // Wait for the lock's ownership to be released AcquireSRWLockExclusive(&m_srwLocks[i]); ReleaseSRWLockExclusive(&m_srwLocks[i]); // Invalidate data memset(&m_srwLocks[i], 0, sizeof(SRWLOCK)); } m_Initialized = false; } static DWORD gTlsIndex = TLS_OUT_OF_INDEXES; TLSData::TLSData() { moduleHashLower.reserve(MAX_MODULE_SIZE); } bool TLSData::notify(DWORD fdwReason) { switch(fdwReason) { case DLL_PROCESS_ATTACH: gTlsIndex = TlsAlloc(); return gTlsIndex != TLS_OUT_OF_INDEXES; case DLL_THREAD_DETACH: { auto data = (TLSData*)TlsGetValue(gTlsIndex); delete data; } return true; case DLL_PROCESS_DETACH: { auto data = (TLSData*)TlsGetValue(gTlsIndex); delete data; TlsFree(gTlsIndex); } return true; } return false; } TLSData* TLSData::get() { auto data = (TLSData*)TlsGetValue(gTlsIndex); if(data == nullptr) { data = new TLSData(); TlsSetValue(gTlsIndex, data); } return data; }