diff options
author | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2002-12-09 23:46:20 +0000 |
---|---|---|
committer | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2002-12-09 23:46:20 +0000 |
commit | 4dd461000c1503391a6701e327f73aac78436176 (patch) | |
tree | de9337fc601f3960793e5e3f777847135884968f /threadproc | |
parent | 6c55927ba0b4a30aa5f20fc03b3312f8670cf6f8 (diff) | |
download | libapr-4dd461000c1503391a6701e327f73aac78436176.tar.gz |
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.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64133 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'threadproc')
-rw-r--r-- | threadproc/win32/thread.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/threadproc/win32/thread.c b/threadproc/win32/thread.c index 12c6f2576..4293b1829 100644 --- a/threadproc/win32/thread.c +++ b/threadproc/win32/thread.c @@ -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_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr, 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 @@ APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr) 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 @@ APR_DECLARE(apr_status_t) apr_thread_data_set(void *data, const char *key, 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, |