From b91e3f8d37797d53b115dd5dd862953a2c595e5f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 28 Jun 2012 13:35:13 +0000 Subject: some atavisms removed git-svn-id: http://svn.miranda-ng.org/main/trunk@667 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Mir_core/miranda.cpp | 35 ++++++++++++++++++++++++++++++----- plugins/Mir_core/miranda.h | 2 ++ plugins/Mir_core/utils.cpp | 2 +- 3 files changed, 33 insertions(+), 6 deletions(-) (limited to 'plugins/Mir_core') diff --git a/plugins/Mir_core/miranda.cpp b/plugins/Mir_core/miranda.cpp index 0ca0f4bd6c..067cff5d4c 100644 --- a/plugins/Mir_core/miranda.cpp +++ b/plugins/Mir_core/miranda.cpp @@ -85,7 +85,7 @@ void __cdecl forkthread_r(void * arg) struct FORK_ARG * fa = (struct FORK_ARG *) arg; void (*callercode)(void*)=fa->threadcode; void * cookie=fa->arg; - CallService(MS_SYSTEM_THREAD_PUSH, 0, (LPARAM)callercode); + Thread_Push(( HINSTANCE)callercode); SetEvent(fa->hEvent); __try { @@ -96,7 +96,7 @@ void __cdecl forkthread_r(void * arg) } SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); - CallService(MS_SYSTEM_THREAD_POP, 0, 0); + Thread_Pop(); return; } @@ -127,7 +127,7 @@ unsigned __stdcall forkthreadex_r(void * arg) void *owner = fa->owner; unsigned long rc = 0; - CallService(MS_SYSTEM_THREAD_PUSH, (WPARAM)fa->owner, (LPARAM)threadcode); + Thread_Push((HINSTANCE)threadcode, fa->owner); SetEvent(fa->hEvent); __try { @@ -141,7 +141,7 @@ unsigned __stdcall forkthreadex_r(void * arg) } SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); - CallService(MS_SYSTEM_THREAD_POP, 0, 0); + Thread_Pop(); return rc; } @@ -278,6 +278,27 @@ MIR_CORE_DLL(void) Thread_Wait(void) typedef LONG (WINAPI *pNtQIT)(HANDLE, LONG, PVOID, ULONG, PULONG); #define ThreadQuerySetWin32StartAddress 9 +static void* GetCurrentThreadEntryPoint() +{ + LONG ntStatus; + HANDLE hDupHandle, hCurrentProcess; + DWORD_PTR dwStartAddress; + + pNtQIT NtQueryInformationThread = (pNtQIT)GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "NtQueryInformationThread" ); + if(NtQueryInformationThread == NULL) return 0; + + hCurrentProcess = GetCurrentProcess(); + if(!DuplicateHandle(hCurrentProcess, GetCurrentThread(), hCurrentProcess, &hDupHandle, THREAD_QUERY_INFORMATION, FALSE, 0)){ + SetLastError(ERROR_ACCESS_DENIED); + return NULL; + } + ntStatus = NtQueryInformationThread(hDupHandle, ThreadQuerySetWin32StartAddress, &dwStartAddress, sizeof(DWORD_PTR), NULL); + CloseHandle(hDupHandle); + + if(ntStatus != ERROR_SUCCESS) return 0; + return ( void* )dwStartAddress; +} + MIR_CORE_DLL(INT_PTR) Thread_Push(HINSTANCE hInst, void* pOwner) { ResetEvent(hThreadQueueEmpty); // thread list is not empty @@ -287,7 +308,11 @@ MIR_CORE_DLL(INT_PTR) Thread_Push(HINSTANCE hInst, void* pOwner) DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &p->hThread, 0, FALSE, DUPLICATE_SAME_ACCESS); p->dwThreadId = GetCurrentThreadId(); p->pObject = pOwner; - p->hOwner = hInst; + if (pluginListAddr.getIndex(hInst) != -1) + p->hOwner = hInst; + else + p->hOwner = GetInstByAddress(( hInst != NULL ) ? (PVOID)hInst : GetCurrentThreadEntryPoint()); + threads.insert(p); ReleaseMutex(hStackMutex); diff --git a/plugins/Mir_core/miranda.h b/plugins/Mir_core/miranda.h index 9faa569eff..5e0a0d2fb1 100644 --- a/plugins/Mir_core/miranda.h +++ b/plugins/Mir_core/miranda.h @@ -77,6 +77,8 @@ struct THook CRITICAL_SECTION csHook; }; +extern LIST pluginListAddr; + /**** langpack.cpp *********************************************************************/ char* LangPackTranslateString(struct LangPackMuuid* pUuid, const char *szEnglish, const int W); diff --git a/plugins/Mir_core/utils.cpp b/plugins/Mir_core/utils.cpp index f0fcdcfa07..5adb7e1cc1 100644 --- a/plugins/Mir_core/utils.cpp +++ b/plugins/Mir_core/utils.cpp @@ -118,7 +118,7 @@ static int sttComparePlugins(const HINSTANCE__* p1, const HINSTANCE__* p2) return (p1 < p2) ? -1 : 1; } -static LIST pluginListAddr(10, sttComparePlugins); +LIST pluginListAddr(10, sttComparePlugins); MIR_CORE_DLL(void) RegisterModule(HINSTANCE hInst) { -- cgit v1.2.3