From 7a47c3988c596c6361a22f7e54c95fa3b8629f52 Mon Sep 17 00:00:00 2001 From: otto <> Date: Wed, 6 Jan 2021 19:54:17 +0000 Subject: Fix two issues related to thread private data in asr. - setting up asr in single thread mode and then starting threads using asr would lead to multiple threads sharing the same resolver. - destruction of a thread that has been using asr would leak data. Problem originally reported by Alexey Sokolov and Uli Schlachter. ok kettenis@ --- src/lib/libc/include/thread_private.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib/libc/include/thread_private.h b/src/lib/libc/include/thread_private.h index 98dfaa6322..237c3fbd03 100644 --- a/src/lib/libc/include/thread_private.h +++ b/src/lib/libc/include/thread_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: thread_private.h,v 1.35 2019/02/13 13:22:14 mpi Exp $ */ +/* $OpenBSD: thread_private.h,v 1.36 2021/01/06 19:54:17 otto Exp $ */ /* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman */ @@ -98,7 +98,8 @@ struct thread_callbacks { void (*tc_mutex_destroy)(void **); void (*tc_tag_lock)(void **); void (*tc_tag_unlock)(void **); - void *(*tc_tag_storage)(void **, void *, size_t, void *); + void *(*tc_tag_storage)(void **, void *, size_t, void (*)(void *), + void *); __pid_t (*tc_fork)(void); __pid_t (*tc_vfork)(void); void (*tc_thread_release)(struct pthread *); @@ -142,6 +143,7 @@ __END_HIDDEN_DECLS #define _THREAD_PRIVATE_MUTEX_LOCK(name) do {} while (0) #define _THREAD_PRIVATE_MUTEX_UNLOCK(name) do {} while (0) #define _THREAD_PRIVATE(keyname, storage, error) &(storage) +#define _THREAD_PRIVATE_DT(keyname, storage, dt, error) &(storage) #define _MUTEX_LOCK(mutex) do {} while (0) #define _MUTEX_UNLOCK(mutex) do {} while (0) #define _MUTEX_DESTROY(mutex) do {} while (0) @@ -168,7 +170,12 @@ __END_HIDDEN_DECLS #define _THREAD_PRIVATE(keyname, storage, error) \ (_thread_cb.tc_tag_storage == NULL ? &(storage) : \ _thread_cb.tc_tag_storage(&(__THREAD_NAME(keyname)), \ - &(storage), sizeof(storage), error)) + &(storage), sizeof(storage), NULL, (error))) + +#define _THREAD_PRIVATE_DT(keyname, storage, dt, error) \ + (_thread_cb.tc_tag_storage == NULL ? &(storage) : \ + _thread_cb.tc_tag_storage(&(__THREAD_NAME(keyname)), \ + &(storage), sizeof(storage), (dt), (error))) /* * Macros used in libc to access mutexes. -- cgit v1.2.3-55-g6feb