1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-06 18:03:13 +02:00

IRCCreateThreadEx() was causing exception on Windows.

This commit is contained in:
mcskaf
2002-12-08 20:09:27 +00:00
parent 2783e635b6
commit c609e0bbb1
4 changed files with 29 additions and 16 deletions
+1
View File
@@ -1715,3 +1715,4 @@ seen. gmtime warning still there
- Added back the commands check that didn't get added in conf3 (lamers
beware)
- Fixed a typo in the module system
- Fixed exception in scanner on Windows
+7 -6
View File
@@ -35,14 +35,14 @@
#include <pthread.h>
typedef pthread_t THREAD;
typedef pthread_mutex_t MUTEX;
#define IRCCreateThreadEx(thread, start, arg) TDebug(CreateThread); pthread_create(&thread, NULL, (void*)start, arg)
#define IRCCreateThread(thread, start, arg) TDebug(CreateThread); pthread_create(&thread, NULL, (void*)start, arg)
#define IRCCreateThreadEx(thread, start, arg, id) TDebug(CreateThread); pthread_create(&thread, NULL, (void*)start, arg)
#define IRCCreateThread(thread, start, arg) TDebug(CreateThread); pthread_create(&thread, NULL, (void*)start, arg)
#define IRCMutexLock(mutex) TDebug(MutexLock); pthread_mutex_lock(&mutex)
#define IRCMutexTryLock(mutex) TDebug(MutexTryLock); pthread_mutex_trylock(&mutex);
#define IRCMutexUnlock(mutex) TDebug(MutexUnlcok); pthread_mutex_unlock(&mutex)
#define IRCCreateMutex(mutex) TDebug(CreateMutex); pthread_mutex_init(&mutex, NULL)
#define IRCMutexDestroy(mutex) TDebug(MutexDestroy); pthread_mutex_destroy(&mutex)
#define IRCJoinThread(thread,return) TDebug(JoinThread); pthread_join(thread, return)
#define IRCJoinThread(thread,ppvalue) TDebug(JoinThread); pthread_join(thread, (void **)ppvalue)
#define IRCExitThreadEx(value) TDebug(ExitThread); pthread_exit(value)
#define IRCExitThread(value) TDebug(ExitThread); pthread_exit(value)
#define IRCDetachThread(value) TDebug(DetachThread); pthread_detach(value);
@@ -50,16 +50,17 @@ typedef pthread_mutex_t MUTEX;
#define IRCThreadSelf() pthread_self()
#define IRCThreadEqual(thread1, thread2) pthread_equal(thread1,thread2)
#else
typedef unsigned long THREAD;
typedef HANDLE THREAD;
typedef HANDLE MUTEX;
#define IRCCreateThreadEx(thread, start, arg) _beginthreadex(NULL, 0, (void *)start, arg, 0, &thread)
typedef unsigned (__stdcall *PTHREAD_START) (void *);
#define IRCCreateThreadEx(thread, start, arg, id) thread = (THREAD)_beginthreadex(NULL, 0, (PTHREAD_START)start, arg, 0, id)
#define IRCCreateThread(thread, start, arg) thread = _beginthread((void *)start, 0, arg)
#define IRCMutexLock(mutex) WaitForSingleObject(mutex, INFINITE)
#define IRCMutexTryLock(mutex) WaitForSingleObject(mutex, 0)
#define IRCMutexUnlock(mutex) ReleaseMutex(mutex)
#define IRCCreateMutex(mutex) mutex = CreateMutex(NULL, FALSE, NULL)
#define IRCMutexDestroy(mutex) CloseHandle(mutex)
#define IRCJoinThread(thread,return) { WaitForSingleObject((HANDLE)thread, INFINITE); GetExitCodeThread((HANDLE)thread, (DWORD)return); CloseHandle((HANDLE)thread); }
#define IRCJoinThread(thread,pdwRc) { WaitForSingleObject((HANDLE)thread, INFINITE); GetExitCodeThread((HANDLE)thread, pdwRc); CloseHandle((HANDLE)thread); }
#define IRCExitThreadEx(value) _endthreadex((unsigned int)value)
#define IRCExitThread(value) _endthread()
#define IRCTerminateThread(thread, value) TerminateThread((HANDLE)thread, value)
+14 -6
View File
@@ -150,31 +150,39 @@ int scan_http_Unload(int module_unload)
void scan_http_scan(Scan_AddrStruct *h)
{
THREAD thread[3];
unsigned id[3];
/* note: on windows dwRc holds the thread return code. on unix
** its a void pointer
*/
DWORD dwRc[3];
HSStruct *p = NULL;
IRCMutexLock((h->lock));
/* First we take 3128 .. */
h->refcnt++;
p = MyMalloc(sizeof(HSStruct));
p->hs = h;
p->port = 3128;
IRCCreateThreadEx(thread[0], scan_http_scan_port, p);
IRCCreateThreadEx(thread[0], scan_http_scan_port, p, &id[0]);
/* Then we take 8080 .. */
h->refcnt++;
p = MyMalloc(sizeof(HSStruct));
p->hs = h;
p->port = 8080;
IRCCreateThreadEx(thread[1], scan_http_scan_port, p);
IRCCreateThreadEx(thread[1], scan_http_scan_port, p, &id[1]);
/* And then we try to infect them with Code Red .. */
h->refcnt++;
p = MyMalloc(sizeof(HSStruct));
p->hs = h;
p->port = 80;
IRCCreateThreadEx(thread[2], scan_http_scan_port, p);
IRCCreateThreadEx(thread[2], scan_http_scan_port, p, &id[2]);
IRCMutexUnlock((h->lock));
IRCJoinThread(thread[0], NULL);
IRCJoinThread(thread[1], NULL);
IRCJoinThread(thread[2], NULL);
IRCJoinThread(thread[0], &dwRc[0]);
IRCJoinThread(thread[1], &dwRc[1]);
IRCJoinThread(thread[2], &dwRc[2]);
IRCMutexLock((h->lock));
h->refcnt--;
IRCMutexUnlock((h->lock));
+7 -4
View File
@@ -146,14 +146,17 @@ int scan_socks_Unload(int module_unload)
void scan_socks_scan(Scan_AddrStruct *h)
{
THREAD thread[2];
unsigned id[2];
DWORD dwRc[2];
IRCMutexLock((h->lock));
h->refcnt++;
IRCCreateThreadEx(thread[0], scan_socks4_scan, h);
IRCCreateThreadEx(thread[0], scan_socks4_scan, h, &id[0]);
h->refcnt++;
IRCCreateThreadEx(thread[1], scan_socks5_scan, h);
IRCCreateThreadEx(thread[1], scan_socks5_scan, h, &id[1]);
IRCMutexUnlock((h->lock));
IRCJoinThread(thread[0], NULL);
IRCJoinThread(thread[1], NULL);
IRCJoinThread(thread[0], &dwRc[0]);
IRCJoinThread(thread[1], &dwRc[1]);
IRCMutexLock((h->lock));
h->refcnt--;
IRCMutexUnlock((h->lock));