From 41d174b7f6b3375e59b27602feb4f86120ae23ab Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Fri, 9 Dec 2016 10:09:01 +0000 Subject: [PATCH] - Fix #1176: stack size too small for Alpine Linux. git-svn-id: file:///svn/unbound/trunk@3959 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 4 ++++ util/locks.h | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 57a13c8c5..47ed3027d 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,9 @@ +9 December 2016: Wouter + - Fix #1176: stack size too small for Alpine Linux. + 8 December 2016: Wouter - Fix downcast warnings from visual studio in sldns code. + - tag 1.6.0rc1 7 December 2016: Ralph - Add DSA support for OpenSSL 1.1.0 diff --git a/util/locks.h b/util/locks.h index 3776912aa..f9a9eed9e 100644 --- a/util/locks.h +++ b/util/locks.h @@ -149,8 +149,25 @@ typedef pthread_spinlock_t lock_quick_t; /** Thread creation */ typedef pthread_t ub_thread_t; -/** Pass where to store tread_t in thr. Use default NULL attributes. */ -#define ub_thread_create(thr, func, arg) LOCKRET(pthread_create(thr, NULL, func, arg)) +/** On alpine linux default thread stack size is 80 Kb. See +http://wiki.musl-libc.org/wiki/Functional_differences_from_glibc#Thread_stack_size +This is not enough and cause segfault. Other linux distros have 2 Mb at least. +Wrapper for set up thread stack size */ +#define PTHREADSTACKSIZE 2*1024*1024 +#define PTHREADCREATE(thr, stackrequired, func, arg) do {\ + pthread_attr_t attr; \ + size_t stacksize; \ + LOCKRET(pthread_attr_init(&attr)); \ + LOCKRET(pthread_attr_getstacksize(&attr, &stacksize)); \ + if (stacksize < stackrequired) { \ + LOCKRET(pthread_attr_setstacksize(&attr, stackrequired)); \ + LOCKRET(pthread_create(thr, &attr, func, arg)); \ + LOCKRET(pthread_attr_getstacksize(&attr, &stacksize)); \ + verbose(VERB_ALGO, "Thread stack size set to %zu", stacksize); \ + } else {LOCKRET(pthread_create(thr, NULL, func, arg));} \ + } while(0) +/** Use wrapper for set thread stack size on attributes. */ +#define ub_thread_create(thr, func, arg) PTHREADCREATE(thr, PTHREADSTACKSIZE, func, arg) /** get self id. */ #define ub_thread_self() pthread_self() /** wait for another thread to terminate */