AK: Use getrlimit() to find the correct main thread stack size on macOS

This is what JavaScriptCore does as well.

(cherry picked from commit 11458f0d91654feed9b4e225c4e6ac8528057355)
This commit is contained in:
Andreas Kling authored and Nico Weber committed 2024-11-10 19:39:05 -05:00
1 parent c00dda5a3a
commit f670b2ca32
1 file changed
+10 -5
+10 -5
View File
@@ -65,11 +65,16 @@ StackInfo::StackInfo()
// MacOS seems inconsistent on what stack size is given for the main thread.
// According to the Apple docs, default for main thread is 8MB, and default for
// other threads is 512KB
constexpr size_t eight_megabytes = 0x800000;
if (pthread_main_np() == 1 && m_size < eight_megabytes) {
// Assume no one messed with stack size linker options for the main thread,
// and just set it to 8MB.
m_size = eight_megabytes;
if (pthread_main_np() == 1) {
// Apparently the main thread's stack size is not reported correctly on macOS
// but we can use getrlimit to get the correct value.
rlimit limit {};
getrlimit(RLIMIT_STACK, &limit);
if (limit.rlim_cur == RLIM_INFINITY) {
m_size = 8 * MiB;
} else {
m_size = limit.rlim_cur;
}
}
m_base = top_of_stack - m_size;
#elif defined(AK_OS_OPENBSD)