|
14 | 14 |
|
15 | 15 | #include "libplatform/libplatform.h"
|
16 | 16 |
|
| 17 | +#include <algorithm> |
17 | 18 | #include <string.h>
|
18 | 19 | #include <sstream>
|
19 | 20 | #include <unordered_map>
|
@@ -101,12 +102,18 @@ static int StartDebugSignalHandler() {
|
101 | 102 | CHECK_EQ(0, uv_sem_init(&start_io_thread_semaphore, 0));
|
102 | 103 | pthread_attr_t attr;
|
103 | 104 | CHECK_EQ(0, pthread_attr_init(&attr));
|
104 |
| - // Don't shrink the thread's stack on FreeBSD. Said platform decided to |
105 |
| - // follow the pthreads specification to the letter rather than in spirit: |
106 |
| - // https://lists.freebsd.org/pipermail/freebsd-current/2014-March/048885.html |
107 |
| -#ifndef __FreeBSD__ |
108 |
| - CHECK_EQ(0, pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN)); |
109 |
| -#endif // __FreeBSD__ |
| 105 | +#if defined(PTHREAD_STACK_MIN) && !defined(__FreeBSD__) |
| 106 | + // PTHREAD_STACK_MIN is 2 KB with musl libc, which is too small to safely |
| 107 | + // receive signals. PTHREAD_STACK_MIN + MINSIGSTKSZ is 8 KB on arm64, which |
| 108 | + // is the musl architecture with the biggest MINSIGSTKSZ so let's use that |
| 109 | + // as a lower bound and let's quadruple it just in case. The goal is to avoid |
| 110 | + // creating a big 2 or 4 MB address space gap (problematic on 32 bits |
| 111 | + // because of fragmentation), not squeeze out every last byte. |
| 112 | + // Omitted on FreeBSD because it doesn't seem to like small stacks. |
| 113 | + const size_t stack_size = std::max(static_cast<size_t>(4 * 8192), |
| 114 | + static_cast<size_t>(PTHREAD_STACK_MIN)); |
| 115 | + CHECK_EQ(0, pthread_attr_setstacksize(&attr, stack_size)); |
| 116 | +#endif // defined(PTHREAD_STACK_MIN) && !defined(__FreeBSD__) |
110 | 117 | CHECK_EQ(0, pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED));
|
111 | 118 | sigset_t sigmask;
|
112 | 119 | // Mask all signals.
|
|
0 commit comments