summaryrefslogtreecommitdiff
path: root/plugins/Mir_core/miranda.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-06-28 13:35:13 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-06-28 13:35:13 +0000
commitb91e3f8d37797d53b115dd5dd862953a2c595e5f (patch)
treedc711a2b068d85047fb56532eefee809f0c979a8 /plugins/Mir_core/miranda.cpp
parente3f12f5b4d905ec856a6f5ab35b50d216876cb07 (diff)
some atavisms removed
git-svn-id: http://svn.miranda-ng.org/main/trunk@667 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Mir_core/miranda.cpp')
-rw-r--r--plugins/Mir_core/miranda.cpp35
1 files changed, 30 insertions, 5 deletions
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);