Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 89483be

Browse filesBrowse files
bnoordhuistargos
authored andcommitted
inspector: more conservative minimum stack size
PTHREAD_STACK_MIN is 2 KB with musl, which is too small to safely receive signals. PTHREAD_STACK_MIN + MINSIGSTKSZ is 8 KB on arm64, which is the musl architecture with the biggest MINSIGSTKSZ so let's use that as a lower bound and let's quadruple it just in case. PR-URL: #27855 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent d948656 commit 89483be
Copy full SHA for 89483be

File tree

Expand file treeCollapse file tree

1 file changed

+13
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-6
lines changed
Open diff view settings
Collapse file

‎src/inspector_agent.cc‎

Copy file name to clipboardExpand all lines: src/inspector_agent.cc
+13-6Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <climits> // PTHREAD_STACK_MIN
2626
#endif // __POSIX__
2727

28+
#include <algorithm>
2829
#include <cstring>
2930
#include <sstream>
3031
#include <unordered_map>
@@ -111,12 +112,18 @@ static int StartDebugSignalHandler() {
111112
CHECK_EQ(0, uv_sem_init(&start_io_thread_semaphore, 0));
112113
pthread_attr_t attr;
113114
CHECK_EQ(0, pthread_attr_init(&attr));
114-
// Don't shrink the thread's stack on FreeBSD. Said platform decided to
115-
// follow the pthreads specification to the letter rather than in spirit:
116-
// https://lists.freebsd.org/pipermail/freebsd-current/2014-March/048885.html
117-
#ifndef __FreeBSD__
118-
CHECK_EQ(0, pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN));
119-
#endif // __FreeBSD__
115+
#if defined(PTHREAD_STACK_MIN) && !defined(__FreeBSD__)
116+
// PTHREAD_STACK_MIN is 2 KB with musl libc, which is too small to safely
117+
// receive signals. PTHREAD_STACK_MIN + MINSIGSTKSZ is 8 KB on arm64, which
118+
// is the musl architecture with the biggest MINSIGSTKSZ so let's use that
119+
// as a lower bound and let's quadruple it just in case. The goal is to avoid
120+
// creating a big 2 or 4 MB address space gap (problematic on 32 bits
121+
// because of fragmentation), not squeeze out every last byte.
122+
// Omitted on FreeBSD because it doesn't seem to like small stacks.
123+
const size_t stack_size = std::max(static_cast<size_t>(4 * 8192),
124+
static_cast<size_t>(PTHREAD_STACK_MIN));
125+
CHECK_EQ(0, pthread_attr_setstacksize(&attr, stack_size));
126+
#endif // defined(PTHREAD_STACK_MIN) && !defined(__FreeBSD__)
120127
CHECK_EQ(0, pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED));
121128
sigset_t sigmask;
122129
// Mask all signals.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.