diff options
author | George Hazan <george.hazan@gmail.com> | 2012-06-28 13:35:13 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-06-28 13:35:13 +0000 |
commit | b91e3f8d37797d53b115dd5dd862953a2c595e5f (patch) | |
tree | dc711a2b068d85047fb56532eefee809f0c979a8 /plugins | |
parent | e3f12f5b4d905ec856a6f5ab35b50d216876cb07 (diff) |
some atavisms removed
git-svn-id: http://svn.miranda-ng.org/main/trunk@667 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/IEView/Utils.cpp | 4 | ||||
-rw-r--r-- | plugins/Mir_core/miranda.cpp | 35 | ||||
-rw-r--r-- | plugins/Mir_core/miranda.h | 2 | ||||
-rw-r--r-- | plugins/Mir_core/utils.cpp | 2 |
4 files changed, 35 insertions, 8 deletions
diff --git a/plugins/IEView/Utils.cpp b/plugins/IEView/Utils.cpp index de2d02694b..fef1056cac 100644 --- a/plugins/IEView/Utils.cpp +++ b/plugins/IEView/Utils.cpp @@ -339,10 +339,10 @@ static void __cdecl forkthread_r(struct FORK_ARG *fa) {
void (*callercode)(void*) = fa->threadcode;
void *arg = fa->arg;
- CallService(MS_SYSTEM_THREAD_PUSH, 0, 0);
+ Thread_Push((HINSTANCE)callercode);
SetEvent(fa->hEvent);
callercode(arg);
- CallService(MS_SYSTEM_THREAD_POP, 0, 0);
+ Thread_Pop();
return;
}
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<HINSTANCE__> 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<HINSTANCE__> pluginListAddr(10, sttComparePlugins);
+LIST<HINSTANCE__> pluginListAddr(10, sttComparePlugins);
MIR_CORE_DLL(void) RegisterModule(HINSTANCE hInst)
{
|