b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | This patch increases the stack size for pthreads from 80 KB, the default |
| 2 | stack size for musl libc, to 2 MB. The default stack size for glibc is 8 MB. |
| 3 | |
| 4 | OpenDKIM, an application that depends on libmilter, segfaults if the stack |
| 5 | size for pthreads is left unchanged at the musl default value of 80 KB. |
| 6 | Apparently, OpenDKIM allocates blocks of 64 KB multiple times, which causes |
| 7 | libmilter and therefore OpenDKIM to crash: |
| 8 | https://git.alpinelinux.org/cgit/aports/commit/?id=95724d1bd53ae87f72e6388cb7323dbd8f84be9d |
| 9 | |
| 10 | This patch follows the patch suggested by an Alpine Linux user in bug report |
| 11 | above. Also, a bug report has been filed upstream: |
| 12 | https://sourceforge.net/p/opendkim/bugs/258/ |
| 13 | |
| 14 | |
| 15 | --- a/libmilter/libmilter.h |
| 16 | +++ b/libmilter/libmilter.h |
| 17 | @@ -127,10 +127,10 @@ struct smfi_str |
| 18 | # define MI_SOCK_READ(s, b, l) read(s, b, l) |
| 19 | # define MI_SOCK_READ_FAIL(x) ((x) < 0) |
| 20 | # define MI_SOCK_WRITE(s, b, l) write(s, b, l) |
| 21 | - |
| 22 | -# define thread_create(ptid,wr,arg) pthread_create(ptid, NULL, wr, arg) |
| 23 | # define sthread_get_id() pthread_self() |
| 24 | |
| 25 | +extern int thread_create(pthread_t *ptid, void *(*wr) (void *), void *arg); |
| 26 | + |
| 27 | typedef pthread_mutex_t smutex_t; |
| 28 | # define smutex_init(mp) (pthread_mutex_init(mp, NULL) == 0) |
| 29 | # define smutex_destroy(mp) (pthread_mutex_destroy(mp) == 0) |
| 30 | --- a/libmilter/main.c |
| 31 | +++ b/libmilter/main.c |
| 32 | @@ -16,6 +16,12 @@ SM_RCSID("@(#)$Id: main.c,v 8.85 2013-11 |
| 33 | #include <fcntl.h> |
| 34 | #include <sys/stat.h> |
| 35 | |
| 36 | +int thread_create(pthread_t *ptid, void *(*wr) (void *), void *arg) { |
| 37 | + pthread_attr_t attr; |
| 38 | + pthread_attr_init(&attr); |
| 39 | + pthread_attr_setstacksize(&attr,2*1024*1024); |
| 40 | + return pthread_create(ptid, &attr, wr, arg); |
| 41 | +} |
| 42 | |
| 43 | static smfiDesc_ptr smfi = NULL; |
| 44 | |