Return-Path: Delivered-To: apmail-apr-cvs-archive@apr.apache.org Received: (qmail 63500 invoked by uid 500); 9 Dec 2002 23:46:22 -0000 Mailing-List: contact cvs-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: dev@apr.apache.org Delivered-To: mailing list cvs@apr.apache.org Received: (qmail 63486 invoked from network); 9 Dec 2002 23:46:22 -0000 Date: 9 Dec 2002 23:46:21 -0000 Message-ID: <20021209234621.41799.qmail@icarus.apache.org> From: wrowe@apache.org To: apr-cvs@apache.org Subject: cvs commit: apr/threadproc/win32 thread.c X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N wrowe 2002/12/09 15:46:20 Modified: threadproc/win32 thread.c Log: Close a bug identified by Juergen Heckel that we would crash when mod_ssl called apr_os_thread_current() against the 'main' thread we had not created. Also address the possibility that the pool scope is bad for a given apr_thread_t and do *not* dereference the ->td member for apr_os_thread_current(). This patch causes us to 'waste' a system handle for every thread that *apr* does not create, that apr_os_thread_current() is called within. In 99% of situations that is a single handle for the main thread. But there is the possibility of an application creating dozens of it's own threads outside of apr, each of which then call apr_os_thread_current(). The scenario appears so abstract and the complications of this code so obnoxious that this patch has chosen not to address the possibility. Revision Changes Path 1.50 +20 -5 apr/threadproc/win32/thread.c Index: thread.c =================================================================== RCS file: /home/cvs/apr/threadproc/win32/thread.c,v retrieving revision 1.49 retrieving revision 1.50 diff -u -r1.49 -r1.50 --- thread.c 25 Nov 2002 05:06:31 -0000 1.49 +++ thread.c 9 Dec 2002 23:46:20 -0000 1.50 @@ -63,7 +63,7 @@ #endif #include "misc.h" -/* Chosen for us in apr_initialize */ +/* Chosen for us by apr_initialize */ DWORD tls_apr_thread = 0; APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new, @@ -84,7 +84,7 @@ apr_int32_t on) { attr->detach = on; - return APR_SUCCESS; + return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr) @@ -97,7 +97,7 @@ static void *dummy_worker(void *opaque) { apr_thread_t *thd = (apr_thread_t *)opaque; - TlsSetValue(tls_apr_thread, thd); + TlsSetValue(tls_apr_thread, thd->td); return thd->func(thd, thd->data); } @@ -216,10 +216,25 @@ return apr_pool_userdata_set(data, key, cleanup, thread->pool); } + APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void) { - apr_thread_t *thd = (apr_thread_t *)TlsGetValue(tls_apr_thread); - return thd->td; + HANDLE hthread = (HANDLE)TlsGetValue(tls_apr_thread); + HANDLE hproc; + + if (hthread) { + return hthread; + } + + hproc = GetCurrentProcess(); + hthread = GetCurrentThread(); + if (!DuplicateHandle(hproc, hthread, + hproc, &hthread, 0, FALSE, + DUPLICATE_SAME_ACCESS)) { + return NULL; + } + TlsSetValue(tls_apr_thread, hthread); + return hthread; } APR_DECLARE(apr_status_t) apr_os_thread_get(apr_os_thread_t **thethd,